Skip to content

Commit

Permalink
Merge branch 'nd/magic-pathspec'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed Dec 6, 2013
2 parents cb6bd57 + 887c6c1 commit e2bcd4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 7 additions & 10 deletions builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ static void stuff_change(struct diff_options *opt,

static int builtin_diff_b_f(struct rev_info *revs,
int argc, const char **argv,
struct blobinfo *blob,
const char *path)
struct blobinfo *blob)
{
/* Blob vs file in the working tree*/
struct stat st;
const char *path;

if (argc > 1)
usage(builtin_diff_usage);

GUARD_PATHSPEC(&revs->prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
path = revs->prune_data.items[0].match;

if (lstat(path, &st))
die_errno(_("failed to stat '%s'"), path);
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
Expand Down Expand Up @@ -255,7 +258,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
struct rev_info rev;
struct object_array ent = OBJECT_ARRAY_INIT;
int blobs = 0, paths = 0;
const char *path = NULL;
struct blobinfo blob[2];
int nongit;
int result = 0;
Expand Down Expand Up @@ -366,13 +368,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
die(_("unhandled object '%s' given."), name);
}
}
if (rev.prune_data.nr) {
/* builtin_diff_b_f() */
GUARD_PATHSPEC(&rev.prune_data, PATHSPEC_FROMTOP | PATHSPEC_LITERAL);
if (!path)
path = rev.prune_data.items[0].match;
if (rev.prune_data.nr)
paths += rev.prune_data.nr;
}

/*
* Now, do the arguments look reasonable?
Expand All @@ -385,7 +382,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
case 1:
if (paths != 1)
usage(builtin_diff_usage);
result = builtin_diff_b_f(&rev, argc, argv, blob, path);
result = builtin_diff_b_f(&rev, argc, argv, blob);
break;
case 2:
if (paths)
Expand Down
6 changes: 6 additions & 0 deletions t/t6131-pathspec-icase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ test_expect_success 'match_pathspec_depth matches :(icase)bar with empty prefix'
test_cmp expect actual
'

test_expect_success '"git diff" can take magic :(icase) pathspec' '
echo FOO/BAR >expect &&
git diff --name-only HEAD^ HEAD -- ":(icase)foo/bar" >actual &&
test_cmp expect actual
'

test_done

0 comments on commit e2bcd4f

Please sign in to comment.