mixu / gr

Multiple git repository management tool
http://mixu.net/gr/
675 stars 104 forks source link

gr status doesn't spot unpushed work in branches #5

Open auntieNeo opened 10 years ago

auntieNeo commented 10 years ago

The gr status command currently only looks for changes in the currently checked out branch. It misses un-pushed commits in branches that aren't checked out. This is a problem for repositories where I might be working on multiple branches at a time, make a commit on one branch, and checkout another branch without pushing. The branch might not even be tracking any remote branches. If that branch is stuck on my laptop or something while it's asleep, I could easily misplace a lot of work.

The scenario is easy to reproduce:

$ cd ~/code/myRepo
$ git checkout -b test master
Switched to a new branch 'test'
$ echo "foo" > bar
$ git add bar && git commit -m "test of unpushed work"
[test 95ab954] test of unpushed work
 1 file changed, 1 insertion(+)
 create mode 100644 bar
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ gr status
~/code/myRepo    Clean

If I'm to trust the output of gr status, that branch is as good as lost.

Fortunately, git has built in functionality to search for this type of thing. The command is rather long though:

$ gr git --no-pager log --branches --not --remotes --simplify-by-decoration --decorate --oneline
in ~/code/myRepo

95ab954 (test) test of unpushed work

I found this command with a quick Google search at this thread on Stackoverflow: http://stackoverflow.com/questions/15134438/git-show-unpushed-work

This functionality is rather important to me, so I might start working on a patch if I can find the time. Another thing to add would be checking stashed changes or un-pushed submodule changes. The idea is that gr status should pick up on ANY work I haven't uploaded somewhere, so it doesn't come back to bite me later.

nichtich commented 9 years ago

You can create a git alias:

git config --global alias.unpushed '!sh -c "git status --short; git log --branches --not --remotes --simplify-by-decoration --decorate --oneline; git stash list"'

Then call via

gr git unpushed