# [PATCH] git-branch: cleanup config file when deleting branches

3 messages from 2007-06-06 to 2007-06-09. Participants: Gerrit Pape, Junio C Hamano.
Thread: https://gitlist.dev/t/8468

## Gerrit Pape, 2007-06-06 10:09

Subject: [PATCH] git-branch: cleanup config file when deleting branches
Message-ID: <20070606100947.18990.qmail@bef1f6489d171f.315fe32.mid.smarden.org>
URL: https://gitlist.dev/e/20070606100947.18990.qmail%40bef1f6489d171f.315fe32.mid.smarden.org

```
When deleting branches, remove the sections referring to these branches
from the config file.

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 builtin-branch.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index a5b6bbe..3a70a7d 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -85,6 +85,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 	unsigned char sha1[20];
 	char *name = NULL;
 	const char *fmt, *remote;
+	char section[PATH_MAX];
 	int i;
 	int ret = 0;
 
@@ -152,9 +153,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 			error("Error deleting %sbranch '%s'", remote,
 			       argv[i]);
 			ret = 1;
-		} else
+		} else {
 			printf("Deleted %sbranch %s.\n", remote, argv[i]);
-
+			snprintf(section, sizeof(section), "branch.%s",
+				 argv[i]);
+			if (git_config_rename_section(section, NULL) < 0)
+				warning("Update of config-file failed");
+		}
 	}
 
 	if (name)
-- 
1.5.2

```

## Junio C Hamano, 2007-06-08 08:45

Subject: Re: [PATCH] git-branch: cleanup config file when deleting branches
Message-ID: <7vzm3akf6g.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzm3akf6g.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070606100947.18990.qmail@bef1f6489d171f.315fe32.mid.smarden.org>

```
Gerrit Pape <pape@smarden.org> writes:

> When deleting branches, remove the sections referring to these branches
> from the config file.
>
> Signed-off-by: Gerrit Pape <pape@smarden.org>

Hmph.  Makes sense and might even be a maint material, but it
probably is safe not to do a behaviour change in maint.

Tests?

```

## Gerrit Pape, 2007-06-09 12:35

Subject: [PATCH] git-branch: cleanup config file when deleting branches
Message-ID: <20070609123526.3856.qmail@5cc189b277f9b4.315fe32.mid.smarden.org>
URL: https://gitlist.dev/e/20070609123526.3856.qmail%405cc189b277f9b4.315fe32.mid.smarden.org
In-Reply-To: <7vzm3akf6g.fsf@assigned-by-dhcp.cox.net>

```
When deleting branches, remove the sections referring to these branches
from the config file.

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
On Fri, Jun 08, 2007 at 01:45:27AM -0700, Junio C Hamano wrote:
> Hmph.  Makes sense and might even be a maint material, but it
> probably is safe not to do a behaviour change in maint.
>
> Tests?
Sure, two tests added.  Regards, Gerrit.

 builtin-branch.c  |    9 +++++++--
 t/t3200-branch.sh |    9 +++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index 67f46c1..9addd1a 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -85,6 +85,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 	unsigned char sha1[20];
 	char *name = NULL;
 	const char *fmt, *remote;
+	char section[PATH_MAX];
 	int i;
 	int ret = 0;
 
@@ -152,9 +153,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 			error("Error deleting %sbranch '%s'", remote,
 			       argv[i]);
 			ret = 1;
-		} else
+		} else {
 			printf("Deleted %sbranch %s.\n", remote, argv[i]);
-
+			snprintf(section, sizeof(section), "branch.%s",
+				 argv[i]);
+			if (git_config_rename_section(section, NULL) < 0)
+				warning("Update of config-file failed");
+		}
 	}
 
 	if (name)
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 6f6d884..1322bfb 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -171,6 +171,15 @@ test_expect_success 'test tracking setup via --track but deeper' \
      test "$(git-config branch.my7.remote)" = local &&
      test "$(git-config branch.my7.merge)" = refs/heads/o/o'
 
+test_expect_success 'test deleting branch deletes branch config' \
+    'git-branch -d my7 &&
+     test "$(git-config branch.my7.remote)" = "" &&
+     test "$(git-config branch.my7.merge)" = ""'
+
+test_expect_success 'test deleting branch without config' \
+    'git-branch my7 s &&
+     test "$(git-branch -d my7)" = "Deleted branch my7."'
+
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000	branch: Created from master
-- 
1.5.2.1

```
