-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prompt before overwriting files, some error handling, and refactoring #34
base: master
Are you sure you want to change the base?
Conversation
Current behavior: ``` gitdir https://github.com/folke/dot/ Traceback (most recent call last): File "/home/alichtman/.local/bin/gitdir", line 8, in <module> sys.exit(main()) β β <function main at 0x7eff15ecd260> β <module 'sys' (built-in)> File "/home/alichtman/.local/lib/python3.12/site-packages/gitdir/gitdir.py", line 172, in main total_files = download(url, flatten, args.output_dir) β β β β Namespace(urls=['https://github.com/folke/dot/'], output_dir='./', flatten=False) β β β False β β 'https://github.com/folke/dot/' β <function download at 0x7eff15eccfe0> File "/home/alichtman/.local/lib/python3.12/site-packages/gitdir/gitdir.py", line 60, in download api_url, download_dirs = create_url(repo_url) β β 'https://github.com/folke/dot/' β <function create_url at 0x7eff15eccf40> File "/home/alichtman/.local/lib/python3.12/site-packages/gitdir/gitdir.py", line 49, in create_url download_dirs = url[branch.end():] β β None β 'https://github.com/folke/dot/' AttributeError: 'NoneType' object has no attribute 'end' ``` New behavior: ``` python3 gitdir.py https://github.com/folke/dot/ β Could not find branch name in the given url ```
And a bunch of refactoring
try: | ||
opener = urllib.request.build_opener() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These only need to be set once, globally.
I left the commits separated for easier reviewing, but I recommend squashing this on merge. |
"/contents/" + download_dirs + "?ref=" + branch.group(2)) | ||
if branch is None: | ||
print_text( | ||
"β Could not find branch name in the given url", "red", in_place=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimally, I think this would try common branch names like main
and master
, but that's out of scope for this PR
Fix #33
Single file downloads still work: