...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@xxxxxxxxx> 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@xxxxxxxxx> --- 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@xxxxxxxxx> 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@xxxxxxxxx> --- 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