Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Absent and confused Ahead/Behind count
Absent and confused Ahead/Behind count [message #1861076] Mon, 18 September 2023 12:53 Go to next message
Eclipse UserFriend
I like the ahead/behind count EGit shows in the Git Staging view but in one case it doesn't show enough info (absent) and in another case it shows the wrong info (confused).

In the image below, Fig A shows the main branch is 2 commits ahead of the Remote and shows the feature-01 branch is up to date. Note that there isn't a remote (tracking) feature-01 branch. I propose a more helpful way to indicate this condition by using "+" (instead of ↑) followed by the number of Local commits as shown in the bottom right of Fig A.

In Fig B, I used "Push commit..." to set the main remote to the commit ID of the head of the Local feature-01 branch. Git Staging correctly shows the local feature-01 branch is still up to date. It also correctly shows the man branch is now 1 commit ahead and 1 commit behind the remote.

If Fig C, I used "Push commit..." to set the main remote back to the head of the local main branch. Git Staging correctly shows the main branch is up to date but now incorrectly shows the feature-01 branch is ahead and behind even though it still doesn't have a remote tracking branch. It looks like it's using a stale memory object from a different branch.

index.php/fa/43516/0/
Re: Absent and confused Ahead/Behind count [message #1861088 is a reply to message #1861076] Tue, 19 September 2023 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Most likely what EGit shows is correct. I cannot tell from your screenshots. Do look in the git config file (or in the branch configuration) to double-check whether there is a remote tracking branch for a local branch, and if so, what it is. Probably your first "Push commit" (mentioned in screenshot B) did set "origin/main" as remote tracking branch for local branch "feature-01".

In any case: showing any "ahead/behind" if there is no remote tracking branch associated with the local branch makes no sense. "Ahead/behind" is always relative to the remote tracking branch.
Re: Absent and confused Ahead/Behind count [message #1861126 is a reply to message #1861088] Thu, 21 September 2023 22:48 Go to previous messageGo to next message
Eclipse UserFriend
Below is the .git "config" file:

[core]
symlinks = false
repositoryformatversion = 0
filemode = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/RayMartin/Tracking-Test-01.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
rebase = false
[branch "feature-01"]
remote = origin
merge = refs/heads/main
rebase = false

When going from Fig B to Fig C, EGit should have cleared "refs/heads/main" from the feature-01 branch in the .git config file? This explains the stale info it's using. Am I supposed to manually edit the .config file?

Why didn't "Fetch from origin" update the config file? Doesn't that tell EGit the state of all commits and branches on the Remote repo?

I added another example in Fig D. This correctly shows the feature-01 remote tracking branch in the History view is the same as the Local but still says it's behind because it thinks the remote branch is main. This looks like a bug.

The idea I mentioned about indicating local commits being "ahead" when there isn't a remote tracking branch. I'm recommending this as an EGit improvement. Using a different symbol (e.g. + instead of ↑) followed by the count is a gentle reminder and fully depicts the present state of that branch.

index.php/fa/43526/0/
Re: Absent and confused Ahead/Behind count [message #1861139 is a reply to message #1861126] Fri, 22 September 2023 16:11 Go to previous messageGo to next message
Eclipse UserFriend
Ray Martin wrote on Fri, 22 September 2023 02:48

When going from Fig B to Fig C, EGit should have cleared "refs/heads/main" from the feature-01 branch in the .git config file? This explains the stale info it's using.

No, EGit should not have cleared the remote tracking branch set for feature-01. Multiple local branches can have the the same remote tracking branch. EGit is not using stale information. Everything is perfectly fine, as it should be.
Quote:

Am I supposed to manually edit the .config file?

No. If you absolutely want to remove a remote tracking branch, you can do so via the branch configuration dialog.
Quote:

Why didn't "Fetch from origin" update the config file? Doesn't that tell EGit the state of all commits and branches on the Remote repo?

Fetching does not update which local branch has which remote tracking branch. That is local information, not anything defined by the remote.
Quote:

The idea I mentioned about indicating local commits being "ahead" when there isn't a remote tracking branch. I'm recommending this as an EGit improvement. Using a different symbol (e.g. + instead of ↑) followed by the count is a gentle reminder and fully depicts the present state of that branch.

Not doable. "Ahead/behind" are always relative to a remote tracking branch. If there isn't one, there is no meaningful way to say the local branch was ahead or behind anything.
Re: Absent and confused Ahead/Behind count [message #1861140 is a reply to message #1861139] Fri, 22 September 2023 16:15 Go to previous messageGo to next message
Eclipse UserFriend
P.S.: I bet in your screenshot D local branch feature-01 still has remote tracking branch origin/main. So no error. The fact that there is an upstream branch with the same name as a local branch does not automatically make that upstream branch the remote tracking branch of the local branch.
Re: Absent and confused Ahead/Behind count [message #1861196 is a reply to message #1861140] Thu, 28 September 2023 15:11 Go to previous message
Eclipse UserFriend
You're right, I incorrectly assumed the name of the local and remote branches were the same. So the entries in the .git "config" file map the local branch name to a remote branch name? Is this entry based on the values specified in the Push Branch window (Fig E)?

Unfortunately, the History view in Fig D implies the name of the remote branch for the Local "feature-01" branch is also "feature-01" but is actually "main" (the value in the config file). This is what caused me to incorrectly conclude the ahead/behind count was wrong. Fig C was another case where it would have helped if the History view indicated the remote for the "feature-01" branch was "main". Something like color coding the branch name text.

index.php/fa/43540/0/
Previous Topic:Using ProxyCommand on JGit
Next Topic:Python script for search for factors of M1277 using random k-intervals
Goto Forum:
  


Current Time: Sat May 17 20:24:31 EDT 2025

Powered by FUDForum. Page generated in 0.04300 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top