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

Fix ugly error when upstream is gone

Open PontusPih opened this issue 2 years ago • 2 comments

If the output of git status gives you:

On branch XYZ
Your branch is based on 'origin/XYZ', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

nothing to commit, working tree clean

then git summary will give you an ugly error message and nothing in the State columns

Repository  Branch    State
==========  ========  =====
fatal: no such branch: '..'
fatal: ambiguous argument '@{u}..': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
.           XYZ       

This commit tries to fix that by using "--verify --quiet" and the exit code of git rev-parse.

PontusPih avatar Sep 11 '23 06:09 PontusPih

How to reproduce:

create new repo with one commit and new branch

mkdir test
cd test
git init
git commit --allow-empty --allow-empty-message --no-edit
git switch -C new_branch
cd ..

clone it: git clone test test_clone

remove upstream branch:

cd test
git switch -
git branch -D new_branch
cd ..

prune branches in clone

cd test_clone
git fetch --prune
cd ..

Now git summary will give the unwanted output:


./test                     master                --
fatal: no such branch: '..'
fatal: ambiguous argument '@{u}..': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
./test_clone               new_branch           

PontusPih avatar Sep 27 '23 08:09 PontusPih

Perhaps it would be better to differentiate this case in the state column. With the suggested fix the state will look like there are no changes on the remote repo. Perhaps " -X" could indicate a missing upstream branch.

PontusPih avatar Sep 27 '23 08:09 PontusPih