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

[PATCH] git-fetch: allow updating the current branch in a bare repository.

From
Junio C Hamano <junkio@cox.net>
Date
Jan 7, 2007, 10:19 UTC
Message-ID
<7vy7of16mn.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<20070107100559.GC10351@spearce.org>

Sometimes, people have only fetch access into a bare repository that is used as a back-up location (or a distribution point) but does not have a push access for networking reasons, e.g. one end being behind a firewall, and updating the "current branch" in such a case is perfectly fine.

This allows such a fetch without --update-head-ok, which is a flag that should never be used by end users otherwise.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 "Shawn O. Pearce" <spearce@spearce.org> writes:
 > Junio C Hamano <junkio@cox.net> wrote:
 >> ...
 >> Here is what I have as a follow-up patch to the one you are
 >> responding to.
 >
 > I like.  :-)
 >
 > Worthy of 1.5.0 me thinks.
 And here is an example of what you would do in the scripts.
 git-fetch.sh    |    9 +++++----
 git-sh-setup.sh |    8 ++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/git-fetch.sh b/git-fetch.sh
index 466fe59..c58704d 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -231,11 +231,12 @@ update_local_ref () {
     esac
 }
 
-case "$update_head_ok" in
-'')
+# updating the current HEAD with git-fetch in a bare
+# repository is always fine.
+if test -z "$update_head_ok" && test $(is_bare_repository) = false
+then
 	orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
-	;;
-esac
+fi
 
 # If --tags (and later --heads or --all) is specified, then we are
 # not talking about defaults stored in Pull: line of remotes or
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 87b939c..7fdc912 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -28,6 +28,14 @@ set_reflog_action() {
 	fi
 }
 
+is_bare_repository () {
+	git-repo-config --bool --get core.bare ||
+	case "$GIT_DIR" in
+	.git | */.git) echo false ;;
+	*) echo true ;;
+	esac
+}
+
 if [ -z "$LONG_USAGE" ]
 then
 	LONG_USAGE="Usage: $0 $USAGE"
Previous: Shawn O. Pearce
Message 5 of 5 in “Moving initialization of log_all_ref_updates”
  1. Junio C HamanoJan 7, 2007
  2. Shawn O. PearceJan 7, 2007
  3. Junio C HamanoJan 7, 2007
  4. Shawn O. PearceJan 7, 2007
  5. git-fetch: allow updating the current branch in a bare repository.Junio C Hamano, Jan 7, 2007

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.