diff options
Diffstat (limited to 't')
33 files changed, 1255 insertions, 177 deletions
diff --git a/t/helper/test-hashmap.c b/t/helper/test-hashmap.c index f38706216f..36ff07bd4b 100644 --- a/t/helper/test-hashmap.c +++ b/t/helper/test-hashmap.c @@ -110,7 +110,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) hashmap_add(&map, &entries[i]->ent); } - hashmap_free(&map); + hashmap_clear(&map); } } else { /* test map lookups */ @@ -130,7 +130,7 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) } } - hashmap_free(&map); + hashmap_clear(&map); } } @@ -151,12 +151,11 @@ static void perf_hashmap(unsigned int method, unsigned int rounds) int cmd__hashmap(int argc, const char **argv) { struct strbuf line = STRBUF_INIT; - struct hashmap map; int icase; + struct hashmap map = HASHMAP_INIT(test_entry_cmp, &icase); /* init hash map */ icase = argc > 1 && !strcmp("ignorecase", argv[1]); - hashmap_init(&map, test_entry_cmp, &icase, 0); /* process commands from stdin */ while (strbuf_getline(&line, stdin) != EOF) { @@ -262,6 +261,6 @@ int cmd__hashmap(int argc, const char **argv) } strbuf_release(&line); - hashmap_free_entries(&map, struct test_entry, ent); + hashmap_clear_and_free(&map, struct test_entry, ent); return 0; } diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c index 42164d9898..cc08506cf0 100644 --- a/t/helper/test-proc-receive.c +++ b/t/helper/test-proc-receive.c @@ -10,8 +10,11 @@ static const char *proc_receive_usage[] = { NULL }; -static int die_version; -static int die_readline; +static int die_read_version; +static int die_write_version; +static int die_read_commands; +static int die_read_push_options; +static int die_write_report; static int no_push_options; static int use_atomic; static int use_push_options; @@ -33,14 +36,23 @@ struct command { static void proc_receive_verison(struct packet_reader *reader) { int server_version = 0; + if (die_read_version) + die("die with the --die-read-version option"); + for (;;) { int linelen; if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; + /* Ignore version negotiation for version 0 */ + if (version == 0) + continue; + if (reader->pktlen > 8 && starts_with(reader->line, "version=")) { server_version = atoi(reader->line+8); + if (server_version != 1) + die("bad protocol version: %d", server_version); linelen = strlen(reader->line); if (linelen < reader->pktlen) { const char *feature_list = reader->line + linelen + 1; @@ -52,12 +64,13 @@ static void proc_receive_verison(struct packet_reader *reader) { } } - if (server_version != 1 || die_version) - die("bad protocol version: %d", server_version); + if (die_write_version) + die("die with the --die-write-version option"); - packet_write_fmt(1, "version=%d%c%s\n", - version, '\0', - use_push_options && !no_push_options ? "push-options": ""); + if (version != 0) + packet_write_fmt(1, "version=%d%c%s\n", + version, '\0', + use_push_options && !no_push_options ? "push-options": ""); packet_flush(1); } @@ -75,11 +88,13 @@ static void proc_receive_read_commands(struct packet_reader *reader, if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; + if (die_read_commands) + die("die with the --die-read-commands option"); + if (parse_oid_hex(reader->line, &old_oid, &p) || *p++ != ' ' || parse_oid_hex(p, &new_oid, &p) || - *p++ != ' ' || - die_readline) + *p++ != ' ') die("protocol error: expected 'old new ref', got '%s'", reader->line); refname = p; @@ -99,6 +114,9 @@ static void proc_receive_read_push_options(struct packet_reader *reader, if (no_push_options || !use_push_options) return; + if (die_read_push_options) + die("die with the --die-read-push-options option"); + while (1) { if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; @@ -117,10 +135,16 @@ int cmd__proc_receive(int argc, const char **argv) struct option options[] = { OPT_BOOL(0, "no-push-options", &no_push_options, "disable push options"), - OPT_BOOL(0, "die-version", &die_version, - "die during version negotiation"), - OPT_BOOL(0, "die-readline", &die_readline, - "die when readline"), + OPT_BOOL(0, "die-read-version", &die_read_version, + "die when reading version"), + OPT_BOOL(0, "die-write-version", &die_write_version, + "die when writing version"), + OPT_BOOL(0, "die-read-commands", &die_read_commands, + "die when reading commands"), + OPT_BOOL(0, "die-read-push-options", &die_read_push_options, + "die when reading push-options"), + OPT_BOOL(0, "die-write-report", &die_write_report, + "die when writing report"), OPT_STRING_LIST('r', "return", &returns, "old/new/ref/status/msg", "return of results"), OPT__VERBOSE(&verbose, "be verbose"), @@ -136,7 +160,7 @@ int cmd__proc_receive(int argc, const char **argv) usage_msg_opt("Too many arguments.", proc_receive_usage, options); packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE | - PACKET_READ_DIE_ON_ERR_PACKET); + PACKET_READ_GENTLE_ON_EOF); sigchain_push(SIGPIPE, SIG_IGN); proc_receive_verison(&reader); @@ -166,6 +190,8 @@ int cmd__proc_receive(int argc, const char **argv) fprintf(stderr, "proc-receive> %s\n", item->string); } + if (die_write_report) + die("die with the --die-write-report option"); if (returns.nr) for_each_string_list_item(item, &returns) packet_write_fmt(1, "%s\n", item->string); diff --git a/t/perf/p1400-update-ref.sh b/t/perf/p1400-update-ref.sh index ce5ac3ed85..dda8a74866 100755 --- a/t/perf/p1400-update-ref.sh +++ b/t/perf/p1400-update-ref.sh @@ -7,13 +7,14 @@ test_description="Tests performance of update-ref" test_perf_fresh_repo test_expect_success "setup" ' - git init --bare target-repo.git && test_commit PRE && test_commit POST && - printf "create refs/heads/%d PRE\n" $(test_seq 1000) >create && - printf "update refs/heads/%d POST PRE\n" $(test_seq 1000) >update && - printf "delete refs/heads/%d POST\n" $(test_seq 1000) >delete && - git update-ref --stdin <create + for i in $(test_seq 5000) + do + printf "start\ncreate refs/heads/%d PRE\ncommit\n" $i && + printf "start\nupdate refs/heads/%d POST PRE\ncommit\n" $i && + printf "start\ndelete refs/heads/%d POST\ncommit\n" $i + done >instructions ' test_perf "update-ref" ' @@ -26,14 +27,7 @@ test_perf "update-ref" ' ' test_perf "update-ref --stdin" ' - git update-ref --stdin <update && - git update-ref --stdin <delete && - git update-ref --stdin <create -' - -test_perf "nonatomic push" ' - git push ./target-repo.git $(test_seq 1000) && - git push --delete ./target-repo.git $(test_seq 1000) + git update-ref --stdin <instructions >/dev/null ' test_done diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 22489c24dc..f4ba2e8c85 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -840,6 +840,27 @@ then exit 1 fi +test_lazy_prereq NESTED_INNER ' + >inner && + rm -f outer +' +test_lazy_prereq NESTED_PREREQ ' + >outer && + test_have_prereq NESTED_INNER && + echo "can create new file in cwd" >file && + test -f outer && + test ! -f inner +' +test_expect_success NESTED_PREREQ 'evaluating nested lazy prereqs dont interfere with each other' ' + nestedworks=yes +' + +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" && test "$nestedworks" != yes +then + say 'bug in test framework: nested lazy prerequisites do not work' + exit 1 +fi + test_expect_success 'lazy prereqs do not turn off tracing' " run_sub_test_lib_test lazy-prereq-and-tracing \ 'lazy prereqs and -x' -v -x <<-\\EOF && diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 825d9a184f..97a04c6cc2 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1917,4 +1917,153 @@ test_expect_success '--replace-all does not invent newlines' ' test_cmp expect .git/config ' +test_expect_success 'set all config with value-pattern' ' + test_when_finished rm -f config initial && + git config --file=initial abc.key one && + + # no match => add new entry + cp initial config && + git config --file=config abc.key two a+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=one + abc.key=two + EOF + test_cmp expect actual && + + # multiple matches => failure + test_must_fail git config --file=config abc.key three o+ 2>err && + test_i18ngrep "has multiple values" err && + + # multiple values, no match => add + git config --file=config abc.key three a+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=one + abc.key=two + abc.key=three + EOF + test_cmp expect actual && + + # single match => replace + git config --file=config abc.key four h+ && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=one + abc.key=two + abc.key=four + EOF + test_cmp expect actual +' + +test_expect_success '--replace-all and value-pattern' ' + test_when_finished rm -f config && + git config --file=config --add abc.key one && + git config --file=config --add abc.key two && + git config --file=config --add abc.key three && + git config --file=config --replace-all abc.key four "o+" && + git config --file=config --list >actual && + cat >expect <<-\EOF && + abc.key=four + abc.key=three + EOF + test_cmp expect actual +' + +test_expect_success 'refuse --fixed-value for incompatible actions' ' + test_when_finished rm -f config && + git config --file=config dev.null bogus && + + # These modes do not allow --fixed-value at all + test_must_fail git config --file=config --fixed-value --add dev.null bogus && + test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && + test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && + test_must_fail git config --file=config --fixed-value --rename-section dev null && + test_must_fail git config --file=config --fixed-value --remove-section dev && + test_must_fail git config --file=config --fixed-value --list && + test_must_fail git config --file=config --fixed-value --get-color dev.null && + test_must_fail git config --file=config --fixed-value --get-colorbool dev.null && + + # These modes complain when --fixed-value has no value-pattern + test_must_fail git config --file=config --fixed-value dev.null bogus && + test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus && + test_must_fail git config --file=config --fixed-value --get dev.null && + test_must_fail git config --file=config --fixed-value --get-all dev.null && + test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" && + test_must_fail git config --file=config --fixed-value --unset dev.null && + test_must_fail git config --file=config --fixed-value --unset-all dev.null +' + +test_expect_success '--fixed-value uses exact string matching' ' + test_when_finished rm -f config initial && + META="a+b*c?d[e]f.g" && + git config --file=initial fixed.test "$META" && + + cp initial config && + git config --file=config fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$META + fixed.test=bogus + EOF + test_cmp expect actual && + + cp initial config && + git config --file=config --fixed-value fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-\EOF && + fixed.test=bogus + EOF + test_cmp expect actual && + + cp initial config && + test_must_fail git config --file=config --unset fixed.test "$META" && + git config --file=config --fixed-value --unset fixed.test "$META" && + test_must_fail git config --file=config fixed.test && + + cp initial config && + test_must_fail git config --file=config --unset-all fixed.test "$META" && + git config --file=config --fixed-value --unset-all fixed.test "$META" && + test_must_fail git config --file=config fixed.test && + + cp initial config && + git config --file=config --replace-all fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=$META + fixed.test=bogus + EOF + test_cmp expect actual && + + git config --file=config --fixed-value --replace-all fixed.test bogus "$META" && + git config --file=config --list >actual && + cat >expect <<-EOF && + fixed.test=bogus + fixed.test=bogus + EOF + test_cmp expect actual +' + +test_expect_success '--get and --get-all with --fixed-value' ' + test_when_finished rm -f config && + META="a+b*c?d[e]f.g" && + git config --file=config fixed.test bogus && + git config --file=config --add fixed.test "$META" && + + git config --file=config --get fixed.test bogus && + test_must_fail git config --file=config --get fixed.test "$META" && + git config --file=config --get --fixed-value fixed.test "$META" && + test_must_fail git config --file=config --get --fixed-value fixed.test non-existent && + + git config --file=config --get-all fixed.test bogus && + test_must_fail git config --file=config --get-all fixed.test "$META" && + git config --file=config --get-all --fixed-value fixed.test "$META" && + test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent && + + git config --file=config --get-regexp fixed+ bogus && + test_must_fail git config --file=config --get-regexp fixed+ "$META" && + git config --file=config --get-regexp --fixed-value fixed+ "$META" && + test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent +' + test_done diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index ebb8e1aecb..b4a9158307 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -91,11 +91,11 @@ test_expect_failure 'ignore .git/ with invalid config' ' test_expect_success 'early config and onbranch' ' echo "[broken" >broken && - test_with_config "[includeif \"onbranch:master\"]path=../broken" + test_with_config "[includeif \"onbranch:topic\"]path=../broken" ' test_expect_success 'onbranch config outside of git repo' ' - test_config_global includeIf.onbranch:master.path non-existent && + test_config_global includeIf.onbranch:topic.path non-existent && nongit git help ' diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 4c01e08551..31b64be521 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -48,17 +48,17 @@ test_expect_success "fail to delete $m with stale ref" ' test $B = "$(git show-ref -s --verify $m)" ' test_expect_success "delete $m" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && git update-ref -d $m $B && - test_path_is_missing .git/$m + test_must_fail git show-ref --verify -q $m ' test_expect_success "delete $m without oldvalue verification" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && git update-ref $m $A && test $A = $(git show-ref -s --verify $m) && git update-ref -d $m && - test_path_is_missing .git/$m + test_must_fail git show-ref --verify -q $m ' test_expect_success "fail to create $n" ' @@ -80,26 +80,26 @@ test_expect_success "fail to delete $m (by HEAD) with stale ref" ' test $B = $(git show-ref -s --verify $m) ' test_expect_success "delete $m (by HEAD)" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && git update-ref -d HEAD $B && - test_path_is_missing .git/$m + test_must_fail git show-ref --verify -q $m ' test_expect_success "deleting current branch adds message to HEAD's log" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && git update-ref $m $A && git symbolic-ref HEAD $m && git update-ref -m delete-$m -d $m && - test_path_is_missing .git/$m && + test_must_fail git show-ref --verify -q $m && grep "delete-$m$" .git/logs/HEAD ' test_expect_success "deleting by HEAD adds message to HEAD's log" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && git update-ref $m $A && git symbolic-ref HEAD $m && git update-ref -m delete-by-head -d HEAD && - test_path_is_missing .git/$m && + test_must_fail git show-ref --verify -q $m && grep "delete-by-head$" .git/logs/HEAD ' @@ -188,31 +188,37 @@ test_expect_success "move $m (by HEAD)" ' test $B = $(git show-ref -s --verify $m) ' test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && git update-ref -d HEAD $B && ! grep "$m" .git/packed-refs && - test_path_is_missing .git/$m + test_must_fail git show-ref --verify -q $m ' -cp -f .git/HEAD .git/HEAD.orig test_expect_success 'delete symref without dereference' ' - test_when_finished "cp -f .git/HEAD.orig .git/HEAD" && - git update-ref --no-deref -d HEAD && - test_path_is_missing .git/HEAD + test_when_finished "git update-ref -d $m" && + echo foo >foo.c && + git add foo.c && + git commit -m foo && + git symbolic-ref SYMREF $m && + git update-ref --no-deref -d SYMREF && + git show-ref --verify -q $m && + test_must_fail git show-ref --verify -q SYMREF && + test_must_fail git symbolic-ref SYMREF ' test_expect_success 'delete symref without dereference when the referred ref is packed' ' - test_when_finished "cp -f .git/HEAD.orig .git/HEAD" && + test_when_finished "git update-ref -d $m" && echo foo >foo.c && git add foo.c && git commit -m foo && + git symbolic-ref SYMREF $m && git pack-refs --all && - git update-ref --no-deref -d HEAD && - test_path_is_missing .git/HEAD + git update-ref --no-deref -d SYMREF && + git show-ref --verify -q $m && + test_must_fail git show-ref --verify -q SYMREF && + test_must_fail git symbolic-ref SYMREF ' -git update-ref -d $m - test_expect_success 'update-ref -d is not confused by self-reference' ' git symbolic-ref refs/heads/self refs/heads/self && test_when_finished "rm -f .git/refs/heads/self" && @@ -226,25 +232,25 @@ test_expect_success 'update-ref --no-deref -d can delete self-reference' ' test_when_finished "rm -f .git/refs/heads/self" && test_path_is_file .git/refs/heads/self && git update-ref --no-deref -d refs/heads/self && - test_path_is_missing .git/refs/heads/self + test_must_fail git show-ref --verify -q refs/heads/self ' test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' ' >.git/refs/heads/bad && test_when_finished "rm -f .git/refs/heads/bad" && git symbolic-ref refs/heads/ref-to-bad refs/heads/bad && - test_when_finished "rm -f .git/refs/heads/ref-to-bad" && + test_when_finished "git update-ref -d refs/heads/ref-to-bad" && test_path_is_file .git/refs/heads/ref-to-bad && git update-ref --no-deref -d refs/heads/ref-to-bad && - test_path_is_missing .git/refs/heads/ref-to-bad + test_must_fail git show-ref --verify -q refs/heads/ref-to-bad ' test_expect_success '(not) create HEAD with old sha1' ' test_must_fail git update-ref HEAD $A $B ' test_expect_success "(not) prior created .git/$m" ' - test_when_finished "rm -f .git/$m" && - test_path_is_missing .git/$m + test_when_finished "git update-ref -d $m" && + test_must_fail git show-ref --verify -q $m ' test_expect_success 'create HEAD' ' @@ -254,7 +260,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' ' test_must_fail git update-ref HEAD $B $Z ' test_expect_success "(not) changed .git/$m" ' - test_when_finished "rm -f .git/$m" && + test_when_finished "git update-ref -d $m" && ! test $B = $(git show-ref -s --verify $m) ' @@ -284,8 +290,8 @@ test_expect_success 'empty directory removal' ' test_path_is_file .git/refs/heads/d1/d2/r1 && test_path_is_file .git/logs/refs/heads/d1/d2/r1 && git branch -d d1/d2/r1 && - test_path_is_missing .git/refs/heads/d1/d2 && - test_path_is_missing .git/logs/refs/heads/d1/d2 && + test_must_fail git show-ref --verify -q refs/heads/d1/d2 && + test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 && test_path_is_file .git/refs/heads/d1/r2 && test_path_is_file .git/logs/refs/heads/d1/r2 ' @@ -298,8 +304,8 @@ test_expect_success 'symref empty directory removal' ' test_path_is_file .git/refs/heads/e1/e2/r1 && test_path_is_file .git/logs/refs/heads/e1/e2/r1 && git update-ref -d HEAD && - test_path_is_missing .git/refs/heads/e1/e2 && - test_path_is_missing .git/logs/refs/heads/e1/e2 && + test_must_fail git show-ref --verify -q refs/heads/e1/e2 && + test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 && test_path_is_file .git/refs/heads/e1/r2 && test_path_is_file .git/logs/refs/heads/e1/r2 && test_path_is_file .git/logs/HEAD @@ -1388,7 +1394,8 @@ test_expect_success 'handle per-worktree refs in refs/bisect' ' git rev-parse refs/bisect/something >../worktree-head && git for-each-ref | grep refs/bisect/something ) && - test_path_is_missing .git/refs/bisect && + git show-ref >actual && + ! grep 'refs/bisect' actual && test_must_fail git rev-parse refs/bisect/something && git update-ref refs/bisect/something HEAD && git rev-parse refs/bisect/something >main-head && @@ -1500,7 +1507,7 @@ test_expect_success 'transaction can handle abort' ' git update-ref --stdin <stdin >actual && printf "%s: ok\n" start abort >expect && test_cmp expect actual && - test_path_is_missing .git/$b + test_must_fail git show-ref --verify -q $b ' test_expect_success 'transaction aborts by default' ' @@ -1511,7 +1518,7 @@ test_expect_success 'transaction aborts by default' ' git update-ref --stdin <stdin >actual && printf "%s: ok\n" start >expect && test_cmp expect actual && - test_path_is_missing .git/$b + test_must_fail git show-ref --verify -q $b ' test_expect_success 'transaction with prepare aborts by default' ' @@ -1523,7 +1530,68 @@ test_expect_success 'transaction with prepare aborts by default' ' git update-ref --stdin <stdin >actual && printf "%s: ok\n" start prepare >expect && test_cmp expect actual && - test_path_is_missing .git/$b + test_must_fail git show-ref --verify -q $b +' + +test_expect_success 'transaction can commit multiple times' ' + cat >stdin <<-EOF && + start + create refs/heads/branch-1 $A + commit + start + create refs/heads/branch-2 $B + commit + EOF + git update-ref --stdin <stdin >actual && + printf "%s: ok\n" start commit start commit >expect && + test_cmp expect actual && + echo "$A" >expect && + git rev-parse refs/heads/branch-1 >actual && + test_cmp expect actual && + echo "$B" >expect && + git rev-parse refs/heads/branch-2 >actual && + test_cmp expect actual +' + +test_expect_success 'transaction can create and delete' ' + cat >stdin <<-EOF && + start + create refs/heads/create-and-delete $A + commit + start + delete refs/heads/create-and-delete $A + commit + EOF + git update-ref --stdin <stdin >actual && + printf "%s: ok\n" start commit start commit >expect && + test_must_fail git show-ref --verify refs/heads/create-and-delete +' + +test_expect_success 'transaction can commit after abort' ' + cat >stdin <<-EOF && + start + create refs/heads/abort $A + abort + start + create refs/heads/abort $A + commit + EOF + git update-ref --stdin <stdin >actual && + printf "%s: ok\n" start abort start commit >expect && + echo "$A" >expect && + git rev-parse refs/heads/abort >actual && + test_cmp expect actual +' + +test_expect_success 'transaction cannot restart ongoing transaction' ' + cat >stdin <<-EOF && + start + create refs/heads/restart $A + start + commit + EOF + test_must_fail git update-ref --stdin <stdin >actual && + test_must_fail git show-ref --verify refs/heads/restart ' test_done diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh index 492edffa9c..dc9fe3cbf1 100755 --- a/t/t1503-rev-parse-verify.sh +++ b/t/t1503-rev-parse-verify.sh @@ -144,4 +144,17 @@ test_expect_success SYMLINKS 'ref resolution not confused by broken symlinks' ' test_must_fail git rev-parse --verify broken ' +test_expect_success 'options can appear after --verify' ' + git rev-parse --verify HEAD >expect && + git rev-parse --verify -q HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'verify respects --end-of-options' ' + git update-ref refs/heads/-tricky HEAD && + git rev-parse --verify HEAD >expect && + git rev-parse --verify --end-of-options -tricky >actual && + test_cmp expect actual +' + test_done diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh index 3e657e693b..e2ae15a2cf 100755 --- a/t/t1506-rev-parse-diagnosis.sh +++ b/t/t1506-rev-parse-diagnosis.sh @@ -254,4 +254,29 @@ test_expect_success 'escaped char does not trigger wildcard rule' ' test_must_fail git rev-parse "foo\\*bar" ' +test_expect_success 'arg after dashdash not interpreted as option' ' + cat >expect <<-\EOF && + -- + --local-env-vars + EOF + git rev-parse -- --local-env-vars >actual && + test_cmp expect actual +' + +test_expect_success 'arg after end-of-options not interpreted as option' ' + test_must_fail git rev-parse --end-of-options --not-real -- 2>err && + test_i18ngrep bad.revision.*--not-real err +' + +test_expect_success 'end-of-options still allows --' ' + cat >expect <<-EOF && + --end-of-options + $(git rev-parse --verify HEAD) + -- + path + EOF + git rev-parse --end-of-options HEAD -- path >actual && + test_cmp expect actual +' + test_done diff --git a/t/t2106-update-index-assume-unchanged.sh b/t/t2106-update-index-assume-unchanged.sh index 99d858c6b7..2d450daf5c 100755 --- a/t/t2106-update-index-assume-unchanged.sh +++ b/t/t2106-update-index-assume-unchanged.sh @@ -5,20 +5,23 @@ test_description='git update-index --assume-unchanged test. . ./test-lib.sh -test_expect_success 'setup' \ - ': >file && - git add file && - git commit -m initial && - git branch other && - echo upstream >file && - git add file && - git commit -m upstream' +test_expect_success 'setup' ' + : >file && + git add file && + git commit -m initial && + git branch other && + echo upstream >file && + git add file && + git commit -m upstream +' -test_expect_success 'do not switch branches with dirty file' \ - 'git reset --hard && - git checkout other && - echo dirt >file && - git update-index --assume-unchanged file && - test_must_fail git checkout master' +test_expect_success 'do not switch branches with dirty file' ' + git reset --hard && + git checkout other && + echo dirt >file && + git update-index --assume-unchanged file && + test_must_fail git checkout - 2>err && + test_i18ngrep overwritten err +' test_done diff --git a/t/t3040-subprojects-basic.sh b/t/t3040-subprojects-basic.sh index b81eb5fd6f..6abdcbbc94 100755 --- a/t/t3040-subprojects-basic.sh +++ b/t/t3040-subprojects-basic.sh @@ -79,7 +79,4 @@ test_expect_success 'checkout in superproject' ' git diff-index --exit-code --raw --cached save -- sub1 ' -# just interesting what happened... -# git diff --name-status -M save master - test_done diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index 8f43303007..ca60faf480 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -672,6 +672,11 @@ test_expect_success 'notes.displayRef respects order' ' test_cmp expect-both-reversed actual ' +test_expect_success 'notes.displayRef with no value handled gracefully' ' + test_must_fail git -c notes.displayRef log -0 --notes && + test_must_fail git -c notes.displayRef diff-tree --notes HEAD +' + test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ git log -2 >actual && diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 1e56696e4f..b06fc36159 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -12,7 +12,7 @@ Initial setup: one - two - three - four (conflict-branch) / - A - B - C - D - E (master) + A - B - C - D - E (primary) | \ | F - G - H (branch1) | \ @@ -30,6 +30,7 @@ Initial setup: . "$TEST_DIRECTORY"/lib-rebase.sh test_expect_success 'setup' ' + git switch -C primary && test_commit A file1 && test_commit B file1 && test_commit C file2 && @@ -65,7 +66,7 @@ SHELL= export SHELL test_expect_success 'rebase --keep-empty' ' - git checkout -b emptybranch master && + git checkout -b emptybranch primary && git commit --allow-empty -m "empty" && git rebase --keep-empty -i HEAD~2 && git log --oneline >actual && @@ -86,7 +87,7 @@ test_expect_success 'rebase -i with empty todo list' ' ' test_expect_success 'rebase -i with the exec command' ' - git checkout master && + git checkout primary && ( set_fake_editor && FAKE_LINES="1 exec_>touch-one @@ -103,12 +104,12 @@ test_expect_success 'rebase -i with the exec command' ' test_path_is_file touch-three && test_path_is_file "touch-file name with spaces" && test_path_is_file touch-after-semicolon && - test_cmp_rev master HEAD && + test_cmp_rev primary HEAD && rm -f touch-* ' test_expect_success 'rebase -i with the exec command runs from tree root' ' - git checkout master && + git checkout primary && mkdir subdir && (cd subdir && set_fake_editor && FAKE_LINES="1 exec_>touch-subdir" \ @@ -121,7 +122,7 @@ test_expect_success 'rebase -i with the exec command runs from tree root' ' test_expect_success 'rebase -i with exec allows git commands in subdirs' ' test_when_finished "rm -rf subdir" && test_when_finished "git rebase --abort ||:" && - git checkout master && + git checkout primary && mkdir subdir && (cd subdir && set_fake_editor && FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \ @@ -139,13 +140,13 @@ test_expect_success 'rebase -i sets work tree properly' ' ' test_expect_success 'rebase -i with the exec command checks tree cleanness' ' - git checkout master && + git checkout primary && ( set_fake_editor && test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \ git rebase -i HEAD^ ) && - test_cmp_rev master^ HEAD && + test_cmp_rev primary^ HEAD && git reset --hard && git rebase --continue ' @@ -168,7 +169,7 @@ test_expect_success 'rebase -x with newline in command fails' ' ' test_expect_success 'rebase -i with exec of inexistent command' ' - git checkout master && + git checkout primary && test_when_finished "git rebase --abort" && ( set_fake_editor && @@ -259,8 +260,8 @@ test_expect_success 'stop on conflicting pick' ' >>>>>>> $commit (G) EOF git tag new-branch1 && - test_must_fail git rebase -i master && - test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && + test_must_fail git rebase -i primary && + test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" && test_cmp expect .git/rebase-merge/patch && test_cmp expect2 file1 && test "$(git diff --name-status | @@ -287,7 +288,7 @@ test_expect_success 'abort' ' test_expect_success 'abort with error when new base cannot be checked out' ' git rm --cached file1 && git commit -m "remove file in base" && - test_must_fail git rebase -i master > output 2>&1 && + test_must_fail git rebase -i primary > output 2>&1 && test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \ output && test_i18ngrep "file1" output && @@ -301,7 +302,7 @@ test_expect_success 'retain authorship' ' test_tick && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && git tag twerp && - git rebase -i --onto master HEAD^ && + git rebase -i --onto primary HEAD^ && git show HEAD | grep "^Author: Twerp Snog" ' @@ -336,10 +337,10 @@ test_expect_success 'squash' ' ( set_fake_editor && FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ - git rebase -i --onto master HEAD~2 + git rebase -i --onto primary HEAD~2 ) && test B = $(cat file7) && - test_cmp_rev HEAD^ master + test_cmp_rev HEAD^ primary ' test_expect_success 'retain authorship when squashing' ' @@ -366,12 +367,12 @@ test_expect_failure REBASE_P 'exchange two commits with -p' ' ' test_expect_success REBASE_P 'preserve merges with -p' ' - git checkout -b to-be-preserved master^ && + git checkout -b to-be-preserved primary^ && : > unrelated-file && git add unrelated-file && test_tick && git commit -m "unrelated" && - git checkout -b another-branch master && + git checkout -b another-branch primary && echo B > file1 && test_tick && git commit -m J file1 && @@ -394,7 +395,7 @@ test_expect_success REBASE_P 'preserve merges with -p' ' git commit -m M file1 && git checkout -b to-be-rebased && test_tick && - git rebase -i -p --onto branch1 master && + git rebase -i -p --onto branch1 primary && git update-index --refresh && git diff-files --quiet && git diff-index --quiet --cached HEAD -- && @@ -437,7 +438,7 @@ test_expect_success '--continue tries to commit' ' ' test_expect_success 'verbose flag is heeded, even after --continue' ' - git reset --hard master@{1} && + git reset --hard primary@{1} && test_tick && test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && echo resolved > file1 && @@ -802,7 +803,7 @@ test_expect_success 'rebase -i continue with unstaged submodule' ' ' test_expect_success 'avoid unnecessary reset' ' - git checkout master && + git checkout primary && git reset --hard && test-tool chmtime =123456789 file3 && git update-index --refresh && @@ -814,14 +815,14 @@ test_expect_success 'avoid unnecessary reset' ' ' test_expect_success 'reword' ' - git checkout -b reword-branch master && + git checkout -b reword-branch primary && ( set_fake_editor && FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \ git rebase -i A && git show HEAD | grep "E changed" && - test $(git rev-parse master) != $(git rev-parse HEAD) && - test_cmp_rev master^ HEAD^ && + test $(git rev-parse primary) != $(git rev-parse HEAD) && + test_cmp_rev primary^ HEAD^ && FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \ git rebase -i A && git show HEAD^ | grep "D changed" && @@ -918,7 +919,7 @@ test_expect_success 'rebase-i history with funny messages' ' ' test_expect_success 'prepare for rebase -i --exec' ' - git checkout master && + git checkout primary && git checkout -b execute && test_commit one_exec main.txt one_exec && test_commit two_exec main.txt two_exec && @@ -1027,7 +1028,7 @@ test_expect_success 'rebase -i --exec without <CMD>' ' git reset --hard execute && test_must_fail git rebase -i --exec 2>actual && test_i18ngrep "requires a value" actual && - git checkout master + git checkout primary ' test_expect_success 'rebase -i --root re-order and drop commits' ' @@ -1079,7 +1080,7 @@ test_expect_success 'rebase -i --root fixup root commit' ' test_expect_success 'rebase -i --root reword original root commit' ' test_when_finished "test_might_fail git rebase --abort" && - git checkout -b reword-original-root-branch master && + git checkout -b reword-original-root-branch primary && ( set_fake_editor && FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ @@ -1091,7 +1092,7 @@ test_expect_success 'rebase -i --root reword original root commit' ' test_expect_success 'rebase -i --root reword new root commit' ' test_when_finished "test_might_fail git rebase --abort" && - git checkout -b reword-now-root-branch master && + git checkout -b reword-now-root-branch primary && ( set_fake_editor && FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ @@ -1251,7 +1252,7 @@ test_expect_success 'rebase -i error on commits with \ in message' ' ' test_expect_success 'short commit ID setup' ' - test_when_finished "git checkout master" && + test_when_finished "git checkout primary" && git checkout --orphan collide && git rm -rf . && ( @@ -1292,7 +1293,7 @@ test_expect_success 'short commit ID collide' ' t3404_collider sha1:ac4f2ee t3404_collider sha256:16697 EOF - test_when_finished "reset_rebase && git checkout master" && + test_when_finished "reset_rebase && git checkout primary" && git checkout collide && colliding_id=$(test_oid t3404_collision) && hexsz=$(test_oid hexsz) && @@ -1416,11 +1417,11 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' rebase_setup_and_clean () { test_when_finished " - git checkout master && + git checkout primary && test_might_fail git branch -D $1 && test_might_fail git rebase --abort " && - git checkout -b $1 ${2:-master} + git checkout -b $1 ${2:-primary} } test_expect_success 'drop' ' @@ -1451,7 +1452,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) To avoid this message, use "drop" to explicitly remove a commit. EOF test_config rebase.missingCommitsCheck warn && @@ -1469,8 +1470,8 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2) To avoid this message, use "drop" to explicitly remove a commit. Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. @@ -1512,11 +1513,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. EOF head -n4 expect >expect.2 && @@ -1546,11 +1547,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. @@ -1635,7 +1636,7 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e ( set_cat_todo_editor && test_must_fail git rebase -i --exec "git show HEAD" \ - --autosquash master >actual + --autosquash primary >actual ) && test_cmp expected actual ' @@ -1646,7 +1647,7 @@ test_expect_success 'static check of bad command' ' set_fake_editor && test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ git rebase -i --root 2>actual && - test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \ + test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \ actual && test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ actual && @@ -1798,13 +1799,13 @@ test_expect_success 'todo has correct onto hash' ' ' test_expect_success 'ORIG_HEAD is updated correctly' ' - test_when_finished "git checkout master && git branch -D test-orig-head" && + test_when_finished "git checkout primary && git branch -D test-orig-head" && git checkout -b test-orig-head A && git commit --allow-empty -m A1 && git commit --allow-empty -m A2 && git commit --allow-empty -m A3 && git commit --allow-empty -m A4 && - git rebase master && + git rebase primary && test_cmp_rev ORIG_HEAD test-orig-head@{1} ' diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index ca04fac417..cc3f434a97 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -589,6 +589,90 @@ test_expect_success 'diffs can be colorized' ' grep "$(printf "\\033")" output ' +test_expect_success 'colors can be overridden' ' + git reset --hard && + test_when_finished "git rm -f color-test" && + test_write_lines context old more-context >color-test && + git add color-test && + test_write_lines context new more-context another-one >color-test && + + echo trigger an error message >input && + force_color git \ + -c color.interactive.error=blue \ + add -i 2>err.raw <input && + test_decode_color <err.raw >err && + grep "<BLUE>Huh (trigger)?<RESET>" err && + + test_write_lines help quit >input && + force_color git \ + -c color.interactive.header=red \ + -c color.interactive.help=green \ + -c color.interactive.prompt=yellow \ + add -i >actual.raw <input && + test_decode_color <actual.raw >actual && + cat >expect <<-\EOF && + <RED> staged unstaged path<RESET> + 1: +3/-0 +2/-1 color-test + + <RED>*** Commands ***<RESET> + 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked + 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp + <YELLOW>What now<RESET>> <GREEN>status - show paths with changes<RESET> + <GREEN>update - add working tree state to the staged set of changes<RESET> + <GREEN>revert - revert staged set of changes back to the HEAD version<RESET> + <GREEN>patch - pick hunks and update selectively<RESET> + <GREEN>diff - view diff between HEAD and index<RESET> + <GREEN>add untracked - add contents of untracked files to the staged set of changes<RESET> + <RED>*** Commands ***<RESET> + 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked + 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp + <YELLOW>What now<RESET>> Bye. + EOF + test_cmp expect actual && + + : exercise recolor_hunk by editing and then look at the hunk again && + test_write_lines s e K q >input && + force_color git \ + -c color.interactive.prompt=yellow \ + -c color.diff.meta=italic \ + -c color.diff.frag=magenta \ + -c color.diff.context=cyan \ + -c color.diff.old=bold \ + -c color.diff.new=blue \ + -c core.editor=touch \ + add -p >actual.raw <input && + test_decode_color <actual.raw >actual.decoded && + sed "s/index [0-9a-f]*\\.\\.[0-9a-f]* 100644/<INDEX-LINE>/" <actual.decoded >actual && + cat >expect <<-\EOF && + <ITALIC>diff --git a/color-test b/color-test<RESET> + <ITALIC><INDEX-LINE><RESET> + <ITALIC>--- a/color-test<RESET> + <ITALIC>+++ b/color-test<RESET> + <MAGENTA>@@ -1,3 +1,4 @@<RESET> + <CYAN> context<RESET> + <BOLD>-old<RESET> + <BLUE>+<RESET><BLUE>new<RESET> + <CYAN> more-context<RESET> + <BLUE>+<RESET><BLUE>another-one<RESET> + <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,?]? <RESET><BOLD>Split into 2 hunks.<RESET> + <MAGENTA>@@ -1,3 +1,3 @@<RESET> + <CYAN> context<RESET> + <BOLD>-old<RESET> + <BLUE>+<RESET><BLUE>new<RESET> + <CYAN> more-context<RESET> + <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET> + <CYAN> more-context<RESET> + <BLUE>+<RESET><BLUE>another-one<RESET> + <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET> + <CYAN> context<RESET> + <BOLD>-old<RESET> + <BLUE>+new<RESET> + <CYAN> more-context<RESET> + <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET> + EOF + test_cmp expect actual +' + test_expect_success 'colorized diffs respect diff.wsErrorHighlight' ' git reset --hard && diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 42588bf6e1..c5e5e0da3f 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -313,6 +313,60 @@ test_expect_success 'multiple files' ' ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch ' +test_expect_success 'filename length limit' ' + test_when_finished "rm -f 000*" && + rm -rf 000[1-9]-*.patch && + for len in 15 25 35 + do + git format-patch --filename-max-length=$len -3 side && + max=$( + for patch in 000[1-9]-*.patch + do + echo "$patch" | wc -c + done | + sort -nr | + head -n 1 + ) && + test $max -le $len || return 1 + done +' + +test_expect_success 'filename length limit from config' ' + test_when_finished "rm -f 000*" && + rm -rf 000[1-9]-*.patch && + for len in 15 25 35 + do + git -c format.filenameMaxLength=$len format-patch -3 side && + max=$( + for patch in 000[1-9]-*.patch + do + echo "$patch" | wc -c + done | + sort -nr | + head -n 1 + ) && + test $max -le $len || return 1 + done +' + +test_expect_success 'filename limit applies only to basename' ' + test_when_finished "rm -rf patches/" && + rm -rf patches/ && + for len in 15 25 35 + do + git format-patch -o patches --filename-max-length=$len -3 side && + max=$( + for patch in patches/000[1-9]-*.patch + do + echo "${patch#patches/}" | wc -c + done | + sort -nr | + head -n 1 + ) && + test $max -le $len || return 1 + done +' + test_expect_success 'reroll count' ' rm -fr patches && git format-patch -o patches --cover-letter --reroll-count 4 master..side >list && diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 8bdaa0a693..47f0e2889d 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -877,13 +877,13 @@ test_expect_success 'rename empty' ' test_expect_success 'combined diff with autocrlf conversion' ' git reset --hard && - echo >x hello && - git commit -m "one side" x && + test_commit "one side" x hello one-side && git checkout HEAD^ && echo >x goodbye && git commit -m "the other side" x && git config core.autocrlf true && - test_must_fail git merge master && + test_must_fail git merge one-side >actual && + test_i18ngrep "Automatic merge failed" actual && git diff >actual.raw && sed -e "1,/^@@@/d" actual.raw >actual && diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh index 5cdd76dfa7..41818d8315 100755 --- a/t/t4129-apply-samemode.sh +++ b/t/t4129-apply-samemode.sh @@ -73,4 +73,30 @@ test_expect_success FILEMODE 'bogus mode is rejected' ' test_i18ngrep "invalid mode" err ' +test_expect_success POSIXPERM 'do not use core.sharedRepository for working tree files' ' + git reset --hard && + test_config core.sharedRepository 0666 && + ( + # Remove a default ACL if possible. + (setfacl -k newdir 2>/dev/null || true) && + umask 0077 && + + # Test both files (f1) and leading dirs (d) + mkdir d && + touch f1 d/f2 && + git add f1 d/f2 && + git diff --staged >patch-f1-and-f2.txt && + + rm -rf d f1 && + git apply patch-f1-and-f2.txt && + + echo "-rw-------" >f1_mode.expected && + echo "drwx------" >d_mode.expected && + test_modebits f1 >f1_mode.actual && + test_modebits d >d_mode.actual && + test_cmp f1_mode.expected f1_mode.actual && + test_cmp d_mode.expected d_mode.actual + ) +' + test_done diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index 8318781d2b..1d40fcad39 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -277,7 +277,7 @@ test_expect_success 'pack with missing parent' ' git pack-objects --stdout --revs <revs >/dev/null ' -test_expect_success JGIT 'we can read jgit bitmaps' ' +test_expect_success JGIT,SHA1 'we can read jgit bitmaps' ' git clone --bare . compat-jgit.git && ( cd compat-jgit.git && @@ -287,7 +287,7 @@ test_expect_success JGIT 'we can read jgit bitmaps' ' ) ' -test_expect_success JGIT 'jgit can read our bitmaps' ' +test_expect_success JGIT,SHA1 'jgit can read our bitmaps' ' git clone --bare . compat-us.git && ( cd compat-us.git && diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index ace469c95c..297de502a9 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -138,7 +138,7 @@ test_expect_success 'write midx with one v2 pack' ' compare_results_with_midx "one v2 pack" -test_expect_success 'corrupt idx not opened' ' +test_expect_success 'corrupt idx reports errors' ' idx=$(test-tool read-midx $objdir | grep "\.idx\$") && mv $objdir/pack/$idx backup-$idx && test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" && @@ -149,7 +149,7 @@ test_expect_success 'corrupt idx not opened' ' test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx && git -c core.multiPackIndex=true rev-list --objects --all 2>err && - test_must_be_empty err + grep "index unavailable" err ' test_expect_success 'add more objects' ' @@ -755,4 +755,30 @@ test_expect_success 'repack --batch-size=<large> repacks everything' ' ) ' +test_expect_success 'load reverse index when missing .idx, .pack' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + git config core.multiPackIndex true && + + test_commit base && + git repack -ad && + git multi-pack-index write && + + git rev-parse HEAD >tip && + pack=$(ls .git/objects/pack/pack-*.pack) && + idx=$(ls .git/objects/pack/pack-*.idx) && + + mv $idx $idx.bak && + git cat-file --batch-check="%(objectsize:disk)" <tip && + + mv $idx.bak $idx && + + mv $pack $pack.bak && + git cat-file --batch-check="%(objectsize:disk)" <tip + ) +' + test_done diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh index 521a347710..344d13f61a 100644 --- a/t/t5411/common-functions.sh +++ b/t/t5411/common-functions.sh @@ -42,7 +42,7 @@ create_commits_in () { make_user_friendly_and_stable_output () { sed \ -e "s/ *\$//" \ - -e "s/ */ /g" \ + -e "s/ */ /g" \ -e "s/'/\"/g" \ -e "s/ / /g" \ -e "s/$A/<COMMIT-A>/g" \ @@ -54,3 +54,8 @@ make_user_friendly_and_stable_output () { -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ -e "/^error: / d" } + +filter_out_user_friendly_and_stable_output () { + make_user_friendly_and_stable_output | + sed -n ${1+"$@"} +} diff --git a/t/t5411/test-0000-standard-git-push.sh b/t/t5411/test-0000-standard-git-push.sh index 2b04b49367..47b058af7e 100644 --- a/t/t5411/test-0000-standard-git-push.sh +++ b/t/t5411/test-0000-standard-git-push.sh @@ -36,11 +36,10 @@ test_expect_success "git-push --atomic ($PROTOCOL)" ' main \ $B:refs/heads/next \ >out 2>&1 && - make_user_friendly_and_stable_output <out | - sed -n \ - -e "/^To / { s/ */ /g; p; }" \ - -e "/^ ! / { s/ */ /g; p; }" \ - >actual && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && cat >expect <<-EOF && To <URL/of/upstream.git> ! [rejected] main -> main (non-fast-forward) diff --git a/t/t5411/test-0001-standard-git-push--porcelain.sh b/t/t5411/test-0001-standard-git-push--porcelain.sh index 747307f8da..bbead12bbb 100644 --- a/t/t5411/test-0001-standard-git-push--porcelain.sh +++ b/t/t5411/test-0001-standard-git-push--porcelain.sh @@ -37,16 +37,15 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" ' main \ $B:refs/heads/next \ >out 2>&1 && - make_user_friendly_and_stable_output <out | - sed -n \ - -e "s/^# GETTEXT POISON #//" \ - -e "/^To / { s/ */ /g; p; }" \ - -e "/^! / { s/ */ /g; p; }" \ - >actual && + filter_out_user_friendly_and_stable_output \ + -e "s/^# GETTEXT POISON #//" \ + -e "/^To / { p; }" \ + -e "/^! / { p; }" \ + <out >actual && cat >expect <<-EOF && To <URL/of/upstream.git> - ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward) - ! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed) + ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward) + ! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed) EOF test_cmp expect actual && git -C "$upstream" show-ref >out && diff --git a/t/t5411/test-0013-bad-protocol.sh b/t/t5411/test-0013-bad-protocol.sh index 854c3e884a..b9be12be77 100644 --- a/t/t5411/test-0013-bad-protocol.sh +++ b/t/t5411/test-0013-bad-protocol.sh @@ -16,7 +16,8 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" ' # Check status report for git-push sed -n \ - -e "/^To / { p; n; p; }" \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ <actual >actual-report && cat >expect <<-EOF && To <URL/of/upstream.git> @@ -41,32 +42,98 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" ' test_cmp expect actual ' -test_expect_success "setup proc-receive hook (hook --die-version, $PROTOCOL)" ' +test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n" - test-tool proc-receive -v --die-version + test-tool proc-receive -v --die-read-version EOF ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push : refs/for/main/topic(A) -test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" ' +test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL)" ' test_must_fail git -C workbench push origin \ HEAD:refs/for/main/topic \ >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-version + EOF +' +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-commands + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && cat >expect <<-EOF && - remote: # pre-receive hook - remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic - remote: # proc-receive hook - remote: fatal: bad protocol version: 1 - remote: error: proc-receive version "0" is not supported To <URL/of/upstream.git> ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) EOF test_cmp expect actual && + grep "remote: fatal: die with the --die-read-commands option" out && git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && @@ -76,23 +143,65 @@ test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" test_cmp expect actual ' -test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" ' +test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n" - test-tool proc-receive -v --die-readline + test-tool proc-receive -v --die-read-push-options EOF ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push : refs/for/main/topic(A) -test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" ' +test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL)" ' + git -C "$upstream" config receive.advertisePushOptions true && test_must_fail git -C workbench push origin \ + -o reviewers=user1,user2 \ HEAD:refs/for/main/topic \ >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-push-options option" out && + + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-report + EOF +' - grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual && +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-report option" out && git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && @@ -130,6 +239,7 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" ' ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -173,6 +283,7 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" ' ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -208,6 +319,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" ' ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && diff --git a/t/t5411/test-0014-bad-protocol--porcelain.sh b/t/t5411/test-0014-bad-protocol--porcelain.sh index 88c56311da..fdb4569109 100644 --- a/t/t5411/test-0014-bad-protocol--porcelain.sh +++ b/t/t5411/test-0014-bad-protocol--porcelain.sh @@ -42,6 +42,175 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porc test_cmp expect actual ' +test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-version + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-version + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-commands + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-commands option" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-push-options + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL/porcelain)" ' + git -C "$upstream" config receive.advertisePushOptions true && + test_must_fail git -C workbench push --porcelain origin \ + -o reviewers=user1,user2 \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-push-options option" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-report + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-report option" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n" @@ -71,6 +240,7 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain) Done EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -84,7 +254,6 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' git -C "$upstream" update-ref -d refs/heads/next - ' test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" ' @@ -115,6 +284,7 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" ' Done EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -151,6 +321,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porce Done EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && diff --git a/t/t5411/test-0026-push-options.sh b/t/t5411/test-0026-push-options.sh index d414be87d0..e88edb16a4 100644 --- a/t/t5411/test-0026-push-options.sh +++ b/t/t5411/test-0026-push-options.sh @@ -32,6 +32,66 @@ test_expect_success "enable push options ($PROTOCOL)" ' git -C "$upstream" config receive.advertisePushOptions true ' +test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + --version 0 \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push -o ... : next(A) refs/for/main/topic +test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL)" ' + git -C workbench push \ + --atomic \ + -o issue=123 \ + -o reviewer=user1 \ + origin \ + HEAD:refs/heads/next \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: proc-receive> ok refs/for/main/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + To <URL/of/upstream.git> + * [new branch] HEAD -> next + * [new reference] HEAD -> refs/for/main/topic + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + <COMMIT-A> refs/heads/next + EOF + test_cmp expect actual +' + +test_expect_success "restore proc-receive hook ($PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) next(A) +# Refs of workbench: main(A) tags/v123 +test_expect_success "cleanup ($PROTOCOL)" ' + git -C "$upstream" update-ref -d refs/heads/next +' + # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push -o ... : next(A) refs/for/main/topic diff --git a/t/t5411/test-0027-push-options--porcelain.sh b/t/t5411/test-0027-push-options--porcelain.sh index d5d0dcb172..3a6561b5ea 100644 --- a/t/t5411/test-0027-push-options--porcelain.sh +++ b/t/t5411/test-0027-push-options--porcelain.sh @@ -33,6 +33,68 @@ test_expect_success "enable push options ($PROTOCOL/porcelain)" ' git -C "$upstream" config receive.advertisePushOptions true ' +test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + --version 0 \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push -o ... : next(A) refs/for/main/topic +test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/porcelain)" ' + git -C workbench push \ + --porcelain \ + --atomic \ + -o issue=123 \ + -o reviewer=user1 \ + origin \ + HEAD:refs/heads/next \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: proc-receive> ok refs/for/main/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + To <URL/of/upstream.git> + * HEAD:refs/heads/next [new branch] + * HEAD:refs/for/main/topic [new reference] + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + <COMMIT-A> refs/heads/next + EOF + test_cmp expect actual +' + +test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) next(A) +# Refs of workbench: main(A) tags/v123 +test_expect_success "cleanup ($PROTOCOL/porcelain)" ' + git -C "$upstream" update-ref -d refs/heads/next +' + # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push -o ... : next(A) refs/for/main/topic diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index 1d75e3b12b..37fd06b0be 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -101,7 +101,12 @@ test_expect_success " --[no-]recurse-submodule and submodule.recurse" ' test_path_is_file super/sub/merge_strategy_4.t ' -test_expect_success 'recursive rebasing pull' ' +test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' ' + # This tests the following scenario : + # - local submodule has new commits + # - local superproject does not have new commits + # - upstream superproject has new commits that change the submodule pointer + # change upstream test_commit -C child rebase_strategy && git -C parent submodule update --remote && @@ -116,7 +121,10 @@ test_expect_success 'recursive rebasing pull' ' test_path_is_file super/sub/local_stuff.t ' -test_expect_success 'pull rebase recursing fails with conflicts' ' +test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' ' + # This tests the following scenario : + # - local superproject has new commits that change the submodule pointer + # - upstream superproject has new commits that change the submodule pointer # local changes in submodule recorded in superproject: test_commit -C super/sub local_stuff_2 && @@ -136,6 +144,50 @@ test_expect_success 'pull rebase recursing fails with conflicts' ' test_i18ngrep "locally recorded submodule modifications" err ' +test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' ' + # This tests the following scenario : + # - local submodule does not have new commits + # - local superproject has new commits that *do not* change the submodule pointer + # - upstream superproject has new commits that *do not* change the submodule pointer + # - local superproject branch has no fork-point with its remote-tracking counter-part + + # create upstream superproject + test_create_repo submodule && + test_commit -C submodule first_in_sub && + + test_create_repo superprojet && + test_commit -C superprojet first_in_super && + git -C superprojet submodule add ../submodule && + git -C superprojet commit -m "add submodule" && + test_commit -C superprojet third_in_super && + + # clone superproject + git clone --recurse-submodules superprojet superclone && + + # add commits upstream + test_commit -C superprojet fourth_in_super && + + # create topic branch in clone, not based on any remote-tracking branch + git -C superclone checkout -b feat HEAD~1 && + test_commit -C superclone first_on_feat && + git -C superclone pull --rebase --recurse-submodules origin master +' + +# NOTE: +# +# This test is particular because there is only a single commit in the upstream superproject +# 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject +# ('child') hard-resets its branch to a new root commit with the same tree as the one +# from the upstream superproject, so that its branch has no merge-base with its +# remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'. +# The result is that the local branch is reset to the remote-tracking branch (as it was +# originally before the hard-reset). + +# The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and +# passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit, +# which adds the submodule. +# However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule) +# because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents. test_expect_success 'branch has no merge base with remote-tracking counterpart' ' rm -rf parent child && diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh new file mode 100755 index 0000000000..f1d189d5bc --- /dev/null +++ b/t/t5705-session-id-in-capabilities.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +test_description='session ID in capabilities' + +. ./test-lib.sh + +REPO="$(pwd)/repo" +LOCAL_PRISTINE="$(pwd)/local_pristine" + +test_expect_success 'setup repos for session ID capability tests' ' + git init "$REPO" && + test_commit -C "$REPO" a && + git clone "file://$REPO" "$LOCAL_PRISTINE" && + test_commit -C "$REPO" b +' + +for PROTO in 0 1 2 +do + test_expect_success "session IDs not advertised by default (fetch v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && + cp -r "$LOCAL_PRISTINE" local && + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local fetch \ + --upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \ + origin && + test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" && + test -z "$(grep \"key\":\"client-sid\" tr2-server-events)" + ' + + test_expect_success "session IDs not advertised by default (push v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && + test_when_finished "git -C local push --delete origin new-branch" && + cp -r "$LOCAL_PRISTINE" local && + git -C local pull --no-rebase origin && + GIT_TRACE2_EVENT_NESTING=5 \ + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local push \ + --receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \ + origin HEAD:new-branch && + test -z "$(grep \"key\":\"server-sid\" tr2-client-events)" && + test -z "$(grep \"key\":\"client-sid\" tr2-server-events)" + ' +done + +test_expect_success 'enable SID advertisement' ' + git -C "$REPO" config transfer.advertiseSID true && + git -C "$LOCAL_PRISTINE" config transfer.advertiseSID true +' + +for PROTO in 0 1 2 +do + test_expect_success "session IDs advertised (fetch v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && + cp -r "$LOCAL_PRISTINE" local && + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local fetch \ + --upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \ + origin && + grep \"key\":\"server-sid\" tr2-client-events && + grep \"key\":\"client-sid\" tr2-server-events + ' + + test_expect_success "session IDs advertised (push v${PROTO})" ' + test_when_finished "rm -rf local tr2-client-events tr2-server-events" && + test_when_finished "git -C local push --delete origin new-branch" && + cp -r "$LOCAL_PRISTINE" local && + git -C local pull --no-rebase origin && + GIT_TRACE2_EVENT_NESTING=5 \ + GIT_TRACE2_EVENT="$(pwd)/tr2-client-events" \ + git -c protocol.version=$PROTO -C local push \ + --receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \ + origin HEAD:new-branch && + grep \"key\":\"server-sid\" tr2-client-events && + grep \"key\":\"client-sid\" tr2-server-events + ' +done + +test_done diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index c5c4ea5fc0..6774e9d86f 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -29,8 +29,11 @@ test_expect_success 'setup' ' test_expect_success 'pull.rebase not set' ' git reset --hard c0 && - git pull . c1 2>err && - test_i18ngrep "Pulling without specifying how to reconcile" err + git -c color.advice=always pull . c1 2>err && + test_decode_color <err >decoded && + test_i18ngrep "<YELLOW>hint: " decoded && + test_i18ngrep "Pulling without specifying how to reconcile" decoded + ' test_expect_success 'pull.rebase not set and pull.ff=true' ' diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 524f30f7dc..a578b35761 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -728,6 +728,19 @@ test_expect_success 'add -N and difftool -d' ' git difftool --dir-diff --extcmd ls ' +test_expect_success 'difftool --cached with unmerged files' ' + test_when_finished git reset --hard && + + test_commit conflicting && + test_commit conflict-a conflict.t a && + git reset --hard conflicting && + test_commit conflict-b conflict.t b && + test_must_fail git merge conflict-a && + + git difftool --cached --no-prompt >output && + test_must_be_empty output +' + test_expect_success 'outside worktree' ' echo 1 >1 && echo 2 >2 && diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index d9e68bb2bf..07acee6ace 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -239,13 +239,15 @@ test_expect_success 'incremental-repack task' ' ' test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' + test_config core.compression 0 && + for i in $(test_seq 1 5) do test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || return 1 done && git add big && - git commit -m "Add big file (1)" && + git commit -qm "Add big file (1)" && # ensure any possible loose objects are in a pack-file git maintenance run --task=loose-objects && @@ -257,7 +259,7 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' return 1 done && git add big && - git commit -m "Add big file (2)" && + git commit -qm "Add big file (2)" && # ensure any possible loose objects are in a pack-file git maintenance run --task=loose-objects && @@ -404,6 +406,18 @@ test_expect_success 'register and unregister' ' test_cmp before actual ' +test_expect_success !MINGW 'register and unregister with regex metacharacters' ' + META="a+b*c" && + git init "$META" && + git -C "$META" maintenance register && + git config --get-all --show-origin maintenance.repo && + git config --get-all --global --fixed-value \ + maintenance.repo "$(pwd)/$META" && + git -C "$META" maintenance unregister && + test_must_fail git config --get-all --global --fixed-value \ + maintenance.repo "$(pwd)/$META" +' + test_expect_success 'start from empty cron table' ' GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 2be9190425..5c01c75d40 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2195,6 +2195,25 @@ test_expect_success 'complete files' ' test_completion "git add mom" "momified" ' +test_expect_success "simple alias" ' + test_config alias.co checkout && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + +test_expect_success "recursive alias" ' + test_config alias.co checkout && + test_config alias.cod "co --detached" && + test_completion "git cod m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && test_completion "git co m" <<-\EOF diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 59bbf75e83..0f7f247159 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -367,9 +367,9 @@ test_chmod () { git update-index --add "--chmod=$@" } -# Get the modebits from a file. +# Get the modebits from a file or directory. test_modebits () { - ls -l "$1" | sed -e 's|^\(..........\).*|\1|' + ls -ld "$1" | sed -e 's|^\(..........\).*|\1|' } # Unset a configuration variable, but don't fail if it doesn't exist. @@ -423,7 +423,7 @@ write_script () { # - Explicitly using test_have_prereq. # # - Implicitly by specifying the prerequisite tag in the calls to -# test_expect_{success,failure,code}. +# test_expect_{success,failure} and test_external{,_without_stderr}. # # The single parameter is the prerequisite tag (a simple word, in all # capital letters by convention). @@ -474,15 +474,15 @@ test_lazy_prereq () { test_run_lazy_prereq_ () { script=' -mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" && +mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" && ( - cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"' + cd "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&'"$2"' )' say >&3 "checking prerequisite: $1" say >&3 "$script" test_eval_ "$script" eval_ret=$? - rm -rf "$TRASH_DIRECTORY/prereq-test-dir" + rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1" if test "$eval_ret" = 0; then say >&3 "prerequisite $1 ok" else |