From d3b25b813b07aa7460f0d72dec45948ad7b07feb Mon Sep 17 00:00:00 2001 From: Matthew Cengia Date: Thu, 8 Aug 2024 21:21:33 +1000 Subject: [PATCH] fix: Exit with error if HEAD commit doesn't yet exist on remote --- bin/git-browse | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/git-browse b/bin/git-browse index 98f315bb1..2b55fc61d 100755 --- a/bin/git-browse +++ b/bin/git-browse @@ -29,6 +29,14 @@ fi commit_hash=$(git rev-parse HEAD 2>/dev/null) commit_or_branch=${commit_hash:-${branch}} +# Check that the commit branch actually *exists* on the remote first: +if ! git branch --remotes --contains "${commit_or_branch}" 2>/dev/null | + grep -q "\<${remote}\>/" +then + echo "Commit not yet pushed to remote '${remote}'" + exit 1 +fi + if [[ $remote_url =~ gitlab ]]; then # construct gitlab urls # https://gitlab.com///-/blob//#L-