twolfson / sexy-bash-prompt

Bash prompt with colors, git statuses, and git branches.
MIT License
1.14k stars 154 forks source link

Wrong symbol (clean, unpushed) on up to date branch #77

Closed rpdelaney closed 5 years ago

rpdelaney commented 5 years ago

Names have been changed to protect the innocent.

ryan.delaney at M-6496 in ~/src/
$ git clone git@github.com:org/repo.git 
Cloning into 'repo'...
remote: Enumerating objects: 544, done.
remote: Counting objects: 100% (544/544), done.                                                                                                                                                                                 
remote: Compressing objects: 100% (197/197), done.
remote: Total 453877 (delta 452), reused 364 (delta 344), pack-reused 453333                                                                                                                                                    
Receiving objects: 100% (453877/453877), 356.36 MiB | 4.65 MiB/s, done.
Resolving deltas: 100% (340993/340993), done.
Checking out files: 100% (10666/10666), done. 
ryan.delaney at M-6496 in ~/src
$ cd repo
ryan.delaney at M-6496 in ~/src/repo on master△
$ git status                                                                               
On branch master                                                           
Your branch is up to date with 'origin/master'.                       

nothing to commit, working tree clean  
ryan.delaney at M-6496 in ~/src/repo on master△
$ git push --dry-run
Everything up-to-date
ryan.delaney at M-6496 in ~/src/repo on master△
$

I don't have a lot of time to troubleshoot this right now but I wanted to create this issue at least so I don't forget.

I'm not 100% sure I'm using the most up to date version on this machine so here's my ~/.bash_prompt for later comparison: http://ix.io/1xUn

@twolfson If you have ideas for stuff I should look at let me know. I'll look into this later regardless.

twolfson commented 5 years ago

Is this a new computer? Did this change happen recently? What version of git is running?

rpdelaney commented 5 years ago
  1. Not a new machine, but the first time I've worked with this particular repo.
  2. Previous answer answered this one
  3. git version 2.20.1

Edit: I'll dig around in /.git/config but IIRC changes to that aren't distributed via a clone

twolfson commented 5 years ago

Oh wow, that's quite the git bleeding edge. Travis CI is currently testing against 2.18.0:

https://travis-ci.org/twolfson/sexy-bash-prompt/jobs/478059170#L512

What happens when you clone another repo (e.g. sexy-bash-prompt)?

Another thing to consider is: Have there been any changes in ~/.gitconfig recently?

rpdelaney commented 5 years ago

The sexy-bash-prompt repo doesn't give me this behavior. I backed up my gitconfig and deleted it, and there's no change.

An amusing fact I just noticed: I get this on master in this repo, but not in the topic branch I've been working in.

Here's a debug firehose:

