posh-git
posh-git copied to clipboard
Git prompt cannot tell if local branch is behind the remote branch
System Details
- posh-git version/path: 0.7.3.1 C:\tools\poshgit\dahlbyk-posh-git-9bda399\src
- PowerShell version: 5.1.17134.407
- Git version: 2.19.2.windows.1
- Operating system name and version: Microsoft Windows NT 10.0.17134.0
Issue Description
Just like git-status, the posh-git prompt doesn't know about the updates on a remote branch, until git-fetch is called, which updates the local tracking branches. This kind of makes the posh-git half-as-useful as it could have been.
I wish there was a feature built-in to posh-git to improve git-status, where the prompt would properly somehow indicate that the local copy of the repository is out-of-date, and suggest you to better just run git-pull before you continue with your work on this machine, especially when you first get into the git directory.
A Suggestion
Posh-git prompt could (optionally) execute git-fetch whenever it is initiated, and possibly with an adjustable cooldown.
A Boolean setting for enabling/disabling the feature, and an integer setting for a cooldown in seconds (?) could be provided for enough control to the user. When the feature is enabled, git-fetch shall get called whenever the posh-git-prompt is about to get printed, if the last time git-fetch has been called was later than the set amount of cooldown.
With a zero-cooldown, git-fetch would be called each and every time. With perhaps -1 cooldown, git-fetch could get called only on the first time user cd's into a git directory.
This is just an idea, and maybe there is a better way to tell just that the local tracking branches are out-of-date, without needing to git-fetch.
This is an interesting idea! I'm hesitant to run a real git fetch
, as that's potentially destructive (forced ref updates), but git fetch --dry-run
goes through the motions without actually updating references.
We wouldn't want to run this on every prompt
, but I wonder if we could get a reasonably good experience out of using background jobs? This seems to work:
Start-Job -Name posh-git-fetch { param($GitDir) cd $GitDir; "$(git fetch --dry-run *>&1)" } -ArgumentList $GitStatus.GitDir
Receive-Job -Name posh-git-fetch
If something along those lines would do the trick, we'd probably want to capture the last fetch
result (refs to update or not), timestamp, and the Git directory fetched.
We'd probably also want a few settings:
- Preemptive fetch interval (< 0 to disable?)
- Symbol/text when up-to-date (default
''
?) - Symbol/text when out-of-date
- Symbol/text when disconnected