Skip to content

Commit 5a9dd39

Browse files
drafnelgitster
authored andcommitted
git-commit: exit non-zero if we fail to commit the index
In certain rare cases, the creation of the commit object and update of HEAD can succeed, but then installing the updated index will fail. This is most likely caused by a full disk or exceeded disk quota. When this happens the new index file will be removed, and the repository will be left with the original now-out-of-sync index. The user can recover with a "git reset HEAD" once the disk space issue is resolved. We should detect this failure and offer the user some helpful guidance. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 28678b4 commit 5a9dd39

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

builtin-commit.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ static void rollback_index_files(void)
122122
}
123123
}
124124

125-
static void commit_index_files(void)
125+
static int commit_index_files(void)
126126
{
127+
int err = 0;
128+
127129
switch (commit_style) {
128130
case COMMIT_AS_IS:
129131
break; /* nothing to do */
130132
case COMMIT_NORMAL:
131-
commit_lock_file(&index_lock);
133+
err = commit_lock_file(&index_lock);
132134
break;
133135
case COMMIT_PARTIAL:
134-
commit_lock_file(&index_lock);
136+
err = commit_lock_file(&index_lock);
135137
rollback_lock_file(&false_lock);
136138
break;
137139
}
140+
141+
return err;
138142
}
139143

140144
/*
@@ -926,7 +930,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
926930
unlink(git_path("MERGE_HEAD"));
927931
unlink(git_path("MERGE_MSG"));
928932

929-
commit_index_files();
933+
if (commit_index_files())
934+
die ("Repository has been updated, but unable to write\n"
935+
"new_index file. Check that disk is not full or quota is\n"
936+
"not exceeded, and then \"git reset HEAD\" to recover.");
930937

931938
rerere();
932939
run_hook(get_index_file(), "post-commit", NULL);

0 commit comments

Comments
 (0)