Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

git.execute('commit -m "word1 word2') fails #1379

Answered by Byron
jcralbino asked this question in Q&A
Discussion options

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 ..

You must be logged in to vote

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}*") into repo.git.add(f"{origin}*")
  • repo.git.execute(f"git commit -m 'word1 word2'") into repo.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

Comment options

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}*") into repo.git.add(f"{origin}*")
  • repo.git.execute(f"git commit -m 'word1 word2'") into repo.git.commit(m='word1 word2')

...and things should work as expected.

More about how to call git directly is in the docs.

You must be logged in to vote
1 reply
Comment options

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

Answer selected by jcralbino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /