浏览代码

feat(git): guess main branch name also from remotes (#10158)

Co-authored-by: Marc Cornellà <hello@mcornella.com>
Vitaly Polonetsky 3 年之前
父节点
当前提交
53b54f5faa
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      plugins/git/git.plugin.zsh

+ 4 - 4
plugins/git/git.plugin.zsh

@@ -32,10 +32,10 @@ function work_in_progress() {
 # Check if main exists and use instead of master
 function git_main_branch() {
   command git rev-parse --git-dir &>/dev/null || return
-  local branch
-  for branch in main trunk; do
-    if command git show-ref -q --verify refs/heads/$branch; then
-      echo $branch
+  local ref
+  for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk}; do
+    if command git show-ref -q --verify $ref; then
+      echo ${ref:t}
       return
     fi
   done