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

print errors from git-update-ref

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jul 18, 2006, 13:13 UTC
Message-ID
<81b0412b0607180613t603551b8t865b407c40ab8aef@mail.gmail.com>
...otherwise it not clear what happened when update-ref fails.

E.g., git checkout -b a/b/c HEAD would print nothing if refs/heads/a exists and is a directory (it does return 1, so scripts checking for return code should be ok).

I'm attaching two patches, because I'm not quite sure where it should be done: git-checkout is the least intrusive, but only builtin-update-ref.c has enough info to help user to resolve the problem (errno is ENOTDIR, which is selfexplanatory). And I happen to use git-update-ref directly sometimes.

From 5398f0ee6bab039701912fdaf784792f4cf76afe Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
Date: Tue, 18 Jul 2006 14:52:15 +0200
Subject: [PATCH] update-ref: print errors
otherwise it not clear what happened
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 builtin-update-ref.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 83094ab..ad4a44d 100644
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
@@ -50,10 +50,14 @@ int cmd_update_ref(int argc, const char 
 		die("%s: not a valid old SHA1", oldval);
 
 	lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL, 0);
-	if (!lock)
+	if (!lock) {
+		error("%s: %s", refname, strerror(errno));
 		return 1;
-	if (write_ref_sha1(lock, sha1, msg) < 0)
+        }
+	if (write_ref_sha1(lock, sha1, msg) < 0) {
+		error("%s: %s", refname, strerror(errno));
 		return 1;
+	}
 
 	/* write_ref_sha1 always unlocks the ref, no need to do it explicitly */
 	return 0;
-- 
1.4.2.rc1.g22734



From 7ea3177aec909e333bacccd00693f223997e2613 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
Date: Tue, 18 Jul 2006 15:10:54 +0200
Subject: [PATCH] git-checkout.sh: print errors, otherwise it is not clear what happened

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 git-checkout.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-checkout.sh b/git-checkout.sh
index 5613bfc..7b335e5 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -198,7 +198,7 @@ if [ "$?" -eq 0 ]; then
 			mkdir -p $(dirname "$GIT_DIR/logs/refs/heads/$newbranch")
 			touch "$GIT_DIR/logs/refs/heads/$newbranch"
 		fi
-		git-update-ref -m "checkout: Created from $new_name" "refs/heads/$newbranch" $new || exit
+		git-update-ref -m "checkout: Created from $new_name" "refs/heads/$newbranch" $new || die "failed to create branch $newbranch"
 		branch="$newbranch"
 	fi
 	[ "$branch" ] &&
-- 
1.4.2.rc1.g22734
Next: Junio C Hamano
Message 1 of 7 in “print errors from git-update-ref”
  1. Alex RiesenJul 18, 2006
  2. Junio C HamanoJul 24, 2006
  3. Shawn PearceJul 27, 2006
  4. Johannes SchindelinJul 27, 2006
  5. Shawn PearceJul 28, 2006
  6. Junio C HamanoJul 28, 2006
  7. Shawn PearceJul 29, 2006

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.