git-branch: cleanup config file when deleting branches
When deleting branches, remove the sections referring to these branches from the config file. Signed-off-by: Gerrit Pape <pape@smarden.org>
Gerrit Pape committed
Jun 9, 2007 at 12:40 UTC
f1eccbab638df66a7d8ec881f6f695514b26f44f
2 files changed
+16
-2
builtin-branch.c
+7
-2
@@ -85,6 +85,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
85
unsigned char sha1[20];
86
char *name = NULL;
87
const char *fmt, *remote;
88
+ char section[PATH_MAX];
89
int i;
90
int ret = 0;
91
@@ -152,9 +153,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
153
error("Error deleting %sbranch '%s'", remote,
154
argv[i]);
155
ret = 1;
155
- } else
156
+ } else {
157
printf("Deleted %sbranch %s.\n", remote, argv[i]);
157
-
158
+ snprintf(section, sizeof(section), "branch.%s",
159
+ argv[i]);
160
+ if (git_config_rename_section(section, NULL) < 0)
161
+ warning("Update of config-file failed");
162
+ }
163
}
164
165
if (name)
t/t3200-branch.sh
+9
@@ -171,6 +171,15 @@ test_expect_success 'test tracking setup via --track but deeper' \
171
test "$(git-config branch.my7.remote)" = local &&
172
test "$(git-config branch.my7.merge)" = refs/heads/o/o'
173
174
+test_expect_success 'test deleting branch deletes branch config' \
175
+ 'git-branch -d my7 &&
176
+ test "$(git-config branch.my7.remote)" = "" &&
177
+ test "$(git-config branch.my7.merge)" = ""'
178
+
179
+test_expect_success 'test deleting branch without config' \
180
+ 'git-branch my7 s &&
181
+ test "$(git-branch -d my7 2>&1)" = "Deleted branch my7."'
182
+
183
# Keep this test last, as it changes the current branch
184
cat >expect <<EOF
185
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master