Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get contributors for each file using git shortlog in python subprocesses

Tags:

git

python-3.x

I've got a problem, when I'm trying to obtain output of following command: git shortlog -s -- [file_path] using python 3.6 subprocess module.

Here the code:

import subprocess

x = subprocess.Popen(['git shortlog -s -- ' + file_path], cwd=path, 
shell=True, stdin=subprocess.PIPE, 
stdout=subprocess.PIPE).communicate()[0]
print(x)

The result of execution is empty. What had I done wrong?

like image 597
Алексей Толкачев Avatar asked Oct 17 '25 10:10

Алексей Толкачев


1 Answers

you need to call git shortlog HEAD

subprocess.Popen(['git shortlog HEAD -s -- ' + file_path],
                  cwd=path,  shell=True, stdin=subprocess.PIPE, 
                  stdout=subprocess.PIPE).communicate()[0]

To learn why, see https://stackoverflow.com/a/43042420/4381942

like image 71
Sam Shleifer Avatar answered Oct 20 '25 00:10

Sam Shleifer