git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Make builtin-branch.c handle the git config file
@ 2007-04-06 12:13 Lars Hjemli
  0 siblings, 0 replies; only message in thread
From: Lars Hjemli @ 2007-04-06 12:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Geert Bosch, git, Lars Hjemli

This moves the knowledge about .git/config usage out of refs.c and into
builtin-branch.c instead, which allows git-branch to update HEAD to point
at the moved branch before attempting to update the config file. It also
allows git-branch to exit with an error code if updating the config file
should fail.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
 builtin-branch.c |    6 ++++++
 refs.c           |   10 ----------
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index a4494ee..7408285 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -493,6 +493,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
 {
 	char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
 	unsigned char sha1[20];
+	char oldsection[PATH_MAX], newsection[PATH_MAX];
 
 	if (!oldname)
 		die("cannot rename the current branch while not on any.");
@@ -521,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force)
 	/* no need to pass logmsg here as HEAD didn't really move */
 	if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL))
 		die("Branch renamed to %s, but HEAD is not updated!", newname);
+
+	snprintf(oldsection, sizeof(oldsection), "branch.%s", oldref + 11);
+	snprintf(newsection, sizeof(newsection), "branch.%s", newref + 11);
+	if (git_config_rename_section(oldsection, newsection) < 0)
+		die("Branch is renamed, but update of config-file failed");
 }
 
 int cmd_branch(int argc, const char **argv, const char *prefix)
diff --git a/refs.c b/refs.c
index 2ac6384..d2b7b7f 100644
--- a/refs.c
+++ b/refs.c
@@ -828,16 +828,6 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 		goto rollback;
 	}
 
-	if (!prefixcmp(oldref, "refs/heads/") &&
-			!prefixcmp(newref, "refs/heads/")) {
-		char oldsection[1024], newsection[1024];
-
-		snprintf(oldsection, 1024, "branch.%s", oldref + 11);
-		snprintf(newsection, 1024, "branch.%s", newref + 11);
-		if (git_config_rename_section(oldsection, newsection) < 0)
-			error("unable to update config-file");
-	}
-
 	return 0;
 
  rollback:
-- 
1.5.1.53.g77e6f

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2007-04-06 12:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-06 12:13 [PATCH] Make builtin-branch.c handle the git config file Lars Hjemli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).