diff: handle relative paths in no-index
When diff-no-index is given a relative path to a file outside the repository, it aborts with error. However, if the file is given using an absolute path, the diff runs as expected. The two cases should be treated the same. Tests and commit message by Tim Henigan. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Tim Henigan <tim.henigan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
785ee4960c
commit
546e0fd9e9
@ -151,23 +151,6 @@ static int queue_diff(struct diff_options *o,
|
||||
}
|
||||
}
|
||||
|
||||
static int path_outside_repo(const char *path)
|
||||
{
|
||||
const char *work_tree;
|
||||
size_t len;
|
||||
|
||||
if (!is_absolute_path(path))
|
||||
return 0;
|
||||
work_tree = get_git_work_tree();
|
||||
if (!work_tree)
|
||||
return 1;
|
||||
len = strlen(work_tree);
|
||||
if (strncmp(path, work_tree, len) ||
|
||||
(path[len] != '\0' && path[len] != '/'))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void diff_no_index(struct rev_info *revs,
|
||||
int argc, const char **argv,
|
||||
int nongit, const char *prefix)
|
||||
@ -197,8 +180,8 @@ void diff_no_index(struct rev_info *revs,
|
||||
* a colourful "diff" replacement.
|
||||
*/
|
||||
if ((argc != i + 2) ||
|
||||
(!path_outside_repo(argv[i]) &&
|
||||
!path_outside_repo(argv[i+1])))
|
||||
(path_inside_repo(prefix, argv[i]) &&
|
||||
path_inside_repo(prefix, argv[i+1])))
|
||||
return;
|
||||
}
|
||||
if (argc != i + 2)
|
||||
|
Reference in New Issue
Block a user