Skip to content

Commit e2bcd4f

Browse files
committed
Merge branch 'nd/magic-pathspec'
"git diff -- ':(icase)makefile'" were rejected unnecessarily. This needs to be merged to 'maint' later. * nd/magic-pathspec: diff: restrict pathspec limitations to diff b/f case only
2 parents cb6bd57 + 887c6c1 commit e2bcd4f

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

builtin/diff.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ static void stuff_change(struct diff_options *opt,
6464

6565
static int builtin_diff_b_f(struct rev_info *revs,
6666
int argc, const char **argv,
67-
struct blobinfo *blob,
68-
const char *path)
67+
struct blobinfo *blob)
6968
{
7069
/* Blob vs file in the working tree*/
7170
struct stat st;
71+
const char *path;
7272

7373
if (argc > 1)
7474
usage(builtin_diff_usage);
7575

76+
GUARD_PATHSPEC(&revs->prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
77+
path = revs->prune_data.items[0].match;
78+
7679
if (lstat(path, &st))
7780
die_errno(_("failed to stat '%s'"), path);
7881
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
@@ -255,7 +258,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
255258
struct rev_info rev;
256259
struct object_array ent = OBJECT_ARRAY_INIT;
257260
int blobs = 0, paths = 0;
258-
const char *path = NULL;
259261
struct blobinfo blob[2];
260262
int nongit;
261263
int result = 0;
@@ -366,13 +368,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
366368
die(_("unhandled object '%s' given."), name);
367369
}
368370
}
369-
if (rev.prune_data.nr) {
370-
/* builtin_diff_b_f() */
371-
GUARD_PATHSPEC(&rev.prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
372-
if (!path)
373-
path = rev.prune_data.items[0].match;
371+
if (rev.prune_data.nr)
374372
paths += rev.prune_data.nr;
375-
}
376373

377374
/*
378375
* Now, do the arguments look reasonable?
@@ -385,7 +382,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
385382
case 1:
386383
if (paths != 1)
387384
usage(builtin_diff_usage);
388-
result = builtin_diff_b_f(&rev, argc, argv, blob, path);
385+
result = builtin_diff_b_f(&rev, argc, argv, blob);
389386
break;
390387
case 2:
391388
if (paths)

t/t6131-pathspec-icase.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ test_expect_success 'match_pathspec_depth matches :(icase)bar with empty prefix'
100100
test_cmp expect actual
101101
'
102102

103+
test_expect_success '"git diff" can take magic :(icase) pathspec' '
104+
echo FOO/BAR >expect &&
105+
git diff --name-only HEAD^ HEAD -- ":(icase)foo/bar" >actual &&
106+
test_cmp expect actual
107+
'
108+
103109
test_done

0 commit comments

Comments
 (0)