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

[PATCH 2/2] git-branch: rename config vars branch.<branch>.*, too

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 16, 2006, 14:15 UTC
Message-ID
<Pine.LNX.4.63.0612161514280.3635@wbgn013.biozentrum.uni-wuerzburg.de>

When renaming a branch, the corresponding config section should be renamed, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 refs.c            |   10 ++++++++++
 t/t3200-branch.sh |    6 ++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/refs.c b/refs.c
index a02957c..d911b9e 100644
--- a/refs.c
+++ b/refs.c
@@ -867,6 +867,16 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 		goto rollback;
 	}
 
+	if (!strncmp(oldref, "refs/heads/", 11) &&
+			!strncmp(newref, "refs/heads/", 11)) {
+		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)
+			return 1;
+	}
+
 	return 0;
 
  rollback:
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 5782c30..a6ea0f6 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -94,6 +94,8 @@ test_expect_failure \
          git-branch r &&
          git-branch -m q r/q'
 
+git-repo-config branch.s/s.dummy Hello
+
 test_expect_success \
     'git branch -m s/s s should work when s/t is deleted' \
        'git-branch -l s/s &&
@@ -104,6 +106,10 @@ test_expect_success \
         git-branch -m s/s s &&
         test -f .git/logs/refs/heads/s'
 
+test_expect_success 'config information was renamed, too' \
+	"test $(git-repo-config branch.s.dummy) = Hello &&
+	 ! git-repo-config branch.s/s/dummy"
+
 test_expect_failure \
     'git-branch -m u v should fail when the reflog for u is a symlink' \
     'git-branch -l u &&
-- 
1.4.4.1.g0604-dirty
Message 1 of 1 in “git-branch: rename config vars branch.<branch>.*, too”
  1. 2/2 git-branch: rename config vars branch.<branch>.*, tooJohannes Schindelin, Dec 16, 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.