Skip to content

Commit

Permalink
Make error message after failing commit_lock_file() less confusing
Browse files Browse the repository at this point in the history
The error message after a failing commit_lock_file() call sometimes
looks like this, causing confusion:

  $ git remote add remote git@server.com/repo.git
  error: could not commit config file .git/config
  # Huh?!
  # I didn't want to commit anything, especially not my config file!

While in the narrow context of the lockfile module using the verb
'commit' in the error message makes perfect sense, in the broader
context of git the word 'commit' already has a very specific meaning,
hence the confusion.

Reword these error messages to say "could not write" instead of "could
not commit".

While at it, include strerror in the error messages after writing the
config file or the credential store fails to provide some information
about the cause of the failure, and update the style of the error
message after writing the reflog fails to match surrounding error
messages (i.e. no '' around the pathname and no () around the error
description).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Jeff King <peff@peff.net>
  • Loading branch information
SZEDER Gábor authored and Jeff King committed Dec 1, 2015
1 parent 908a6e4 commit 08a3651
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
}

if (commit_lock_file(lock) < 0) {
error("could not commit config file %s", config_filename);
error("could not write config file %s: %s", config_filename,
strerror(errno));
ret = CONFIG_NO_WRITE;
lock = NULL;
goto out_free;
Expand Down Expand Up @@ -2330,7 +2331,8 @@ int git_config_rename_section_in_file(const char *config_filename,
fclose(config_file);
unlock_and_out:
if (commit_lock_file(lock) < 0)
ret = error("could not commit config file %s", config_filename);
ret = error("could not write config file %s: %s",
config_filename, strerror(errno));
out:
free(filename_buf);
return ret;
Expand Down
3 changes: 2 additions & 1 deletion credential-store.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
print_line(extra);
parse_credential_file(fn, c, NULL, print_line);
if (commit_lock_file(&credential_lock) < 0)
die_errno("unable to commit credential store");
die_errno("unable to write credential store: %s",
strerror(errno));
}

static void store_credential_file(const char *fn, struct credential *c)
Expand Down
2 changes: 1 addition & 1 deletion fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ static void dump_marks(void)

dump_marks_helper(f, 0, marks);
if (commit_lock_file(&mark_lock)) {
failure |= error("Unable to commit marks file %s: %s",
failure |= error("Unable to write file %s: %s",
export_marks_file, strerror(errno));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4643,7 +4643,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
get_lock_file_path(lock->lk));
rollback_lock_file(&reflog_lock);
} else if (commit_lock_file(&reflog_lock)) {
status |= error("unable to commit reflog '%s' (%s)",
status |= error("unable to write reflog %s: %s",
log_file, strerror(errno));
} else if (update && commit_ref(lock)) {
status |= error("couldn't set %s", lock->ref_name);
Expand Down

0 comments on commit 08a3651

Please sign in to comment.