jesseduffield / lazygit

simple terminal UI for git commands
MIT License
51.38k stars 1.8k forks source link

Divergence from base branch display #3613

Closed stefanhaller closed 4 months ago

stefanhaller commented 4 months ago

Add a new config option showDivergenceFromBaseBranch; if not "none", it indicates in the branches view for each branch if it has fallen behind its base branch, and optionally by how much. If set to "onlyArrow", it will append after the branch status; if set to "arrowAndNumber", it appends ↓17, where the count indicates how many commits it is behind the base branch. These are colored in blue, and go after the existing yellow ↓3↑7 indication of divergence from the upstream.

The option is off by default, since we are afraid that people may find this too noisy. We may reconsider this choice in the future if the response is positive.

codacy-production[bot] commented 4 months ago

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 7492521829114b935c91a4eab856a554160122bd[^1] :white_check_mark: 93.36%
Coverage variation details | | Coverable lines | Covered lines | Coverage | | ------------- | ------------- | ------------- | ------------- | | Common ancestor commit (7492521829114b935c91a4eab856a554160122bd) | Report Missing | Report Missing | Report Missing | | | Head commit (c6113f6a281de471525e0695687689023a1fd284) | 51359 | 43262 | 84.23% | **Coverage variation** is the difference between the coverage for the head and common ancestor commits of the pull request branch: ` - `
Diff coverage details | | Coverable lines | Covered lines | Diff coverage | | ------------- | ------------- | ------------- | ------------- | | Pull request (#3613) | 271 | 253 | **93.36%** | **Diff coverage** is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: `/ * 100%`

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more [^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

jesseduffield commented 4 months ago

I'm happy with the code, but I'm getting a bug when testing:

image

Each branch is reported as being behind the base branch, but that includes master, which is definitely not behind origin/master!

The issue went away after I removed my assets worktree (which was attached to the assets branch) and then restarted lazygit, but I don't know if simply restarting lazygit is what fixed it. I can't re-create the issue.

stefanhaller commented 4 months ago

Each branch is reported as being behind the base branch, but that includes master, which is definitely not behind origin/master!

Wow, that's bad. I have no idea how that could happen; would have been good to debug it on your machine when it was still there. Now that it's not recreatable, I'm not sure what to do about it...

jesseduffield commented 4 months ago

I'm not too fussed: given it's an opt-in feature I'm happy for us to merge and I'll just dig deeper next time (if) it happens

karimkhaleel commented 4 months ago

I played around with the feature and I like it. Is there any way I can get it to update after rebasing without having to restart lazygit?

https://github.com/jesseduffield/lazygit/assets/94621779/44f28005-74a5-445b-b6b3-63568956edd5

stefanhaller commented 4 months ago

Is there any way I can get it to update after rebasing without having to restart lazygit?

If it doesn't do that automatically, that would be a bug of course. It does for me, so it would be important to figure out under what conditions it doesn't. Maybe it is related to the problem Jesse was seeing.

I'll hold off merging for now, until we know more about this. If you can do more testing and somehow narrow it down, that would be awesome.

codacy-production[bot] commented 4 months ago

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 7c51ec21bf0f787c6f2d0079e920f3d5f566c9f0[^1] :white_check_mark: 93.77%
Coverage variation details | | Coverable lines | Covered lines | Coverage | | ------------- | ------------- | ------------- | ------------- | | Common ancestor commit (7c51ec21bf0f787c6f2d0079e920f3d5f566c9f0) | Report Missing | Report Missing | Report Missing | | | Head commit (373b1970cab78b639bbdb5e5a7c684735f4d95a7) | 51603 | 43535 | 84.37% | **Coverage variation** is the difference between the coverage for the head and common ancestor commits of the pull request branch: ` - `
Diff coverage details | | Coverable lines | Covered lines | Diff coverage | | ------------- | ------------- | ------------- | ------------- | | Pull request (#3613) | 273 | 256 | **93.77%** | **Diff coverage** is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: `/ * 100%`

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more [^1]: Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

stefanhaller commented 4 months ago

@karimkhaleel I'd like to make progress on this, but I don't know how. From your video above, it looks like the "behind base branch" indicators are correct right after startup, but then never update again, neither when you make commits nor when you rebase a branch. Is that true, and is that always the behavior you see, or only sometimes? In all repos, or only in certain ones?

Maybe I need to add some more logging so that we can get to the bottom of this, but I'm not even sure which conditions to look for.

karimkhaleel commented 4 months ago

I did a little bit of testing, and so far I haven't been able to get it to behave correctly.

I did some more testing, and I am seeing the same behavior again.

go version go1.22.3 linux/amd64
commit=cb0a9a732cb023f86f8fc294ca27a69cdd8cc7c5, build date=2024-06-01T17:57:24Z, build source=unknown, version=cb0a9a73, os=linux, arch=amd64, git version=2.34.1
gui:
  showDivergenceFromBaseBranch: arrowAndNumber

https://github.com/jesseduffield/lazygit/assets/94621779/51945072-9649-446a-b355-ab9cf9ac0afb

Any other things I can try?

stefanhaller commented 4 months ago

@karimkhaleel Thanks for testing again.

What a stupid bug, updating the counts just didn't work at all when local branches are sorted by recency. Since I sort my branches by date, I didn't notice.

aaa457889337 should fix it, could you test again?

@jesseduffield I'm pretty sure this was also the reason for the bug you reported above.

karimkhaleel commented 4 months ago

https://github.com/jesseduffield/lazygit/commit/aaa457889337a1eba13a4a96417761b8c065a437 should fix it, could you test again?

It works! Awesome!

georgeguimaraes commented 4 months ago

I really liked this, tks for coding it