Skip to content

Commit a8344ab

Browse files
nazrigitster
authored andcommitted
Bugfix: GIT_EXTERNAL_DIFF with more than one changed files
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30aa4fb commit a8344ab

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ static int remove_tempfile_installed;
184184
static void remove_tempfile(void)
185185
{
186186
int i;
187-
for (i = 0; i < ARRAY_SIZE(diff_temp); i++)
188-
if (diff_temp[i].name == diff_temp[i].tmp_path) {
187+
for (i = 0; i < ARRAY_SIZE(diff_temp); i++) {
188+
if (diff_temp[i].name == diff_temp[i].tmp_path)
189189
unlink(diff_temp[i].name);
190-
diff_temp[i].name = NULL;
191-
}
190+
diff_temp[i].name = NULL;
191+
}
192192
}
193193

194194
static void remove_tempfile_on_signal(int signo)

t/t4020-diff-external.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,12 @@ test_expect_success 'force diff with "diff"' '
128128
test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
129129
'
130130

131+
test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
132+
echo anotherfile > file2 &&
133+
git add file2 &&
134+
git commit -m "added 2nd file" &&
135+
echo modified >file2 &&
136+
GIT_EXTERNAL_DIFF=echo git diff
137+
'
138+
131139
test_done

0 commit comments

Comments
 (0)