emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

vc-dir fails if Git upstream branch is local


From: Tobias Bading
Subject: vc-dir fails if Git upstream branch is local
Date: Sun, 30 Apr 2023 10:58:15 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0

Hi.

Is it just me, am I using Git wrong, or does vc-dir fail for everyone in a
working tree whose upstream branch is a local branch, not a remote-tracking
branch?

I have a local branch named “my-emacs-29” which was created from “emacs-29”,
which is my local branch that tracks “origin/emacs-29”.

After a “git branch --set-upstream-to=origin/emacs-29”, vc-dir works just
fine and its buffer contains

Remote     : git://git.sv.gnu.org/emacs.git

After “git branch --unset-upstream”, vc-dir still works and its buffer does
not contain a Remote line (as expected).

Things go sideways after a “git branch --set-upstream-to=emacs-29”. This
works fine with Git 2.40.0 on GNU/Linux in a shell. “git status” correctly
prints

Your branch is ahead of 'emacs-29' by 9 commits.

But vc-dir fails completely with

Failed (status 2): git --no-pager remote get-url . .

in *Messages*. This is caused by vc-git-dir-extra-headers running
“git config branch.my-emacs-29.remote”, which returns a period due to
.git/config containing

[branch "my-emacs-29"]
    remote = .

Then vc-git-repository-url runs “git --no-pager remote get-url .”, which
produces

error: No such remote '.'

in a shell.

It looks like this is fixable with a simple

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 7ae763d2ee..cdeebd9e0b 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -770,7 +770,7 @@ vc-git-dir-extra-headers
                                     (concat "branch." branch
".remote")))))
       (when (string-match "\\([^\n]+\\)" remote)
         (setq remote (match-string 1 remote)))
-          (when (> (length remote) 0)
+          (when (> (length remote) 1)
         (setq remote-url (vc-git-repository-url dir remote))))
       (setq branch "not (detached HEAD)"))
     (when stash-list

Am I the only one who uses upstream branches this way? If you have a local
feature branch created from another local branch, doesn’t it make sense to
have it track the local branch it was created from? Especially if both
branches are local and never have been pushed to any remote.

Tobias

PS: please keep me CC’d, thanks




reply via email to

[Prev in Thread] Current Thread [Next in Thread]