git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Improve error message about fetch into current branch

From
Alex Riesen <raa.lkml@gmail.com>
Date
Mar 22, 2009, 22:07 UTC
Message-ID
<20090322220732.GA6736@blimp.localdomain>

Otherwise, it is hard to guess why the fetch failed. Make sure we at least mention that the repository must be bare. Also the current branch is printed.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

In particular, a repository not marked bare with core.bare is, for some reason, considered non-bare even if there is no work tree nor index. I found about the message while trying to run git remote, in an essentially bare repository without core.bare set. Funny, git --bare fetch worked properly, but git --bare remote update failed:

    $ GIT_TRACE=1 ~/projects/git/git --bare remote -v update
    trace: built-in: git 'remote' '-v' 'update'
    Updating origin
    trace: run_command: 'fetch' '-v' 'origin'
    trace: exec: 'git' 'fetch' '-v' 'origin'
    trace: built-in: git 'fetch' '-v' 'origin'
    fatal: Refusing to fetch into current branch refs/heads/master
    error: Could not fetch origin
    $ git --bare fetch -v origin
    From git://git.kernel.org/pub/scm/linux/hotplug/udev
     = [up to date]      master     -> master
    $
Looks like --bare is lost somewhere.
 builtin-fetch.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 7fb35fc..7293146 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -544,7 +544,8 @@ static void check_not_current_branch(struct ref *ref_map)
 	for (; ref_map; ref_map = ref_map->next)
 		if (ref_map->peer_ref && !strcmp(current_branch->refname,
 					ref_map->peer_ref->name))
-			die("Refusing to fetch into current branch");
+			die("Refusing to fetch into current branch %s "
+			    "of non-bare repository", current_branch->refname);
 }
 
 static int do_fetch(struct transport *transport,
-- 
1.6.2.1.316.g4241
Message 1 of 1 in “Improve error message about fetch into current branch”
  1. Improve error message about fetch into current branchAlex Riesen, Mar 22, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.