2006-03-05 11:24:15 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Shawn Pearce
|
|
|
|
#
|
|
|
|
|
2007-07-03 09:52:14 +04:00
|
|
|
test_description='git checkout-index --temp test.
|
2006-03-05 11:24:15 +03:00
|
|
|
|
2007-07-03 09:52:14 +04:00
|
|
|
With --temp flag, git checkout-index writes to temporary merge files
|
2006-03-05 11:24:15 +03:00
|
|
|
rather than the tracked path.'
|
|
|
|
|
2021-10-12 16:56:41 +03:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2006-03-05 11:24:15 +03:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2014-12-24 12:43:12 +03:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
mkdir asubdir &&
|
|
|
|
echo tree1path0 >path0 &&
|
|
|
|
echo tree1path1 >path1 &&
|
|
|
|
echo tree1path3 >path3 &&
|
|
|
|
echo tree1path4 >path4 &&
|
|
|
|
echo tree1asubdir/path5 >asubdir/path5 &&
|
|
|
|
git update-index --add path0 path1 path3 path4 asubdir/path5 &&
|
|
|
|
t1=$(git write-tree) &&
|
|
|
|
rm -f path* .merge_* actual .git/index &&
|
|
|
|
echo tree2path0 >path0 &&
|
|
|
|
echo tree2path1 >path1 &&
|
|
|
|
echo tree2path2 >path2 &&
|
|
|
|
echo tree2path4 >path4 &&
|
|
|
|
git update-index --add path0 path1 path2 path4 &&
|
|
|
|
t2=$(git write-tree) &&
|
|
|
|
rm -f path* .merge_* actual .git/index &&
|
|
|
|
echo tree2path0 >path0 &&
|
|
|
|
echo tree3path1 >path1 &&
|
|
|
|
echo tree3path2 >path2 &&
|
|
|
|
echo tree3path3 >path3 &&
|
|
|
|
git update-index --add path0 path1 path2 path3 &&
|
|
|
|
t3=$(git write-tree)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout one stage 0 to temporary file' '
|
|
|
|
rm -f path* .merge_* actual .git/index &&
|
|
|
|
git read-tree $t1 &&
|
|
|
|
git checkout-index --temp -- path1 >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
test $(cut "-d " -f2 actual) = path1 &&
|
|
|
|
p=$(cut "-d " -f1 actual) &&
|
2006-03-05 11:24:15 +03:00
|
|
|
test -f $p &&
|
2014-12-24 12:43:12 +03:00
|
|
|
test $(cat $p) = tree1path1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout all stage 0 to temporary files' '
|
|
|
|
rm -f path* .merge_* actual .git/index &&
|
|
|
|
git read-tree $t1 &&
|
|
|
|
git checkout-index -a --temp >actual &&
|
|
|
|
test_line_count = 5 actual &&
|
|
|
|
for f in path0 path1 path3 path4 asubdir/path5
|
|
|
|
do
|
|
|
|
test $(grep $f actual | cut "-d " -f2) = $f &&
|
|
|
|
p=$(grep $f actual | cut "-d " -f1) &&
|
|
|
|
test -f $p &&
|
|
|
|
test $(cat $p) = tree1$f
|
|
|
|
done
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup 3-way merge' '
|
|
|
|
rm -f path* .merge_* actual .git/index &&
|
|
|
|
git read-tree -m $t1 $t2 $t3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout one stage 2 to temporary file' '
|
|
|
|
rm -f path* .merge_* actual &&
|
|
|
|
git checkout-index --stage=2 --temp -- path1 >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
test $(cut "-d " -f2 actual) = path1 &&
|
|
|
|
p=$(cut "-d " -f1 actual) &&
|
2006-03-05 11:24:15 +03:00
|
|
|
test -f $p &&
|
2014-12-24 12:43:12 +03:00
|
|
|
test $(cat $p) = tree2path1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout all stage 2 to temporary files' '
|
|
|
|
rm -f path* .merge_* actual &&
|
|
|
|
git checkout-index --all --stage=2 --temp >actual &&
|
|
|
|
test_line_count = 3 actual &&
|
|
|
|
for f in path1 path2 path4
|
|
|
|
do
|
|
|
|
test $(grep $f actual | cut "-d " -f2) = $f &&
|
|
|
|
p=$(grep $f actual | cut "-d " -f1) &&
|
|
|
|
test -f $p &&
|
|
|
|
test $(cat $p) = tree2$f
|
|
|
|
done
|
|
|
|
'
|
|
|
|
|
2020-10-27 10:37:14 +03:00
|
|
|
test_expect_success 'checkout all stages of unknown path' '
|
checkout-index: drop error message from empty --stage=all
If checkout-index is given --stage=all for a specific path, it will try
to write stages 1-3 (if present) for that path to temporary files.
However, if the file is present only at stage 0, it writes nothing but
gives a confusing message:
$ git checkout-index --stage=all -- Makefile
git checkout-index: Makefile does not exist at stage 4
This is nonsense. There is no stage 4 (it's just an internal enum value
we use for "all"), and the documentation clearly states:
Paths which only have a stage 0 entry will always be omitted from the
output.
Here it's talking about the list of tempfiles written to stdout, but it
seems clear that this case was not meant to be an error. We even have a
test which covers it, but it only checks that the command reports an
exit code of 0, not its stderr. And it reports 0 only because of another
bug which fails to propagate errors (which will be fixed in a subsequent
patch).
So let's make the test more thorough. We'll also cover the case that we
found _no_ entry, not even a stage zero, which should still be an error.
However, because of the other bug, we'll have to mark this as expecting
failure for the moment.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-27 10:36:02 +03:00
|
|
|
rm -f path* .merge_* actual &&
|
|
|
|
test_must_fail git checkout-index --stage=all --temp \
|
|
|
|
-- does-not-exist 2>stderr &&
|
|
|
|
test_i18ngrep not.in.the.cache stderr
|
|
|
|
'
|
|
|
|
|
2014-12-24 12:43:12 +03:00
|
|
|
test_expect_success 'checkout all stages/one file to nothing' '
|
|
|
|
rm -f path* .merge_* actual &&
|
checkout-index: drop error message from empty --stage=all
If checkout-index is given --stage=all for a specific path, it will try
to write stages 1-3 (if present) for that path to temporary files.
However, if the file is present only at stage 0, it writes nothing but
gives a confusing message:
$ git checkout-index --stage=all -- Makefile
git checkout-index: Makefile does not exist at stage 4
This is nonsense. There is no stage 4 (it's just an internal enum value
we use for "all"), and the documentation clearly states:
Paths which only have a stage 0 entry will always be omitted from the
output.
Here it's talking about the list of tempfiles written to stdout, but it
seems clear that this case was not meant to be an error. We even have a
test which covers it, but it only checks that the command reports an
exit code of 0, not its stderr. And it reports 0 only because of another
bug which fails to propagate errors (which will be fixed in a subsequent
patch).
So let's make the test more thorough. We'll also cover the case that we
found _no_ entry, not even a stage zero, which should still be an error.
However, because of the other bug, we'll have to mark this as expecting
failure for the moment.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-10-27 10:36:02 +03:00
|
|
|
git checkout-index --stage=all --temp -- path0 >actual 2>stderr &&
|
|
|
|
test_must_be_empty stderr &&
|
2014-12-24 12:43:12 +03:00
|
|
|
test_line_count = 0 actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout all stages/one file to temporary files' '
|
|
|
|
rm -f path* .merge_* actual &&
|
|
|
|
git checkout-index --stage=all --temp -- path1 >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
test $(cut "-d " -f2 actual) = path1 &&
|
|
|
|
cut "-d " -f1 actual | (read s1 s2 s3 &&
|
|
|
|
test -f $s1 &&
|
|
|
|
test -f $s2 &&
|
|
|
|
test -f $s3 &&
|
|
|
|
test $(cat $s1) = tree1path1 &&
|
|
|
|
test $(cat $s2) = tree2path1 &&
|
|
|
|
test $(cat $s3) = tree3path1)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout some stages/one file to temporary files' '
|
|
|
|
rm -f path* .merge_* actual &&
|
|
|
|
git checkout-index --stage=all --temp -- path2 >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
test $(cut "-d " -f2 actual) = path2 &&
|
|
|
|
cut "-d " -f1 actual | (read s1 s2 s3 &&
|
|
|
|
test $s1 = . &&
|
|
|
|
test -f $s2 &&
|
|
|
|
test -f $s3 &&
|
|
|
|
test $(cat $s2) = tree2path2 &&
|
|
|
|
test $(cat $s3) = tree3path2)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout all stages/all files to temporary files' '
|
|
|
|
rm -f path* .merge_* actual &&
|
|
|
|
git checkout-index -a --stage=all --temp >actual &&
|
|
|
|
test_line_count = 5 actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-- path0: no entry' '
|
|
|
|
test x$(grep path0 actual | cut "-d " -f2) = x
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-- path1: all 3 stages' '
|
|
|
|
test $(grep path1 actual | cut "-d " -f2) = path1 &&
|
|
|
|
grep path1 actual | cut "-d " -f1 | (read s1 s2 s3 &&
|
|
|
|
test -f $s1 &&
|
|
|
|
test -f $s2 &&
|
|
|
|
test -f $s3 &&
|
|
|
|
test $(cat $s1) = tree1path1 &&
|
|
|
|
test $(cat $s2) = tree2path1 &&
|
|
|
|
test $(cat $s3) = tree3path1)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-- path2: no stage 1, have stage 2 and 3' '
|
|
|
|
test $(grep path2 actual | cut "-d " -f2) = path2 &&
|
|
|
|
grep path2 actual | cut "-d " -f1 | (read s1 s2 s3 &&
|
|
|
|
test $s1 = . &&
|
|
|
|
test -f $s2 &&
|
|
|
|
test -f $s3 &&
|
|
|
|
test $(cat $s2) = tree2path2 &&
|
|
|
|
test $(cat $s3) = tree3path2)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-- path3: no stage 2, have stage 1 and 3' '
|
|
|
|
test $(grep path3 actual | cut "-d " -f2) = path3 &&
|
|
|
|
grep path3 actual | cut "-d " -f1 | (read s1 s2 s3 &&
|
|
|
|
test -f $s1 &&
|
|
|
|
test $s2 = . &&
|
|
|
|
test -f $s3 &&
|
|
|
|
test $(cat $s1) = tree1path3 &&
|
|
|
|
test $(cat $s3) = tree3path3)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-- path4: no stage 3, have stage 1 and 3' '
|
|
|
|
test $(grep path4 actual | cut "-d " -f2) = path4 &&
|
|
|
|
grep path4 actual | cut "-d " -f1 | (read s1 s2 s3 &&
|
|
|
|
test -f $s1 &&
|
|
|
|
test -f $s2 &&
|
|
|
|
test $s3 = . &&
|
|
|
|
test $(cat $s1) = tree1path4 &&
|
|
|
|
test $(cat $s2) = tree2path4)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '-- asubdir/path5: no stage 2 and 3 have stage 1' '
|
|
|
|
test $(grep asubdir/path5 actual | cut "-d " -f2) = asubdir/path5 &&
|
|
|
|
grep asubdir/path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
|
|
|
|
test -f $s1 &&
|
|
|
|
test $s2 = . &&
|
|
|
|
test $s3 = . &&
|
|
|
|
test $(cat $s1) = tree1asubdir/path5)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --temp within subdir' '
|
|
|
|
(
|
|
|
|
cd asubdir &&
|
|
|
|
git checkout-index -a --stage=all >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
test $(grep path5 actual | cut "-d " -f2) = path5 &&
|
|
|
|
grep path5 actual | cut "-d " -f1 | (read s1 s2 s3 &&
|
|
|
|
test -f ../$s1 &&
|
|
|
|
test $s2 = . &&
|
|
|
|
test $s3 = . &&
|
|
|
|
test $(cat ../$s1) = tree1asubdir/path5)
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --temp symlink' '
|
|
|
|
rm -f path* .merge_* actual .git/index &&
|
2014-12-24 12:43:14 +03:00
|
|
|
test_ln_s_add path7 path6 &&
|
2014-12-24 12:43:12 +03:00
|
|
|
git checkout-index --temp -a >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2014-12-24 12:43:14 +03:00
|
|
|
test $(cut "-d " -f2 actual) = path6 &&
|
2014-12-24 12:43:12 +03:00
|
|
|
p=$(cut "-d " -f1 actual) &&
|
|
|
|
test -f $p &&
|
2014-12-24 12:43:14 +03:00
|
|
|
test $(cat $p) = path7
|
2014-12-24 12:43:12 +03:00
|
|
|
'
|
2006-03-05 11:24:15 +03:00
|
|
|
|
checkout-index: fix --temp relative path mangling
checkout-index --temp only properly prints relative paths which are
descendants of the current directory. Paths in ancestor or sibling
directories (or their children) are often printed in mangled form. For
example:
mkdir a bbb &&
>file &&
>bbb/file &&
git update-index --add file bbb/file &&
cd a &&
git checkout-index --temp ../file ../bbb/file
prints:
.merge_file_ooblek le
.merge_file_igloo0 b/file
rather than the correct:
.merge_file_ooblek ../file
.merge_file_igloo0 ../bbb/file
Internally, given the above example, checkout-index prefixes each input
argument with the name of the current directory ("a/", in this case),
and then assumes that it can simply skip forward by strlen("a/") bytes
to recover the original name. This works for files in the current
directory or its descendants, but fails for files in ancestors or
siblings (or their children) due to path normalization.
For instance, given "../file", "a/" is prepended, giving "a/../file".
Path normalization folds out "a/../", resulting in "file". Attempting
to recover the original name by skipping strlen("a/") bytes gives the
incorrect "le" rather than the desired "../file".
Fix this by taking advantage of write_name_quoted_relative() to recover
the original name properly, rather than assuming that it can be
recovered by skipping strlen(prefix) bytes.
As a bonus, this also fixes a bug in which checkout-index --temp
accessed and printed memory beyond the end-of-string. For instance,
within a subdirectory named "subdirectory", and given argument
"../file", prefixing would give "subdirectory/../file", which would
become "file" after normalization. checkout-index would then attempt to
recover the original name by skipping strlen("subdirectory/") bytes of
"file", which placed it well beyond end-of-string. Despite this error,
it often appeared to give the correct result, but only due to an
accident of implementation which left an apparently correct copy of the
path in memory following the normalized value. In particular, handed
"subdirectory/../file", in-place processing by normalize_path_copy_len()
resulted in "file\0rectory/../file". When checkout-index skipped
strlen("subdirectory/") bytes, it ended up back at "../file" and thus
appeared to give the correct answer, despite being past end-of-string.
Reported-by: Russ Cox <rsc@golang.org>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-24 12:43:16 +03:00
|
|
|
test_expect_success 'emit well-formed relative path' '
|
2014-12-24 12:43:15 +03:00
|
|
|
rm -f path* .merge_* actual .git/index &&
|
|
|
|
>path0123456789 &&
|
|
|
|
git update-index --add path0123456789 &&
|
|
|
|
(
|
|
|
|
cd asubdir &&
|
|
|
|
git checkout-index --temp -- ../path0123456789 >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
|
|
|
test $(cut "-d " -f2 actual) = ../path0123456789
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2006-03-05 11:24:15 +03:00
|
|
|
test_done
|