-
-
Notifications
You must be signed in to change notification settings - Fork 954
-
when using git execute to send a comment in the commit message i am getting an error that seems to be a buggy behavior where a space is not accepted
I am using python v3.10 with GitPython==3.1.18
Example code:
import git
gitlab_url ="https://..url"
username = credentials['username']
password = credentials['password']
remote = f"https://{username}:{password}@{gitlab_url.replace('https://','')}"
origin = "localpath"
repo = Repo.clone_from(remote,origin,branch="master")
f = open("newfile.txt", "w")
f.write("Now the file needs to be uploaded")
f.close()
repo.git.execute(f"git add {origin}*")
repo.git.execute(f"git commit -m 'word1 word2'")
Result:
repo.git.execute(f"git commit -m 'word1 word2'")
Traceback (most recent call last):
File "E:\Program Files\JetBrains\PyCharm 2021年2月2日\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "<homefolder>\Repository\iac\infra-netbox-updates\update-vlans-from-imc\venv\lib\site-packages\git\cmd.py", line 928, in execute
raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('g') failed due to: exit code(1)
cmdline: g i t c o m m i t - m ' w o r d 1 w o r d 2 '
stderr: 'error: pathspec 'word2'' did not match any file(s) known to git'
without the space it works
repo.git.execute(f"git commit -m 'word1_word2'")
"[master 0dd6731] 'word1_word2'\n 12 files changed, 6533 insertions(+)\n create mode 100644 newfile.txt
<information redacted>
...
I tried to use
repo.commit('master')
and it works also , but i am clueless on how to place a message in this wrappers ..
Beta Was this translation helpful? Give feedback.
All reactions
Despite the name, execute()
(instead of _execute()
is a low-level method that shouldn't be used.
Turn...
-
repo.git.execute(f"git add {origin}*")
intorepo.git.add(f"{origin}*")
-
repo.git.execute(f"git commit -m 'word1 word2'")
intorepo.git.commit(m='word1 word2')
...and things should work as expected.
More about how to call git directly is in the docs.
Replies: 1 comment 1 reply
-
Despite the name, execute()
(instead of _execute()
is a low-level method that shouldn't be used.
Turn...
repo.git.execute(f"git add {origin}*")
intorepo.git.add(f"{origin}*")
repo.git.execute(f"git commit -m 'word1 word2'")
intorepo.git.commit(m='word1 word2')
...and things should work as expected.
More about how to call git directly is in the docs.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks for the reply . Indeed the .execute is not working as i expect and after adapting the calls as you said i got a working config
Beta Was this translation helpful? Give feedback.