-
-
Notifications
You must be signed in to change notification settings - Fork 954
-
Hello guys.
I am preparing scrip that is meant to pull/checkout more repositories in different directories.
However, soemtimes can happen this:
Exception Cmd('git') failed due to: exit code(1)
cmdline: git pull -v origin
stderr: 'error: Your local changes to the following files would be overwritten by merge:
common_logic.py
git_jobs.py
svn_jobs.py
test_updating.py
updater.py
updater_core.py
updating_conf.py
updating_consts.py
Please commit your changes or stash them before you merge.
Aborting'
But when I try to put my code into try:except block, like this:
import git
try:
repo = git.Repo("/path/to/my/repo")
o = repo.remotes.origin
result = o.pull()
for item in result:
print("Item : {}".format(item))
except Exception as e:
print("Exception {}".format(e))
Nothing changes, the script still throws exception and fails. Is it possible to cover this case, and make it not to crash?
PS: Is it possible to make it, that it does not ask me for credentials every time? (like put them inside of my code)
Beta Was this translation helpful? Give feedback.
All reactions
Nothing changes, the script still throws exception and fails. Is it possible to cover this case, and make it not to crash?
This would prevent the exception from stopping the program there, maybe there are other exceptions happening later due to the pull not being successful after all? Manually checking for this case would certainly be required to avoid exceptions.
Is it possible to make it, that it does not ask me for credentials every time? (like put them inside of my code)
There is some information about this in the Handling Remotes
section of the docs.
Replies: 1 comment 2 replies
-
Nothing changes, the script still throws exception and fails. Is it possible to cover this case, and make it not to crash?
This would prevent the exception from stopping the program there, maybe there are other exceptions happening later due to the pull not being successful after all? Manually checking for this case would certainly be required to avoid exceptions.
Is it possible to make it, that it does not ask me for credentials every time? (like put them inside of my code)
There is some information about this in the Handling Remotes
section of the docs.
Beta Was this translation helpful? Give feedback.
All reactions
-
No, there are no other exceptions, or at least, those are not visible:
my_user@my_pc: ~/my_dir/my_subdir $ python3 test_pull.py
1
2
3
4
Username for 'https://git.my_server.eu': myusername
Password for 'https://myusername@git.my_server.eu':
Exception Cmd('git') failed due to: exit code(1)
cmdline: git pull -v origin
stderr: 'error: Your local changes to the following files would be overwritten by merge:
common_logic.py
git_jobs.py
svn_jobs.py
test_updating.py
updater.py
updater_core.py
updating_conf.py
updating_consts.py
Please commit your changes or stash them before you merge.
Aborting'
my_user@my_pc: ~/my_dir/my_subdir $
I added debug prints after each line. The exception is exactly on pull.
print(2)
o = repo.remotes.origin
print(3)
#print(repo.untracked_files)
print(4)
result = o.pull()
print(5)
for item in result:
Beta Was this translation helpful? Give feedback.
All reactions
-
Interesting, I have no clue how a caught exception can still halt a python program.
Beta Was this translation helpful? Give feedback.