clustergit icon indicating copy to clipboard operation
clustergit copied to clipboard

clustergit forgot to say "Unpushed comits"

Open velle opened this issue 7 months ago • 3 comments

I got a new pc. So I used clustergit to make sure that all repos had been pushed. This is few months ago, so I don't remember exactly how I did it.

But today I realized that something had not been pushed. I opened the old pc, went to the folder ~/a which contains all the repos (42 in total), and ran "clustergit". They are all just "Green", also the one I suspected was not pushed.

So I entered that repo folder and did "git push", and it did push something. So obviously, somehow, clustergit made the mistake of not listing it as "Unpushed commits".

It seems that there is some kind of bug here, right?

I wanted to see if I could reproduce, so I made a change, did a commit, went back out in the parent folder and ran clustergit. And this time it did show "Unpushed commits".

Im running clustergit, newest version, inside a WSL with Ubuntu 22.04.

velle avatar Jul 03 '25 11:07 velle

The problem happened for me, because the repo was brand new, and did not have anything pushed yet, and therefore had no branch on upstream.

When creating a new repo on GitHub website, and cloning, there is yet no actual branch on GitHub, not even main. When I clone it, my local git client defaults to believing (hoping?) that the upstream branch is "main", even though it does not know. So upstream is "origin/main" even though that does not yet exist on GitHub. And that results in the following status message (even after having committed, but while not yet having pushed):

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

nothing to commit, working tree clean

To reproduce

$ cd ~
$ mkdir c
$ cd c
$ git clone [email protected]:velle/testrepo.git
$ clustergit 
Scanning sub directories of ['.']
./testrepo                              : Clean
Done
$ cd testrepo
$ touch foo.txt
$ git add foo.txt
$ git commit -m foo.txt
$ clustergit -d ..
$ clustergit -d ..
Scanning sub directories of ['..']
../testrepo                             : Clean
Done

A few more details

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

nothing to commit, working tree clean
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 210 bytes | 210.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:velle/testrepo.git
 * [new branch]      main -> main
$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

Is my git-client or GitHub to blame?

I don't know these tools well enough. Maybe git should not just guess a remote branch. Maybe github should start by creating a branch. Or maybe this behavior is actually just fine and expected :)

Better behavior by clustergit

In any case, I think its misleading (and dangerous) that clustergit just says "Clean". An easy fix would be printing "No such upstream"

velle avatar Jul 03 '25 12:07 velle

Hi there, thanks for the message.

The logic clustergit uses is decidedly simple and the same you as a user run, no API or magic in sight. It runs git status and parses the output. Relevant check is:

 if 'Your branch is ahead of' in out:
            messages.append(colorize(Colors.FAIL, "Unpushed commits"))

If you have a suggestion how to improve, we can consider.

mnagel avatar Jul 06 '25 10:07 mnagel

Thanks for replying. I would like to ask a basic question first.

Each of my local branches always have an upstream branch set. If not, thats either a very temporary state, or because I forgot. And in any case, I would like clustergit to warn me if a branch does not have an upstream set (when running "clustergit --all-branches" it should check this for all the other branches too).

But maybe my habits/workflow is not typical, and therefore it would be pointless or even noisy/annoying for other users. If my wishes for such behavior are not shared by others, then now is the time for me to realize that :) So what are your thoughts?

velle avatar Jul 09 '25 09:07 velle