Prompt before overwriting files, some error handling, and refactoring#34
Open
alichtman wants to merge 4 commits intosdushantha:masterfrom
Open
Prompt before overwriting files, some error handling, and refactoring#34alichtman wants to merge 4 commits intosdushantha:masterfrom
alichtman wants to merge 4 commits intosdushantha:masterfrom
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
alichtman
commented
Jan 13, 2024
| dir_out = Path(dir_out) | ||
|
|
||
| try: | ||
| opener = urllib.request.build_opener() |
Author
There was a problem hiding this comment.
These only need to be set once, globally.
Author
|
I left the commits separated for easier reviewing, but I recommend squashing this on merge. |
alichtman
commented
Jan 13, 2024
| "/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 |
Author
There was a problem hiding this comment.
Optimally, I think this would try common branch names like main and master, but that's out of scope for this PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #33
Single file downloads still work: