-
Notifications
You must be signed in to change notification settings - Fork 947
Clarify remote name <-> remote branch #1248
base: next
Are you sure you want to change the base?
Conversation
A few observations:
diff --git a/segments/vcs/vcs_git.spec b/segments/vcs/vcs_git.spec
index b963109b..859b5aac 100755
--- a/segments/vcs/vcs_git.spec
+++ b/segments/vcs/vcs_git.spec
@@ -425,11 +425,15 @@ function testAlwaysShowRemoteBranch() {
git clone . ../vcs-test2 1>/dev/null 2>&1
cd ../vcs-test2
+ git remote rename origin some/remote
- assertEquals "%K{002} %F{000} master→master@origin %k%F{002}%f " "$(__p9k_build_left_prompt)"
+ assertEquals "%K{002} %F{000} master→master@some/remote %k%F{002}%f " "$(__p9k_build_left_prompt)"
local P9K_VCS_GIT_ALWAYS_SHOW_REMOTE_BRANCH='false'
assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(__p9k_build_left_prompt)"
+
+ git branch -m master new/ref/master
+ assertEquals "%K{002} %F{000} new/ref/master→master@some/remote %k%F{002}%f " "$(__p9k_build_left_prompt)"
}
function testGitDirClobber() { |
Thanks for the review @Syphdias . Yep, how we merge that configuration array is still unsolved. I'm open to suggestions ;) The obvious one - merge that automatically - won't work, as we cannot know if a user configured that hook away for any reason, or if that hook was added by us.. I deliberately went away from the git syntax, because the git syntax is ambiguous as well ( Agreed with making the tests more robust. Will do. |
Two things:
[[ -n ${remote_name} ]] \
&& hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${remote_branch}${P9K_VCS_REMOTE_DELIMITER}${remote_name}" \
|| hook_com[branch]+="${__P9K_ICONS[VCS_REMOTE_BRANCH]}${remote_branch}"
Just to be clear: I'm not totally disagreeing with the I would opt for |
Correct. It is possible to truncate long branch names. That is why I saved the original branch name as early as possible.
Well. The problem with that approach would be that we either need to cache the value on the first call (and there is no guarantee that the first call already truncated the branch name), or that we have to query
Fair point. The main problem is that our approach is still not very flexible. We are bound to the initial structure (branch first, remote second information). Sure, we could change that, but not the user (I'd love to have some simple templating for such things). |
Hmm. I even introduced a new hook |
This fixes the original issue from #1209 . The
vcs
segment now shows<remote_branch>@<remote_name>
, if there is a remote. The delimiter is configurable by settingP9K_VCS_REMOTE_DELIMITER
.In the screenshot I have a local branch
next2
pointing atnext
fromorigin
.I hope that clarifies what the remote name is and what the remote branch is. Performance might got a bit worse, if a remote was detected (one subshell more)..
Additionally, this PR fixes some documentation issues and moves truncating the branch name in a better named hook (
git-branch
, instead ofgit-remote-branch
).// cc @Syphdias @romkatv