ryan.delaney at M-6496 in ~/src/client/repo on master△
$ set -xv
_direnv_hook;
++ source():line 54: _direnv_hook
++ source():line 54: local previous_exit_status=0
+++ source():line 54: /usr/local/bin/direnv export bash
++ source():line 54: eval ''
++ source():line 54: return 0
++ source():line 54: sexy_bash_prompt_is_on_git
++ source():line 54: git rev-parse
++ source():line 54: echo -n ' on '
+++ source():line 54: sexy_bash_prompt_get_git_info
++++ source():line 54: sexy_bash_prompt_get_git_branch
+++++ source():line 54: git symbolic-ref HEAD
+++++ source():line 54: sed -e 's/refs\/heads\///'
++++ source():line 54: ref=master
++++ source():line 54: [[ master != '' ]]
++++ source():line 54: echo master
+++ source():line 54: branch=master
+++ source():line 54: [[ master != '' ]]
+++ source():line 54: output=master
++++ source():line 54: sexy_bash_prompt_get_git_status
+++++ source():line 54: sexy_bash_prompt_parse_git_dirty
++++++ source():line 54: git status --porcelain
+++++ source():line 54: [[ -n '' ]]
++++ source():line 54: dirty_branch=
+++++ source():line 54: sexy_bash_prompt_parse_git_ahead
++++++ source():line 54: sexy_bash_prompt_get_git_branch
+++++++ source():line 54: git symbolic-ref HEAD
+++++++ source():line 54: sed -e 's/refs\/heads\///'
++++++ source():line 54: ref=master
++++++ source():line 54: [[ master != '' ]]
++++++ source():line 54: echo master
+++++ source():line 54: branch=master
+++++ source():line 54: remote_branch=origin/master
+++++ source():line 54: sexy_bash_prompt_is_branch1_behind_branch2 origin/master master
++++++ source():line 54: git log origin/master..master -1
+++++ source():line 54: first_log=
+++++ source():line 54: [[ -n '' ]]
+++++ source():line 54: sexy_bash_prompt_branch_exists origin/master
+++++ source():line 54: git branch --remote
+++++ source():line 54: grep --quiet origin/master
+++++ source():line 54: echo 1
++++ source():line 54: branch_ahead=1
+++++ source():line 54: sexy_bash_prompt_parse_git_behind
++++++ source():line 54: sexy_bash_prompt_get_git_branch
+++++++ source():line 54: git symbolic-ref HEAD
+++++++ source():line 54: sed -e 's/refs\/heads\///'
++++++ source():line 54: ref=master
++++++ source():line 54: [[ master != '' ]]
++++++ source():line 54: echo master
+++++ source():line 54: branch=master
+++++ source():line 54: remote_branch=origin/master
+++++ source():line 54: sexy_bash_prompt_is_branch1_behind_branch2 master origin/master
++++++ source():line 54: git log master..origin/master -1
+++++ source():line 54: first_log=
+++++ source():line 54: [[ -n '' ]]
++++ source():line 54: branch_behind=
++++ source():line 54: [[ '' == 1 ]]
++++ source():line 54: [[ 1 == 1 ]]
++++ source():line 54: [[ '' == 1 ]]
++++ source():line 54: [[ '' == 1 ]]
++++ source():line 54: [[ 1 == 1 ]]
++++ source():line 54: echo △
+++ source():line 54: output=master△
+++ source():line 54: echo master△
++ source():line 54: echo -n 'master△'
+++ source():line 54: sexy_bash_prompt_get_git_progress
++++ source():line 54: git rev-parse --git-dir
+++ source():line 54: git_dir=/Users/ryan.delaney/src/client/repo/.git
+++ source():line 54: [[ -f /Users/ryan.delaney/src/client/repo/.git/MERGE_HEAD ]]
+++ source():line 54: [[ -d /Users/ryan.delaney/src/client/repo/.git/rebase-apply ]]
+++ source():line 54: [[ -d /Users/ryan.delaney/src/client/repo/.git/rebase-merge ]]
+++ source():line 54: [[ -f /Users/ryan.delaney/src/client/repo/.git/CHERRY_PICK_HEAD ]]
+++ source():line 54: [[ -f /Users/ryan.delaney/src/client/repo/.git/BISECT_LOG ]]
+++ source():line 54: [[ -f /Users/ryan.delaney/src/client/repo/.git/REVERT_HEAD ]]
++ source():line 54: echo -n ''
++ source():line 54: echo -n ''
ryan.delaney at M-6496 in ~/src/client/repo on master△
twolfson commented 5 years ago

For the .gitconfig, you'd prob need to delete it and create a new clone. Sometimes it uses .gitconfig for initial setup (e.g. hooks, template directory)

I'm starting to regret not using constants instead of "1" (e.g. "DIFFERENT", "SAME"). Anyway, it looks like sexy_bash_prompt_parse_git_ahead is evaluating to true

It looks like git branch thinks origin/master doesn't exist:

+++++ source():line 54: sexy_bash_prompt_branch_exists origin/master
+++++ source():line 54: git branch --remote
+++++ source():line 54: grep --quiet origin/master
+++++ source():line 54: echo 1

What's the output of git branch --remote?

rpdelaney commented 5 years ago

My git aliases stopped working so I took that as a signal I'd done something right.

Anyway, I pulled from origin and now I can't duplicate this anymore. I should have made a backup of the repo in the problem state but, derp.

The upside is that if some commit to this repo fixed it, that would be really handy to find. I might be able to find that commit with git bisect run. You think I should try to find one where sexy_bash_prompt_parse_git_ahead returns true?

twolfson commented 5 years ago

Yea, git bisect run and sexy_bash_prompt_parse_git_ahead sounds promising

If we don't find it though, it won't be the end of the world -- it seems that you're the first to report this kind of behavior in our long lifetime so it sounds very infrequent

twolfson commented 5 years ago

Going to close this issue for now. We can reopen if we discover how to replicate it