Git command not working in subprocess in Python

We've been using python to automate some git work for some time now in my group and everything works fine. Unfortunately I ran into something that I would like to use but does not work when put into a python subprocess. Here's the command:

git describe --tags `git rev-list --tags --max-count=1`

      

When I use it in my git bash (we are using Windows) it works fine, but when I put it in a python subprocess it complains that git rev-list --tags --max-count=1

it is not a valid command. I was wondering if someone could tell me why and preferably use it. I got the line from this question:

How do I get the latest tag name in the current branch in Git?

I am trying to get the LATEST tag on the branch that is closest to the current HEAD. Right now I have a hacky solution that lists all the tags and then sorts them numerically, but that only works because we don't expose any non-numeric tags, which won't necessarily always be the case.

Can anyone help me?

+1


source to share


1 answer


The Popen

default constructor does not use a wrapper to parse the command you give it. This means shell metacharacters like backquote and things like that won't work. You can go through shell = True

or run first git rev-list --tags --max-count=1

and then create a whole command after that.



+1


source







All Articles