Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Propagate ELOCKED error when updating the config #1942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
GITERR_CHECK_ALLOC(esc_value);
}

if (config_write(b, key, NULL, esc_value) < 0) {
if ((ret = config_write(b, key, NULL, esc_value)) < 0) {
git__free(esc_value);
cvar_free(var);
return -1;
return ret;
}

git__free(esc_value);
Expand Down Expand Up @@ -1210,8 +1210,8 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
write_start = data_start;

/* Lock the file */
if (git_filebuf_open(&file, cfg->file_path, 0, GIT_CONFIG_FILE_MODE) < 0)
return -1;
if ((result = git_filebuf_open(&file, cfg->file_path, 0, GIT_CONFIG_FILE_MODE)) < 0)
return result;

skip_bom(reader);
ldot = strrchr(key, '.');
Expand Down
13 changes: 13 additions & 0 deletions tests-clar/config/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,16 @@ void test_config_write__can_set_an_empty_value(void)
git_config_free(config);
cl_git_sandbox_cleanup();
}

void test_config_write__updating_a_locked_config_file_returns_ELOCKED(void)
{
git_config *cfg;

cl_git_pass(git_config_open_ondisk(&cfg, "config9"));

cl_git_mkfile("config9.lock", "[core]\n");

cl_git_fail_with(git_config_set_string(cfg, "core.dump", "boom"), GIT_ELOCKED);

git_config_free(cfg);
}