2

We've been using python to automate some git work for quite some time in my group, and everything has worked fine. Unfortunately, I've come across something I would like to use, but doesn't 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're using Windows) it works fine, but when I put it in a python subprocess, it complains that git rev-list --tags --max-count=1 is not a valid command. I was wondering if anyone could enlighten me as to why, and preferably, a way of using it. I got the line from this question:

How to get the latest tag name in current branch in Git?

I'm trying to get the LATEST tag on a branch, that is closest to the current HEAD. I've got a hacky workaround right now that lists all of the tags and then sorts them numerically, but that's only working because we haven't put out any non-numeric tags, which won't necessarily be the case always.

Can anyone please help me?

asked May 19, 2015 at 14:15

1 Answer 1

2

The Popen constructor by default doesn't use a shell to parse the command you're giving it. This means that shell metacharacters like the backquote and such things will not work. You can either pass shell = True or first run git rev-list --tags --max-count=1 and then create the whole command after that.

answered May 19, 2015 at 14:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.