Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ugly error when upstream is gone #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PontusPih
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants