git-extras icon indicating copy to clipboard operation
git-extras copied to clipboard

git-browse doesn't check if a commit exists on upstream

Open mattcen opened this issue 1 year ago • 2 comments

When using git-browse to generate a web link to a repo, it constructs a URL based on the commit at the HEAD of the local repo, but doesn't actually check if this HEAD exists on the remote. This means that if I have a local commit that I've yet to push, and I run git-browse, it will fail because the remote end doesn't know about the commit the URL references.

Ideally, we should test whether the commit exists upstream first, using:

git branch --remotes --contains "${commit_or_branch}" 2>/dev/null | grep -q "\<${remote}\>/"

Which will exit non-zero if there's no remote ref for this commit. We could then display an error to the user.

mattcen avatar Aug 08 '24 11:08 mattcen

LGTM. Would you submit this change?

spacewander avatar Aug 09 '24 03:08 spacewander

Sure. See #1155

mattcen avatar Aug 10 '24 04:08 mattcen