-
Notifications
You must be signed in to change notification settings - Fork 938
vcs segment shows incorrect remote branch when tracking remote isn't called "origin" #1209
Comments
Hey @romkatv . I've been thinking about this, since I implemented the remote name in |
Oops, sorry about that. I should've tried my own reproduction instructions before posting them. This should demonstrate the issue: git remote rename origin my/source Full setup: docker run -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -e TERM=$TERM -it --rm ubuntu bash -uexc '
apt update && apt install -y zsh git
git clone https://github.com/bhilburn/powerlevel9k.git ~/powerlevel9k
cd ~/powerlevel9k
git remote rename origin my/source
echo "
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
source ~/powerlevel9k/powerlevel9k.zsh-theme" >~/.zshrc
zsh -i' Note that branches also can have slashes in their names, so it's not possible to extract branch name from the symbolic name of a remote reference. That is, if |
Oh, now I see why you wrote that code with special-casing Names of the remotes have no meaning on their own. A user can assign meaning to them but it's not enforced by git and thus won't be shared by other users. A theme shouldn't assume predefined meaning, at least not with default settings, so any mention of To distinguish between your and not-your repositories you could look at the remote URL. If the repo is under |
Agreed, and it does not show up in code. (only in (old) comments)
I don't think that's the idea. The idea is to show the remote branch if the name differs. So what it should check is, if the tracking branch is This should(tm) not collide with the issue of not not knowing where the remote ends and where the branch names start since this combination is unique locally, maybe??? (No deep research done just checked my I don't know how to check this though. Is there a way to get just the remote without the remote branch? |
Hm... if @dritter wanted this, he would've written it so: if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
$VCS_STATUS_REMOTE_BRANCH != VCS_STATUS_LOCAL_BRANCH ]]; then
local r="$VCS_STATUS_REMOTE_NAME/$VCS_STATUS_REMOTE_BRANCH"
segment_content+=("${__P9K_ICONS[GITSTATUS_REMOTE_BRANCH]}$r")
fi But in fact he has written something much more complex. I don't understand what he's trying to achieve with that code but based on the discussion at #1229 (comment) I though he wants to distinguish between his own remotes (which are usually "origin") and other remotes (he used "ben" as an example). @dritter It would help if you could clarify. |
TBH, my first idea was indeed to distinguish between my branches and foreign ones. But as you, @romkatv , correctly pointed out, this is not possible without the help of the user.. A good alternative to that is @Syphdias suggestion. Could either of you create a PR? That would be nice. |
@dritter So there are two ideas here:
diff --git a/segments/vcs/vcs.p9k b/segments/vcs/vcs.p9k
index de678514..b4214a5c 100644
--- a/segments/vcs/vcs.p9k
+++ b/segments/vcs/vcs.p9k
@@ -209,7 +209,7 @@ function +vi-git-remotebranch() {
if [[ -n ${remote} \
&& ( \
"${P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH}" == 'true' \
- || "${remote#*/}" != "${branch_name#heads/}" \
+ || ! "${remote}" =~ "/${branch_name#heads/}$" \
) ]]; then
hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${${remote// /}//\%/%%}"
fi |
@Syphdias agreed on idea 1. That should be a new feature. And about your second idea: I wouldn't change the @romkatv in gitstatus you strip away the remote name. So could we distinguish between the remotes? Coming back to my initial example: if I track a branch |
@dritter I'm not sure I understand the question. If HEAD is a branch, then If the branch is tracking a remote branch, then both
Or to put it another way, if HEAD is a branch that tracks a remote branch, then the output of Concatenating strings is easier than splitting, so it's fairly easy to do anything you want with the data gitstatus provides. There is also |
@romkatv I didn't even take a look at the
@dritter Are you saying there is no bug here or just a "won't fix"? The behaviour original intended is no possible as we agreed on. But what is it, it is supposed to do then? If the intention is to show differently named local branches, it is very straight forward to fix in If this is not wanted (currently buggy) behaviour. What should it do? Display the remote ref if there is a |
Yeah, it's confusing because we have two parallel threads here. One is the original bug I reported against |
Haha. Sorry for contributing to the confusion here. I'll try to bring some light into the dark here: About
|
@dritter, could you describe when and how the right part should be displayed? If there is more than one remote? So for your example: Edit: Probably like that if you want to include different local branch names PS: Adding to the confusion: my |
Having slept one night about this problem, I think my use case is an edge case and is not solvable. My use case is about ownership, which git does not know about, hence we need user input for this case. I'll think some more about this and create a new PR, if I got to somewhere.. |
Seems like the level of confusion is getting boringly low here. Let's bump it up a notch.
If you literally run gitstatus has straightforward logic here. P9K has different logic. What it shows as local branch name isn't always a branch. For example, if you run This diversity of local branch name formats and meanings makes it challenging for users to build a consistent model for interpreting what they are seeing. If P9K says I'm on |
Yeah. I forgot a
Full Ack. We should try to make that as consistent as possible. I'll have a look into the vcs segment. |
Tested on master with the default config.
cd
into it.git remote rename origin source
Expected: There is no remote branch in the vcs prompt (because remote is the same as local).
Actual: vcs prompt shows remote branch "source/master".
The text was updated successfully, but these errors were encountered: