1

At the end of a Python program I have:

subprocess.call(["git", "add", "."], shell=True)
subprocess.call(["git", "commit", "-m", "'{}'".format("commit message"), "--allow-empty"], shell=True)

This commit has no changes from the previous commit besides the commit message, hence the --allow-empty.

When I run git status in my repository, I get that all of the files are not staged for commit (and I cannot re-base because of this).

However, if I comment those two lines out, run the program again, and manually run in shell once the program is finished:

git add .
git commit -m "commit message"

The files are all added and committed and I am able to re-base successfully.

Even when adding another two subprocess git add and git commit commands, with or without --allow-empty to the end of the program, the only way to actually add and commit the files is manually through a shell.

Am I missing something here? Shouldn't the subprocess hypothetically be doing the exact same thing as the shell commands?

phd
  • 82,685
  • 13
  • 120
  • 165
BigMike
  • 11
  • 2
  • 2
    The first question I would look into is: *what is the current working directory at the time of the `subprocess.call` calls?* There are more, but that's a good first one to consider, I think. You might also try spawning an interactive shell at that point, which will let you investigate other settings as well. – torek Jul 06 '17 at 21:06
  • 1
    don't add quotes when passing command as list of args: try `subprocess.call(["git", "commit", "-m", "commit message", "--allow-empty"], shell=True)`. Also try without `shell=True`, because if it works without, well, it's one less thing to worry about – Jean-François Fabre Jul 06 '17 at 21:13
  • also replace `call` by `check_call` so the program crashes if something goes wrong instead of failing silently – Jean-François Fabre Jul 06 '17 at 21:14

1 Answers1

0

This worked for me,

p = subprocess.Popen(["git","commit","."],shell=True);
p.terminate();
Chinmay Kulkarni
  • 265
  • 1
  • 5
  • 17