Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why CalledProcessError during subprocess.check_output(['cmd', 'arg'])

I ahve django project hosted with Apache+mod_wsgi.I am trying to pull update using git command via subprocess, like:

subprocess.check_output(['git', 'pull', 'origin', 'mybranch']) 

However, I am getting error like:

Command '['git', 'pull', 'origin', 'mybranch']' returned non-zero exit status 128

This problem appears when I call this function via browser. If I run subprocess.check_output(['git', 'pull', 'origin', 'mybranch']) from python sell, there will not error. It works perfectly as intended.

like image 803
Elisa Avatar asked Nov 12 '22 03:11

Elisa


1 Answers

I had the same issue twice with git grep.

It came the second time from the fact I forgot to add www-data to the group which has read rights on the git repository folder.

Also, as git command need to be run from inside a git repo, you may want to try by adding '--git-dir=' and '--work-tree=' in your argument list, just after the git main command :

   gd = '--git-dir=' + os.path.join(repo_path, '.git')
   wt = '--work-tree=' + repo_path
   gg_matches = subprocess.check_output(["git", gd, wt, "grep"] + gg_opt)

It is required if your cwd is different from your repo_path.

like image 85
Mat M Avatar answered Nov 15 '22 13:11

Mat M