0

On command line I am running

git log \
    --merges \
    --grep='^Merge pull request .* in repo/foo from' \
    --grep='^Merged .* to master' \
    tag1..tag2

This gives me a list of merge commits to master between the two given tags.

Now I am struggling getting the same from GitPython.

What I have tried so far:

git.Git(os.getcwd()).log(
    '--merges',
    '--grep="^Merge pull request .* in repo/foo from"',
    '--grep="^Merged .* to master"',
    'tag1..tag2')

This works only if I remove the grep lines. With grep it returns an empty string. Same behaviour here:

git.Git(os.getcwd()).execute(['git', 'log',
    '--merges',
    '--grep="^Merge pull request .* in repo/foo from"',
    '--grep="^Merged .* to master"',
    'tag1..tag2'])

Another thing I tried:

git.repo.fun.rev_parse(repo=git.Repo(), rev='tag1..tag2')

This errors out with BadName because the tag1..tag2 doesn't resolve to an object.

Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74

2 Answers2

1

The quotes are required by the shell to prevent it from interpreting metacharacters in the strings; but here, you have no shell.

git.Git(os.getcwd()).execute(['git', 'log',
    '--merges',
    '--grep=^Merge pull request .* in repo/foo from',
    '--grep=^Merged .* to master',
    'tag1..tag2'])

I'm guessing you could also replace os.getcwd() with simply '.'.

tripleee
  • 175,061
  • 34
  • 275
  • 318
0

Found the answer. It's about bad quoting. This works:

git.Git(os.getcwd()).log(
    '--merges',
    '--grep=^Merge pull request .* in repo/foo from',
    '--grep=^Merged .* to master',
    'tag1..tag2')

I think the quotes are necessary on command line to keep the parameter together, but when passing params in Python each param is a string and therefore already "quoted".

Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74