]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/diff-notice-has-drive-prefix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Oct 2018 06:43:45 +0000 (15:43 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Oct 2018 06:43:45 +0000 (15:43 +0900)
Under certain circumstances, "git diff D:/a/b/c D:/a/b/d" on
Windows would strip initial parts from the paths because they
were not recognized as absolute, which has been corrected.

* js/diff-notice-has-drive-prefix:
  diff: don't attempt to strip prefix from absolute Windows paths

diff.c
t/t4053-diff-no-index.sh

diff --git a/diff.c b/diff.c
index e82b6341ee539882a7f0a21322ab304070a47a23..8647db3d307c297448c91b328b1dabf19635fb94 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4302,12 +4302,12 @@ static void diff_fill_oid_info(struct diff_filespec *one, struct index_state *is
 static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
 {
        /* Strip the prefix but do not molest /dev/null and absolute paths */
-       if (*namep && **namep != '/') {
+       if (*namep && !is_absolute_path(*namep)) {
                *namep += prefix_length;
                if (**namep == '/')
                        ++*namep;
        }
-       if (*otherp && **otherp != '/') {
+       if (*otherp && !is_absolute_path(*otherp)) {
                *otherp += prefix_length;
                if (**otherp == '/')
                        ++*otherp;
index 453e6c35eb89fd82649401cb20a462c560a102cf..6e0dd6f9e5c482631147bb4770498dc4e7a8165f 100755 (executable)
@@ -127,4 +127,14 @@ test_expect_success 'diff --no-index from repo subdir respects config (implicit)
        test_cmp expect actual.head
 '
 
+test_expect_success 'diff --no-index from repo subdir with absolute paths' '
+       cat <<-EOF >expect &&
+       1       1       $(pwd)/non/git/{a => b}
+       EOF
+       test_expect_code 1 \
+               git -C repo/sub diff --numstat \
+               "$(pwd)/non/git/a" "$(pwd)/non/git/b" >actual &&
+       test_cmp expect actual
+'
+
 test_done