From: Junio C Hamano Date: Wed, 25 Apr 2018 04:29:00 +0000 (+0900) Subject: Merge branch 'ps/test-chmtime-get' X-Git-Tag: v2.18.0-rc0~116 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/deb9845a0a180d27caf581da2bc0c46f5288db6f?hp=-c Merge branch 'ps/test-chmtime-get' Test cleanup. * ps/test-chmtime-get: t/helper: 'test-chmtime (--get|-g)' to print only the mtime --- deb9845a0a180d27caf581da2bc0c46f5288db6f diff --combined t/helper/test-chmtime.c index 1790ceab51,611e9520a8..aa22af48c2 --- a/t/helper/test-chmtime.c +++ b/t/helper/test-chmtime.c @@@ -5,33 -5,42 +5,43 @@@ * * The mtime can be changed to an absolute value: * - * test-chmtime = file... + * test-tool chmtime = file... * * Relative to the current time as returned by time(3): * - * test-chmtime =+ (or =-) file... + * test-tool chmtime =+ (or =-) file... * * Or relative to the current mtime of the file: * - * test-chmtime file... - * test-chmtime + (or -) file... + * test-tool chmtime file... + * test-tool chmtime + (or -) file... * * Examples: * - * To just print the mtime use --verbose and set the file mtime offset to 0: + * To print the mtime and the file name use --verbose and set + * the file mtime offset to 0: * - * test-chmtime -v +0 file + * test-tool chmtime -v +0 file * + * To print only the mtime use --get: + * - * test-chmtime --get file ++ * test-tool chmtime --get file + * * To set the mtime to current time: * - * test-chmtime =+0 file + * test-tool chmtime =+0 file * + * To set the file mtime offset to +1 and print the new value: + * - * test-chmtime --get +1 file ++ * test-tool chmtime --get +1 file + * */ +#include "test-tool.h" #include "git-compat-util.h" #include - static const char usage_str[] = "-v|--verbose (+|=|=+|=-|-) ..."; + static const char usage_str[] = + "(-v|--verbose|-g|--get) (+|=|=+|=-|-) ..."; static int timespec_arg(const char *arg, long int *set_time, int *set_eq) { @@@ -47,7 -56,6 +57,6 @@@ } *set_time = strtol(timespec, &test, 10); if (*test) { - fprintf(stderr, "Not a base-10 integer: %s\n", arg + 1); return 0; } if ((*set_eq && *set_time < 0) || *set_eq == 2) { @@@ -57,9 -65,10 +66,10 @@@ return 1; } -int cmd_main(int argc, const char **argv) +int cmd__chmtime(int argc, const char **argv) { static int verbose; + static int get; int i = 1; /* no mtime change by default */ @@@ -69,18 -78,34 +79,34 @@@ if (argc < 3) goto usage; - if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) { + if (strcmp(argv[i], "--get") == 0 || strcmp(argv[i], "-g") == 0) { + get = 1; + ++i; + } else if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) { verbose = 1; ++i; } - if (timespec_arg(argv[i], &set_time, &set_eq)) + + if (i == argc) { + goto usage; + } + + if (timespec_arg(argv[i], &set_time, &set_eq)) { ++i; - else + } else { + if (get == 0) { + fprintf(stderr, "Not a base-10 integer: %s\n", argv[i] + 1); + goto usage; + } + } + + if (i == argc) goto usage; for (; i < argc; i++) { struct stat sb; struct utimbuf utb; + uintmax_t mtime; if (stat(argv[i], &sb) < 0) { fprintf(stderr, "Failed to stat %s: %s\n", @@@ -100,8 -125,10 +126,10 @@@ utb.actime = sb.st_atime; utb.modtime = set_eq ? set_time : sb.st_mtime + set_time; - if (verbose) { - uintmax_t mtime = utb.modtime < 0 ? 0: utb.modtime; + mtime = utb.modtime < 0 ? 0: utb.modtime; + if (get) { + printf("%"PRIuMAX"\n", mtime); + } else if (verbose) { printf("%"PRIuMAX"\t%s\n", mtime, argv[i]); } diff --combined t/t2022-checkout-paths.sh index e74d58b9e1,2a42083bf8..fc3eb43b89 --- a/t/t2022-checkout-paths.sh +++ b/t/t2022-checkout-paths.sh @@@ -68,13 -68,13 +68,13 @@@ test_expect_success 'do not touch file git add file1 file2 && git commit -m base && echo modified >file1 && - test-chmtime =1000000000 file2 && + test-tool chmtime =1000000000 file2 && git update-index -q --refresh && git checkout HEAD -- file1 file2 && echo one >expect && test_cmp expect file1 && - echo "1000000000 file2" >expect && - test-tool chmtime -v +0 file2 >actual && + echo "1000000000" >expect && - test-chmtime --get file2 >actual && ++ test-tool chmtime --get file2 >actual && test_cmp expect actual ' diff --combined t/t3404-rebase-interactive.sh index 756de26c19,6dfe77b18f..59c766540e --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@@ -225,14 -225,6 +225,14 @@@ test_expect_success 'stop on conflictin test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo) ' +test_expect_success 'show conflicted patch' ' + GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr && + grep "show.*REBASE_HEAD" stderr && + # the original stopped-sha1 is abbreviated + stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" && + test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1" +' + test_expect_success 'abort' ' git rebase --abort && test $(git rev-parse new-branch1) = $(git rev-parse HEAD) && @@@ -461,10 -453,6 +461,10 @@@ test_expect_success C_LOCALE_OUTPUT 'sq git rebase -i $base && git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup && test_cmp expect-squash-fixup actual-squash-fixup && + git cat-file commit HEAD@{2} | + grep "^# This is a combination of 3 commits\." && + git cat-file commit HEAD@{3} | + grep "^# This is a combination of 2 commits\." && git checkout to-be-rebased && git branch -D squash-fixup ' @@@ -711,13 -699,13 +711,13 @@@ test_expect_success 'rebase -i continu test_expect_success 'avoid unnecessary reset' ' git checkout master && git reset --hard && - test-chmtime =123456789 file3 && + test-tool chmtime =123456789 file3 && git update-index --refresh && HEAD=$(git rev-parse HEAD) && set_fake_editor && git rebase -i HEAD~4 && test $HEAD = $(git rev-parse HEAD) && - MTIME=$(test-tool chmtime -v +0 file3 | sed 's/[^0-9].*$//') && - MTIME=$(test-chmtime --get file3) && ++ MTIME=$(test-tool chmtime --get file3) && test 123456789 = $MTIME ' @@@ -927,8 -915,10 +927,8 @@@ test_expect_success 'rebase --exec work test_expect_success 'rebase -i --exec without ' ' git reset --hard execute && set_fake_editor && - test_must_fail git rebase -i --exec 2>tmp && - sed -e "1d" tmp >actual && - test_must_fail git rebase -h >expected && - test_cmp expected actual && + test_must_fail git rebase -i --exec 2>actual && + test_i18ngrep "requires a value" actual && git checkout master ' @@@ -1346,16 -1336,6 +1346,16 @@@ test_expect_success 'editor saves as CR SQ="'" test_expect_success 'rebase -i --gpg-sign=' ' + test_when_finished "test_might_fail git rebase --abort" && + set_fake_editor && + FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \ + >out 2>err && + test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err +' + +test_expect_success 'rebase -i --gpg-sign= overrides commit.gpgSign' ' + test_when_finished "test_might_fail git rebase --abort" && + test_config commit.gpgsign true && set_fake_editor && FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \ >out 2>err && diff --combined t/t3510-cherry-pick-sequence.sh index 9f93445f1e,34f2c7b49b..21b4f194a2 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@@ -247,9 -247,9 +247,9 @@@ test_expect_success '--abort after las test_expect_success 'cherry-pick does not implicitly stomp an existing operation' ' pristine_detach initial && test_expect_code 1 git cherry-pick base..anotherpick && - test-tool chmtime -v +0 .git/sequencer >expect && - test-chmtime --get .git/sequencer >expect && ++ test-tool chmtime --get .git/sequencer >expect && test_expect_code 128 git cherry-pick unrelatedpick && - test-tool chmtime -v +0 .git/sequencer >actual && - test-chmtime --get .git/sequencer >actual && ++ test-tool chmtime --get .git/sequencer >actual && test_cmp expect actual ' diff --combined t/t4200-rerere.sh index deafaa3e07,e49f9862c7..eaf18c81cb --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@@ -166,7 -166,7 +166,7 @@@ test_expect_success 'first postimage wi git commit -q -a -m "prefer first over second" && test -f $rr/postimage && - oldmtimepost=$(test-tool chmtime -v -60 $rr/postimage | cut -f 1) && - oldmtimepost=$(test-chmtime --get -60 $rr/postimage) && ++ oldmtimepost=$(test-tool chmtime --get -60 $rr/postimage) && git checkout -b third master && git show second^:a1 | sed "s/To die: t/To die! T/" >a1 && @@@ -179,7 -179,7 +179,7 @@@ ' test_expect_success 'rerere updates postimage timestamp' ' - newmtimepost=$(test-tool chmtime -v +0 $rr/postimage | cut -f 1) && - newmtimepost=$(test-chmtime --get $rr/postimage) && ++ newmtimepost=$(test-tool chmtime --get $rr/postimage) && test $oldmtimepost -lt $newmtimepost ' @@@ -220,9 -220,9 +220,9 @@@ test_expect_success 'set up for garbag almost_60_days_ago=$((60-60*86400)) && just_over_60_days_ago=$((-1-60*86400)) && - test-chmtime =$just_over_60_days_ago $rr/preimage && - test-chmtime =$almost_60_days_ago $rr/postimage && - test-chmtime =$almost_15_days_ago $rr2/preimage + test-tool chmtime =$just_over_60_days_ago $rr/preimage && + test-tool chmtime =$almost_60_days_ago $rr/postimage && + test-tool chmtime =$almost_15_days_ago $rr2/preimage ' test_expect_success 'gc preserves young or recently used records' ' @@@ -232,8 -232,8 +232,8 @@@ ' test_expect_success 'old records rest in peace' ' - test-chmtime =$just_over_60_days_ago $rr/postimage && - test-chmtime =$just_over_15_days_ago $rr2/preimage && + test-tool chmtime =$just_over_60_days_ago $rr/postimage && + test-tool chmtime =$just_over_15_days_ago $rr2/preimage && git rerere gc && ! test -f $rr/preimage && ! test -f $rr2/preimage @@@ -249,8 -249,8 +249,8 @@@ rerere_gc_custom_expiry_test () >"$rr/postimage" && two_days_ago=$((-2*86400)) && - test-chmtime =$two_days_ago "$rr/preimage" && - test-chmtime =$two_days_ago "$rr/postimage" && + test-tool chmtime =$two_days_ago "$rr/preimage" && + test-tool chmtime =$two_days_ago "$rr/postimage" && find .git/rr-cache -type f | sort >original && @@@ -512,7 -512,7 +512,7 @@@ test_expect_success 'multiple identica count_pre_post 2 0 && # Pretend that the conflicts were made quite some time ago - find .git/rr-cache/ -type f | xargs test-tool chmtime -172800 && - test-chmtime -172800 $(find .git/rr-cache/ -type f) && ++ test-tool chmtime -172800 $(find .git/rr-cache/ -type f) && # Unresolved entries have not expired yet git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc && @@@ -568,7 -568,7 +568,7 @@@ git rerere && # Pretend that the resolutions are old again - find .git/rr-cache/ -type f | xargs test-tool chmtime -172800 && - test-chmtime -172800 $(find .git/rr-cache/ -type f) && ++ test-tool chmtime -172800 $(find .git/rr-cache/ -type f) && # Resolved entries have not expired yet git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc && diff --combined t/t5000-tar-tree.sh index af4d9b8876,161a700af8..2a97b27b0a --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@@ -101,7 -101,7 +101,7 @@@ test_expect_success ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten && echo long filename >a/four$hundred && mkdir a/bin && - test-genrandom "frotz" 500000 >a/bin/sh && + test-tool genrandom "frotz" 500000 >a/bin/sh && printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && printf "A not substituted O" >a/substfile2 && if test_have_prereq SYMLINKS; then @@@ -192,7 -192,7 +192,7 @@@ test_expect_success 'validate file modification time' \ 'mkdir extract && "$TAR" xf b.tar -C extract a/a && - test-tool chmtime -v +0 extract/a/a |cut -f 1 >b.mtime && - test-chmtime --get extract/a/a >b.mtime && ++ test-tool chmtime --get extract/a/a >b.mtime && echo "1117231200" >expected.mtime && test_cmp expected.mtime b.mtime' diff --combined t/t6022-merge-rename.sh index a1fad6980b,206aea0cc5..48747e71df --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@@ -635,10 -635,9 +635,9 @@@ test_expect_success 'setup avoid unnece test_expect_success 'avoid unnecessary update, normal rename' ' git checkout -q avoid-unnecessary-update-1^0 && - test-tool chmtime =1000000000 rename && - test-tool chmtime -v +0 rename >expect && - test-chmtime --get =1000000000 rename >expect && ++ test-tool chmtime --get =1000000000 rename >expect && git merge merge-branch-1 && - test-tool chmtime -v +0 rename >actual && - test-chmtime --get rename >actual && ++ test-tool chmtime --get rename >actual && test_cmp expect actual # "rename" should have stayed intact ' @@@ -668,10 -667,9 +667,9 @@@ test_expect_success 'setup to test avoi test_expect_success 'avoid unnecessary update, with D/F conflict' ' git checkout -q avoid-unnecessary-update-2^0 && - test-tool chmtime =1000000000 df && - test-tool chmtime -v +0 df >expect && - test-chmtime --get =1000000000 df >expect && ++ test-tool chmtime --get =1000000000 df >expect && git merge merge-branch-2 && - test-tool chmtime -v +0 df >actual && - test-chmtime --get df >actual && ++ test-tool chmtime --get df >actual && test_cmp expect actual # "df" should have stayed intact ' @@@ -700,10 -698,9 +698,9 @@@ test_expect_success 'setup avoid unnece test_expect_success 'avoid unnecessary update, dir->(file,nothing)' ' git checkout -q master^0 && - test-tool chmtime =1000000000 df && - test-tool chmtime -v +0 df >expect && - test-chmtime --get =1000000000 df >expect && ++ test-tool chmtime --get =1000000000 df >expect && git merge side && - test-tool chmtime -v +0 df >actual && - test-chmtime --get df >actual && ++ test-tool chmtime --get df >actual && test_cmp expect actual # "df" should have stayed intact ' @@@ -730,10 -727,9 +727,9 @@@ test_expect_success 'setup avoid unnece test_expect_success 'avoid unnecessary update, modify/delete' ' git checkout -q master^0 && - test-tool chmtime =1000000000 file && - test-tool chmtime -v +0 file >expect && - test-chmtime --get =1000000000 file >expect && ++ test-tool chmtime --get =1000000000 file >expect && test_must_fail git merge side && - test-tool chmtime -v +0 file >actual && - test-chmtime --get file >actual && ++ test-tool chmtime --get file >actual && test_cmp expect actual # "file" should have stayed intact ' @@@ -759,10 -755,9 +755,9 @@@ test_expect_success 'setup avoid unnece test_expect_success 'avoid unnecessary update, rename/add-dest' ' git checkout -q master^0 && - test-tool chmtime =1000000000 newfile && - test-tool chmtime -v +0 newfile >expect && - test-chmtime --get =1000000000 newfile >expect && ++ test-tool chmtime --get =1000000000 newfile >expect && git merge side && - test-tool chmtime -v +0 newfile >actual && - test-chmtime --get newfile >actual && ++ test-tool chmtime --get newfile >actual && test_cmp expect actual # "file" should have stayed intact ' diff --combined t/t6501-freshen-objects.sh index 765cced60b,fa12bba985..033871ee5f --- a/t/t6501-freshen-objects.sh +++ b/t/t6501-freshen-objects.sh @@@ -72,8 -72,7 +72,7 @@@ for repack in '' true; d ' test_expect_success "simulate time passing ($title)" ' - find .git/objects -type f | - xargs test-tool chmtime -v -86400 - test-chmtime --get -86400 $(find .git/objects -type f) ++ test-tool chmtime --get -86400 $(find .git/objects -type f) ' test_expect_success "start writing new commit with old blob ($title)" ' @@@ -103,8 -102,7 +102,7 @@@ test_expect_success "abandon objects again ($title)" ' git reset --hard HEAD^ && - find .git/objects -type f | - xargs test-tool chmtime -v -86400 - test-chmtime --get -86400 $(find .git/objects -type f) ++ test-tool chmtime --get -86400 $(find .git/objects -type f) ' test_expect_success "start writing new commit with same tree ($title)" ' diff --combined t/t7508-status.sh index 7afadb175a,2e19d590e5..18a40257fb --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@@ -1672,12 -1672,12 +1672,12 @@@ test_expect_success '"Initial commit" s ' test_expect_success '--no-optional-locks prevents index update' ' - test-chmtime =1234567890 .git/index && + test-tool chmtime =1234567890 .git/index && git --no-optional-locks status && - test-tool chmtime -v +0 .git/index >out && - test-chmtime --get .git/index >out && ++ test-tool chmtime --get .git/index >out && grep ^1234567890 out && git status && - test-tool chmtime -v +0 .git/index >out && - test-chmtime --get .git/index >out && ++ test-tool chmtime --get .git/index >out && ! grep ^1234567890 out ' diff --combined t/t7701-repack-unpack-unreachable.sh index 8a586ab021,47f22555f1..48261ba080 --- a/t/t7701-repack-unpack-unreachable.sh +++ b/t/t7701-repack-unpack-unreachable.sh @@@ -55,8 -55,8 +55,8 @@@ test_expect_success '-A with -d option compare_mtimes () { - read tref rest && - while read t rest; do + read tref && + while read t; do test "$tref" = "$t" || return 1 done } @@@ -90,7 -90,7 +90,7 @@@ test_expect_success 'unpacked objects r tmppack=".git/objects/pack/tmp_pack" && ln "$packfile" "$tmppack" && git repack -A -l -d && - test-tool chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \ - test-chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \ ++ test-tool chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \ > mtimes && compare_mtimes < mtimes ' @@@ -103,7 -103,7 +103,7 @@@ test_expect_success 'do not bother loos git prune-packed && git cat-file -p $obj1 && git cat-file -p $obj2 && - test-chmtime =-86400 .git/objects/pack/pack-$pack2.pack && + test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack && git repack -A -d --unpack-unreachable=1.hour.ago && git cat-file -p $obj1 && test_must_fail git cat-file -p $obj2 @@@ -117,7 -117,7 +117,7 @@@ test_expect_success 'keep packed object git reset HEAD^ && git reflog expire --expire=now --all && git add file && - test-chmtime =-86400 .git/objects/pack/* && + test-tool chmtime =-86400 .git/objects/pack/* && git gc --prune=1.hour.ago && git cat-file blob :file '