ejoffe / spr

Stacked Pull Requests on GitHub
MIT License
794 stars 68 forks source link

`pull request stack is empty` when abbrevCommit=true #368

Open dansimau opened 10 months ago

dansimau commented 10 months ago

As mentioned here: https://github.com/ejoffe/spr/issues/213#issuecomment-1825873127

Problem

git spr up returns pull request stack is empty — even when there are local commits to be pushed and PRs created — when the following git config is present:

[log]
    abbrevCommit=true

helpers.go:78 defines the following regexp for extracting the commit hash:

^commit ([a-f0-9]{40})

However, when using abbreviated commit hashes, this regexp doesn't match. Here is an example of log output with an abbreviated commit hash:

commit ca06022

Using the following config options, the commit hash length could be anywhere between 1-40 characters:

Solutions

  1. Modify the regexp to reflect that a commit hash can be between 1-40 chars, i.e.:
-       commitHashRegex := regexp.MustCompile(`^commit ([a-f0-9]{40})`)
+       commitHashRegex := regexp.MustCompile(`^commit ([a-f0-9]{1,40})`)
  1. Always add --no-abbrev-commit when running git log

I would go with option (1), because it is backwards-compatible with git versions prior to the --no-abbrev-commit flag appearing (didn't check when this was though).

dekimsey commented 2 months ago

I was trying spr out and I thought I was going nuts because it kept reporting pull request stack is empty. Thank you for raising this issue.

FWIW, I'd recommend option 2 because then the program doesn't care what the user's config has done here.