Skip to content

Commit

Permalink
Fix renaming branch without config file
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Geert Bosch authored and Junio C Hamano committed Apr 5, 2007
1 parent 1e31fbe commit 01ebb9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)
}

if (!(config_file = fopen(config_filename, "rb"))) {
ret = error("Could not open config file!");
goto out;
/* no config file means nothing to rename, no error */
goto unlock_and_out;
}

while (fgets(buf, sizeof(buf), config_file)) {
Expand Down Expand Up @@ -951,6 +951,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)
}
}
fclose(config_file);
unlock_and_out:
if (close(out_fd) || commit_lock_file(lock) < 0)
ret = error("Cannot commit config file!");
out:
Expand Down
9 changes: 9 additions & 0 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ test_expect_failure \
git-branch r &&
git-branch -m q r/q'

mv .git/config .git/config-saved

test_expect_success 'git branch -m q Q without config should succeed' '
git-branch -m q Q &&
git-branch -m Q q
'

mv .git/config-saved .git/config

git-config branch.s/s.dummy Hello

test_expect_success \
Expand Down

0 comments on commit 01ebb9d

Please sign in to comment.