Fix renaming branch without config file
Make git_config_rename_section return success if no config file exists. Otherwise, renaming a branch would abort, leaving the repository in an inconsistent state. [jc: test] Signed-off-by: Geert Bosch <bosch@gnat.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Geert Bosch committed
Apr 5, 2007 at 10:20 UTC
01ebb9dc8846af729c13d5d8c9d939a6d1159240
2 files changed
+12
-2
config.c
+3
-2
@@ -916,8 +916,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
916
}
917
918
if (!(config_file = fopen(config_filename, "rb"))) {
919
- ret = error("Could not open config file!");
920
- goto out;
919
+ /* no config file means nothing to rename, no error */
920
+ goto unlock_and_out;
921
}
922
923
while (fgets(buf, sizeof(buf), config_file)) {
@@ -951,6 +951,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
951
}
952
}
953
fclose(config_file);
954
+ unlock_and_out:
955
if (close(out_fd) || commit_lock_file(lock) < 0)
956
ret = error("Cannot commit config file!");
957
out:
t/t3200-branch.sh
+9
@@ -83,6 +83,15 @@ test_expect_failure \
83
git-branch r &&
84
git-branch -m q r/q'
85
86
+mv .git/config .git/config-saved
87
+
88
+test_expect_success 'git branch -m q Q without config should succeed' '
89
+ git-branch -m q Q &&
90
+ git-branch -m Q q
91
+'
92
+
93
+mv .git/config-saved .git/config
94
+
95
git-config branch.s/s.dummy Hello
96
97
test_expect_success \