Skip to content

Commit

Permalink
Bugfix: GIT_EXTERNAL_DIFF with more than one changed files
Browse files Browse the repository at this point in the history
When there is more than one file that are changed, running git diff with
GIT_EXTERNAL_DIFF incorrectly diagnoses an programming error and dies.
The check introduced in 479b0ae (diff: refactor tempfile cleanup handling,
2009-01-22) to detect a temporary file slot that forgot to remove its
temporary file was inconsistent with the way the codepath to remove the
temporary to mark the slot that it is done with it.

This patch fixes this problem and adds a test case for it.

Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nazri Ramliy authored and Junio C Hamano committed Feb 12, 2009
1 parent 30aa4fb commit a8344ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ static int remove_tempfile_installed;
static void remove_tempfile(void)
{
int i;
for (i = 0; i < ARRAY_SIZE(diff_temp); i++)
if (diff_temp[i].name == diff_temp[i].tmp_path) {
for (i = 0; i < ARRAY_SIZE(diff_temp); i++) {
if (diff_temp[i].name == diff_temp[i].tmp_path)
unlink(diff_temp[i].name);
diff_temp[i].name = NULL;
}
diff_temp[i].name = NULL;
}
}

static void remove_tempfile_on_signal(int signo)
Expand Down
8 changes: 8 additions & 0 deletions t/t4020-diff-external.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ test_expect_success 'force diff with "diff"' '
test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
'

test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
echo anotherfile > file2 &&
git add file2 &&
git commit -m "added 2nd file" &&
echo modified >file2 &&
GIT_EXTERNAL_DIFF=echo git diff
'

test_done

0 comments on commit a8344ab

Please sign in to comment.