GNOME Bugzilla – Bug 699023
indicate when local commits are unpushed
Last modified: 2017-12-13 19:02:52 UTC
In git (and probably other distributed version control systems too) it's all too easy to make commits locally and then forget to push them to the server. When there are unpushed local commits, it would be nice if Meld would display an indication to that effect in the 'Status' column for the root directory of the local working copy. The text could read e.g. '2 local commits'.
I can't figure out how to get this information properly in git *at all*. Any assistance would be most appreciated.
Any simple status text that we could do would probably be somewhat misleading (though that's not necessarily a deal-breaker as long as it works for common cases). Ideally, what we want to show is: this is what will be pushed if you click the "Push" button. However, a simple count of unpushed changes would be a good start.
When I have unpushed commits and I run 'git status', the output begins with this:
# Your branch is ahead of 'origin/master' by 2 commits.
# (use "git push" to publish your local commits)
Isn't that exactly what we're looking for here?
Unfortunately not, in two ways. Firstly, we try very hard not to use porcelain git commands (like status) when we do output parsing, because it's not guaranteed to be in any way stable across releases. Secondly and more importantly, it only tells us what the status of the current branch is, which isn't what we push.
What we *need* is for git to tell us what it would push if we ran git push.
This should now work in HEAD. It doesn't actually tell us what git would push, but rather returns the number of changes in all branches that have origin information, which should be the same thing in most cases, and a sensible piece of information in all others.
Showing what would be pushed requires contacting the remote, which we're not going to do here. We *could* do that when setting up the push, but that would be part of bug 699689.
Nice to see this. A few remarks:
1. I personally would rather have Meld tell me only about unpushed commits on the current branch. I feel it's odd to have Meld display information about unpushed commits in other branches since everything else I see in Meld only reflects the current branch. Note that 'git status', the command-line analogue, only mentions unpushed commits in the current branch. And I have push.default set to 'simple' (as I think most people do or will), so 'git push' will push only on the current branch anyway.
2. Regardless of how you feel about (1), I vote for less verbosity:
- When there are no unpushed commits, instead of
No unpushed commits found
I'd simply display nothing (just as 'git status' displays no text about unpushed commits in this situation). This wll be the most common state, and I find the "No unpushed commits" message to be noisy.
- When there are unpushed commits, instead of
Unpushed commits found: 1 in 1 branch
1 local commit (or "1 unpushed commit" if you think that's clearer)
Only if commits are unpushed in more than one branch (a less common situation) I'd include a branch count:
2 local commits in 2 branches
(In reply to comment #5)
> Nice to see this. A few remarks:
> 1. I personally would rather have Meld tell me only about unpushed commits on
> the current branch. I feel it's odd to have Meld display information about
> unpushed commits in other branches since everything else I see in Meld only
> reflects the current branch. Note that 'git status', the command-line
> analogue, only mentions unpushed commits in the current branch. And I have
> push.default set to 'simple' (as I think most people do or will), so 'git push'
> will push only on the current branch anyway.
I'm pretty convinced that as long as we're defaulting to a global git push, we have to show unpushed commits in all branches. Otherwise there's just too strong a suggestion that what you see there is what's going to get pushed, and in the default (now old default, but still) git setup, that isn't true.
> 2. Regardless of how you feel about (1), I vote for less verbosity:
> - When there are no unpushed commits, instead of
> No unpushed commits found
> I'd simply display nothing (just as 'git status' displays no text about
> unpushed commits in this situation). This wll be the most common state, and I
> find the "No unpushed commits" message to be noisy.
> - When there are unpushed commits, instead of
> Unpushed commits found: 1 in 1 branch
> I'd display
> 1 local commit (or "1 unpushed commit" if you think that's clearer)
> Only if commits are unpushed in more than one branch (a less common situation)
> I'd include a branch count:
> 2 local commits in 2 branches
The original wording was in fact:
"%d unpushed commits in %d branches"
but I changed it so that it was actually ngettext-able (dependencies on two plurals won't work).
However, I like the idea of just omitting the branch count if it's one, which seems fine for translations. This and the no-unpushed-commits case have been fixed in HEAD. Cheers.
Thanks for decreasing the verbosity. :)
Regarding counting unpushed commits in all branches, I do appreciate your wanting the count to reflect exactly what will be pushed. At the same time, the current behavior is confusing for users like me who have push.default=simple. For example, just now I was working on a project, saw the message "1 unpushed commit" and was briefly confused before realizing that aha, the unpushed commit was in a different branch.
- Could we detect when push.default is 'simple', 'current' or 'upstream' and only display an unpushed count for the current branch when that is so?
- When the unpushed commits are in other branches, could we indicate that by displaying a status such as "1 unpushed commit (in branch 'meld-1.6')"?
Both good suggestions. However, I've been spending far too much time on the push-related UI recently and ignoring other things, so I'm going to leave this here for now.
In case someone else wants to pick this up, 'git config push.default' gives us the current setting, and we need to also support 'tracking', which is a deprecated version of 'upstream'. Everything for this should live in meld/vc/git.py:Vc.get_commits_to_push_summary.
Sounds reasonable. No promises, but I myself may try to pick this up if and when I get a chance.
-- GitLab Migration Automatic Message --
This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/meld/issues/53.