diff options
Diffstat (limited to 't')
328 files changed, 9142 insertions, 1386 deletions
@@ -35,7 +35,6 @@ TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) CHAINLINTTMP_SQ = $(subst ','\'',$(CHAINLINTTMP)) T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) -TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh)) THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh))) TPERF = $(sort $(wildcard perf/p[0-9][0-9][0-9][0-9]-*.sh)) CHAINLINTTESTS = $(sort $(patsubst chainlint/%.test,%,$(wildcard chainlint/*.test))) @@ -112,9 +111,6 @@ aggregate-results: echo "$$f"; \ done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh -gitweb-test: - $(MAKE) $(TGITWEB) - valgrind: $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind" @@ -405,8 +405,8 @@ every 'git commit-graph write', as if the `--changed-paths` option was passed in. GIT_TEST_FSMONITOR=$PWD/t7519/fsmonitor-all exercises the fsmonitor -code path for utilizing a file system monitor to speed up detecting -new or changed files. +code paths for utilizing a (hook based) file system monitor to speed up +detecting new or changed files. GIT_TEST_INDEX_VERSION=<n> exercises the index read/write code path for the index version specified. Can be set to any valid version @@ -419,7 +419,7 @@ the --sparse command-line argument. GIT_TEST_PRELOAD_INDEX=<boolean> exercises the preload-index code path by overriding the minimum number of cache entries required per thread. -GIT_TEST_ADD_I_USE_BUILTIN=<boolean>, when true, enables the +GIT_TEST_ADD_I_USE_BUILTIN=<boolean>, when false, disables the built-in version of git add -i. See 'add.interactive.useBuiltin' in git-config(1). @@ -547,6 +547,61 @@ This test harness library does the following things: consistently when command line arguments --verbose (or -v), --debug (or -d), and --immediate (or -i) is given. +Recommended style +----------------- +Here are some recommented styles when writing test case. + + - Keep test title the same line with test helper function itself. + + Take test_expect_success helper for example, write it like: + + test_expect_success 'test title' ' + ... test body ... + ' + + Instead of: + + test_expect_success \ + 'test title' \ + '... test body ...' + + + - End the line with a single quote. + + - Indent the body of here-document, and use "<<-" instead of "<<" + to strip leading TABs used for indentation: + + test_expect_success 'test something' ' + cat >expect <<-\EOF && + one + two + three + EOF + test_something > actual && + test_cmp expect actual + ' + + Instead of: + + test_expect_success 'test something' ' + cat >expect <<\EOF && + one + two + three + EOF + test_something > actual && + test_cmp expect actual + ' + + - Quote or escape the EOF delimiter that begins a here-document if + there is no parameter and other expansion in it, to signal readers + that they can skim it more casually: + + cmd <<-\EOF + literal here-document text without any expansion + EOF + + Do's & don'ts ------------- diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 09e86f9..f1b9a6c 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -56,6 +56,10 @@ check_count () { ' "$@" <actual } +get_progress_result () { + tr '\015' '\012' | tail -n 1 +} + test_expect_success 'setup A lines' ' echo "1A quick brown fox jumps over the" >file && echo "lazy dog" >>file && @@ -149,7 +153,7 @@ test_expect_success 'blame evil merge' ' test_expect_success 'blame huge graft' ' test_when_finished "git checkout branch2" && - test_when_finished "rm -f .git/info/grafts" && + test_when_finished "rm -rf .git/info" && graft= && for i in 0 1 2 do @@ -164,6 +168,7 @@ test_expect_success 'blame huge graft' ' graft="$graft$commit " || return 1 done done && + mkdir .git/info && printf "%s " $graft >.git/info/grafts && check_count -h 00 01 1 10 1 ' @@ -604,3 +609,39 @@ test_expect_success 'blame -L X,-N (non-numeric N)' ' test_expect_success 'blame -L ,^/RE/' ' test_must_fail $PROG -L1,^/99/ file ' + +test_expect_success 'blame progress on a full file' ' + cat >expect <<-\EOF && + Blaming lines: 100% (10/10), done. + EOF + + GIT_PROGRESS_DELAY=0 \ + git blame --progress hello.c 2>stderr && + + get_progress_result <stderr >actual && + test_cmp expect actual +' + +test_expect_success 'blame progress on a single range' ' + cat >expect <<-\EOF && + Blaming lines: 100% (4/4), done. + EOF + + GIT_PROGRESS_DELAY=0 \ + git blame --progress -L 3,6 hello.c 2>stderr && + + get_progress_result <stderr >actual && + test_cmp expect actual +' + +test_expect_success 'blame progress on multiple ranges' ' + cat >expect <<-\EOF && + Blaming lines: 100% (7/7), done. + EOF + + GIT_PROGRESS_DELAY=0 \ + git blame --progress -L 3,6 -L 8,10 hello.c 2>stderr && + + get_progress_result <stderr >actual && + test_cmp expect actual +' diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c index ad3ef1c..6c900ca 100644 --- a/t/helper/test-bloom.c +++ b/t/helper/test-bloom.c @@ -16,6 +16,7 @@ static void add_string_to_filter(const char *data, struct bloom_filter *filter) } printf("\n"); add_key_to_filter(&key, filter, &settings); + clear_bloom_key(&key); } static void print_bloom_filter(struct bloom_filter *filter) { @@ -80,6 +81,7 @@ int cmd__bloom(int argc, const char **argv) } print_bloom_filter(&filter); + free(filter.data); } if (!strcmp(argv[1], "get_filter_for_commit")) { diff --git a/t/helper/test-chmtime.c b/t/helper/test-chmtime.c index 524b55c..dc28890 100644 --- a/t/helper/test-chmtime.c +++ b/t/helper/test-chmtime.c @@ -134,6 +134,21 @@ int cmd__chmtime(int argc, const char **argv) } if (utb.modtime != sb.st_mtime && utime(argv[i], &utb) < 0) { +#ifdef GIT_WINDOWS_NATIVE + if (S_ISDIR(sb.st_mode)) { + /* + * NEEDSWORK: The Windows version of `utime()` + * (aka `mingw_utime()`) does not correctly + * handle directory arguments, since it uses + * `_wopen()`. Ignore it for now since this + * is just a test. + */ + fprintf(stderr, + ("Failed to modify time on directory %s. " + "Skipping\n"), argv[i]); + continue; + } +#endif fprintf(stderr, "Failed to modify time on %s: %s\n", argv[i], strerror(errno)); return 1; diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c index e749a49..b15481e 100644 --- a/t/helper/test-delta.c +++ b/t/helper/test-delta.c @@ -20,8 +20,9 @@ int cmd__delta(int argc, const char **argv) { int fd; struct stat st; - void *from_buf, *data_buf, *out_buf; + void *from_buf = NULL, *data_buf = NULL, *out_buf = NULL; unsigned long from_size, data_size, out_size; + int ret = 1; if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) { fprintf(stderr, "usage: %s\n", usage_str); @@ -38,21 +39,21 @@ int cmd__delta(int argc, const char **argv) if (read_in_full(fd, from_buf, from_size) < 0) { perror(argv[2]); close(fd); - return 1; + goto cleanup; } close(fd); fd = open(argv[3], O_RDONLY); if (fd < 0 || fstat(fd, &st)) { perror(argv[3]); - return 1; + goto cleanup; } data_size = st.st_size; data_buf = xmalloc(data_size); if (read_in_full(fd, data_buf, data_size) < 0) { perror(argv[3]); close(fd); - return 1; + goto cleanup; } close(fd); @@ -66,14 +67,20 @@ int cmd__delta(int argc, const char **argv) &out_size); if (!out_buf) { fprintf(stderr, "delta operation failed (returned NULL)\n"); - return 1; + goto cleanup; } fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666); if (fd < 0 || write_in_full(fd, out_buf, out_size) < 0) { perror(argv[4]); - return 1; + goto cleanup; } - return 0; + ret = 0; +cleanup: + free(from_buf); + free(data_buf); + free(out_buf); + + return ret; } diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 6a3f88f..0d6d7f1 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -59,11 +59,16 @@ int cmd__dump_cache_tree(int ac, const char **av) { struct index_state istate; struct cache_tree *another = cache_tree(); + int ret; + setup_git_directory(); if (read_cache() < 0) die("unable to read index file"); istate = the_index; istate.cache_tree = another; cache_tree_update(&istate, WRITE_TREE_DRY_RUN); - return dump_cache_tree(active_cache_tree, another, ""); + ret = dump_cache_tree(active_cache_tree, another, ""); + cache_tree_free(&another); + + return ret; } diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index fc2d460..4e5553e 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -99,6 +99,7 @@ int cmd__fast_rebase(int argc, const char **argv) struct merge_result result; struct strbuf reflog_msg = STRBUF_INIT; struct strbuf branch_name = STRBUF_INIT; + int ret = 0; /* * test-tool stuff doesn't set up the git directory by default; need to @@ -137,13 +138,17 @@ int cmd__fast_rebase(int argc, const char **argv) revs.topo_order = 1; strvec_pushl(&rev_walk_args, "", argv[4], "--not", argv[3], NULL); - if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) - return error(_("unhandled options")); + if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) { + ret = error(_("unhandled options")); + goto cleanup; + } strvec_clear(&rev_walk_args); - if (prepare_revision_walk(&revs) < 0) - return error(_("error preparing revisions")); + if (prepare_revision_walk(&revs) < 0) { + ret = error(_("error preparing revisions")); + goto cleanup; + } init_merge_options(&merge_opt, the_repository); memset(&result, 0, sizeof(result)); @@ -201,8 +206,6 @@ int cmd__fast_rebase(int argc, const char **argv) } if (create_symref("HEAD", branch_name.buf, reflog_msg.buf) < 0) die(_("unable to update HEAD")); - strbuf_release(&reflog_msg); - strbuf_release(&branch_name); prime_cache_tree(the_repository, the_repository->index, result.tree); @@ -221,5 +224,11 @@ int cmd__fast_rebase(int argc, const char **argv) if (write_locked_index(&the_index, &lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("unable to write %s"), get_index_file()); - return (result.clean == 0); + + ret = (result.clean == 0); +cleanup: + strbuf_release(&reflog_msg); + strbuf_release(&branch_name); + release_revisions(&revs); + return ret; } diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c new file mode 100644 index 0000000..54a4856 --- /dev/null +++ b/t/helper/test-fsmonitor-client.c @@ -0,0 +1,222 @@ +/* + * test-fsmonitor-client.c: client code to send commands/requests to + * a `git fsmonitor--daemon` daemon. + */ + +#include "test-tool.h" +#include "cache.h" +#include "parse-options.h" +#include "fsmonitor-ipc.h" +#include "thread-utils.h" +#include "trace2.h" + +#ifndef HAVE_FSMONITOR_DAEMON_BACKEND +int cmd__fsmonitor_client(int argc, const char **argv) +{ + die("fsmonitor--daemon not available on this platform"); +} +#else + +/* + * Read the `.git/index` to get the last token written to the + * FSMonitor Index Extension. + */ +static const char *get_token_from_index(void) +{ + struct index_state *istate = the_repository->index; + + if (do_read_index(istate, the_repository->index_file, 0) < 0) + die("unable to read index file"); + if (!istate->fsmonitor_last_update) + die("index file does not have fsmonitor extension"); + + return istate->fsmonitor_last_update; +} + +/* + * Send an IPC query to a `git-fsmonitor--daemon` daemon and + * ask for the changes since the given token or from the last + * token in the index extension. + * + * This will implicitly start a daemon process if necessary. The + * daemon process will persist after we exit. + */ +static int do_send_query(const char *token) +{ + struct strbuf answer = STRBUF_INIT; + int ret; + + if (!token || !*token) + token = get_token_from_index(); + + ret = fsmonitor_ipc__send_query(token, &answer); + if (ret < 0) + die("could not query fsmonitor--daemon"); + + write_in_full(1, answer.buf, answer.len); + strbuf_release(&answer); + + return 0; +} + +/* + * Send a "flush" command to the `git-fsmonitor--daemon` (if running) + * and tell it to flush its cache. + * + * This feature is primarily used by the test suite to simulate a loss of + * sync with the filesystem where we miss kernel events. + */ +static int do_send_flush(void) +{ + struct strbuf answer = STRBUF_INIT; + int ret; + + ret = fsmonitor_ipc__send_command("flush", &answer); + if (ret) + return ret; + + write_in_full(1, answer.buf, answer.len); + strbuf_release(&answer); + + return 0; +} + +struct hammer_thread_data +{ + pthread_t pthread_id; + int thread_nr; + + int nr_requests; + const char *token; + + int sum_successful; + int sum_errors; +}; + +static void *hammer_thread_proc(void *_hammer_thread_data) +{ + struct hammer_thread_data *data = _hammer_thread_data; + struct strbuf answer = STRBUF_INIT; + int k; + int ret; + + trace2_thread_start("hammer"); + + for (k = 0; k < data->nr_requests; k++) { + strbuf_reset(&answer); + + ret = fsmonitor_ipc__send_query(data->token, &answer); + if (ret < 0) + data->sum_errors++; + else + data->sum_successful++; + } + + strbuf_release(&answer); + trace2_thread_exit(); + return NULL; +} + +/* + * Start a pool of client threads that will each send a series of + * commands to the daemon. + * + * The goal is to overload the daemon with a sustained series of + * concurrent requests. + */ +static int do_hammer(const char *token, int nr_threads, int nr_requests) +{ + struct hammer_thread_data *data = NULL; + int k; + int sum_join_errors = 0; + int sum_commands = 0; + int sum_errors = 0; + + if (!token || !*token) + token = get_token_from_index(); + if (nr_threads < 1) + nr_threads = 1; + if (nr_requests < 1) + nr_requests = 1; + + CALLOC_ARRAY(data, nr_threads); + + for (k = 0; k < nr_threads; k++) { + struct hammer_thread_data *p = &data[k]; + p->thread_nr = k; + p->nr_requests = nr_requests; + p->token = token; + + if (pthread_create(&p->pthread_id, NULL, hammer_thread_proc, p)) { + warning("failed to create thread[%d] skipping remainder", k); + nr_threads = k; + break; + } + } + + for (k = 0; k < nr_threads; k++) { + struct hammer_thread_data *p = &data[k]; + + if (pthread_join(p->pthread_id, NULL)) + sum_join_errors++; + sum_commands += p->sum_successful; + sum_errors += p->sum_errors; + } + + fprintf(stderr, "HAMMER: [threads %d][requests %d] [ok %d][err %d][join %d]\n", + nr_threads, nr_requests, sum_commands, sum_errors, sum_join_errors); + + free(data); + + /* + * Return an error if any of the _send_query requests failed. + * We don't care about thread create/join errors. + */ + return sum_errors > 0; +} + +int cmd__fsmonitor_client(int argc, const char **argv) +{ + const char *subcmd; + const char *token = NULL; + int nr_threads = 1; + int nr_requests = 1; + + const char * const fsmonitor_client_usage[] = { + "test-tool fsmonitor-client query [<token>]", + "test-tool fsmonitor-client flush", + "test-tool fsmonitor-client hammer [<token>] [<threads>] [<requests>]", + NULL, + }; + + struct option options[] = { + OPT_STRING(0, "token", &token, "token", + "command token to send to the server"), + + OPT_INTEGER(0, "threads", &nr_threads, "number of client threads"), + OPT_INTEGER(0, "requests", &nr_requests, "number of requests per thread"), + + OPT_END() + }; + + argc = parse_options(argc, argv, NULL, options, fsmonitor_client_usage, 0); + + if (argc != 1) + usage_with_options(fsmonitor_client_usage, options); + + subcmd = argv[0]; + + setup_git_directory(); + + if (!strcmp(subcmd, "query")) + return !!do_send_query(token); + + if (!strcmp(subcmd, "flush")) + return !!do_send_flush(); + + if (!strcmp(subcmd, "hammer")) + return !!do_hammer(token, nr_threads, nr_requests); + + die("Unhandled subcommand: '%s'", subcmd); +} +#endif diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c index 261c545..5860dab 100644 --- a/t/helper/test-hash.c +++ b/t/helper/test-hash.c @@ -54,5 +54,6 @@ int cmd_hash_impl(int ac, const char **av, int algo) fwrite(hash, 1, algop->rawsz, stdout); else puts(hash_to_hex_algop(hash, algop)); + free(buffer); return 0; } diff --git a/t/helper/test-hexdump.c b/t/helper/test-hexdump.c new file mode 100644 index 0000000..811e89c --- /dev/null +++ b/t/helper/test-hexdump.c @@ -0,0 +1,30 @@ +#include "test-tool.h" +#include "git-compat-util.h" + +/* + * Read stdin and print a hexdump to stdout. + */ +int cmd__hexdump(int argc, const char **argv) +{ + char buf[1024]; + ssize_t i, len; + int have_data = 0; + + for (;;) { + len = xread(0, buf, sizeof(buf)); + if (len < 0) + die_errno("failure reading stdin"); + if (!len) + break; + + have_data = 1; + + for (i = 0; i < len; i++) + printf("%02x ", (unsigned char)buf[i]); + } + + if (have_data) + putchar('\n'); + + return 0; +} diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c index 37c4525..8c3edac 100644 --- a/t/helper/test-json-writer.c +++ b/t/helper/test-json-writer.c @@ -181,12 +181,18 @@ static struct json_writer nest1 = JSON_WRITER_INIT; static void make_nest1(int pretty) { + make_obj1(0); + make_arr1(0); + jw_object_begin(&nest1, pretty); { jw_object_sub_jw(&nest1, "obj1", &obj1); jw_object_sub_jw(&nest1, "arr1", &arr1); } jw_end(&nest1); + + jw_release(&obj1); + jw_release(&arr1); } static char *expect_inline1 = @@ -313,6 +319,9 @@ static void make_mixed1(int pretty) jw_object_sub_jw(&mixed1, "arr1", &arr1); } jw_end(&mixed1); + + jw_release(&obj1); + jw_release(&arr1); } static void cmp(const char *test, const struct json_writer *jw, const char *exp) @@ -325,8 +334,8 @@ static void cmp(const char *test, const struct json_writer *jw, const char *exp) exit(1); } -#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); } while (0) -#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); } while (0) +#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); jw_release(&v); } while (0) +#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); jw_release(&v); } while (0) /* * Run some basic regression tests with some known patterns. @@ -381,7 +390,6 @@ static int unit_tests(void) /* mixed forms */ t(mixed1); - jw_init(&mixed1); p(mixed1); return 0; @@ -544,7 +552,7 @@ static int scripted(void) printf("%s\n", jw.json.buf); - strbuf_release(&jw.json); + jw_release(&jw); return 0; } diff --git a/t/helper/test-pack-mtimes.c b/t/helper/test-pack-mtimes.c new file mode 100644 index 0000000..f7b79da --- /dev/null +++ b/t/helper/test-pack-mtimes.c @@ -0,0 +1,56 @@ +#include "git-compat-util.h" +#include "test-tool.h" +#include "strbuf.h" +#include "object-store.h" +#include "packfile.h" +#include "pack-mtimes.h" + +static void dump_mtimes(struct packed_git *p) +{ + uint32_t i; + if (load_pack_mtimes(p) < 0) + die("could not load pack .mtimes"); + + for (i = 0; i < p->num_objects; i++) { + struct object_id oid; + if (nth_packed_object_id(&oid, p, i) < 0) + die("could not load object id at position %"PRIu32, i); + + printf("%s %"PRIu32"\n", + oid_to_hex(&oid), nth_packed_mtime(p, i)); + } +} + +static const char *pack_mtimes_usage = "\n" +" test-tool pack-mtimes <pack-name.mtimes>"; + +int cmd__pack_mtimes(int argc, const char **argv) +{ + struct strbuf buf = STRBUF_INIT; + struct packed_git *p; + + setup_git_directory(); + + if (argc != 2) + usage(pack_mtimes_usage); + + for (p = get_all_packs(the_repository); p; p = p->next) { + strbuf_addstr(&buf, basename(p->pack_name)); + strbuf_strip_suffix(&buf, ".pack"); + strbuf_addstr(&buf, ".mtimes"); + + if (!strcmp(buf.buf, argv[1])) + break; + + strbuf_reset(&buf); + } + + strbuf_release(&buf); + + if (!p) + die("could not find pack '%s'", argv[1]); + + dump_mtimes(p); + + return 0; +} diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 229ed41..d20e1b7 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -296,9 +296,8 @@ int cmd__path_utils(int argc, const char **argv) if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) { char *buf = xmallocz(strlen(argv[2])); int rv = normalize_path_copy(buf, argv[2]); - if (rv) - buf = "++failed++"; - puts(buf); + puts(rv ? "++failed++" : buf); + free(buf); return 0; } @@ -356,7 +355,10 @@ int cmd__path_utils(int argc, const char **argv) int nongit_ok; setup_git_directory_gently(&nongit_ok); while (argc > 3) { - puts(prefix_path(prefix, prefix_len, argv[3])); + char *pfx = prefix_path(prefix, prefix_len, argv[3]); + + puts(pfx); + free(pfx); argc--; argv++; } @@ -366,6 +368,7 @@ int cmd__path_utils(int argc, const char **argv) if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) { char *prefix = strip_path_suffix(argv[2], argv[3]); printf("%s\n", prefix ? prefix : "(null)"); + free(prefix); return 0; } diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 9646d85..4d18bfb 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -96,6 +96,7 @@ static const char **get_store(const char **argv, struct ref_store **refs) die("no such worktree: %s", gitdir); *refs = get_worktree_ref_store(*p); + free_worktrees(worktrees); } else die("unknown backend %s", argv[0]); diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c index d6f28ca..bd871a7 100644 --- a/t/helper/test-regex.c +++ b/t/helper/test-regex.c @@ -34,6 +34,7 @@ static int test_regex_bug(void) if (m[0].rm_so == 3) /* matches '\n' when it should not */ die("regex bug confirmed: re-build git with NO_REGEX=1"); + regfree(&r); return 0; } @@ -94,18 +95,20 @@ int cmd__regex(int argc, const char **argv) die("failed regcomp() for pattern '%s' (%s)", pat, errbuf); } if (!str) - return 0; + goto cleanup; ret = regexec(&r, str, 1, m, 0); if (ret) { if (silent || ret == REG_NOMATCH) - return ret; + goto cleanup; regerror(ret, &r, errbuf, sizeof(errbuf)); die("failed regexec() for subject '%s' (%s)", str, errbuf); } - return 0; +cleanup: + regfree(&r); + return ret; usage: usage("\ttest-tool regex --bug\n" "\ttest-tool regex [--silent] <pattern>\n" diff --git a/t/helper/test-revision-walking.c b/t/helper/test-revision-walking.c index 625b2db..4a45d5b 100644 --- a/t/helper/test-revision-walking.c +++ b/t/helper/test-revision-walking.c @@ -43,6 +43,7 @@ static int run_revision_walk(void) } reset_revision_walk(); + release_revisions(&rev); return got_revision; } diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index f3b90aa..c9283b4 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -31,7 +31,11 @@ static int parallel_next(struct child_process *cp, return 0; strvec_pushv(&cp->args, d->args.v); - strbuf_addstr(err, "preloaded output of a child\n"); + if (err) + strbuf_addstr(err, "preloaded output of a child\n"); + else + fprintf(stderr, "preloaded output of a child\n"); + number_callbacks++; return 1; } @@ -41,7 +45,10 @@ static int no_job(struct child_process *cp, void *cb, void **task_cb) { - strbuf_addstr(err, "no further jobs available\n"); + if (err) + strbuf_addstr(err, "no further jobs available\n"); + else + fprintf(stderr, "no further jobs available\n"); return 0; } @@ -50,7 +57,10 @@ static int task_finished(int result, void *pp_cb, void *pp_task_cb) { - strbuf_addstr(err, "asking for a quick stop\n"); + if (err) + strbuf_addstr(err, "asking for a quick stop\n"); + else + fprintf(stderr, "asking for a quick stop\n"); return 1; } @@ -390,7 +400,7 @@ int cmd__run_command(int argc, const char **argv) while (!strcmp(argv[1], "env")) { if (!argv[2]) die("env specifier without a value"); - strvec_push(&proc.env_array, argv[2]); + strvec_push(&proc.env, argv[2]); argv += 2; argc -= 2; } @@ -407,6 +417,12 @@ int cmd__run_command(int argc, const char **argv) if (!strcmp(argv[1], "run-command")) exit(run_command(&proc)); + if (!strcmp(argv[1], "--ungroup")) { + argv += 1; + argc -= 1; + run_processes_parallel_ungroup = 1; + } + jobs = atoi(argv[2]); strvec_clear(&proc.args); strvec_pushv(&proc.args, (const char **)argv + 3); diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c index 393f160..026c802 100644 --- a/t/helper/test-scrap-cache-tree.c +++ b/t/helper/test-scrap-cache-tree.c @@ -12,6 +12,7 @@ int cmd__scrap_cache_tree(int ac, const char **av) hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); if (read_cache() < 0) die("unable to read index file"); + cache_tree_free(&active_cache_tree); active_cache_tree = NULL; if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) die("unable to write index file"); diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index e6ec69c..318fdba 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -32,11 +32,13 @@ static struct test_cmd cmds[] = { { "dump-untracked-cache", cmd__dump_untracked_cache }, { "example-decorate", cmd__example_decorate }, { "fast-rebase", cmd__fast_rebase }, + { "fsmonitor-client", cmd__fsmonitor_client }, { "genrandom", cmd__genrandom }, { "genzeros", cmd__genzeros }, { "getcwd", cmd__getcwd }, { "hashmap", cmd__hashmap }, { "hash-speed", cmd__hash_speed }, + { "hexdump", cmd__hexdump }, { "index-version", cmd__index_version }, { "json-writer", cmd__json_writer }, { "lazy-init-name-hash", cmd__lazy_init_name_hash }, @@ -47,6 +49,7 @@ static struct test_cmd cmds[] = { { "oidmap", cmd__oidmap }, { "oidtree", cmd__oidtree }, { "online-cpus", cmd__online_cpus }, + { "pack-mtimes", cmd__pack_mtimes }, { "parse-options", cmd__parse_options }, { "parse-pathspec-file", cmd__parse_pathspec_file }, { "partial-clone", cmd__partial_clone }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 20756ee..bb79927 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -23,11 +23,13 @@ int cmd__dump_untracked_cache(int argc, const char **argv); int cmd__dump_reftable(int argc, const char **argv); int cmd__example_decorate(int argc, const char **argv); int cmd__fast_rebase(int argc, const char **argv); +int cmd__fsmonitor_client(int argc, const char **argv); int cmd__genrandom(int argc, const char **argv); int cmd__genzeros(int argc, const char **argv); int cmd__getcwd(int argc, const char **argv); int cmd__hashmap(int argc, const char **argv); int cmd__hash_speed(int argc, const char **argv); +int cmd__hexdump(int argc, const char **argv); int cmd__index_version(int argc, const char **argv); int cmd__json_writer(int argc, const char **argv); int cmd__lazy_init_name_hash(int argc, const char **argv); @@ -37,6 +39,7 @@ int cmd__mktemp(int argc, const char **argv); int cmd__oidmap(int argc, const char **argv); int cmd__oidtree(int argc, const char **argv); int cmd__online_cpus(int argc, const char **argv); +int cmd__pack_mtimes(int argc, const char **argv); int cmd__parse_options(int argc, const char **argv); int cmd__parse_pathspec_file(int argc, const char** argv); int cmd__partial_clone(int argc, const char **argv); diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index 59b124b..a714130 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -198,7 +198,7 @@ static int ut_006data(int argc, const char **argv) return 0; } -static int ut_007bug(int argc, const char **argv) +static int ut_007BUG(int argc, const char **argv) { /* * Exercise BUG() to ensure that the message is printed to trace2. @@ -206,6 +206,28 @@ static int ut_007bug(int argc, const char **argv) BUG("the bug message"); } +static int ut_008bug(int argc, const char **argv) +{ + bug("a bug message"); + bug("another bug message"); + BUG_if_bug("an explicit BUG_if_bug() following bug() call(s) is nice, but not required"); + return 0; +} + +static int ut_009bug_BUG(int argc, const char **argv) +{ + bug("a bug message"); + bug("another bug message"); + /* The BUG_if_bug(...) isn't here, but we'll spot bug() calls on exit()! */ + return 0; +} + +static int ut_010bug_BUG(int argc, const char **argv) +{ + bug("a %s message", "bug"); + BUG("a %s message", "BUG"); +} + /* * Usage: * test-tool trace2 <ut_name_1> <ut_usage_1> @@ -222,7 +244,10 @@ static struct unit_test ut_table[] = { { ut_004child, "004child", "[<child_command_line>]" }, { ut_005exec, "005exec", "<git_command_args>" }, { ut_006data, "006data", "[<category> <key> <value>]+" }, - { ut_007bug, "007bug", "" }, + { ut_007BUG, "007bug", "" }, + { ut_008bug, "008bug", "" }, + { ut_009bug_BUG, "009bug_BUG","" }, + { ut_010bug_BUG, "010bug_BUG","" }, }; /* clang-format on */ diff --git a/t/helper/test-urlmatch-normalization.c b/t/helper/test-urlmatch-normalization.c index 8f4d67e..86edd45 100644 --- a/t/helper/test-urlmatch-normalization.c +++ b/t/helper/test-urlmatch-normalization.c @@ -5,8 +5,9 @@ int cmd__urlmatch_normalization(int argc, const char **argv) { const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>"; - char *url1, *url2; + char *url1 = NULL, *url2 = NULL; int opt_p = 0, opt_l = 0; + int ret = 0; /* * For one url, succeed if url_normalize succeeds on it, fail otherwise. @@ -39,7 +40,7 @@ int cmd__urlmatch_normalization(int argc, const char **argv) printf("%s\n", url1); if (opt_l) printf("%u\n", (unsigned)info.url_len); - return 0; + goto cleanup; } if (opt_p || opt_l) @@ -47,5 +48,9 @@ int cmd__urlmatch_normalization(int argc, const char **argv) url1 = url_normalize(argv[1], NULL); url2 = url_normalize(argv[2], NULL); - return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1; + ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1; +cleanup: + free(url1); + free(url2); + return ret; } diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh index 5aff2ab..2a5b873 100644 --- a/t/lib-git-p4.sh +++ b/t/lib-git-p4.sh @@ -142,10 +142,11 @@ start_p4d () { p4_add_user () { name=$1 && + fullname="${2:-Dr. $1}" p4 user -f -i <<-EOF User: $name Email: $name@example.com - FullName: Dr. $name + FullName: $fullname EOF } diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index 2fde235..ea28971 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -1,3 +1,7 @@ +if test -z "$TEST_FAILS_SANITIZE_LEAK" +then + TEST_PASSES_SANITIZE_LEAK=true +fi . ./test-lib.sh if test -n "$NO_SVN_TESTS" diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 7828919..1f6b9b0 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -29,7 +29,7 @@ # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> # -if test -n "$NO_CURL" +if ! test_have_prereq LIBCURL then skip_all='skipping test, git built without http support' test_done diff --git a/t/lib-parallel-checkout.sh b/t/lib-parallel-checkout.sh index 83b279a..acaee9c 100644 --- a/t/lib-parallel-checkout.sh +++ b/t/lib-parallel-checkout.sh @@ -25,7 +25,11 @@ test_checkout_workers () { local trace_file=trace-test-checkout-workers && rm -f "$trace_file" && - GIT_TRACE2="$(pwd)/$trace_file" "$@" 2>&8 && + ( + GIT_TRACE2="$(pwd)/$trace_file" && + export GIT_TRACE2 && + "$@" 2>&8 + ) && local workers="$(grep "child_start\[..*\] git checkout--worker" "$trace_file" | wc -l)" && test $workers -eq $expected_workers && diff --git a/t/lib-proto-disable.sh b/t/lib-proto-disable.sh index 83babe5..890622b 100644 --- a/t/lib-proto-disable.sh +++ b/t/lib-proto-disable.sh @@ -1,7 +1,7 @@ # Test routines for checking protocol disabling. -# Test clone/fetch/push with GIT_ALLOW_PROTOCOL whitelist -test_whitelist () { +# Test clone/fetch/push with GIT_ALLOW_PROTOCOL environment variable +test_allow_var () { desc=$1 proto=$2 url=$3 @@ -183,7 +183,7 @@ test_config () { # $2 - machine-readable name of the protocol # $3 - the URL to try cloning test_proto () { - test_whitelist "$@" + test_allow_var "$@" test_config "$@" } diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index ec6b9b1..b575413 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -207,3 +207,18 @@ check_reworded_commits () { >reword-log && test_cmp reword-expected reword-log } + +# usage: set_replace_editor <file> +# +# Replace the todo file with the exact contents of the given file. +set_replace_editor () { + cat >script <<-\EOF && + cat FILENAME >"$1" + + echo 'rebase -i script after editing:' + cat "$1" + EOF + + sed -e "s/FILENAME/$1/g" <script | write_script fake-editor.sh && + test_set_editor "$(pwd)/fake-editor.sh" +} diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index f7c7df0..03e0abb 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -207,7 +207,7 @@ prolog () { # should be updated to an existing commit. reset_work_tree_to () { rm -rf submodule_update && - git clone submodule_update_repo submodule_update && + git clone --template= submodule_update_repo submodule_update && ( cd submodule_update && rm -rf sub1 && @@ -902,13 +902,14 @@ test_submodule_switch_recursing_with_args () { ' # ... but an ignored file is fine. test_expect_$RESULTOI "$command: added submodule removes an untracked ignored file" ' - test_when_finished "rm submodule_update/.git/info/exclude" && + test_when_finished "rm -rf submodule_update/.git/info" && prolog && reset_work_tree_to_interested no_submodule && ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && : >sub1 && + mkdir .git/info && echo sub1 >.git/info/exclude && $command add_sub1 && test_superproject_content origin/add_sub1 && @@ -951,7 +952,9 @@ test_submodule_switch_recursing_with_args () { reset_work_tree_to_interested add_sub1 && ( cd submodule_update && + rm -rf .git/modules/sub1/info && git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + mkdir .git/modules/sub1/info && echo ignored >.git/modules/sub1/info/exclude && : >sub1/ignored && $command replace_sub1_with_file && diff --git a/t/lib-sudo.sh b/t/lib-sudo.sh new file mode 100644 index 0000000..b4d7788 --- /dev/null +++ b/t/lib-sudo.sh @@ -0,0 +1,15 @@ +# Helpers for running git commands under sudo. + +# Runs a scriplet passed through stdin under sudo. +run_with_sudo () { + local ret + local RUN="$TEST_DIRECTORY/$$.sh" + write_script "$RUN" "$TEST_SHELL_PATH" + # avoid calling "$RUN" directly so sudo doesn't get a chance to + # override the shell, add aditional restrictions or even reject + # running the script because its security policy deem it unsafe + sudo "$TEST_SHELL_PATH" -c "\"$RUN\"" + ret=$? + rm -f "$RUN" + return $ret +} diff --git a/t/lib-t3100.sh b/t/lib-t3100.sh new file mode 100644 index 0000000..eabb5fd --- /dev/null +++ b/t/lib-t3100.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +setup_basic_ls_tree_data () { + mkdir dir && + test_commit dir/sub-file && + test_commit top-file && + git clone . submodule && + git submodule add ./submodule && + git commit -m"add submodule" +} diff --git a/t/lib-unicode-nfc-nfd.sh b/t/lib-unicode-nfc-nfd.sh new file mode 100755 index 0000000..2223224 --- /dev/null +++ b/t/lib-unicode-nfc-nfd.sh @@ -0,0 +1,162 @@ +# Help detect how Unicode NFC and NFD are handled on the filesystem. + +# A simple character that has a NFD form. +# +# NFC: U+00e9 LATIN SMALL LETTER E WITH ACUTE +# UTF8(NFC): \xc3 \xa9 +# +# NFD: U+0065 LATIN SMALL LETTER E +# U+0301 COMBINING ACUTE ACCENT +# UTF8(NFD): \x65 + \xcc \x81 +# +utf8_nfc=$(printf "\xc3\xa9") +utf8_nfd=$(printf "\x65\xcc\x81") + +# Is the OS or the filesystem "Unicode composition sensitive"? +# +# That is, does the OS or the filesystem allow files to exist with +# both the NFC and NFD spellings? Or, does the OS/FS lie to us and +# tell us that the NFC and NFD forms are equivalent. +# +# This is or may be independent of what type of filesystem we have, +# since it might be handled by the OS at a layer above the FS. +# Testing shows on MacOS using APFS, HFS+, and FAT32 reports a +# collision, for example. +# +# This does not tell us how the Unicode pathname will be spelled +# on disk, but rather only that the two spelling "collide". We +# will examine the actual on disk spelling in a later prereq. +# +test_lazy_prereq UNICODE_COMPOSITION_SENSITIVE ' + mkdir trial_${utf8_nfc} && + mkdir trial_${utf8_nfd} +' + +# Is the spelling of an NFC pathname preserved on disk? +# +# On MacOS with HFS+ and FAT32, NFC paths are converted into NFD +# and on APFS, NFC paths are preserved. As we have established +# above, this is independent of "composition sensitivity". +# +test_lazy_prereq UNICODE_NFC_PRESERVED ' + mkdir c_${utf8_nfc} && + ls | test-tool hexdump >dump && + grep "63 5f c3 a9" dump +' + +# Is the spelling of an NFD pathname preserved on disk? +# +test_lazy_prereq UNICODE_NFD_PRESERVED ' + mkdir d_${utf8_nfd} && + ls | test-tool hexdump >dump && + grep "64 5f 65 cc 81" dump +' + +# The following _DOUBLE_ forms are more for my curiosity, +# but there may be quirks lurking when there are multiple +# combining characters in non-canonical order. + +# Unicode also allows multiple combining characters +# that can be decomposed in pieces. +# +# NFC: U+1f67 GREEK SMALL LETTER OMEGA WITH DASIA AND PERISPOMENI +# UTF8(NFC): \xe1 \xbd \xa7 +# +# NFD1: U+1f61 GREEK SMALL LETTER OMEGA WITH DASIA +# U+0342 COMBINING GREEK PERISPOMENI +# UTF8(NFD1): \xe1 \xbd \xa1 + \xcd \x82 +# +# But U+1f61 decomposes into +# NFD2: U+03c9 GREEK SMALL LETTER OMEGA +# U+0314 COMBINING REVERSED COMMA ABOVE +# UTF8(NFD2): \xcf \x89 + \xcc \x94 +# +# Yielding: \xcf \x89 + \xcc \x94 + \xcd \x82 +# +# Note that I've used the canonical ordering of the +# combinining characters. It is also possible to +# swap them. My testing shows that that non-standard +# ordering also causes a collision in mkdir. However, +# the resulting names don't draw correctly on the +# terminal (implying that the on-disk format also has +# them out of order). +# +greek_nfc=$(printf "\xe1\xbd\xa7") +greek_nfd1=$(printf "\xe1\xbd\xa1\xcd\x82") +greek_nfd2=$(printf "\xcf\x89\xcc\x94\xcd\x82") + +# See if a double decomposition also collides. +# +test_lazy_prereq UNICODE_DOUBLE_COMPOSITION_SENSITIVE ' + mkdir trial_${greek_nfc} && + mkdir trial_${greek_nfd2} +' + +# See if the NFC spelling appears on the disk. +# +test_lazy_prereq UNICODE_DOUBLE_NFC_PRESERVED ' + mkdir c_${greek_nfc} && + ls | test-tool hexdump >dump && + grep "63 5f e1 bd a7" dump +' + +# See if the NFD spelling appears on the disk. +# +test_lazy_prereq UNICODE_DOUBLE_NFD_PRESERVED ' + mkdir d_${greek_nfd2} && + ls | test-tool hexdump >dump && + grep "64 5f cf 89 cc 94 cd 82" dump +' + +# The following is for debugging. I found it useful when +# trying to understand the various (OS, FS) quirks WRT +# Unicode and how composition/decomposition is handled. +# For example, when trying to understand how (macOS, APFS) +# and (macOS, HFS) and (macOS, FAT32) compare. +# +# It is rather noisy, so it is disabled by default. +# +if test "$unicode_debug" = "true" +then + if test_have_prereq UNICODE_COMPOSITION_SENSITIVE + then + echo NFC and NFD are distinct on this OS/filesystem. + else + echo NFC and NFD are aliases on this OS/filesystem. + fi + + if test_have_prereq UNICODE_NFC_PRESERVED + then + echo NFC maintains original spelling. + else + echo NFC is modified. + fi + + if test_have_prereq UNICODE_NFD_PRESERVED + then + echo NFD maintains original spelling. + else + echo NFD is modified. + fi + + if test_have_prereq UNICODE_DOUBLE_COMPOSITION_SENSITIVE + then + echo DOUBLE NFC and NFD are distinct on this OS/filesystem. + else + echo DOUBLE NFC and NFD are aliases on this OS/filesystem. + fi + + if test_have_prereq UNICODE_DOUBLE_NFC_PRESERVED + then + echo Double NFC maintains original spelling. + else + echo Double NFC is modified. + fi + + if test_have_prereq UNICODE_DOUBLE_NFD_PRESERVED + then + echo Double NFD maintains original spelling. + else + echo Double NFD is modified. + fi +fi diff --git a/t/lib-unique-files.sh b/t/lib-unique-files.sh new file mode 100644 index 0000000..a14080f --- /dev/null +++ b/t/lib-unique-files.sh @@ -0,0 +1,34 @@ +# Helper to create files with unique contents + +# Create multiple files with unique contents within this test run. Takes the +# number of directories, the number of files in each directory, and the base +# directory. +# +# test_create_unique_files 2 3 my_dir -- Creates 2 directories with 3 files +# each in my_dir, all with contents +# different from previous invocations +# of this command in this run. + +test_create_unique_files () { + test "$#" -ne 3 && BUG "3 param" + + local dirs="$1" && + local files="$2" && + local basedir="$3" && + local counter="0" && + local i && + local j && + test_tick && + local basedata="$basedir$test_tick" && + rm -rf "$basedir" && + for i in $(test_seq $dirs) + do + local dir="$basedir/dir$i" && + mkdir -p "$dir" && + for j in $(test_seq $files) + do + counter=$((counter + 1)) && + echo "$basedata.$counter">"$dir/file$j.txt" + done + done +} diff --git a/t/perf/p0008-odb-fsync.sh b/t/perf/p0008-odb-fsync.sh new file mode 100755 index 0000000..b3a90f3 --- /dev/null +++ b/t/perf/p0008-odb-fsync.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# +# This test measures the performance of adding new files to the object +# database. The test was originally added to measure the effect of the +# core.fsyncMethod=batch mode, which is why we are testing different values of +# that setting explicitly and creating a lot of unique objects. + +test_description="Tests performance of adding things to the object database" + +. ./perf-lib.sh + +. $TEST_DIRECTORY/lib-unique-files.sh + +test_perf_fresh_repo +test_checkout_worktree + +dir_count=10 +files_per_dir=50 +total_files=$((dir_count * files_per_dir)) + +populate_files () { + test_create_unique_files $dir_count $files_per_dir files +} + +setup_repo () { + (rm -rf .git || 1) && + git init && + test_commit first && + populate_files +} + +test_perf_fsync_cfgs () { + local method && + local cfg && + for method in none fsync batch writeout-only + do + case $method in + none) + cfg="-c core.fsync=none" + ;; + *) + cfg="-c core.fsync=loose-object -c core.fsyncMethod=$method" + esac && + + # Set GIT_TEST_FSYNC=1 explicitly since fsync is normally + # disabled by t/test-lib.sh. + if ! test_perf "$1 (fsyncMethod=$method)" \ + --setup "$2" \ + "GIT_TEST_FSYNC=1 git $cfg $3" + then + break + fi + done +} + +test_perf_fsync_cfgs "add $total_files files" \ + "setup_repo" \ + "add -- files" + +test_perf_fsync_cfgs "stash $total_files files" \ + "setup_repo" \ + "stash push -u -- files" + +test_perf_fsync_cfgs "unpack $total_files files" \ + " + setup_repo && + git -c core.fsync=none add -- files && + git -c core.fsync=none commit -q -m second && + echo HEAD | git pack-objects -q --stdout --revs >test_pack.pack && + setup_repo + " \ + "unpack-objects -q <test_pack.pack" + +test_perf_fsync_cfgs "commit $total_files files" \ + " + setup_repo && + git -c core.fsync=none add -- files && + populate_files + " \ + "commit -q -a -m test" + +test_done diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh index 382716c..c181110 100755 --- a/t/perf/p2000-sparse-operations.sh +++ b/t/perf/p2000-sparse-operations.sh @@ -106,10 +106,13 @@ test_perf_on_all () { } test_perf_on_all git status +test_perf_on_all 'git stash && git stash pop' +test_perf_on_all 'echo >>new && git stash -u && git stash pop' test_perf_on_all git add -A test_perf_on_all git add . test_perf_on_all git commit -a -m A test_perf_on_all git checkout -f - +test_perf_on_all "git sparse-checkout add f2/f3/f1 && git sparse-checkout set $SPARSE_CONE" test_perf_on_all git reset test_perf_on_all git reset --hard test_perf_on_all git reset -- does-not-exist diff --git a/t/perf/p4220-log-grep-engines.sh b/t/perf/p4220-log-grep-engines.sh index 2bc47de..03fbfbb 100755 --- a/t/perf/p4220-log-grep-engines.sh +++ b/t/perf/p4220-log-grep-engines.sh @@ -36,7 +36,8 @@ do else prereq="" fi - test_perf $prereq "$engine log$GIT_PERF_4220_LOG_OPTS --grep='$pattern'" " + test_perf "$engine log$GIT_PERF_4220_LOG_OPTS --grep='$pattern'" \ + --prereq "$prereq" " git -c grep.patternType=$engine log --pretty=format:%h$GIT_PERF_4220_LOG_OPTS --grep='$pattern' >'out.$engine' || : " done diff --git a/t/perf/p4221-log-grep-engines-fixed.sh b/t/perf/p4221-log-grep-engines-fixed.sh index 0609712..0a6d6df 100755 --- a/t/perf/p4221-log-grep-engines-fixed.sh +++ b/t/perf/p4221-log-grep-engines-fixed.sh @@ -26,7 +26,8 @@ do else prereq="" fi - test_perf $prereq "$engine log$GIT_PERF_4221_LOG_OPTS --grep='$pattern'" " + test_perf "$engine log$GIT_PERF_4221_LOG_OPTS --grep='$pattern'" \ + --prereq "$prereq" " git -c grep.patternType=$engine log --pretty=format:%h$GIT_PERF_4221_LOG_OPTS --grep='$pattern' >'out.$engine' || : " done diff --git a/t/perf/p5302-pack-index.sh b/t/perf/p5302-pack-index.sh index c16f6a3..14c601b 100755 --- a/t/perf/p5302-pack-index.sh +++ b/t/perf/p5302-pack-index.sh @@ -26,9 +26,8 @@ test_expect_success 'set up thread-counting tests' ' done ' -test_perf PERF_EXTRA 'index-pack 0 threads' ' - rm -rf repo.git && - git init --bare repo.git && +test_perf 'index-pack 0 threads' --prereq PERF_EXTRA \ + --setup 'rm -rf repo.git && git init --bare repo.git' ' GIT_DIR=repo.git git index-pack --threads=1 --stdin < $PACK ' @@ -36,17 +35,15 @@ for t in $threads do THREADS=$t export THREADS - test_perf PERF_EXTRA "index-pack $t threads" ' - rm -rf repo.git && - git init --bare repo.git && + test_perf "index-pack $t threads" --prereq PERF_EXTRA \ + --setup 'rm -rf repo.git && git init --bare repo.git' ' GIT_DIR=repo.git GIT_FORCE_THREADS=1 \ git index-pack --threads=$THREADS --stdin <$PACK ' done -test_perf 'index-pack default number of threads' ' - rm -rf repo.git && - git init --bare repo.git && +test_perf 'index-pack default number of threads' \ + --setup 'rm -rf repo.git && git init --bare repo.git' ' GIT_DIR=repo.git git index-pack --stdin < $PACK ' diff --git a/t/perf/p7519-fsmonitor.sh b/t/perf/p7519-fsmonitor.sh index c8be58f..b1cb238 100755 --- a/t/perf/p7519-fsmonitor.sh +++ b/t/perf/p7519-fsmonitor.sh @@ -60,19 +60,7 @@ then esac fi -if test -n "$GIT_PERF_7519_DROP_CACHE" -then - # When using GIT_PERF_7519_DROP_CACHE, GIT_PERF_REPEAT_COUNT must be 1 to - # generate valid results. Otherwise the caching that happens for the nth - # run will negate the validity of the comparisons. - if test "$GIT_PERF_REPEAT_COUNT" -ne 1 - then - echo "warning: Setting GIT_PERF_REPEAT_COUNT=1" >&2 - GIT_PERF_REPEAT_COUNT=1 - fi -fi - -trace_start() { +trace_start () { if test -n "$GIT_PERF_7519_TRACE" then name="$1" @@ -91,13 +79,20 @@ trace_start() { fi } -trace_stop() { +trace_stop () { if test -n "$GIT_PERF_7519_TRACE" then unset GIT_TRACE2_PERF fi } +touch_files () { + n=$1 && + d="$n"_files && + + (cd $d && test_seq 1 $n | xargs touch ) +} + test_expect_success "one time repo setup" ' # set untrackedCache depending on the environment if test -n "$GIT_PERF_7519_UNTRACKED_CACHE" @@ -119,10 +114,11 @@ test_expect_success "one time repo setup" ' fi && mkdir 1_file 10_files 100_files 1000_files 10000_files && - for i in $(test_seq 1 10); do touch 10_files/$i || return 1; done && - for i in $(test_seq 1 100); do touch 100_files/$i || return 1; done && - for i in $(test_seq 1 1000); do touch 1000_files/$i || return 1; done && - for i in $(test_seq 1 10000); do touch 10000_files/$i || return 1; done && + : 1_file directory should be left empty && + touch_files 10 && + touch_files 100 && + touch_files 1000 && + touch_files 10000 && git add 1_file 10_files 100_files 1000_files 10000_files && git commit -qm "Add files" && @@ -133,7 +129,7 @@ test_expect_success "one time repo setup" ' fi ' -setup_for_fsmonitor() { +setup_for_fsmonitor_hook () { # set INTEGRATION_SCRIPT depending on the environment if test -n "$INTEGRATION_PATH" then @@ -167,14 +163,18 @@ setup_for_fsmonitor() { test_perf_w_drop_caches () { if test -n "$GIT_PERF_7519_DROP_CACHE"; then - test-tool drop-caches + test_perf "$1" --setup "test-tool drop-caches" "$2" + else + test_perf "$@" fi - - test_perf "$@" } -test_fsmonitor_suite() { - if test -n "$INTEGRATION_SCRIPT"; then +test_fsmonitor_suite () { + if test -n "$USE_FSMONITOR_DAEMON" + then + DESC="builtin fsmonitor--daemon" + elif test -n "$INTEGRATION_SCRIPT" + then DESC="fsmonitor=$(basename $INTEGRATION_SCRIPT)" else DESC="fsmonitor=disabled" @@ -199,15 +199,15 @@ test_fsmonitor_suite() { # Update the mtimes on upto 100k files to make status think # that they are dirty. For simplicity, omit any files with - # LFs (i.e. anything that ls-files thinks it needs to dquote). - # Then fully backslash-quote the paths to capture any - # whitespace so that they pass thru xargs properly. + # LFs (i.e. anything that ls-files thinks it needs to dquote) + # and any files with whitespace so that they pass thru xargs + # properly. # test_perf_w_drop_caches "status (dirty) ($DESC)" ' git ls-files | \ head -100000 | \ grep -v \" | \ - sed '\''s/\(.\)/\\\1/g'\'' | \ + grep -v " ." | \ xargs test-tool chmtime -300 && git status ' @@ -253,11 +253,11 @@ test_fsmonitor_suite() { trace_start fsmonitor-watchman if test -n "$GIT_PERF_7519_FSMONITOR"; then for INTEGRATION_PATH in $GIT_PERF_7519_FSMONITOR; do - test_expect_success "setup for fsmonitor $INTEGRATION_PATH" 'setup_for_fsmonitor' + test_expect_success "setup for fsmonitor $INTEGRATION_PATH" 'setup_for_fsmonitor_hook' test_fsmonitor_suite done else - test_expect_success "setup for fsmonitor" 'setup_for_fsmonitor' + test_expect_success "setup for fsmonitor hook" 'setup_for_fsmonitor_hook' test_fsmonitor_suite fi @@ -285,4 +285,30 @@ test_expect_success "setup without fsmonitor" ' test_fsmonitor_suite trace_stop +# +# Run a full set of perf tests using the built-in fsmonitor--daemon. +# It does not use the Hook API, so it has a different setup. +# Explicitly start the daemon here and before we start client commands +# so that we can later add custom tracing. +# +if test_have_prereq FSMONITOR_DAEMON +then + USE_FSMONITOR_DAEMON=t + + test_expect_success "setup for builtin fsmonitor" ' + trace_start fsmonitor--daemon--server && + git fsmonitor--daemon start && + + trace_start fsmonitor--daemon--client && + + git config core.fsmonitor true && + git update-index --fsmonitor + ' + + test_fsmonitor_suite + + git fsmonitor--daemon stop + trace_stop +fi + test_done diff --git a/t/perf/p7527-builtin-fsmonitor.sh b/t/perf/p7527-builtin-fsmonitor.sh new file mode 100755 index 0000000..9338b9e --- /dev/null +++ b/t/perf/p7527-builtin-fsmonitor.sh @@ -0,0 +1,257 @@ +#!/bin/sh + +test_description="Perf test for the builtin FSMonitor" + +. ./perf-lib.sh + +if ! test_have_prereq FSMONITOR_DAEMON +then + skip_all="fsmonitor--daemon is not supported on this platform" + test_done +fi + +test_lazy_prereq UNTRACKED_CACHE ' + { git update-index --test-untracked-cache; ret=$?; } && + test $ret -ne 1 +' + +# Lie to perf-lib and ask for a new empty repo and avoid +# the complaints about GIT_PERF_REPO not being big enough +# the perf hit when GIT_PERF_LARGE_REPO is copied into +# the trash directory. +# +# NEEDSWORK: It would be nice if perf-lib had an option to +# "borrow" an existing large repo (especially for gigantic +# monorepos) and use it in-place. For now, fake it here. +# +test_perf_fresh_repo + + +# Use a generated synthetic monorepo. If it doesn't exist, we will +# generate it. If it does exist, we will put it in a known state +# before we start our timings. +# +PARAM_D=5 +PARAM_W=10 +PARAM_F=9 + +PARAMS="$PARAM_D"."$PARAM_W"."$PARAM_F" + +BALLAST_BR=p0006-ballast +export BALLAST_BR + +TMP_BR=tmp_br +export TMP_BR + +REPO=../repos/gen-many-files-"$PARAMS".git +export REPO + +if ! test -d $REPO +then + (cd ../repos; ./many-files.sh -d $PARAM_D -w $PARAM_W -f $PARAM_F) +fi + + +enable_uc () { + git -C $REPO config core.untrackedcache true + git -C $REPO update-index --untracked-cache + git -C $REPO status >/dev/null 2>&1 +} + +disable_uc () { + git -C $REPO config core.untrackedcache false + git -C $REPO update-index --no-untracked-cache + git -C $REPO status >/dev/null 2>&1 +} + +start_fsm () { + git -C $REPO fsmonitor--daemon start + git -C $REPO fsmonitor--daemon status + git -C $REPO config core.fsmonitor true + git -C $REPO update-index --fsmonitor + git -C $REPO status >/dev/null 2>&1 +} + +stop_fsm () { + git -C $REPO config --unset core.fsmonitor + git -C $REPO update-index --no-fsmonitor + test_might_fail git -C $REPO fsmonitor--daemon stop 2>/dev/null + git -C $REPO status >/dev/null 2>&1 +} + + +# Ensure that FSMonitor is turned off on the borrowed repo. +# +test_expect_success "Setup borrowed repo (fsm+uc)" " + stop_fsm && + disable_uc +" + +# Also ensure that it starts in a known state. +# +# Because we assume that $GIT_PERF_REPEAT_COUNT > 1, we are not going to time +# the ballast checkout, since only the first invocation does any work and the +# subsequent ones just print "already on branch" and quit, so the reported +# time is not useful. +# +# Create a temp branch and do all work relative to it so that we don't +# accidentially alter the real ballast branch. +# +test_expect_success "Setup borrowed repo (temp ballast branch)" " + test_might_fail git -C $REPO checkout $BALLAST_BR && + test_might_fail git -C $REPO reset --hard && + git -C $REPO clean -d -f && + test_might_fail git -C $REPO branch -D $TMP_BR && + git -C $REPO branch $TMP_BR $BALLAST_BR && + git -C $REPO checkout $TMP_BR +" + + +echo Data >data.txt + +# NEEDSWORK: We assume that $GIT_PERF_REPEAT_COUNT > 1. With +# FSMonitor enabled, we can get a skewed view of status times, since +# the index MAY (or may not) be updated after the first invocation +# which will update the FSMonitor Token, so the subsequent invocations +# may get a smaller response from the daemon. +# +do_status () { + msg=$1 + + test_perf "$msg" " + git -C $REPO status >/dev/null 2>&1 + " +} + +do_matrix () { + uc=$1 + fsm=$2 + + t="[uc $uc][fsm $fsm]" + MATRIX_BR="$TMP_BR-$uc-$fsm" + + test_expect_success "$t Setup matrix branch" " + git -C $REPO clean -d -f && + git -C $REPO checkout $TMP_BR && + test_might_fail git -C $REPO branch -D $MATRIX_BR && + git -C $REPO branch $MATRIX_BR $TMP_BR && + git -C $REPO checkout $MATRIX_BR + " + + if test $uc = true + then + enable_uc + else + disable_uc + fi + + if test $fsm = true + then + start_fsm + else + stop_fsm + fi + + do_status "$t status after checkout" + + # Modify many files in the matrix branch. + # Stage them. + # Commit them. + # Rollback. + # + test_expect_success "$t modify tracked files" " + find $REPO -name file1 -exec cp data.txt {} \\; + " + + do_status "$t status after big change" + + # Don't bother timing the "add" because _REPEAT_COUNT + # issue described above. + # + test_expect_success "$t add all" " + git -C $REPO add -A + " + + do_status "$t status after add all" + + test_expect_success "$t add dot" " + git -C $REPO add . + " + + do_status "$t status after add dot" + + test_expect_success "$t commit staged" " + git -C $REPO commit -a -m data + " + + do_status "$t status after commit" + + test_expect_success "$t reset HEAD~1 hard" " + git -C $REPO reset --hard HEAD~1 >/dev/null 2>&1 + " + + do_status "$t status after reset hard" + + # Create some untracked files. + # + test_expect_success "$t create untracked files" " + cp -R $REPO/ballast/dir1 $REPO/ballast/xxx1 + " + + do_status "$t status after create untracked files" + + # Remove the new untracked files. + # + test_expect_success "$t clean -df" " + git -C $REPO clean -d -f + " + + do_status "$t status after clean" + + if test $fsm = true + then + stop_fsm + fi +} + +# Begin testing each case in the matrix that we care about. +# +uc_values="false" +test_have_prereq UNTRACKED_CACHE && uc_values="false true" + +fsm_values="false true" + +for uc_val in $uc_values +do + for fsm_val in $fsm_values + do + do_matrix $uc_val $fsm_val + done +done + +cleanup () { + uc=$1 + fsm=$2 + + MATRIX_BR="$TMP_BR-$uc-$fsm" + + test_might_fail git -C $REPO branch -D $MATRIX_BR +} + + +# We're borrowing this repo. We should leave it in a clean state. +# +test_expect_success "Cleanup temp and matrix branches" " + git -C $REPO clean -d -f && + test_might_fail git -C $REPO checkout $BALLAST_BR && + test_might_fail git -C $REPO branch -D $TMP_BR && + for uc_val in $uc_values + do + for fsm_val in $fsm_values + do + cleanup $uc_val $fsm_val + done + done +" + +test_done diff --git a/t/perf/p7820-grep-engines.sh b/t/perf/p7820-grep-engines.sh index 8b09c5b..9bfb868 100755 --- a/t/perf/p7820-grep-engines.sh +++ b/t/perf/p7820-grep-engines.sh @@ -49,13 +49,15 @@ do fi if ! test_have_prereq PERF_GREP_ENGINES_THREADS then - test_perf $prereq "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern'" " + test_perf "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern'" \ + --prereq "$prereq" " git -c grep.patternType=$engine grep$GIT_PERF_7820_GREP_OPTS -- '$pattern' >'out.$engine' || : " else for threads in $GIT_PERF_GREP_THREADS do - test_perf PTHREADS,$prereq "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern' with $threads threads" " + test_perf "$engine grep$GIT_PERF_7820_GREP_OPTS '$pattern' with $threads threads" + --prereq PTHREADS,$prereq " git -c grep.patternType=$engine -c grep.threads=$threads grep$GIT_PERF_7820_GREP_OPTS -- '$pattern' >'out.$engine.$threads' || : " done diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh index 407252b..27c2801 100644 --- a/t/perf/perf-lib.sh +++ b/t/perf/perf-lib.sh @@ -78,7 +78,7 @@ test_perf_copy_repo_contents () { for stuff in "$1"/* do case "$stuff" in - */objects|*/hooks|*/config|*/commondir|*/gitdir|*/worktrees) + */objects|*/hooks|*/config|*/commondir|*/gitdir|*/worktrees|*/fsmonitor--daemon*) ;; *) cp -R "$stuff" "$repo/.git/" || exit 1 @@ -189,19 +189,39 @@ exit $ret' >&3 2>&4 } test_wrapper_ () { - test_wrapper_func_=$1; shift + local test_wrapper_func_="$1"; shift + local test_title_="$1"; shift test_start_ - test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= - test "$#" = 2 || - BUG "not 2 or 3 parameters to test-expect-success" + test_prereq= + test_perf_setup_= + while test $# != 0 + do + case $1 in + --prereq) + test_prereq=$2 + shift + ;; + --setup) + test_perf_setup_=$2 + shift + ;; + *) + break + ;; + esac + shift + done + test "$#" = 1 || BUG "test_wrapper_ needs 2 positional parameters" export test_prereq - if ! test_skip "$@" + export test_perf_setup_ + + if ! test_skip "$test_title_" "$@" then base=$(basename "$0" .sh) echo "$test_count" >>"$perf_results_dir"/$base.subtests - echo "$1" >"$perf_results_dir"/$base.$test_count.descr + echo "$test_title_" >"$perf_results_dir"/$base.$test_count.descr base="$perf_results_dir"/"$PERF_RESULTS_PREFIX$(basename "$0" .sh)"."$test_count" - "$test_wrapper_func_" "$@" + "$test_wrapper_func_" "$test_title_" "$@" fi test_finish_ @@ -214,6 +234,16 @@ test_perf_ () { echo "perf $test_count - $1:" fi for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do + if test -n "$test_perf_setup_" + then + say >&3 "setup: $test_perf_setup_" + if ! test_eval_ $test_perf_setup_ + then + test_failure_ "$test_perf_setup_" + break + fi + + fi say >&3 "running: $2" if test_run_perf_ "$2" then @@ -237,11 +267,24 @@ test_perf_ () { rm test_time.* } +# Usage: test_perf 'title' [options] 'perf-test' +# Run the performance test script specified in perf-test with +# optional prerequisite and setup steps. +# Options: +# --prereq prerequisites: Skip the test if prequisites aren't met +# --setup "setup-steps": Run setup steps prior to each measured iteration +# test_perf () { test_wrapper_ test_perf_ "$@" } test_size_ () { + if test -n "$test_perf_setup_" + then + say >&3 "setup: $test_perf_setup_" + test_eval_ $test_perf_setup_ + fi + say >&3 "running: $2" if test_eval_ "$2" 3>"$base".result; then test_ok_ "$1" @@ -250,6 +293,14 @@ test_size_ () { fi } +# Usage: test_size 'title' [options] 'size-test' +# Run the size test script specified in size-test with optional +# prerequisites and setup steps. Returns the numeric value +# returned by size-test. +# Options: +# --prereq prerequisites: Skip the test if prequisites aren't met +# --setup "setup-steps": Run setup steps prior to the size measurement + test_size () { test_wrapper_ test_size_ "$@" } diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 9dcbf51..17a268c 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -101,6 +101,19 @@ test_expect_success 'subtest: 2/3 tests passing' ' EOF ' +test_expect_success 'subtest: --immediate' ' + run_sub_test_lib_test_err partial-pass \ + --immediate && + check_sub_test_lib_test_err partial-pass \ + <<-\EOF_OUT 3<<-EOF_ERR + > ok 1 - passing test #1 + > not ok 2 - failing test #2 + > # false + > 1..2 + EOF_OUT + EOF_ERR +' + test_expect_success 'subtest: a failing TODO test' ' write_and_run_sub_test_lib_test failing-todo <<-\EOF && test_expect_success "passing test" "true" diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 143f100..f7ee2f2 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -3,6 +3,7 @@ test_description=gitattributes TEST_PASSES_SANITIZE_LEAK=true +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh attr_check_basic () { @@ -284,7 +285,7 @@ test_expect_success 'using --git-dir and --work-tree' ' ' test_expect_success 'setup bare' ' - git clone --bare . bare.git + git clone --template= --bare . bare.git ' test_expect_success 'bare repository: check that .gitattribute is ignored' ' @@ -315,6 +316,7 @@ test_expect_success 'bare repository: check that --cached honors index' ' test_expect_success 'bare repository: test info/attributes' ' ( cd bare.git && + mkdir info && ( echo "f test=f" && echo "a/i test=a/i" @@ -360,6 +362,7 @@ test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' ' test_expect_success SYMLINKS 'symlinks respected in info/attributes' ' test_when_finished "rm .git/info/attributes" && + mkdir .git/info && ln -s ../../attr .git/info/attributes && attr_check file set ' diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 5575dad..c70d11b 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -3,6 +3,7 @@ test_description=check-ignore TEST_PASSES_SANITIZE_LEAK=true +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh init_vars () { @@ -225,7 +226,8 @@ test_expect_success 'setup' ' !globaltwo globalthree EOF - cat <<-\EOF >>.git/info/exclude + mkdir .git/info && + cat <<-\EOF >.git/info/exclude per-repo EOF ' @@ -543,9 +545,9 @@ test_expect_success_multi 'submodule from subdirectory' '' ' test_expect_success 'global ignore not yet enabled' ' expect_from_stdin <<-\EOF && - .git/info/exclude:7:per-repo per-repo + .git/info/exclude:1:per-repo per-repo a/.gitignore:2:*three a/globalthree - .git/info/exclude:7:per-repo a/per-repo + .git/info/exclude:1:per-repo a/per-repo EOF test_check_ignore "-v globalone per-repo a/globalthree a/per-repo not-ignored a/globaltwo" ' @@ -566,10 +568,10 @@ test_expect_success 'global ignore with -v' ' enable_global_excludes && expect_from_stdin <<-EOF && $global_excludes:1:globalone globalone - .git/info/exclude:7:per-repo per-repo + .git/info/exclude:1:per-repo per-repo $global_excludes:3:globalthree globalthree a/.gitignore:2:*three a/globalthree - .git/info/exclude:7:per-repo a/per-repo + .git/info/exclude:1:per-repo a/per-repo $global_excludes:2:!globaltwo globaltwo EOF test_check_ignore "-v globalone per-repo globalthree a/globalthree a/per-repo not-ignored globaltwo" diff --git a/t/t0012-help.sh b/t/t0012-help.sh index 6c3e1f7..6c33a43 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -181,7 +181,7 @@ for cmd in git "git help" do test_expect_success "'$cmd' section spacing" ' test_section_spacing_trailer git help <<-\EOF && - usage: git [--version] [--help] [-C <path>] [-c <name>=<value>] + usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>] These are common Git commands used in various situations: diff --git a/t/t0015-hash.sh b/t/t0015-hash.sh index 086822f..0a087a1 100755 --- a/t/t0015-hash.sh +++ b/t/t0015-hash.sh @@ -1,8 +1,9 @@ #!/bin/sh test_description='test basic hash implementation' -. ./test-lib.sh +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh test_expect_success 'test basic SHA-1 hash values' ' test-tool sha1 </dev/null >actual && diff --git a/t/t0019-json-writer.sh b/t/t0019-json-writer.sh index 3b0c336..19a730c 100755 --- a/t/t0019-json-writer.sh +++ b/t/t0019-json-writer.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test json-writer JSON generation' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'unit test of json-writer routines' ' diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index bad37ab..1c84034 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -1132,4 +1132,26 @@ do ' done +test_expect_success PERL 'delayed checkout correctly reports the number of updated entries' ' + rm -rf repo && + git init repo && + ( + cd repo && + git config filter.delay.process "../rot13-filter.pl delayed.log clean smudge delay" && + git config filter.delay.required true && + + echo "*.a filter=delay" >.gitattributes && + echo a >test-delay10.a && + echo a >test-delay11.a && + git add . && + git commit -m files && + + rm *.a && + git checkout . 2>err && + grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delayed.log && + grep "IN: smudge test-delay11.a .* \\[DELAYED\\]" delayed.log && + grep "Updated 2 paths from the index" err + ) +' + test_done diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh index 0feb41a..7f80f46 100755 --- a/t/t0027-auto-crlf.sh +++ b/t/t0027-auto-crlf.sh @@ -77,12 +77,12 @@ create_NNO_MIX_files () { check_warning () { case "$1" in - LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;; - CRLF_LF) echo "warning: CRLF will be replaced by LF" >"$2".expect ;; - '') >"$2".expect ;; + LF_CRLF) echo "LF will be replaced by CRLF" >"$2".expect ;; + CRLF_LF) echo "CRLF will be replaced by LF" >"$2".expect ;; + '') >"$2".expect ;; *) echo >&2 "Illegal 1": "$1" ; return false ;; esac - grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" | uniq >"$2".actual + sed -e "s/^.* \([^ ]* will be replaced by [^ ]*\) .*$/\1/" "$2" | uniq >"$2".actual test_cmp "$2".expect "$2".actual } diff --git a/t/t0028-working-tree-encoding.sh b/t/t0028-working-tree-encoding.sh index 82905a2..c196fdb 100755 --- a/t/t0028-working-tree-encoding.sh +++ b/t/t0028-working-tree-encoding.sh @@ -5,6 +5,8 @@ test_description='working-tree-encoding conversion via gitattributes' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh . "$TEST_DIRECTORY/lib-encoding.sh" @@ -69,6 +71,7 @@ test_expect_success 'check $GIT_DIR/info/attributes support' ' test_when_finished "rm -f test.utf32.git" && test_when_finished "git reset --hard HEAD" && + mkdir .git/info && echo "*.utf32 text working-tree-encoding=utf-32" >.git/info/attributes && git add test.utf32 && diff --git a/t/t0029-core-unsetenvvars.sh b/t/t0029-core-unsetenvvars.sh index b138e1d..4e8e90d 100755 --- a/t/t0029-core-unsetenvvars.sh +++ b/t/t0029-core-unsetenvvars.sh @@ -12,8 +12,7 @@ then fi test_expect_success 'setup' ' - mkdir -p "$TRASH_DIRECTORY/.git/hooks" && - write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF + test_hook --setup pre-commit <<-\EOF echo $HOBBES >&2 EOF ' diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh new file mode 100755 index 0000000..f4d737d --- /dev/null +++ b/t/t0033-safe-directory.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +test_description='verify safe.directory checks' + +. ./test-lib.sh + +GIT_TEST_ASSUME_DIFFERENT_OWNER=1 +export GIT_TEST_ASSUME_DIFFERENT_OWNER + +expect_rejected_dir () { + test_must_fail git status 2>err && + grep "dubious ownership" err +} + +test_expect_success 'safe.directory is not set' ' + expect_rejected_dir +' + +test_expect_success 'safe.directory on the command line' ' + git -c safe.directory="$(pwd)" status +' + +test_expect_success 'safe.directory in the environment' ' + env GIT_CONFIG_COUNT=1 \ + GIT_CONFIG_KEY_0="safe.directory" \ + GIT_CONFIG_VALUE_0="$(pwd)" \ + git status +' + +test_expect_success 'safe.directory in GIT_CONFIG_PARAMETERS' ' + env GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \ + git status +' + +test_expect_success 'ignoring safe.directory in repo config' ' + ( + unset GIT_TEST_ASSUME_DIFFERENT_OWNER && + git config safe.directory "$(pwd)" + ) && + expect_rejected_dir +' + +test_expect_success 'safe.directory does not match' ' + git config --global safe.directory bogus && + expect_rejected_dir +' + +test_expect_success 'path exist as different key' ' + git config --global foo.bar "$(pwd)" && + expect_rejected_dir +' + +test_expect_success 'safe.directory matches' ' + git config --global --add safe.directory "$(pwd)" && + git status +' + +test_expect_success 'safe.directory matches, but is reset' ' + git config --global --add safe.directory "" && + expect_rejected_dir +' + +test_expect_success 'safe.directory=*' ' + git config --global --add safe.directory "*" && + git status +' + +test_expect_success 'safe.directory=*, but is reset' ' + git config --global --add safe.directory "" && + expect_rejected_dir +' + +test_done diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh new file mode 100755 index 0000000..ff31176 --- /dev/null +++ b/t/t0034-root-safe-directory.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +test_description='verify safe.directory checks while running as root' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-sudo.sh + +if [ "$GIT_TEST_ALLOW_SUDO" != "YES" ] +then + skip_all="You must set env var GIT_TEST_ALLOW_SUDO=YES in order to run this test" + test_done +fi + +if ! test_have_prereq NOT_ROOT +then + skip_all="These tests do not support running as root" + test_done +fi + +test_lazy_prereq SUDO ' + sudo -n id -u >u && + id -u root >r && + test_cmp u r && + command -v git >u && + sudo command -v git >r && + test_cmp u r +' + +if ! test_have_prereq SUDO +then + skip_all="Your sudo/system configuration is either too strict or unsupported" + test_done +fi + +test_expect_success SUDO 'setup' ' + sudo rm -rf root && + mkdir -p root/r && + ( + cd root/r && + git init + ) +' + +test_expect_success SUDO 'sudo git status as original owner' ' + ( + cd root/r && + git status && + sudo git status + ) +' + +test_expect_success SUDO 'setup root owned repository' ' + sudo mkdir -p root/p && + sudo git init root/p +' + +test_expect_success 'cannot access if owned by root' ' + ( + cd root/p && + test_must_fail git status + ) +' + +test_expect_success 'can access if addressed explicitly' ' + ( + cd root/p && + GIT_DIR=.git GIT_WORK_TREE=. git status + ) +' + +test_expect_success SUDO 'can access with sudo if root' ' + ( + cd root/p && + sudo git status + ) +' + +test_expect_success SUDO 'can access with sudo if root by removing SUDO_UID' ' + ( + cd root/p && + run_with_sudo <<-END + unset SUDO_UID && + git status + END + ) +' + +# this MUST be always the last test +test_expect_success SUDO 'cleanup' ' + sudo rm -rf root +' + +test_done diff --git a/t/t0035-safe-bare-repository.sh b/t/t0035-safe-bare-repository.sh new file mode 100755 index 0000000..ecbdc82 --- /dev/null +++ b/t/t0035-safe-bare-repository.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +test_description='verify safe.bareRepository checks' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +pwd="$(pwd)" + +expect_accepted () { + git "$@" rev-parse --git-dir +} + +expect_rejected () { + test_must_fail git "$@" rev-parse --git-dir 2>err && + grep -F "cannot use bare repository" err +} + +test_expect_success 'setup bare repo in worktree' ' + git init outer-repo && + git init --bare outer-repo/bare-repo +' + +test_expect_success 'safe.bareRepository unset' ' + expect_accepted -C outer-repo/bare-repo +' + +test_expect_success 'safe.bareRepository=all' ' + test_config_global safe.bareRepository all && + expect_accepted -C outer-repo/bare-repo +' + +test_expect_success 'safe.bareRepository=explicit' ' + test_config_global safe.bareRepository explicit && + expect_rejected -C outer-repo/bare-repo +' + +test_expect_success 'safe.bareRepository in the repository' ' + # safe.bareRepository must not be "explicit", otherwise + # git config fails with "fatal: not in a git directory" (like + # safe.directory) + test_config -C outer-repo/bare-repo safe.bareRepository \ + all && + test_config_global safe.bareRepository explicit && + expect_rejected -C outer-repo/bare-repo +' + +test_expect_success 'safe.bareRepository on the command line' ' + test_config_global safe.bareRepository explicit && + expect_accepted -C outer-repo/bare-repo \ + -c safe.bareRepository=all +' + +test_done diff --git a/t/t0056-git-C.sh b/t/t0056-git-C.sh index 2630e75..752aa8c 100755 --- a/t/t0056-git-C.sh +++ b/t/t0056-git-C.sh @@ -2,6 +2,7 @@ test_description='"-C <path>" option and its effects on other path-related options' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success '"git -C <path>" runs git from the directory <path>' ' diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 71a5d37..1f2007e 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -5,6 +5,7 @@ test_description='Test various path utilities' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh norm_path() { @@ -55,12 +56,15 @@ fi ancestor() { # We do some math with the expected ancestor length. expected=$3 - if test -n "$rootoff" && test "x$expected" != x-1; then - expected=$(($expected-$rootslash)) - test $expected -lt 0 || - expected=$(($expected+$rootoff)) - fi - test_expect_success "longest ancestor: $1 $2 => $expected" \ + case "$rootoff,$expected,$2" in + *,*,//*) ;; # leave UNC paths alone + [0-9]*,[0-9]*,/*) + # On Windows, expect MSYS2 pseudo root translation for + # Unix-style absolute paths + expected=$(($expected-$rootslash+$rootoff)) + ;; + esac + test_expect_success $4 "longest ancestor: $1 $2 => $expected" \ "actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') && test \"\$actual\" = '$expected'" } @@ -156,6 +160,11 @@ ancestor /foo/bar /foo 4 ancestor /foo/bar /foo:/bar 4 ancestor /foo/bar /bar -1 +# Windows-specific: DOS drives, network shares +ancestor C:/Users/me C:/ 2 MINGW +ancestor D:/Users/me C:/ -1 MINGW +ancestor //server/share/my-directory //server/share/ 14 MINGW + test_expect_success 'strip_path_suffix' ' test c:/msysgit = $(test-tool path-utils strip_path_suffix \ c:/msysgit/libexec//git-core libexec/git-core) @@ -534,7 +543,7 @@ test_lazy_prereq CAN_EXEC_IN_PWD ' ./git rev-parse ' -test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' +test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' mkdir -p pretend/bin pretend/libexec/git-core && echo "echo HERE" | write_script pretend/libexec/git-core/git-here && cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && @@ -542,7 +551,7 @@ test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' echo HERE >expect && test_cmp expect actual' -test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' ' +test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' ' mkdir -p pretend/bin && cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && git config yes.path "%(prefix)/yes" && diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh index ee28190..7b5423e 100755 --- a/t/t0061-run-command.sh +++ b/t/t0061-run-command.sh @@ -134,16 +134,34 @@ test_expect_success 'run_command runs in parallel with more jobs available than test_cmp expect actual ' +test_expect_success 'run_command runs ungrouped in parallel with more jobs available than tasks' ' + test-tool run-command --ungroup run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" >out 2>err && + test_line_count = 8 out && + test_line_count = 4 err +' + test_expect_success 'run_command runs in parallel with as many jobs as tasks' ' test-tool run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && test_cmp expect actual ' +test_expect_success 'run_command runs ungrouped in parallel with as many jobs as tasks' ' + test-tool run-command --ungroup run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" >out 2>err && + test_line_count = 8 out && + test_line_count = 4 err +' + test_expect_success 'run_command runs in parallel with more tasks than jobs available' ' test-tool run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual && test_cmp expect actual ' +test_expect_success 'run_command runs ungrouped in parallel with more tasks than jobs available' ' + test-tool run-command --ungroup run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" >out 2>err && + test_line_count = 8 out && + test_line_count = 4 err +' + cat >expect <<-EOF preloaded output of a child asking for a quick stop @@ -158,6 +176,12 @@ test_expect_success 'run_command is asked to abort gracefully' ' test_cmp expect actual ' +test_expect_success 'run_command is asked to abort gracefully (ungroup)' ' + test-tool run-command --ungroup run-command-abort 3 false >out 2>err && + test_must_be_empty out && + test_line_count = 6 err +' + cat >expect <<-EOF no further jobs available EOF @@ -167,6 +191,12 @@ test_expect_success 'run_command outputs ' ' test_cmp expect actual ' +test_expect_success 'run_command outputs (ungroup) ' ' + test-tool run-command --ungroup run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" >out 2>err && + test_must_be_empty out && + test_cmp expect err +' + test_trace () { expect="$1" shift diff --git a/t/t0062-revision-walking.sh b/t/t0062-revision-walking.sh index 8e21586..b9480c8 100755 --- a/t/t0062-revision-walking.sh +++ b/t/t0062-revision-walking.sh @@ -5,6 +5,7 @@ test_description='Test revision walking api' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >run_twice_expected <<-EOF diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 9067572..d8e2fc4 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -5,6 +5,8 @@ test_description="Test whether cache-tree is properly updated Tests whether various commands properly update and/or rewrite the cache-tree extension. " + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cmp_cache_tree () { diff --git a/t/t0091-bugreport.sh b/t/t0091-bugreport.sh index eeedbfa..08f5fe9 100755 --- a/t/t0091-bugreport.sh +++ b/t/t0091-bugreport.sh @@ -60,18 +60,22 @@ test_expect_success 'can create leading directories outside of a git dir' ' test_expect_success 'indicates populated hooks' ' test_when_finished rm git-bugreport-hooks.txt && - test_when_finished rm -fr .git/hooks && - rm -fr .git/hooks && - mkdir .git/hooks && - for hook in applypatch-msg prepare-commit-msg.sample - do - write_script ".git/hooks/$hook" <<-EOF || return 1 - echo "hook $hook exists" - EOF - done && + + test_hook applypatch-msg <<-\EOF && + true + EOF + test_hook unknown-hook <<-\EOF && + true + EOF git bugreport -s hooks && - grep applypatch-msg git-bugreport-hooks.txt && - ! grep prepare-commit-msg git-bugreport-hooks.txt + + sort >expect <<-\EOF && + [Enabled Hooks] + applypatch-msg + EOF + + sed -ne "/^\[Enabled Hooks\]$/,/^$/p" <git-bugreport-hooks.txt >actual && + test_cmp expect actual ' test_done diff --git a/t/t0095-bloom.sh b/t/t0095-bloom.sh index 5945973..daeb4a5 100755 --- a/t/t0095-bloom.sh +++ b/t/t0095-bloom.sh @@ -67,7 +67,7 @@ test_expect_success 'compute bloom key for test string 2' ' test_cmp expect actual ' -test_expect_success 'get bloom filters for commit with no changes' ' +test_expect_success !SANITIZE_LEAK 'get bloom filters for commit with no changes' ' git init && git commit --allow-empty -m "c0" && cat >expect <<-\EOF && diff --git a/t/t0100-previous.sh b/t/t0100-previous.sh index 69beb59..a16cc3d 100755 --- a/t/t0100-previous.sh +++ b/t/t0100-previous.sh @@ -5,6 +5,7 @@ test_description='previous branch syntax @{-n}' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'branch -d @{-1}' ' diff --git a/t/t0101-at-syntax.sh b/t/t0101-at-syntax.sh index a1998b5..878aadd 100755 --- a/t/t0101-at-syntax.sh +++ b/t/t0101-at-syntax.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='various @{whatever} syntax tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh index 4dc9fec..12d817f 100755 --- a/t/t0110-urlmatch-normalization.sh +++ b/t/t0110-urlmatch-normalization.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='urlmatch URL normalization' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # The base name of the test url files diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh index 37c359b..80e76a4 100755 --- a/t/t0210-trace2-normal.sh +++ b/t/t0210-trace2-normal.sh @@ -168,6 +168,82 @@ test_expect_success 'BUG messages are written to trace2' ' test_cmp expect actual ' +test_expect_success 'bug messages with BUG_if_bug() are written to trace2' ' + test_when_finished "rm trace.normal actual expect" && + test_expect_code 99 env GIT_TRACE2="$(pwd)/trace.normal" \ + test-tool trace2 008bug 2>err && + cat >expect <<-\EOF && + a bug message + another bug message + an explicit BUG_if_bug() following bug() call(s) is nice, but not required + EOF + sed "s/^.*: //" <err >actual && + test_cmp expect actual && + + perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + cat >expect <<-EOF && + version $V + start _EXE_ trace2 008bug + cmd_name trace2 (trace2) + error a bug message + error another bug message + error an explicit BUG_if_bug() following bug() call(s) is nice, but not required + exit elapsed:_TIME_ code:99 + atexit elapsed:_TIME_ code:99 + EOF + test_cmp expect actual +' + +test_expect_success 'bug messages without explicit BUG_if_bug() are written to trace2' ' + test_when_finished "rm trace.normal actual expect" && + test_expect_code 99 env GIT_TRACE2="$(pwd)/trace.normal" \ + test-tool trace2 009bug_BUG 2>err && + cat >expect <<-\EOF && + a bug message + another bug message + had bug() call(s) in this process without explicit BUG_if_bug() + EOF + sed "s/^.*: //" <err >actual && + test_cmp expect actual && + + perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + cat >expect <<-EOF && + version $V + start _EXE_ trace2 009bug_BUG + cmd_name trace2 (trace2) + error a bug message + error another bug message + error on exit(): had bug() call(s) in this process without explicit BUG_if_bug() + exit elapsed:_TIME_ code:99 + atexit elapsed:_TIME_ code:99 + EOF + test_cmp expect actual +' + +test_expect_success 'bug messages followed by BUG() are written to trace2' ' + test_when_finished "rm trace.normal actual expect" && + test_expect_code 99 env GIT_TRACE2="$(pwd)/trace.normal" \ + test-tool trace2 010bug_BUG 2>err && + cat >expect <<-\EOF && + a bug message + a BUG message + EOF + sed "s/^.*: //" <err >actual && + test_cmp expect actual && + + perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + cat >expect <<-EOF && + version $V + start _EXE_ trace2 010bug_BUG + cmd_name trace2 (trace2) + error a bug message + error a BUG message + exit elapsed:_TIME_ code:99 + atexit elapsed:_TIME_ code:99 + EOF + test_cmp expect actual +' + sane_unset GIT_TRACE2_BRIEF # Now test without environment variables and get all Trace2 settings diff --git a/t/t0211/scrub_perf.perl b/t/t0211/scrub_perf.perl index d164b750..299999f 100644 --- a/t/t0211/scrub_perf.perl +++ b/t/t0211/scrub_perf.perl @@ -59,6 +59,10 @@ while (<>) { # and highly variable. Just omit them. goto SKIP_LINE; } + if ($tokens[$col_category] =~ m/fsync/) { + # fsync events aren't interesting for the test + goto SKIP_LINE; + } } # t_abs and t_rel are either blank or a float. Replace the float diff --git a/t/t0212/parse_events.perl b/t/t0212/parse_events.perl index b640856..30a9f51 100644 --- a/t/t0212/parse_events.perl +++ b/t/t0212/parse_events.perl @@ -216,12 +216,19 @@ while (<>) { elsif ($event eq 'data') { my $cat = $line->{'category'}; - if ($cat eq 'test_category') { - - my $key = $line->{'key'}; - my $value = $line->{'value'}; - $processes->{$sid}->{'data'}->{$cat}->{$key} = $value; - } + my $key = $line->{'key'}; + my $value = $line->{'value'}; + $processes->{$sid}->{'data'}->{$cat}->{$key} = $value; + } + + elsif ($event eq 'data_json') { + # NEEDSWORK: Ignore due to + # compat/win32/trace2_win32_process_info.c, which should log a + # "cmd_ancestry" event instead. + } + + else { + push @{$processes->{$sid}->{$event}} => $line->{value}; } # This trace2 target does not emit 'printf' events. diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 0710b1f..516a611 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -21,6 +21,7 @@ In the test, these paths are used: yomin - not in H or M ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-read-tree.sh diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh index 46cbd55..bd5313c 100755 --- a/t/t1002-read-tree-m-u-2way.sh +++ b/t/t1002-read-tree-m-u-2way.sh @@ -9,6 +9,7 @@ This is identical to t1001, but uses -u to update the work tree as well. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-read-tree.sh diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 1b85207..dadf3b1 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -681,7 +681,7 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' ' # Setup and create the empty blob and its path empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) && - git hash-object -w --stdin </dev/null && + empty_blob=$(git hash-object -w --stdin </dev/null) && # Create another blob and its path echo other >other.blob && @@ -722,7 +722,13 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' ' # content out as-is. Try to make it zlib-invalid. mv -f other.blob "$empty_path" && test_must_fail git fsck 2>err.fsck && - grep "^error: inflate: data stream error (" err.fsck + cat >expect <<-EOF && + error: inflate: data stream error (incorrect header check) + error: unable to unpack header of ./$empty_path + error: $empty_blob: object corrupt or missing: ./$empty_path + EOF + grep "^error: " err.fsck >actual && + test_cmp expect actual ) ' diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index dd957be..742f0fa 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -11,6 +11,7 @@ test_description='sparse checkout tests A init.t ' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh . "$TEST_DIRECTORY"/lib-read-tree.sh @@ -53,12 +54,13 @@ test_expect_success 'read-tree without .git/info/sparse-checkout' ' ' test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' ' + mkdir .git/info && echo >.git/info/sparse-checkout && read_tree_u_must_succeed -m -u HEAD && git ls-files -t >result && test_cmp expected.swt result && - test -f init.t && - test -f sub/added + test_path_is_file init.t && + test_path_is_file sub/added ' test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' ' @@ -67,8 +69,8 @@ test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse- read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD && git ls-files -t >result && test_cmp expected.swt result && - test -f init.t && - test -f sub/added + test_path_is_file init.t && + test_path_is_file sub/added ' test_expect_success 'read-tree with empty .git/info/sparse-checkout' ' @@ -85,8 +87,8 @@ test_expect_success 'read-tree with empty .git/info/sparse-checkout' ' S subsub/added EOF test_cmp expected.swt result && - ! test -f init.t && - ! test -f sub/added + test_path_is_missing init.t && + test_path_is_missing sub/added ' test_expect_success 'match directories with trailing slash' ' @@ -101,8 +103,8 @@ test_expect_success 'match directories with trailing slash' ' read_tree_u_must_succeed -m -u HEAD && git ls-files -t > result && test_cmp expected.swt-noinit result && - test ! -f init.t && - test -f sub/added + test_path_is_missing init.t && + test_path_is_file sub/added ' test_expect_success 'match directories without trailing slash' ' @@ -110,8 +112,8 @@ test_expect_success 'match directories without trailing slash' ' read_tree_u_must_succeed -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-noinit result && - test ! -f init.t && - test -f sub/added + test_path_is_missing init.t && + test_path_is_file sub/added ' test_expect_success 'match directories with negated patterns' ' @@ -129,9 +131,9 @@ EOF git read-tree -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-negation result && - test ! -f init.t && - test ! -f sub/added && - test -f sub/addedtoo + test_path_is_missing init.t && + test_path_is_missing sub/added && + test_path_is_file sub/addedtoo ' test_expect_success 'match directories with negated patterns (2)' ' @@ -150,9 +152,9 @@ EOF git read-tree -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-negation2 result && - test -f init.t && - test -f sub/added && - test ! -f sub/addedtoo + test_path_is_file init.t && + test_path_is_file sub/added && + test_path_is_missing sub/addedtoo ' test_expect_success 'match directory pattern' ' @@ -160,8 +162,8 @@ test_expect_success 'match directory pattern' ' read_tree_u_must_succeed -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-noinit result && - test ! -f init.t && - test -f sub/added + test_path_is_missing init.t && + test_path_is_file sub/added ' test_expect_success 'checkout area changes' ' @@ -176,15 +178,15 @@ test_expect_success 'checkout area changes' ' read_tree_u_must_succeed -m -u HEAD && git ls-files -t >result && test_cmp expected.swt-nosub result && - test -f init.t && - test ! -f sub/added + test_path_is_file init.t && + test_path_is_missing sub/added ' test_expect_success 'read-tree updates worktree, absent case' ' echo sub/added >.git/info/sparse-checkout && git checkout -f top && read_tree_u_must_succeed -m -u HEAD^ && - test ! -f init.t + test_path_is_missing init.t ' test_expect_success 'read-tree will not throw away dirty changes, non-sparse' ' @@ -229,7 +231,7 @@ test_expect_success 'read-tree adds to worktree, absent case' ' echo init.t >.git/info/sparse-checkout && git checkout -f removed && read_tree_u_must_succeed -u -m HEAD^ && - test ! -f sub/added + test_path_is_missing sub/added ' test_expect_success 'read-tree adds to worktree, dirty case' ' @@ -248,7 +250,7 @@ test_expect_success 'index removal and worktree narrowing at the same time' ' echo init.t >.git/info/sparse-checkout && git checkout removed && git ls-files sub/added >result && - test ! -f sub/added && + test_path_is_missing sub/added && test_must_be_empty result ' diff --git a/t/t1051-large-conversion.sh b/t/t1051-large-conversion.sh index 042b0e4..f6709c9 100755 --- a/t/t1051-large-conversion.sh +++ b/t/t1051-large-conversion.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test conversion filters on large files' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh set_attr() { diff --git a/t/t1060-object-corruption.sh b/t/t1060-object-corruption.sh index bc89371..5b8e47e 100755 --- a/t/t1060-object-corruption.sh +++ b/t/t1060-object-corruption.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='see how we handle various forms of corruption' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # convert "1234abcd" to ".git/objects/12/34abcd" diff --git a/t/t1090-sparse-checkout-scope.sh b/t/t1090-sparse-checkout-scope.sh index d1833c0..3a14218 100755 --- a/t/t1090-sparse-checkout-scope.sh +++ b/t/t1090-sparse-checkout-scope.sh @@ -5,6 +5,7 @@ test_description='sparse checkout scope tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh test_expect_success 'setup' ' @@ -25,6 +26,7 @@ test_expect_success 'create feature branch' ' test_expect_success 'perform sparse checkout of main' ' git config --local --bool core.sparsecheckout true && + mkdir .git/info && echo "!/*" >.git/info/sparse-checkout && echo "/a" >>.git/info/sparse-checkout && echo "/c" >>.git/info/sparse-checkout && @@ -73,7 +75,7 @@ test_expect_success 'skip-worktree on files outside sparse patterns' ' test_expect_success 'in partial clone, sparse checkout only fetches needed blobs' ' test_create_repo server && - git clone "file://$(pwd)/server" client && + git clone --template= "file://$(pwd)/server" client && test_config -C server uploadpack.allowfilter 1 && test_config -C server uploadpack.allowanysha1inwant 1 && @@ -85,6 +87,7 @@ test_expect_success 'in partial clone, sparse checkout only fetches needed blobs git -C server commit -m message && test_config -C client core.sparsecheckout 1 && + mkdir client/.git/info && echo "!/*" >client/.git/info/sparse-checkout && echo "/a" >>client/.git/info/sparse-checkout && git -C client fetch --filter=blob:none origin && diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 9a90031..de1ec89 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -72,7 +72,7 @@ test_expect_success 'git sparse-checkout list (populated)' ' ' test_expect_success 'git sparse-checkout init' ' - git -C repo sparse-checkout init && + git -C repo sparse-checkout init --no-cone && cat >expect <<-\EOF && /* !/*/ @@ -111,6 +111,7 @@ test_expect_success 'init with existing sparse-checkout' ' test_expect_success 'clone --sparse' ' git clone --sparse "file://$(pwd)/repo" clone && + git -C clone sparse-checkout reapply --no-cone && git -C clone sparse-checkout list >actual && cat >expect <<-\EOF && /* @@ -124,7 +125,7 @@ test_expect_success 'switching to cone mode with non-cone mode patterns' ' git init bad-patterns && ( cd bad-patterns && - git sparse-checkout init && + git sparse-checkout init --no-cone && git sparse-checkout add dir && git config --worktree core.sparseCheckoutCone true && test_must_fail git sparse-checkout add dir 2>err && @@ -402,7 +403,7 @@ test_expect_success 'revert to old sparse-checkout on empty update' ' git sparse-checkout set nothing 2>err && test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err && test_i18ngrep ! ".git/index.lock" err && - git sparse-checkout set file + git sparse-checkout set --no-cone file ) ' @@ -424,7 +425,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' git clone repo dirty && echo dirty >dirty/folder1/a && - git -C dirty sparse-checkout init 2>err && + git -C dirty sparse-checkout init --no-cone 2>err && test_i18ngrep "warning.*The following paths are not up to date" err && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err && @@ -435,7 +436,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status' test_must_be_empty err && git -C dirty reset --hard && - git -C dirty sparse-checkout init && + git -C dirty sparse-checkout init --no-cone && git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* && test_path_is_missing dirty/folder1/a && git -C dirty sparse-checkout disable && @@ -451,7 +452,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat EOF git -C unmerged update-index --index-info <input && - git -C unmerged sparse-checkout init 2>err && + git -C unmerged sparse-checkout init --no-cone 2>err && test_i18ngrep "warning.*The following paths are unmerged" err && git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* 2>err && @@ -462,7 +463,7 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat test_i18ngrep "warning.*The following paths are unmerged" err && git -C unmerged reset --hard && - git -C unmerged sparse-checkout init && + git -C unmerged sparse-checkout init --no-cone && git -C unmerged sparse-checkout set /folder2/* /deep/deeper1/* && git -C unmerged sparse-checkout disable ' diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index dcc0a30..763c6cc 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -16,7 +16,9 @@ test_expect_success 'setup' ' echo "after deep" >e && echo "after folder1" >g && echo "after x" >z && - mkdir folder1 folder2 deep x && + mkdir folder1 folder2 deep before x && + echo "before deep" >before/a && + echo "before deep again" >before/b && mkdir deep/deeper1 deep/deeper2 deep/before deep/later && mkdir deep/deeper1/deepest && mkdir deep/deeper1/deepest2 && @@ -203,36 +205,68 @@ test_sparse_unstaged () { done } -test_expect_success 'sparse-index contents' ' - init_repos && - +# Usage: test_sprase_checkout_set "<c1> ... <cN>" "<s1> ... <sM>" +# Verifies that "git sparse-checkout set <c1> ... <cN>" succeeds and +# leaves the sparse index in a state where <s1> ... <sM> are sparse +# directories (and <c1> ... <cN> are not). +test_sparse_checkout_set () { + CONE_DIRS=$1 && + SPARSE_DIRS=$2 && + git -C sparse-index sparse-checkout set --skip-checks $CONE_DIRS && git -C sparse-index ls-files --sparse --stage >cache && - for dir in folder1 folder2 x + + # Check that the directories outside of the sparse-checkout cone + # have sparse directory entries. + for dir in $SPARSE_DIRS do TREE=$(git -C sparse-index rev-parse HEAD:$dir) && grep "040000 $TREE 0 $dir/" cache \ || return 1 done && - git -C sparse-index sparse-checkout set folder1 && - - git -C sparse-index ls-files --sparse --stage >cache && - for dir in deep folder2 x + # Check that the directories in the sparse-checkout cone + # are not sparse directory entries. + for dir in $CONE_DIRS do - TREE=$(git -C sparse-index rev-parse HEAD:$dir) && - grep "040000 $TREE 0 $dir/" cache \ + # Allow TREE to not exist because + # $dir does not exist at HEAD. + TREE=$(git -C sparse-index rev-parse HEAD:$dir) || + ! grep "040000 $TREE 0 $dir/" cache \ || return 1 - done && + done +} - git -C sparse-index sparse-checkout set deep/deeper1 && +test_expect_success 'sparse-index contents' ' + init_repos && - git -C sparse-index ls-files --sparse --stage >cache && - for dir in deep/deeper2 folder1 folder2 x - do - TREE=$(git -C sparse-index rev-parse HEAD:$dir) && - grep "040000 $TREE 0 $dir/" cache \ - || return 1 - done && + # Remove deep, add three other directories. + test_sparse_checkout_set \ + "folder1 folder2 x" \ + "before deep" && + + # Remove folder1, add deep + test_sparse_checkout_set \ + "deep folder2 x" \ + "before folder1" && + + # Replace deep with deep/deeper2 (dropping deep/deeper1) + # Add folder1 + test_sparse_checkout_set \ + "deep/deeper2 folder1 folder2 x" \ + "before deep/deeper1" && + + # Replace deep/deeper2 with deep/deeper1 + # Replace folder1 with folder1/0/0 + # Replace folder2 with non-existent folder2/2/3 + # Add non-existent "bogus" + test_sparse_checkout_set \ + "bogus deep/deeper1 folder1/0/0 folder2/2/3 x" \ + "before deep/deeper2 folder2/0" && + + # Drop down to only files at root + test_sparse_checkout_set \ + "" \ + "before deep folder1 folder2 x" && # Disabling the sparse-index replaces tree entries with full ones git -C sparse-index sparse-checkout init --no-sparse-index && @@ -254,6 +288,7 @@ test_expect_success 'root directory cannot be sparse' ' # Verify sparse directories still present, root directory is not sparse cat >expect <<-EOF && + before/ folder1/ folder2/ x/ @@ -1031,6 +1066,55 @@ test_expect_success 'cherry-pick with conflicts' ' test_all_match test_must_fail git cherry-pick to-cherry-pick ' +test_expect_success 'stash' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + + # Stash a sparse directory (folder1) + test_all_match git checkout -b test-branch rename-base && + test_all_match git reset --soft rename-out-to-out && + test_all_match git stash && + test_all_match git status --porcelain=v2 && + + # Apply the sparse directory stash without reinstating the index + test_all_match git stash apply -q && + test_all_match git status --porcelain=v2 && + + # Reset to state where stash can be applied + test_sparse_match git sparse-checkout reapply && + test_all_match git reset --hard rename-out-to-out && + + # Apply the sparse directory stash *with* reinstating the index + test_all_match git stash apply --index -q && + test_all_match git status --porcelain=v2 && + + # Reset to state where we will get a conflict applying the stash + test_sparse_match git sparse-checkout reapply && + test_all_match git reset --hard update-folder1 && + + # Apply the sparse directory stash with conflicts + test_all_match test_must_fail git stash apply --index -q && + test_all_match test_must_fail git stash apply -q && + test_all_match git status --porcelain=v2 && + + # Reset to base branch + test_sparse_match git sparse-checkout reapply && + test_all_match git reset --hard base && + + # Stash & unstash an untracked file outside of the sparse checkout + # definition. + run_on_sparse mkdir -p folder1 && + run_on_all ../edit-contents folder1/new && + test_all_match git stash -u && + test_all_match git status --porcelain=v2 && + + test_all_match git stash pop -q && + test_all_match git status --porcelain=v2 +' + test_expect_success 'checkout-index inside sparse definition' ' init_repos && @@ -1148,6 +1232,33 @@ test_expect_success 'clean' ' test_sparse_match test_path_is_dir folder1 ' +for builtin in show rev-parse +do + test_expect_success "$builtin (cached blobs/trees)" " + init_repos && + + test_all_match git $builtin :a && + test_all_match git $builtin :deep/a && + test_sparse_match git $builtin :folder1/a && + + # The error message differs depending on whether + # the directory exists in the worktree. + test_all_match test_must_fail git $builtin :deep/ && + test_must_fail git -C full-checkout $builtin :folder1/ && + test_sparse_match test_must_fail git $builtin :folder1/ && + + # Change the sparse cone for an extra case: + run_on_sparse git sparse-checkout set deep/deeper1 && + + # deep/deeper2 is a sparse directory in the sparse index. + test_sparse_match test_must_fail git $builtin :deep/deeper2/ && + + # deep/deeper2/deepest is not in the sparse index, but + # will trigger an index expansion. + test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/ + " +done + test_expect_success 'submodule handling' ' init_repos && @@ -1219,7 +1330,10 @@ test_expect_success 'index.sparse disabled inline uses full index' ' ensure_not_expanded () { rm -f trace2.txt && - echo >>sparse-index/untracked.txt && + if test -z "$WITHOUT_UNTRACKED_TXT" + then + echo >>sparse-index/untracked.txt + fi && if test "$1" = "!" then @@ -1323,6 +1437,30 @@ test_expect_success 'sparse-index is not expanded: merge conflict in cone' ' ) ' +test_expect_success 'sparse-index is not expanded: stash' ' + init_repos && + + echo >>sparse-index/a && + ensure_not_expanded stash && + ensure_not_expanded stash list && + ensure_not_expanded stash show stash@{0} && + ensure_not_expanded stash apply stash@{0} && + ensure_not_expanded stash drop stash@{0} && + + echo >>sparse-index/deep/new && + ensure_not_expanded stash -u && + ( + WITHOUT_UNTRACKED_TXT=1 && + ensure_not_expanded stash pop + ) && + + ensure_not_expanded stash create && + oid=$(git -C sparse-index stash create) && + ensure_not_expanded stash store -m "test" $oid && + ensure_not_expanded reset --hard && + ensure_not_expanded stash pop +' + test_expect_success 'sparse index is not expanded: diff' ' init_repos && @@ -1369,6 +1507,15 @@ test_expect_success 'sparse index is not expanded: diff' ' ensure_not_expanded diff --cached ' +test_expect_success 'sparse index is not expanded: show and rev-parse' ' + init_repos && + + ensure_not_expanded show :a && + ensure_not_expanded show :deep/a && + ensure_not_expanded rev-parse :a && + ensure_not_expanded rev-parse :deep/a +' + test_expect_success 'sparse index is not expanded: update-index' ' init_repos && @@ -1444,6 +1591,7 @@ test_expect_success 'ls-files' ' cat >expect <<-\EOF && a + before/ deep/ e folder1- @@ -1491,6 +1639,7 @@ test_expect_success 'ls-files' ' cat >expect <<-\EOF && a + before/ deep/ e folder1- @@ -1511,6 +1660,31 @@ test_expect_success 'ls-files' ' ensure_not_expanded ls-files --sparse ' +test_expect_success 'sparse index is not expanded: sparse-checkout' ' + init_repos && + + ensure_not_expanded sparse-checkout set deep/deeper2 && + ensure_not_expanded sparse-checkout set deep/deeper1 && + ensure_not_expanded sparse-checkout set deep && + ensure_not_expanded sparse-checkout add folder1 && + ensure_not_expanded sparse-checkout set deep/deeper1 && + ensure_not_expanded sparse-checkout set folder2 && + + # Demonstrate that the checks that "folder1/a" is a file + # do not cause a sparse-index expansion (since it is in the + # sparse-checkout cone). + echo >>sparse-index/folder2/a && + git -C sparse-index add folder2/a && + + ensure_not_expanded sparse-checkout add folder1 && + + # Skip checks here, since deep/deeper1 is inside a sparse directory + # that must be expanded to check whether `deep/deeper1` is a file + # or not. + ensure_not_expanded sparse-checkout set --skip-checks deep/deeper1 && + ensure_not_expanded sparse-checkout set +' + # NEEDSWORK: a sparse-checkout behaves differently from a full checkout # in this scenario, but it shouldn't. test_expect_success 'reset mixed and checkout orphan' ' @@ -1654,4 +1828,29 @@ test_expect_success 'checkout behaves oddly with df-conflict-2' ' test_cmp full-checkout-err sparse-index-err ' +test_expect_success 'mv directory from out-of-cone to in-cone' ' + init_repos && + + # <source> as a sparse directory (or SKIP_WORKTREE_DIR without enabling + # sparse index). + test_all_match git mv --sparse folder1 deep && + test_all_match git status --porcelain=v2 && + test_sparse_match git ls-files -t && + git -C sparse-checkout ls-files -t >actual && + grep -e "H deep/folder1/0/0/0" actual && + grep -e "H deep/folder1/0/1" actual && + grep -e "H deep/folder1/a" actual && + + test_all_match git reset --hard && + + # <source> as a directory deeper than sparse index boundary (where + # sparse index will expand). + test_sparse_match git mv --sparse folder1/0 deep && + test_sparse_match git status --porcelain=v2 && + test_sparse_match git ls-files -t && + git -C sparse-checkout ls-files -t >actual && + grep -e "H deep/0/0/0" actual && + grep -e "H deep/0/1" actual +' + test_done diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 7dd9b32..c6661e6 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2024,8 +2024,17 @@ test_expect_success '--show-scope with --list' ' local user.override=local local include.path=../include/relative.include local user.relative=include + local core.repositoryformatversion=1 + local extensions.worktreeconfig=true + worktree user.worktree=true command user.cmdline=true EOF + git worktree add wt1 && + # We need these to test for worktree scope, but outside of this + # test, this is just noise + test_config core.repositoryformatversion 1 && + test_config extensions.worktreeConfig true && + git config --worktree user.worktree true && git -c user.cmdline=true config --list --show-scope >output && test_cmp expect output ' @@ -2074,12 +2083,13 @@ test_expect_success '--show-scope with --show-origin' ' ' test_expect_success 'override global and system config' ' - test_when_finished rm -f "$HOME"/.config/git && - + test_when_finished rm -f \"\$HOME\"/.gitconfig && cat >"$HOME"/.gitconfig <<-EOF && [home] config = true EOF + + test_when_finished rm -rf \"\$HOME\"/.config/git && mkdir -p "$HOME"/.config/git && cat >"$HOME"/.config/git/config <<-EOF && [xdg] diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh index 84bf197..93a2f91 100755 --- a/t/t1301-shared-repo.sh +++ b/t/t1301-shared-repo.sh @@ -48,7 +48,7 @@ done test_expect_success 'shared=all' ' mkdir sub && cd sub && - git init --shared=all && + git init --template= --shared=all && test 2 = $(git config core.sharedrepository) ' @@ -57,6 +57,7 @@ test_expect_success POSIXPERM 'update-server-info honors core.sharedRepository' git add a1 && test_tick && git commit -m a1 && + mkdir .git/info && umask 0277 && git update-server-info && actual="$(ls -l .git/info/refs)" && diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh index fa9647a..f6dc83e 100755 --- a/t/t1350-config-hooks-path.sh +++ b/t/t1350-config-hooks-path.sh @@ -6,11 +6,11 @@ test_description='Test the core.hooksPath configuration variable' test_expect_success 'set up a pre-commit hook in core.hooksPath' ' >actual && - mkdir -p .git/custom-hooks .git/hooks && + mkdir -p .git/custom-hooks && write_script .git/custom-hooks/pre-commit <<-\EOF && echo CUSTOM >>actual EOF - write_script .git/hooks/pre-commit <<-\EOF + test_hook --setup pre-commit <<-\EOF echo NORMAL >>actual EOF ' diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh index 132a1b8..9fb0b90 100755 --- a/t/t1401-symbolic-ref.sh +++ b/t/t1401-symbolic-ref.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='basic symbolic-ref tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # If the tests munging HEAD fail, they can break detection of diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh index cabc516..5ed9d73 100755 --- a/t/t1402-check-ref-format.sh +++ b/t/t1402-check-ref-format.sh @@ -2,6 +2,7 @@ test_description='Test git check-ref-format' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh valid_ref() { diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index ea8e6ac..aa59954 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -106,6 +106,28 @@ test_expect_success setup ' test_line_count = 4 output ' +test_expect_success 'correct usage on sub-command -h' ' + test_expect_code 129 git reflog expire -h >err && + grep "git reflog expire" err +' + +test_expect_success 'correct usage on "git reflog show -h"' ' + test_expect_code 129 git reflog show -h >err && + grep -F "git reflog [show]" err +' + +test_expect_success 'pass through -- to sub-command' ' + test_when_finished "rm -rf repo" && + git init repo && + test_commit -C repo message --a-file contents dash-tag && + + git -C repo reflog show -- --does-not-exist >out && + test_must_be_empty out && + git -C repo reflog show >expect && + git -C repo reflog show -- --a-file >actual && + test_cmp expect actual +' + test_expect_success rewind ' test_tick && git reset --hard HEAD~2 && test -f C && diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 0bb319b..da581ec 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -4,6 +4,7 @@ test_description='Test reflog display routines' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' @@ -169,9 +170,4 @@ test_expect_success 'git log -g -p shows diffs vs. parents' ' test_cmp expect actual ' -test_expect_success 'reflog exists works' ' - git reflog exists refs/heads/main && - ! git reflog exists refs/heads/nonexistent -' - test_done diff --git a/t/t1412-reflog-loop.sh b/t/t1412-reflog-loop.sh index 977603f..ff30874 100755 --- a/t/t1412-reflog-loop.sh +++ b/t/t1412-reflog-loop.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='reflog walk shows repeated commits again' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup commits' ' diff --git a/t/t1415-worktree-refs.sh b/t/t1415-worktree-refs.sh index a3e6ea0..3b53184 100755 --- a/t/t1415-worktree-refs.sh +++ b/t/t1415-worktree-refs.sh @@ -2,6 +2,7 @@ test_description='per-worktree refs' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 4e1e84a..2773172 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -8,7 +8,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success setup ' - mkdir -p .git/hooks && test_commit PRE && PRE_OID=$(git rev-parse PRE) && test_commit POST && @@ -16,9 +15,8 @@ test_expect_success setup ' ' test_expect_success 'hook allows updating ref if successful' ' - test_when_finished "rm .git/hooks/reference-transaction" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && echo "$*" >>actual EOF cat >expect <<-EOF && @@ -30,9 +28,8 @@ test_expect_success 'hook allows updating ref if successful' ' ' test_expect_success 'hook aborts updating ref in prepared state' ' - test_when_finished "rm .git/hooks/reference-transaction" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = prepared then exit 1 @@ -43,9 +40,9 @@ test_expect_success 'hook aborts updating ref in prepared state' ' ' test_expect_success 'hook gets all queued updates in prepared state' ' - test_when_finished "rm .git/hooks/reference-transaction actual" && + test_when_finished "rm actual" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = prepared then while read -r line @@ -66,9 +63,9 @@ test_expect_success 'hook gets all queued updates in prepared state' ' ' test_expect_success 'hook gets all queued updates in committed state' ' - test_when_finished "rm .git/hooks/reference-transaction actual" && + test_when_finished "rm actual" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = committed then while read -r line @@ -86,9 +83,9 @@ test_expect_success 'hook gets all queued updates in committed state' ' ' test_expect_success 'hook gets all queued updates in aborted state' ' - test_when_finished "rm .git/hooks/reference-transaction actual" && + test_when_finished "rm actual" && git reset --hard PRE && - write_script .git/hooks/reference-transaction <<-\EOF && + test_hook reference-transaction <<-\EOF && if test "$1" = aborted then while read -r line @@ -115,11 +112,11 @@ test_expect_success 'interleaving hook calls succeed' ' git init --bare target-repo.git && - write_script target-repo.git/hooks/reference-transaction <<-\EOF && + test_hook -C target-repo.git reference-transaction <<-\EOF && echo $0 "$@" >>actual EOF - write_script target-repo.git/hooks/update <<-\EOF && + test_hook -C target-repo.git update <<-\EOF && echo $0 "$@" >>actual EOF @@ -136,54 +133,4 @@ test_expect_success 'interleaving hook calls succeed' ' test_cmp expect target-repo.git/actual ' -test_expect_success 'hook does not get called on packing refs' ' - # Pack references first such that we are in a known state. - git pack-refs --all && - - write_script .git/hooks/reference-transaction <<-\EOF && - echo "$@" >>actual - cat >>actual - EOF - rm -f actual && - - git update-ref refs/heads/unpacked-ref $POST_OID && - git pack-refs --all && - - # We only expect a single hook invocation, which is the call to - # git-update-ref(1). - cat >expect <<-EOF && - prepared - $ZERO_OID $POST_OID refs/heads/unpacked-ref - committed - $ZERO_OID $POST_OID refs/heads/unpacked-ref - EOF - - test_cmp expect actual -' - -test_expect_success 'deleting packed ref calls hook once' ' - # Create a reference and pack it. - git update-ref refs/heads/to-be-deleted $POST_OID && - git pack-refs --all && - - write_script .git/hooks/reference-transaction <<-\EOF && - echo "$@" >>actual - cat >>actual - EOF - rm -f actual && - - git update-ref -d refs/heads/to-be-deleted $POST_OID && - - # We only expect a single hook invocation, which is the logical - # deletion. - cat >expect <<-EOF && - prepared - $POST_OID $ZERO_OID refs/heads/to-be-deleted - committed - $POST_OID $ZERO_OID refs/heads/to-be-deleted - EOF - - test_cmp expect actual -' - test_done diff --git a/t/t1418-reflog-exists.sh b/t/t1418-reflog-exists.sh new file mode 100755 index 0000000..d51ecd5 --- /dev/null +++ b/t/t1418-reflog-exists.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +test_description='Test reflog display routines' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit A +' + +test_expect_success 'usage' ' + test_expect_code 129 git reflog exists && + test_expect_code 129 git reflog exists -h +' + +test_expect_success 'usage: unknown option' ' + test_expect_code 129 git reflog exists --unknown-option +' + +test_expect_success 'reflog exists works' ' + git reflog exists refs/heads/main && + test_must_fail git reflog exists refs/heads/nonexistent +' + +test_expect_success 'reflog exists works with a "--" delimiter' ' + git reflog exists -- refs/heads/main && + test_must_fail git reflog exists -- refs/heads/nonexistent +' + +test_expect_success 'reflog exists works with a "--end-of-options" delimiter' ' + git reflog exists --end-of-options refs/heads/main && + test_must_fail git reflog exists --end-of-options refs/heads/nonexistent +' + +test_done diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index de50c0e..ab7f31f 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -774,10 +774,19 @@ test_expect_success 'fsck finds problems in duplicate loose objects' ' # no "-d" here, so we end up with duplicates git repack && # now corrupt the loose copy - file=$(sha1_file "$(git rev-parse HEAD)") && + oid="$(git rev-parse HEAD)" && + file=$(sha1_file "$oid") && rm "$file" && echo broken >"$file" && - test_must_fail git fsck + test_must_fail git fsck 2>err && + + cat >expect <<-EOF && + error: inflate: data stream error (incorrect header check) + error: unable to unpack header of $file + error: $oid: object corrupt or missing: $file + EOF + grep "^error: " err >actual && + test_cmp expect actual ) ' diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 29718aa..210f429 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -4,6 +4,7 @@ test_description='git-hook command' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-terminal.sh test_expect_success 'git hook usage' ' test_expect_code 129 git hook && @@ -27,7 +28,7 @@ test_expect_success 'git hook run: nonexistent hook with --ignore-missing' ' ' test_expect_success 'git hook run: basic' ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && echo Test hook EOF @@ -39,7 +40,7 @@ test_expect_success 'git hook run: basic' ' ' test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && echo >&1 Will end up on stderr echo >&2 Will end up on stderr EOF @@ -53,38 +54,23 @@ test_expect_success 'git hook run: stdout and stderr both write to our stderr' ' test_must_be_empty stdout.actual ' -test_expect_success 'git hook run: exit codes are passed along' ' - write_script .git/hooks/test-hook <<-EOF && - exit 1 - EOF - - test_expect_code 1 git hook run test-hook && - - write_script .git/hooks/test-hook <<-EOF && - exit 2 - EOF - - test_expect_code 2 git hook run test-hook && - - write_script .git/hooks/test-hook <<-EOF && - exit 128 - EOF +for code in 1 2 128 129 +do + test_expect_success "git hook run: exit code $code is passed along" ' + test_hook test-hook <<-EOF && + exit $code + EOF - test_expect_code 128 git hook run test-hook && - - write_script .git/hooks/test-hook <<-EOF && - exit 129 - EOF - - test_expect_code 129 git hook run test-hook -' + test_expect_code $code git hook run test-hook + ' +done test_expect_success 'git hook run arg u ments without -- is not allowed' ' test_expect_code 129 git hook run test-hook arg u ments ' test_expect_success 'git hook run -- pass arguments' ' - write_script .git/hooks/test-hook <<-\EOF && + test_hook test-hook <<-\EOF && echo $1 echo $2 EOF @@ -99,7 +85,7 @@ test_expect_success 'git hook run -- pass arguments' ' ' test_expect_success 'git hook run -- out-of-repo runs excluded' ' - write_script .git/hooks/test-hook <<-EOF && + test_hook test-hook <<-EOF && echo Test hook EOF @@ -120,6 +106,10 @@ test_expect_success 'git -c core.hooksPath=<PATH> hook run' ' Hook ran four EOF + test_hook test-hook <<-EOF && + echo Test hook + EOF + # Test various ways of specifying the path. See also # t1350-config-hooks-path.sh >actual && @@ -131,4 +121,34 @@ test_expect_success 'git -c core.hooksPath=<PATH> hook run' ' test_cmp expect actual ' +test_hook_tty () { + cat >expect <<-\EOF + STDOUT TTY + STDERR TTY + EOF + + test_when_finished "rm -rf repo" && + git init repo && + + test_commit -C repo A && + test_commit -C repo B && + git -C repo reset --soft HEAD^ && + + test_hook -C repo pre-commit <<-EOF && + test -t 1 && echo STDOUT TTY >>actual || echo STDOUT NO TTY >>actual && + test -t 2 && echo STDERR TTY >>actual || echo STDERR NO TTY >>actual + EOF + + test_terminal git -C repo "$@" && + test_cmp expect repo/actual +} + +test_expect_success TTY 'git hook run: stdout and stderr are connected to a TTY' ' + test_hook_tty hook run pre-commit +' + +test_expect_success TTY 'git commit: stdout and stderr are connected to a TTY' ' + test_hook_tty commit -m"B.new" +' + test_done diff --git a/t/t2015-checkout-unborn.sh b/t/t2015-checkout-unborn.sh index a972121..9425aae 100755 --- a/t/t2015-checkout-unborn.sh +++ b/t/t2015-checkout-unborn.sh @@ -4,6 +4,7 @@ test_description='checkout from unborn branch' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh index abfd586..a5822e4 100755 --- a/t/t2016-checkout-patch.sh +++ b/t/t2016-checkout-patch.sh @@ -4,7 +4,13 @@ test_description='git checkout --patch' . ./lib-patch-mode.sh -test_expect_success PERL 'setup' ' +if ! test_have_prereq ADD_I_USE_BUILTIN && ! test_have_prereq PERL +then + skip_all='skipping interactive add tests, PERL not set' + test_done +fi + +test_expect_success 'setup' ' mkdir dir && echo parent > dir/foo && echo dummy > bar && @@ -18,44 +24,40 @@ test_expect_success PERL 'setup' ' # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar' -# NEEDSWORK: Since the builtin add-p is used when $GIT_TEST_ADD_I_USE_BUILTIN -# is given, we should replace the PERL prerequisite with an ADD_I prerequisite -# which first checks if $GIT_TEST_ADD_I_USE_BUILTIN is defined before checking -# PERL. -test_expect_success PERL 'saying "n" does nothing' ' +test_expect_success 'saying "n" does nothing' ' set_and_save_state dir/foo work head && test_write_lines n n | git checkout -p && verify_saved_state bar && verify_saved_state dir/foo ' -test_expect_success PERL 'git checkout -p' ' +test_expect_success 'git checkout -p' ' test_write_lines n y | git checkout -p && verify_saved_state bar && verify_state dir/foo head head ' -test_expect_success PERL 'git checkout -p with staged changes' ' +test_expect_success 'git checkout -p with staged changes' ' set_state dir/foo work index && test_write_lines n y | git checkout -p && verify_saved_state bar && verify_state dir/foo index index ' -test_expect_success PERL 'git checkout -p HEAD with NO staged changes: abort' ' +test_expect_success 'git checkout -p HEAD with NO staged changes: abort' ' set_and_save_state dir/foo work head && test_write_lines n y n | git checkout -p HEAD && verify_saved_state bar && verify_saved_state dir/foo ' -test_expect_success PERL 'git checkout -p HEAD with NO staged changes: apply' ' +test_expect_success 'git checkout -p HEAD with NO staged changes: apply' ' test_write_lines n y y | git checkout -p HEAD && verify_saved_state bar && verify_state dir/foo head head ' -test_expect_success PERL 'git checkout -p HEAD with change already staged' ' +test_expect_success 'git checkout -p HEAD with change already staged' ' set_state dir/foo index index && # the third n is to get out in case it mistakenly does not apply test_write_lines n y n | git checkout -p HEAD && @@ -63,21 +65,21 @@ test_expect_success PERL 'git checkout -p HEAD with change already staged' ' verify_state dir/foo head head ' -test_expect_success PERL 'git checkout -p HEAD^...' ' +test_expect_success 'git checkout -p HEAD^...' ' # the third n is to get out in case it mistakenly does not apply test_write_lines n y n | git checkout -p HEAD^... && verify_saved_state bar && verify_state dir/foo parent parent ' -test_expect_success PERL 'git checkout -p HEAD^' ' +test_expect_success 'git checkout -p HEAD^' ' # the third n is to get out in case it mistakenly does not apply test_write_lines n y n | git checkout -p HEAD^ && verify_saved_state bar && verify_state dir/foo parent parent ' -test_expect_success PERL 'git checkout -p handles deletion' ' +test_expect_success 'git checkout -p handles deletion' ' set_state dir/foo work index && rm dir/foo && test_write_lines n y | git checkout -p && @@ -90,28 +92,28 @@ test_expect_success PERL 'git checkout -p handles deletion' ' # dir/foo. There's always an extra 'n' to reject edits to dir/foo in # the failure case (and thus get out of the loop). -test_expect_success PERL 'path limiting works: dir' ' +test_expect_success 'path limiting works: dir' ' set_state dir/foo work head && test_write_lines y n | git checkout -p dir && verify_saved_state bar && verify_state dir/foo head head ' -test_expect_success PERL 'path limiting works: -- dir' ' +test_expect_success 'path limiting works: -- dir' ' set_state dir/foo work head && test_write_lines y n | git checkout -p -- dir && verify_saved_state bar && verify_state dir/foo head head ' -test_expect_success PERL 'path limiting works: HEAD^ -- dir' ' +test_expect_success 'path limiting works: HEAD^ -- dir' ' # the third n is to get out in case it mistakenly does not apply test_write_lines y n n | git checkout -p HEAD^ -- dir && verify_saved_state bar && verify_state dir/foo parent parent ' -test_expect_success PERL 'path limiting works: foo inside dir' ' +test_expect_success 'path limiting works: foo inside dir' ' set_state dir/foo work head && # the third n is to get out in case it mistakenly does not apply test_write_lines y n n | (cd dir && git checkout -p foo) && @@ -119,11 +121,11 @@ test_expect_success PERL 'path limiting works: foo inside dir' ' verify_state dir/foo head head ' -test_expect_success PERL 'none of this moved HEAD' ' +test_expect_success 'none of this moved HEAD' ' verify_saved_head ' -test_expect_success PERL 'empty tree can be handled' ' +test_expect_success 'empty tree can be handled' ' test_when_finished "git reset --hard" && git checkout -p $(test_oid empty_tree) -- ' diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index 52e51b0..771c3c3 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -2,6 +2,7 @@ test_description='checkout' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh # Arguments: [!] <branch> <oid> [<checkout options>] @@ -257,11 +258,12 @@ test_expect_success 'checkout -b to a new branch preserves mergeable changes des git checkout branch1-scratch && test_might_fail git branch -D branch3 && git config core.sparseCheckout false && - rm .git/info/sparse-checkout" && + rm -rf .git/info" && test_commit file2 && echo stuff >>file1 && + mkdir .git/info && echo file2 >.git/info/sparse-checkout && git config core.sparseCheckout true && diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh index f691e6d..2d8c70b 100755 --- a/t/t2030-unresolve-info.sh +++ b/t/t2030-unresolve-info.sh @@ -194,4 +194,75 @@ test_expect_success 'rerere forget (add-add conflict)' ' test_i18ngrep "no remembered" actual ' +test_expect_success 'resolve-undo keeps blobs from gc' ' + git checkout -f main && + + # First make sure we do not have any cruft left in the object store + git repack -a -d && + git prune --expire=now && + git prune-packed && + git gc --prune=now && + git fsck --unreachable >cruft && + test_must_be_empty cruft && + + # Now add three otherwise unreferenced blob objects to the index + git reset --hard && + B1=$(echo "resolve undo test data 1" | git hash-object -w --stdin) && + B2=$(echo "resolve undo test data 2" | git hash-object -w --stdin) && + B3=$(echo "resolve undo test data 3" | git hash-object -w --stdin) && + git update-index --add --index-info <<-EOF && + 100644 $B1 1 frotz + 100644 $B2 2 frotz + 100644 $B3 3 frotz + EOF + + # These three blob objects are reachable (only) from the index + git fsck --unreachable >cruft && + test_must_be_empty cruft && + # and they should be protected from GC + git gc --prune=now && + git cat-file -e $B1 && + git cat-file -e $B2 && + git cat-file -e $B3 && + + # Now resolve the conflicted path + B0=$(echo "resolve undo test data 0" | git hash-object -w --stdin) && + git update-index --add --cacheinfo 100644,$B0,frotz && + + # These three blob objects are now reachable only from the resolve-undo + git fsck --unreachable >cruft && + test_must_be_empty cruft && + + # and they should survive GC + git gc --prune=now && + git cat-file -e $B0 && + git cat-file -e $B1 && + git cat-file -e $B2 && + git cat-file -e $B3 && + + # Now we switch away, which nukes resolve-undo, and + # blobs B0..B3 would become dangling. fsck should + # notice that they are now unreachable. + git checkout -f side && + git fsck --unreachable >cruft && + sort cruft >actual && + sort <<-EOF >expect && + unreachable blob $B0 + unreachable blob $B1 + unreachable blob $B2 + unreachable blob $B3 + EOF + test_cmp expect actual && + + # And they should go away when gc runs. + git gc --prune=now && + git fsck --unreachable >cruft && + test_must_be_empty cruft && + + test_must_fail git cat-file -e $B0 && + test_must_fail git cat-file -e $B1 && + test_must_fail git cat-file -e $B2 && + test_must_fail git cat-file -e $B3 +' + test_done diff --git a/t/t2080-parallel-checkout-basics.sh b/t/t2080-parallel-checkout-basics.sh index 3e0f8c6..c683e60 100755 --- a/t/t2080-parallel-checkout-basics.sh +++ b/t/t2080-parallel-checkout-basics.sh @@ -226,4 +226,52 @@ test_expect_success SYMLINKS 'parallel checkout checks for symlinks in leading d ) ' +# This test is here (and not in e.g. t2022-checkout-paths.sh), because we +# check the final report including sequential, parallel, and delayed entries +# all at the same time. So we must have finer control of the parallel checkout +# variables. +test_expect_success PERL '"git checkout ." report should not include failed entries' ' + write_script rot13-filter.pl "$PERL_PATH" \ + <"$TEST_DIRECTORY"/t0021/rot13-filter.pl && + + test_config_global filter.delay.process \ + "\"$(pwd)/rot13-filter.pl\" --always-delay delayed.log clean smudge delay" && + test_config_global filter.delay.required true && + test_config_global filter.cat.clean cat && + test_config_global filter.cat.smudge cat && + test_config_global filter.cat.required true && + + set_checkout_config 2 0 && + git init failed_entries && + ( + cd failed_entries && + cat >.gitattributes <<-EOF && + *delay* filter=delay + parallel-ineligible* filter=cat + EOF + echo a >missing-delay.a && + echo a >parallel-ineligible.a && + echo a >parallel-eligible.a && + echo b >success-delay.b && + echo b >parallel-ineligible.b && + echo b >parallel-eligible.b && + git add -A && + git commit -m files && + + a_blob="$(git rev-parse :parallel-ineligible.a)" && + rm .git/objects/$(test_oid_to_path $a_blob) && + rm *.a *.b && + + test_checkout_workers 2 test_must_fail git checkout . 2>err && + + # All *.b entries should succeed and all *.a entries should fail: + # - missing-delay.a: the delay filter will drop this path + # - parallel-*.a: the blob will be missing + # + grep "Updated 3 paths from the index" err && + test_stdout_line_count = 3 ls *.b && + ! ls *.a + ) +' + test_done diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index a30b7ca..07e6de8 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -36,9 +36,14 @@ test_expect_success '--cacheinfo does not accept blob null sha1' ' echo content >file && git add file && git rev-parse :file >expect && - test_must_fail git update-index --cacheinfo 100644 $ZERO_OID file && + test_must_fail git update-index --verbose --cacheinfo 100644 $ZERO_OID file >out && git rev-parse :file >actual && - test_cmp expect actual + test_cmp expect actual && + + cat >expect <<-\EOF && + add '\''file'\'' + EOF + test_cmp expect out ' test_expect_success '--cacheinfo does not accept gitlink null sha1' ' @@ -59,9 +64,14 @@ test_expect_success '--cacheinfo mode,sha1,path (new syntax)' ' git rev-parse :file >actual && test_cmp expect actual && - git update-index --add --cacheinfo "100644,$(cat expect),elif" && + git update-index --add --verbose --cacheinfo "100644,$(cat expect),elif" >out && git rev-parse :elif >actual && - test_cmp expect actual + test_cmp expect actual && + + cat >expect <<-\EOF && + add '\''elif'\'' + EOF + test_cmp expect out ' test_expect_success '.lock files cleaned up' ' @@ -74,7 +84,8 @@ test_expect_success '.lock files cleaned up' ' git config core.worktree ../../worktree && # --refresh triggers late setup_work_tree, # active_cache_changed is zero, rollback_lock_file fails - git update-index --refresh && + git update-index --refresh --verbose >out && + test_must_be_empty out && ! test -f .git/index.lock ) ' @@ -83,7 +94,15 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' ' >A && >B && git add A B && - git update-index --chmod=+x A --chmod=-x B && + git update-index --verbose --chmod=+x A --chmod=-x B >out && + cat >expect <<-\EOF && + add '\''A'\'' + chmod +x '\''A'\'' + add '\''B'\'' + chmod -x '\''B'\'' + EOF + test_cmp expect out && + cat >expect <<-EOF && 100755 $EMPTY_BLOB 0 A 100644 $EMPTY_BLOB 0 B diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index 0c38f8e..be394f1 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -14,6 +14,7 @@ only the updates to dir/sub. Also tested are "git add -u" without limiting, and "git add -u" without contents changes, and other conditions' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh index db7ca55..ebf58db 100755 --- a/t/t2203-add-intent.sh +++ b/t/t2203-add-intent.sh @@ -2,6 +2,7 @@ test_description='Intent to add' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'intent to add' ' diff --git a/t/t2205-add-worktree-config.sh b/t/t2205-add-worktree-config.sh new file mode 100755 index 0000000..43d950d --- /dev/null +++ b/t/t2205-add-worktree-config.sh @@ -0,0 +1,265 @@ +#!/bin/sh + +test_description='directory traversal respects user config + +This test verifies the traversal of the directory tree when the traversal begins +outside the repository. Two instances for which this can occur are tested: + + 1) The user manually sets the worktree. For this instance, the test sets + the worktree two levels above the `.git` directory and checks whether we + are able to add to the index those files that are in either (1) the + manually configured worktree directory or (2) the standard worktree + location with respect to the `.git` directory (i.e. ensuring that the + encountered `.git` directory is not treated as belonging to a foreign + nested repository). + 2) The user manually sets the `git_dir` while the working directory is + outside the repository. The test checks that files inside the + repository can be added to the index. + ' + +. ./test-lib.sh + +test_expect_success '1a: setup--config worktree' ' + mkdir test1 && + ( + cd test1 && + test_create_repo repo && + git --git-dir="repo/.git" config core.worktree "$(pwd)" && + + mkdir -p outside-tracked outside-untracked && + mkdir -p repo/inside-tracked repo/inside-untracked && + >file-tracked && + >file-untracked && + >outside-tracked/file && + >outside-untracked/file && + >repo/file-tracked && + >repo/file-untracked && + >repo/inside-tracked/file && + >repo/inside-untracked/file && + + cat >expect-tracked-unsorted <<-EOF && + ../file-tracked + ../outside-tracked/file + file-tracked + inside-tracked/file + EOF + + cat >expect-untracked-unsorted <<-EOF && + ../file-untracked + ../outside-untracked/file + file-untracked + inside-untracked/file + EOF + + cat >expect-all-dir-unsorted <<-EOF && + ../file-untracked + ../file-tracked + ../outside-untracked/ + ../outside-tracked/ + ./ + EOF + + cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted && + + cat >.gitignore <<-EOF + .gitignore + actual-* + expect-* + EOF + ) +' + +test_expect_success '1b: pre-add all' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + git -C repo ls-files -o --exclude-standard "$parent_dir" >actual-all-unsorted && + sort actual-all-unsorted >actual-all && + sort expect-all-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '1c: pre-add dir all' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + git -C repo ls-files -o --directory --exclude-standard "$parent_dir" >actual-all-dir-unsorted && + sort actual-all-dir-unsorted >actual-all && + sort expect-all-dir-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '1d: post-add tracked' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + ( + cd repo && + git add file-tracked && + git add inside-tracked && + git add ../outside-tracked && + git add "$parent_dir/file-tracked" && + git ls-files "$parent_dir" >../actual-tracked-unsorted + ) && + sort actual-tracked-unsorted >actual-tracked && + sort expect-tracked-unsorted >expect-tracked && + test_cmp expect-tracked actual-tracked + ) +' + +test_expect_success '1e: post-add untracked' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + git -C repo ls-files -o --exclude-standard "$parent_dir" >actual-untracked-unsorted && + sort actual-untracked-unsorted >actual-untracked && + sort expect-untracked-unsorted >expect-untracked && + test_cmp expect-untracked actual-untracked + ) +' + +test_expect_success '2a: setup--set git-dir' ' + mkdir test2 && + ( + cd test2 && + test_create_repo repo && + # create two foreign repositories that should remain untracked + test_create_repo repo-outside && + test_create_repo repo/repo-inside && + + mkdir -p repo/inside-tracked repo/inside-untracked && + >repo/file-tracked && + >repo/file-untracked && + >repo/inside-tracked/file && + >repo/inside-untracked/file && + >repo-outside/file && + >repo/repo-inside/file && + + cat >expect-tracked-unsorted <<-EOF && + repo/file-tracked + repo/inside-tracked/file + EOF + + cat >expect-untracked-unsorted <<-EOF && + repo/file-untracked + repo/inside-untracked/file + repo/repo-inside/ + repo-outside/ + EOF + + cat >expect-all-dir-unsorted <<-EOF && + repo/ + repo-outside/ + EOF + + cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted && + + cat >.gitignore <<-EOF + .gitignore + actual-* + expect-* + EOF + ) +' + +test_expect_success '2b: pre-add all' ' + ( + cd test2 && + git --git-dir=repo/.git ls-files -o --exclude-standard >actual-all-unsorted && + sort actual-all-unsorted >actual-all && + sort expect-all-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '2c: pre-add dir all' ' + ( + cd test2 && + git --git-dir=repo/.git ls-files -o --directory --exclude-standard >actual-all-dir-unsorted && + sort actual-all-dir-unsorted >actual-all && + sort expect-all-dir-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '2d: post-add tracked' ' + ( + cd test2 && + git --git-dir=repo/.git add repo/file-tracked && + git --git-dir=repo/.git add repo/inside-tracked && + git --git-dir=repo/.git ls-files >actual-tracked-unsorted && + sort actual-tracked-unsorted >actual-tracked && + sort expect-tracked-unsorted >expect-tracked && + test_cmp expect-tracked actual-tracked + ) +' + +test_expect_success '2e: post-add untracked' ' + ( + cd test2 && + git --git-dir=repo/.git ls-files -o --exclude-standard >actual-untracked-unsorted && + sort actual-untracked-unsorted >actual-untracked && + sort expect-untracked-unsorted >expect-untracked && + test_cmp expect-untracked actual-untracked + ) +' + +test_expect_success '3a: setup--add repo dir' ' + mkdir test3 && + ( + cd test3 && + test_create_repo repo && + + mkdir -p repo/inside-tracked repo/inside-ignored && + >repo/file-tracked && + >repo/file-ignored && + >repo/inside-tracked/file && + >repo/inside-ignored/file && + + cat >.gitignore <<-EOF && + .gitignore + actual-* + expect-* + *ignored + EOF + + cat >expect-tracked-unsorted <<-EOF && + repo/file-tracked + repo/inside-tracked/file + EOF + + cat >expect-ignored-unsorted <<-EOF + repo/file-ignored + repo/inside-ignored/ + .gitignore + actual-ignored-unsorted + expect-ignored-unsorted + expect-tracked-unsorted + EOF + ) +' + +test_expect_success '3b: ignored' ' + ( + cd test3 && + git --git-dir=repo/.git ls-files -io --directory --exclude-standard >actual-ignored-unsorted && + sort actual-ignored-unsorted >actual-ignored && + sort expect-ignored-unsorted >expect-ignored && + test_cmp expect-ignored actual-ignored + ) +' + +test_expect_success '3c: add repo' ' + ( + cd test3 && + git --git-dir=repo/.git add repo && + git --git-dir=repo/.git ls-files >actual-tracked-unsorted && + sort actual-tracked-unsorted >actual-tracked && + sort expect-tracked-unsorted >expect-tracked && + test_cmp expect-tracked actual-tracked + ) +' + +test_done diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index 43139af..f3242fe 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -5,6 +5,7 @@ test_description='test git worktree add' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh @@ -229,6 +230,7 @@ test_expect_success 'checkout with grafts' ' SHA1=$(git rev-parse HEAD) && test_commit def && test_commit xyz && + mkdir .git/info && echo "$(git rev-parse HEAD) $SHA1" >.git/info/grafts && cat >expected <<-\EOF && xyz @@ -559,10 +561,9 @@ test_expect_success 'git worktree --no-guess-remote option overrides config' ' ' post_checkout_hook () { - gitdir=${1:-.git} - test_when_finished "rm -f $gitdir/hooks/post-checkout" && - mkdir -p $gitdir/hooks && - write_script $gitdir/hooks/post-checkout <<-\EOF + test_when_finished "rm -rf .git/hooks" && + mkdir .git/hooks && + test_hook -C "$1" post-checkout <<-\EOF { echo $* git rev-parse --git-dir --show-toplevel diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index c8a5a0a..79e0fce 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -64,6 +64,25 @@ test_expect_success '"list" all worktrees --porcelain' ' test_cmp expect actual ' +test_expect_success '"list" all worktrees --porcelain -z' ' + test_when_finished "rm -rf here _actual actual expect && + git worktree prune" && + printf "worktree %sQHEAD %sQbranch %sQQ" \ + "$(git rev-parse --show-toplevel)" \ + $(git rev-parse HEAD --symbolic-full-name HEAD) >expect && + git worktree add --detach here main && + printf "worktree %sQHEAD %sQdetachedQQ" \ + "$(git -C here rev-parse --show-toplevel)" \ + "$(git rev-parse HEAD)" >>expect && + git worktree list --porcelain -z >_actual && + nul_to_q <_actual >actual && + test_cmp expect actual +' + +test_expect_success '"list" -z fails without --porcelain' ' + test_must_fail git worktree list -z +' + test_expect_success '"list" all worktrees with locked annotation' ' test_when_finished "rm -rf locked unlocked out && git worktree prune" && git worktree add --detach locked main && diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh new file mode 100755 index 0000000..50815ac --- /dev/null +++ b/t/t2407-worktree-heads.sh @@ -0,0 +1,180 @@ +#!/bin/sh + +test_description='test operations trying to overwrite refs at worktree HEAD' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit init && + + for i in 1 2 3 4 + do + git checkout -b conflict-$i && + echo "not I" >$i.t && + git add $i.t && + git commit -m "will conflict" && + + git checkout - && + test_commit $i && + git branch wt-$i && + git branch fake-$i && + git worktree add wt-$i wt-$i || return 1 + done && + + # Create a server that updates each branch by one commit + git init server && + test_commit -C server initial && + git remote add server ./server && + for i in 1 2 3 4 + do + git -C server checkout -b wt-$i && + test_commit -C server A-$i || return 1 + done && + for i in 1 2 + do + git -C server checkout -b fake-$i && + test_commit -C server f-$i || return 1 + done +' + +test_expect_success 'refuse to overwrite: checked out in worktree' ' + for i in 1 2 3 4 + do + test_must_fail git branch -f wt-$i HEAD 2>err + grep "cannot force update the branch" err && + + test_must_fail git branch -D wt-$i 2>err + grep "Cannot delete branch" err || return 1 + done +' + +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in bisect' ' + test_when_finished git -C wt-4 bisect reset && + + # Set up a bisect so HEAD no longer points to wt-4. + git -C wt-4 bisect start && + git -C wt-4 bisect bad wt-4 && + git -C wt-4 bisect good wt-1 && + + test_must_fail git branch -f wt-4 HEAD 2>err && + grep "cannot force update the branch '\''wt-4'\'' checked out at.*wt-4" err +' + +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (apply)' ' + test_when_finished git -C wt-2 rebase --abort && + + # This will fail part-way through due to a conflict. + test_must_fail git -C wt-2 rebase --apply conflict-2 && + + test_must_fail git branch -f wt-2 HEAD 2>err && + grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err +' + +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase (merge)' ' + test_when_finished git -C wt-2 rebase --abort && + + # This will fail part-way through due to a conflict. + test_must_fail git -C wt-2 rebase conflict-2 && + + test_must_fail git branch -f wt-2 HEAD 2>err && + grep "cannot force update the branch '\''wt-2'\'' checked out at.*wt-2" err +' + +test_expect_success !SANITIZE_LEAK 'refuse to overwrite: worktree in rebase with --update-refs' ' + test_when_finished git -C wt-3 rebase --abort && + + git branch -f can-be-updated wt-3 && + test_must_fail git -C wt-3 rebase --update-refs conflict-3 && + + for i in 3 4 + do + test_must_fail git branch -f can-be-updated HEAD 2>err && + grep "cannot force update the branch '\''can-be-updated'\'' checked out at.*wt-3" err || + return 1 + done +' + +test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: checked out' ' + test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && + grep "refusing to fetch into branch '\''refs/heads/wt-3'\''" err && + + # General fetch into refs/heads/ will fail on first ref, + # so use a generic error message check. + test_must_fail git fetch server +refs/heads/*:refs/heads/* 2>err && + grep "refusing to fetch into branch" err +' + +test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in bisect' ' + test_when_finished git -C wt-4 bisect reset && + + # Set up a bisect so HEAD no longer points to wt-4. + git -C wt-4 bisect start && + git -C wt-4 bisect bad wt-4 && + git -C wt-4 bisect good wt-1 && + + test_must_fail git fetch server +refs/heads/wt-4:refs/heads/wt-4 2>err && + grep "refusing to fetch into branch" err +' + +test_expect_success !SANITIZE_LEAK 'refuse to fetch over ref: worktree in rebase' ' + test_when_finished git -C wt-3 rebase --abort && + + # This will fail part-way through due to a conflict. + test_must_fail git -C wt-3 rebase conflict-3 && + + test_must_fail git fetch server +refs/heads/wt-3:refs/heads/wt-3 2>err && + grep "refusing to fetch into branch" err +' + +test_expect_success 'refuse to overwrite when in error states' ' + test_when_finished rm -rf .git/worktrees/wt-*/rebase-merge && + test_when_finished rm -rf .git/worktrees/wt-*/BISECT_* && + + # Both branches are currently under rebase. + mkdir -p .git/worktrees/wt-3/rebase-merge && + touch .git/worktrees/wt-3/rebase-merge/interactive && + echo refs/heads/fake-1 >.git/worktrees/wt-3/rebase-merge/head-name && + echo refs/heads/fake-2 >.git/worktrees/wt-3/rebase-merge/onto && + mkdir -p .git/worktrees/wt-4/rebase-merge && + touch .git/worktrees/wt-4/rebase-merge/interactive && + echo refs/heads/fake-2 >.git/worktrees/wt-4/rebase-merge/head-name && + echo refs/heads/fake-1 >.git/worktrees/wt-4/rebase-merge/onto && + + # Both branches are currently under bisect. + touch .git/worktrees/wt-4/BISECT_LOG && + echo refs/heads/fake-2 >.git/worktrees/wt-4/BISECT_START && + touch .git/worktrees/wt-1/BISECT_LOG && + echo refs/heads/fake-1 >.git/worktrees/wt-1/BISECT_START && + + for i in 1 2 + do + test_must_fail git branch -f fake-$i HEAD 2>err && + grep "cannot force update the branch '\''fake-$i'\'' checked out at" err || + return 1 + done +' + +. "$TEST_DIRECTORY"/lib-rebase.sh + +test_expect_success !SANITIZE_LEAK 'refuse to overwrite during rebase with --update-refs' ' + git commit --fixup HEAD~2 --allow-empty && + ( + set_cat_todo_editor && + test_must_fail git rebase -i --update-refs HEAD~3 >todo && + ! grep "update-refs" todo + ) && + git branch -f allow-update HEAD~2 && + ( + set_cat_todo_editor && + test_must_fail git rebase -i --update-refs HEAD~3 >todo && + grep "update-ref refs/heads/allow-update" todo + ) +' + +# This must be the last test in this file +test_expect_success '$EDITOR and friends are unchanged' ' + test_editor_unchanged +' + +test_done diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index 48cec4e..e07ac6c 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -67,26 +67,26 @@ echo '!*.2 allignores='.gitignore one/.gitignore one/two/.gitignore' -test_expect_success \ - 'git ls-files --others with various exclude options.' \ - 'git ls-files --others \ +test_expect_success 'git ls-files --others with various exclude options.' ' + git ls-files --others \ --exclude=\*.6 \ --exclude-per-directory=.gitignore \ --exclude-from=.git/ignore \ - >output && - test_cmp expect output' + >output && + test_cmp expect output +' # Test \r\n (MSDOS-like systems) printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore -test_expect_success \ - 'git ls-files --others with \r\n line endings.' \ - 'git ls-files --others \ +test_expect_success 'git ls-files --others with \r\n line endings.' ' + git ls-files --others \ --exclude=\*.6 \ --exclude-per-directory=.gitignore \ --exclude-from=.git/ignore \ - >output && - test_cmp expect output' + >output && + test_cmp expect output +' test_expect_success 'setup skip-worktree gitignore' ' git add $allignores && @@ -94,14 +94,14 @@ test_expect_success 'setup skip-worktree gitignore' ' rm $allignores ' -test_expect_success \ - 'git ls-files --others with various exclude options.' \ - 'git ls-files --others \ +test_expect_success 'git ls-files --others with various exclude options.' ' + git ls-files --others \ --exclude=\*.6 \ --exclude-per-directory=.gitignore \ --exclude-from=.git/ignore \ - >output && - test_cmp expect output' + >output && + test_cmp expect output +' test_expect_success !SANITIZE_LEAK 'restore gitignore' ' git checkout --ignore-skip-worktree-bits $allignores && @@ -283,12 +283,12 @@ test_expect_success 'pattern matches prefix completely' ' ' test_expect_success 'ls-files with "**" patterns' ' - cat <<\EOF >expect && -a.1 -one/a.1 -one/two/a.1 -three/a.1 -EOF + cat <<-\EOF >expect && + a.1 + one/a.1 + one/two/a.1 + three/a.1 + EOF git ls-files -o -i --exclude "**/a.1" >actual && test_cmp expect actual ' diff --git a/t/t3002-ls-files-dashpath.sh b/t/t3002-ls-files-dashpath.sh index 54d22a4..4dd2455 100755 --- a/t/t3002-ls-files-dashpath.sh +++ b/t/t3002-ls-files-dashpath.sh @@ -16,56 +16,62 @@ filesystem. TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh -test_expect_success \ - setup \ - 'echo frotz >path0 && +test_expect_success 'setup' ' + echo frotz >path0 && echo frotz >./-foo && - echo frotz >./--' + echo frotz >./-- +' -test_expect_success \ - 'git ls-files without path restriction.' \ - 'git ls-files --others >output && - test_cmp output - <<EOF --- --foo -output -path0 -EOF +test_expect_success 'git ls-files without path restriction.' ' + test_when_finished "rm -f expect" && + git ls-files --others >output && + cat >expect <<-\EOF && + -- + -foo + output + path0 + EOF + test_cmp output expect ' -test_expect_success \ - 'git ls-files with path restriction.' \ - 'git ls-files --others path0 >output && - test_cmp output - <<EOF -path0 -EOF +test_expect_success 'git ls-files with path restriction.' ' + test_when_finished "rm -f expect" && + git ls-files --others path0 >output && + cat >expect <<-\EOF && + path0 + EOF + test_cmp output expect ' -test_expect_success \ - 'git ls-files with path restriction with --.' \ - 'git ls-files --others -- path0 >output && - test_cmp output - <<EOF -path0 -EOF +test_expect_success 'git ls-files with path restriction with --.' ' + test_when_finished "rm -f expect" && + git ls-files --others -- path0 >output && + cat >expect <<-\EOF && + path0 + EOF + test_cmp output expect ' -test_expect_success \ - 'git ls-files with path restriction with -- --.' \ - 'git ls-files --others -- -- >output && - test_cmp output - <<EOF --- -EOF +test_expect_success 'git ls-files with path restriction with -- --.' ' + test_when_finished "rm -f expect" && + git ls-files --others -- -- >output && + cat >expect <<-\EOF && + -- + EOF + test_cmp output expect ' -test_expect_success \ - 'git ls-files with no path restriction.' \ - 'git ls-files --others -- >output && - test_cmp output - <<EOF --- --foo -output -path0 -EOF +test_expect_success 'git ls-files with no path restriction.' ' + test_when_finished "rm -f expect" && + git ls-files --others -- >output && + cat >expect <<-\EOF && + -- + -foo + output + path0 + EOF + test_cmp output expect + ' test_done diff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh index 2cbcbc0..133593d 100755 --- a/t/t3020-ls-files-error-unmatch.sh +++ b/t/t3020-ls-files-error-unmatch.sh @@ -19,12 +19,12 @@ test_expect_success 'setup' ' git commit -m "add foo bar" ' -test_expect_success \ - 'git ls-files --error-unmatch should fail with unmatched path.' \ - 'test_must_fail git ls-files --error-unmatch foo bar-does-not-match' +test_expect_success 'git ls-files --error-unmatch should fail with unmatched path.' ' + test_must_fail git ls-files --error-unmatch foo bar-does-not-match +' -test_expect_success \ - 'git ls-files --error-unmatch should succeed with matched paths.' \ - 'git ls-files --error-unmatch foo bar' +test_expect_success 'git ls-files --error-unmatch should succeed with matched paths.' ' + git ls-files --error-unmatch foo bar +' test_done diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh index b257c79..52f76f7 100755 --- a/t/t3060-ls-files-with-tree.sh +++ b/t/t3060-ls-files-with-tree.sh @@ -10,7 +10,7 @@ a scenario known to trigger a crash with some versions of git. ' . ./test-lib.sh -test_expect_success setup ' +test_expect_success 'setup' ' # The bug we are exercising requires a fair number of entries # in a sub-directory so that add_index_entry will trigger a @@ -62,9 +62,9 @@ test_expect_success 'git ls-files --with-tree should succeed from subdir' ' ) ' -test_expect_success \ - 'git ls-files --with-tree should add entries from named tree.' \ - 'test_cmp expected output' +test_expect_success 'git ls-files --with-tree should add entries from named tree.' ' + test_cmp expected output +' test_expect_success 'no duplicates in --with-tree output' ' git ls-files --with-tree=HEAD >actual && diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh index 05fde64..217006d 100755 --- a/t/t3101-ls-tree-dirname.sh +++ b/t/t3101-ls-tree-dirname.sh @@ -201,31 +201,34 @@ EOF test_cmp expected check ' -test_expect_success 'ls-tree --name-only' ' - git ls-tree --name-only $tree >current && - cat >expected <<\EOF && -1.txt -2.txt -path0 -path1 -path2 -path3 -EOF - test_output -' - -test_expect_success 'ls-tree --name-only -r' ' - git ls-tree --name-only -r $tree >current && - cat >expected <<\EOF && -1.txt -2.txt -path0/a/b/c/1.txt -path1/b/c/1.txt -path2/1.txt -path3/1.txt -path3/2.txt -EOF - test_output -' +for opt in --name-only --name-status +do + test_expect_success "ls-tree $opt" ' + git ls-tree $opt $tree >current && + cat >expected <<-\EOF && + 1.txt + 2.txt + path0 + path1 + path2 + path3 + EOF + test_output + ' + + test_expect_success "ls-tree $opt -r" ' + git ls-tree $opt -r $tree >current && + cat >expected <<-\EOF && + 1.txt + 2.txt + path0/a/b/c/1.txt + path1/b/c/1.txt + path2/1.txt + path3/1.txt + path3/2.txt + EOF + test_output + ' +done test_done diff --git a/t/t3103-ls-tree-misc.sh b/t/t3103-ls-tree-misc.sh index d18ba1b..81c6343 100755 --- a/t/t3103-ls-tree-misc.sh +++ b/t/t3103-ls-tree-misc.sh @@ -23,4 +23,19 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' ' test_must_fail git ls-tree -r HEAD ' +for opts in \ + "--long --name-only" \ + "--name-only --name-status" \ + "--name-status --object-only" \ + "--object-only --long" +do + test_expect_success "usage: incompatible options: $opts" ' + test_expect_code 129 git ls-tree $opts $tree + ' + + one_opt=$(echo "$opts" | cut -d' ' -f1) + test_expect_success "usage: incompatible options: $one_opt and --format" ' + test_expect_code 129 git ls-tree $one_opt --format=fmt $tree + ' +done test_done diff --git a/t/t3104-ls-tree-format.sh b/t/t3104-ls-tree-format.sh new file mode 100755 index 0000000..3838966 --- /dev/null +++ b/t/t3104-ls-tree-format.sh @@ -0,0 +1,75 @@ +#!/bin/sh + +test_description='ls-tree --format' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-t3100.sh + +test_expect_success 'ls-tree --format usage' ' + test_expect_code 129 git ls-tree --format=fmt -l HEAD && + test_expect_code 129 git ls-tree --format=fmt --name-only HEAD && + test_expect_code 129 git ls-tree --format=fmt --name-status HEAD +' + +test_expect_success 'setup' ' + setup_basic_ls_tree_data +' + +test_ls_tree_format () { + format=$1 && + opts=$2 && + fmtopts=$3 && + shift 2 && + + test_expect_success "ls-tree '--format=<$format>' is like options '$opts $fmtopts'" ' + git ls-tree $opts -r HEAD >expect && + git ls-tree --format="$format" -r $fmtopts HEAD >actual && + test_cmp expect actual + ' + + test_expect_success "ls-tree '--format=<$format>' on optimized v.s. non-optimized path" ' + git ls-tree --format="$format" -r $fmtopts HEAD >expect && + git ls-tree --format="> $format" -r $fmtopts HEAD >actual.raw && + sed "s/^> //" >actual <actual.raw && + test_cmp expect actual + ' +} + +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ + "" + +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname) %(objectsize:padded)%x09%(path)" \ + "--long" + +test_ls_tree_format \ + "%(path)" \ + "--name-only" + +test_ls_tree_format \ + "%(objectname)" \ + "--object-only" + +test_ls_tree_format \ + "%(objectname)" \ + "--object-only --abbrev" \ + "--abbrev" + +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ + "-t" \ + "-t" + +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ + "--full-name" \ + "--full-name" + +test_ls_tree_format \ + "%(objectmode) %(objecttype) %(objectname)%x09%(path)" \ + "--full-tree" \ + "--full-tree" + +test_done diff --git a/t/t3105-ls-tree-output.sh b/t/t3105-ls-tree-output.sh new file mode 100755 index 0000000..ce2391e --- /dev/null +++ b/t/t3105-ls-tree-output.sh @@ -0,0 +1,192 @@ +#!/bin/sh + +test_description='ls-tree output' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-t3100.sh + +test_expect_success 'ls-tree --format usage' ' + test_expect_code 129 git ls-tree --format=fmt -l HEAD && + test_expect_code 129 git ls-tree --format=fmt --name-only HEAD && + test_expect_code 129 git ls-tree --format=fmt --name-status HEAD +' + +test_expect_success 'setup' ' + setup_basic_ls_tree_data +' + +test_ls_tree_format_mode_output () { + local opts="$1" && + shift && + cat >expect && + + while test $# -gt 0 + do + local mode="$1" && + shift && + + test_expect_success "'ls-tree $opts${mode:+ $mode}' output" ' + git ls-tree ${mode:+$mode }$opts HEAD >actual && + test_cmp expect actual + ' + + case "$opts" in + --full-tree) + test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir, fails)" ' + test_must_fail git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ + ' + ;; + *) + test_expect_success "'ls-tree $opts${mode:+ $mode}' output (via subdir)" ' + git -C dir ls-tree --full-name ${mode:+$mode }$opts HEAD -- ../ >actual && + test_cmp expect actual + ' + ;; + esac + done +} + +# test exact output of option (none, --long, ...) and mode (none and +# -d, -r -t) and combinations +test_expect_success 'setup: HEAD_* variables' ' + HEAD_gitmodules=$(git rev-parse HEAD:.gitmodules) && + HEAD_dir=$(git rev-parse HEAD:dir) && + HEAD_top_file=$(git rev-parse HEAD:top-file.t) && + HEAD_submodule=$(git rev-parse HEAD:submodule) && + HEAD_dir_sub_file=$(git rev-parse HEAD:dir/sub-file.t) +' +## opt = +test_ls_tree_format_mode_output "" "" "-t" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF +test_ls_tree_format_mode_output "" "-d" <<-EOF + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + EOF +test_ls_tree_format_mode_output "" "-r" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 100644 blob $HEAD_dir_sub_file dir/sub-file.t + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF +## opt = --long +test_ls_tree_format_mode_output "--long" "" "-t" <<-EOF + 100644 blob $HEAD_gitmodules 61 .gitmodules + 040000 tree $HEAD_dir - dir + 160000 commit $HEAD_submodule - submodule + 100644 blob $HEAD_top_file 9 top-file.t + EOF +test_ls_tree_format_mode_output "--long" "-d" <<-EOF + 040000 tree $HEAD_dir - dir + 160000 commit $HEAD_submodule - submodule + EOF +test_ls_tree_format_mode_output "--long" "-r" <<-EOF + 100644 blob $HEAD_gitmodules 61 .gitmodules + 100644 blob $HEAD_dir_sub_file 13 dir/sub-file.t + 160000 commit $HEAD_submodule - submodule + 100644 blob $HEAD_top_file 9 top-file.t + EOF +## opt = --name-only +test_ls_tree_format_mode_output "--name-only" "" "-t" <<-EOF + .gitmodules + dir + submodule + top-file.t + EOF +test_ls_tree_format_mode_output "--name-only" "-d" <<-EOF + dir + submodule + EOF +test_ls_tree_format_mode_output "--name-only" "-r" <<-EOF + .gitmodules + dir/sub-file.t + submodule + top-file.t + EOF +## opt = --object-only +test_ls_tree_format_mode_output "--object-only" "" "-t" <<-EOF + $HEAD_gitmodules + $HEAD_dir + $HEAD_submodule + $HEAD_top_file + EOF +test_ls_tree_format_mode_output "--object-only" "-d" <<-EOF + $HEAD_dir + $HEAD_submodule + EOF +test_ls_tree_format_mode_output "--object-only" "-r" <<-EOF + $HEAD_gitmodules + $HEAD_dir_sub_file + $HEAD_submodule + $HEAD_top_file + EOF +## opt = --object-only --abbrev +test_expect_success 'setup: HEAD_short_* variables' ' + HEAD_short_gitmodules=$(git rev-parse --short HEAD:.gitmodules) && + HEAD_short_dir=$(git rev-parse --short HEAD:dir) && + HEAD_short_top_file=$(git rev-parse --short HEAD:top-file.t) && + HEAD_short_submodule=$(git rev-parse --short HEAD:submodule) && + HEAD_short_dir_sub_file=$(git rev-parse --short HEAD:dir/sub-file.t) +' +test_ls_tree_format_mode_output "--object-only --abbrev" "" "-t" <<-EOF + $HEAD_short_gitmodules + $HEAD_short_dir + $HEAD_short_submodule + $HEAD_short_top_file + EOF +test_ls_tree_format_mode_output "--object-only --abbrev" "-d" <<-EOF + $HEAD_short_dir + $HEAD_short_submodule + EOF +test_ls_tree_format_mode_output "--object-only --abbrev" "-r" <<-EOF + $HEAD_short_gitmodules + $HEAD_short_dir_sub_file + $HEAD_short_submodule + $HEAD_short_top_file + EOF +## opt = --full-name +test_ls_tree_format_mode_output "--full-name" "" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF +test_ls_tree_format_mode_output "--full-name" "-d" <<-EOF + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + EOF +test_ls_tree_format_mode_output "--full-name" "-r" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 100644 blob $HEAD_dir_sub_file dir/sub-file.t + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF +test_ls_tree_format_mode_output "--full-name" "-t" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF +## opt = --full-tree +test_ls_tree_format_mode_output "--full-tree" "" "-t" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF +test_ls_tree_format_mode_output "--full-tree" "-d" <<-EOF + 040000 tree $HEAD_dir dir + 160000 commit $HEAD_submodule submodule + EOF +test_ls_tree_format_mode_output "--full-tree" "-r" <<-EOF + 100644 blob $HEAD_gitmodules .gitmodules + 100644 blob $HEAD_dir_sub_file dir/sub-file.t + 160000 commit $HEAD_submodule submodule + 100644 blob $HEAD_top_file top-file.t + EOF + +test_done diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 7a0ff75..9723c28 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -886,6 +886,41 @@ test_expect_success 'branch from tag w/--track causes failure' ' test_must_fail git branch --track my11 foobar ' +test_expect_success 'simple tracking works when remote branch name matches' ' + test_when_finished "rm -rf otherserver" && + git init otherserver && + test_commit -C otherserver my_commit 1 && + git -C otherserver branch feature && + test_config branch.autosetupmerge simple && + test_config remote.otherserver.url otherserver && + test_config remote.otherserver.fetch refs/heads/*:refs/remotes/otherserver/* && + git fetch otherserver && + git branch feature otherserver/feature && + test_cmp_config otherserver branch.feature.remote && + test_cmp_config refs/heads/feature branch.feature.merge +' + +test_expect_success 'simple tracking skips when remote branch name does not match' ' + test_config branch.autosetupmerge simple && + test_config remote.local.url . && + test_config remote.local.fetch refs/heads/*:refs/remotes/local/* && + git fetch local && + git branch my-other local/main && + test_cmp_config "" --default "" branch.my-other.remote && + test_cmp_config "" --default "" branch.my-other.merge +' + +test_expect_success 'simple tracking skips when remote ref is not a branch' ' + test_config branch.autosetupmerge simple && + test_config remote.localtags.url . && + test_config remote.localtags.fetch refs/tags/*:refs/remotes/localtags/* && + git tag mytag12 main && + git fetch localtags && + git branch mytag12 localtags/mytag12 && + test_cmp_config "" --default "" branch.mytag12.remote && + test_cmp_config "" --default "" branch.mytag12.merge +' + test_expect_success '--set-upstream-to fails on multiple branches' ' echo "fatal: too many arguments to set new upstream" >expect && test_must_fail git branch --set-upstream-to main a b c 2>err && @@ -1039,13 +1074,27 @@ test_expect_success 'checkout -b with -l makes reflog when core.logAllRefUpdates git rev-parse --verify gamma@{0} ' -test_expect_success 'avoid ambiguous track' ' +test_expect_success 'avoid ambiguous track and advise' ' git config branch.autosetupmerge true && git config remote.ambi1.url lalala && git config remote.ambi1.fetch refs/heads/lalala:refs/heads/main && git config remote.ambi2.url lilili && git config remote.ambi2.fetch refs/heads/lilili:refs/heads/main && - test_must_fail git branch all1 main && + cat <<-EOF >expected && + fatal: not tracking: ambiguous information for ref '\''refs/heads/main'\'' + hint: There are multiple remotes whose fetch refspecs map to the remote + hint: tracking ref '\''refs/heads/main'\'': + hint: ambi1 + hint: ambi2 + hint: '' + hint: This is typically a configuration error. + hint: '' + hint: To support setting up tracking branches, ensure that + hint: different remotes'\'' fetch refspecs map into different + hint: tracking namespaces. + EOF + test_must_fail git branch all1 main 2>actual && + test_cmp expected actual && test -z "$(git config branch.all1.merge)" ' diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh index 7a1be73..f2b9199 100755 --- a/t/t3202-show-branch.sh +++ b/t/t3202-show-branch.sh @@ -161,4 +161,18 @@ test_expect_success 'show branch --reflog=2' ' test_cmp actual expect ' +# incompatible options +while read combo +do + test_expect_success "show-branch $combo (should fail)" ' + test_must_fail git show-branch $combo 2>error && + grep -e "cannot be used together" -e "usage:" error + ' +done <<\EOF +--all --reflog +--merge-base --reflog +--list --merge-base +--reflog --current +EOF + test_done diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index e30bc48..d12e4e4 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -772,4 +772,55 @@ test_expect_success '--left-only/--right-only' ' test_cmp expect actual ' +test_expect_success 'submodule changes are shown irrespective of diff.submodule' ' + git init sub-repo && + test_commit -C sub-repo sub-first && + sub_oid1=$(git -C sub-repo rev-parse HEAD) && + test_commit -C sub-repo sub-second && + sub_oid2=$(git -C sub-repo rev-parse HEAD) && + test_commit -C sub-repo sub-third && + sub_oid3=$(git -C sub-repo rev-parse HEAD) && + + git checkout -b main-sub topic && + git submodule add ./sub-repo sub && + git -C sub checkout --detach sub-first && + git commit -m "add sub" sub && + sup_oid1=$(git rev-parse --short HEAD) && + git checkout -b topic-sub && + git -C sub checkout sub-second && + git commit -m "change sub" sub && + sup_oid2=$(git rev-parse --short HEAD) && + git checkout -b modified-sub main-sub && + git -C sub checkout sub-third && + git commit -m "change sub" sub && + sup_oid3=$(git rev-parse --short HEAD) && + sup_oid0=$(test_oid __) && + + test_config diff.submodule log && + git range-diff topic topic-sub modified-sub >actual && + cat >expect <<-EOF && + 1: $sup_oid1 = 1: $sup_oid1 add sub + 2: $sup_oid2 < -: $sup_oid0 change sub + -: $sup_oid0 > 2: $sup_oid3 change sub + EOF + test_cmp expect actual && + test_config diff.submodule diff && + git range-diff topic topic-sub modified-sub >actual && + git range-diff --creation-factor=100 topic topic-sub modified-sub >actual && + cat >expect <<-EOF && + 1: $sup_oid1 = 1: $sup_oid1 add sub + 2: $sup_oid2 ! 2: $sup_oid3 change sub + @@ Commit message + ## sub ## + @@ + -Subproject commit $sub_oid1 + -+Subproject commit $sub_oid2 + ++Subproject commit $sub_oid3 + EOF + test_cmp expect actual && + test_config diff.submodule diff && + git range-diff --creation-factor=100 topic topic-sub modified-sub >actual && + test_cmp expect actual +' + test_done diff --git a/t/t3207-branch-submodule.sh b/t/t3207-branch-submodule.sh index 0d93f75..cfde6b2 100755 --- a/t/t3207-branch-submodule.sh +++ b/t/t3207-branch-submodule.sh @@ -260,7 +260,7 @@ test_expect_success 'should get fatal error upon branch creation when submodule ) ' -test_expect_success 'should set up tracking of remote-tracking branches' ' +test_expect_success 'should set up tracking of remote-tracking branches by default' ' test_when_finished "reset_remote_test" && ( cd super-clone && @@ -289,4 +289,40 @@ test_expect_success 'should not fail when unable to set up tracking in submodule ) ' +test_expect_success '--track=inherit should set up tracking correctly' ' + test_when_finished "reset_remote_test" && + ( + cd super-clone && + git branch --recurse-submodules branch-a origin/branch-a && + # Set this manually instead of using branch --set-upstream-to + # to circumvent the "nonexistent upstream" check. + git -C sub config branch.branch-a.remote origin && + git -C sub config branch.branch-a.merge refs/heads/sub-branch-a && + git -C sub/sub-sub config branch.branch-a.remote other && + git -C sub/sub-sub config branch.branch-a.merge refs/heads/sub-sub-branch-a && + + git branch --recurse-submodules --track=inherit branch-b branch-a && + test_cmp_config origin branch.branch-b.remote && + test_cmp_config refs/heads/branch-a branch.branch-b.merge && + test_cmp_config -C sub origin branch.branch-b.remote && + test_cmp_config -C sub refs/heads/sub-branch-a branch.branch-b.merge && + test_cmp_config -C sub/sub-sub other branch.branch-b.remote && + test_cmp_config -C sub/sub-sub refs/heads/sub-sub-branch-a branch.branch-b.merge + ) +' + +test_expect_success '--no-track should not set up tracking' ' + test_when_finished "reset_remote_test" && + ( + cd super-clone && + git branch --recurse-submodules --no-track branch-a origin/branch-a && + test_cmp_config "" --default "" branch.branch-a.remote && + test_cmp_config "" --default "" branch.branch-a.merge && + test_cmp_config -C sub "" --default "" branch.branch-a.remote && + test_cmp_config -C sub "" --default "" branch.branch-a.merge && + test_cmp_config -C sub/sub-sub "" --default "" branch.branch-a.remote && + test_cmp_config -C sub/sub-sub "" --default "" branch.branch-a.merge + ) +' + test_done diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index bb5fea0..d0c4d38 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -8,6 +8,7 @@ test_description='Test commit notes index (expensive!)' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh create_repo () { diff --git a/t/t3303-notes-subtrees.sh b/t/t3303-notes-subtrees.sh index eac1937..bc9b791 100755 --- a/t/t3303-notes-subtrees.sh +++ b/t/t3303-notes-subtrees.sh @@ -5,6 +5,7 @@ test_description='Test commit notes organized in subtrees' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh number_of_commits=100 diff --git a/t/t3304-notes-mixed.sh b/t/t3304-notes-mixed.sh index 03dfcd3..2c3a245 100755 --- a/t/t3304-notes-mixed.sh +++ b/t/t3304-notes-mixed.sh @@ -5,6 +5,7 @@ test_description='Test notes trees that also contain non-notes' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh number_of_commits=100 diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh index 9976d78..64a9915 100755 --- a/t/t3305-notes-fanout.sh +++ b/t/t3305-notes-fanout.sh @@ -2,6 +2,7 @@ test_description='Test that adding/removing many notes triggers automatic fanout restructuring' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh path_has_fanout() { diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 71b1735..d5a8ee3 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -18,10 +18,7 @@ GIT_AUTHOR_EMAIL=bogus@email@address export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL test_expect_success 'prepare repository with topic branches' ' - git config core.logAllRefUpdates true && - echo First >A && - git update-index --add A && - git commit -m "Add A." && + test_commit "Add A." A First First && git checkout -b force-3way && echo Dummy >Y && git update-index --add Y && @@ -32,9 +29,7 @@ test_expect_success 'prepare repository with topic branches' ' git mv A D/A && git commit -m "Move A." && git checkout -b my-topic-branch main && - echo Second >B && - git update-index --add B && - git commit -m "Add B." && + test_commit "Add B." B Second Second && git checkout -f main && echo Third >>A && git update-index A && @@ -399,6 +394,15 @@ test_expect_success 'switch to branch not checked out' ' git rebase main other ' +test_expect_success 'switch to non-branch detaches HEAD' ' + git checkout main && + old_main=$(git rev-parse HEAD) && + git rebase First Second^0 && + test_cmp_rev HEAD Second && + test_cmp_rev main $old_main && + test_must_fail git symbolic-ref HEAD +' + test_expect_success 'refuse to switch to branch checked out elsewhere' ' git checkout main && git worktree add wt && diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index a38f2da..688b01e 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -619,9 +619,7 @@ test_expect_success 'rebase a detached HEAD' ' ' test_expect_success 'rebase a commit violating pre-commit' ' - - mkdir -p .git/hooks && - write_script .git/hooks/pre-commit <<-\EOF && + test_hook pre-commit <<-\EOF && test -z "$(git diff --cached --check)" EOF echo "monde! " >> file1 && @@ -636,8 +634,6 @@ test_expect_success 'rebase a commit violating pre-commit' ' ' test_expect_success 'rebase with a file named HEAD in worktree' ' - - rm -fr .git/hooks && git reset --hard && git checkout -b branch3 A && @@ -1688,10 +1684,8 @@ test_expect_success 'valid author header when author contains single quote' ' ' test_expect_success 'post-commit hook is called' ' - test_when_finished "rm -f .git/hooks/post-commit" && >actual && - mkdir -p .git/hooks && - write_script .git/hooks/post-commit <<-\EOS && + test_hook post-commit <<-\EOS && git rev-parse HEAD >>actual EOS ( @@ -1749,6 +1743,279 @@ test_expect_success 'ORIG_HEAD is updated correctly' ' test_cmp_rev ORIG_HEAD test-orig-head@{1} ' +test_expect_success '--update-refs adds label and update-ref commands' ' + git checkout -b update-refs no-conflict-branch && + git branch -f base HEAD~4 && + git branch -f first HEAD~3 && + git branch -f second HEAD~3 && + git branch -f third HEAD~1 && + git commit --allow-empty --fixup=third && + git branch -f is-not-reordered && + git commit --allow-empty --fixup=HEAD~4 && + git branch -f shared-tip && + ( + set_cat_todo_editor && + + cat >expect <<-EOF && + pick $(git log -1 --format=%h J) J + fixup $(git log -1 --format=%h update-refs) fixup! J # empty + update-ref refs/heads/second + update-ref refs/heads/first + pick $(git log -1 --format=%h K) K + pick $(git log -1 --format=%h L) L + fixup $(git log -1 --format=%h is-not-reordered) fixup! L # empty + update-ref refs/heads/third + pick $(git log -1 --format=%h M) M + update-ref refs/heads/no-conflict-branch + update-ref refs/heads/is-not-reordered + update-ref refs/heads/shared-tip + EOF + + test_must_fail git rebase -i --autosquash --update-refs primary >todo && + test_cmp expect todo && + + test_must_fail git -c rebase.autosquash=true \ + -c rebase.updaterefs=true \ + rebase -i primary >todo && + + test_cmp expect todo + ) +' + +test_expect_success '--update-refs adds commands with --rebase-merges' ' + git checkout -b update-refs-with-merge no-conflict-branch && + git branch -f base HEAD~4 && + git branch -f first HEAD~3 && + git branch -f second HEAD~3 && + git branch -f third HEAD~1 && + git merge -m merge branch2 && + git branch -f merge-branch && + git commit --fixup=third --allow-empty && + ( + set_cat_todo_editor && + + cat >expect <<-EOF && + label onto + reset onto + pick $(git log -1 --format=%h branch2~1) F + pick $(git log -1 --format=%h branch2) I + update-ref refs/heads/branch2 + label merge + reset onto + pick $(git log -1 --format=%h refs/heads/second) J + update-ref refs/heads/second + update-ref refs/heads/first + pick $(git log -1 --format=%h refs/heads/third~1) K + pick $(git log -1 --format=%h refs/heads/third) L + fixup $(git log -1 --format=%h update-refs-with-merge) fixup! L # empty + update-ref refs/heads/third + pick $(git log -1 --format=%h HEAD~2) M + update-ref refs/heads/no-conflict-branch + merge -C $(git log -1 --format=%h HEAD~1) merge # merge + update-ref refs/heads/merge-branch + EOF + + test_must_fail git rebase -i --autosquash \ + --rebase-merges=rebase-cousins \ + --update-refs primary >todo && + + test_cmp expect todo && + + test_must_fail git -c rebase.autosquash=true \ + -c rebase.updaterefs=true \ + rebase -i \ + --rebase-merges=rebase-cousins \ + primary >todo && + + test_cmp expect todo + ) +' + +test_expect_success '--update-refs updates refs correctly' ' + git checkout -B update-refs no-conflict-branch && + git branch -f base HEAD~4 && + git branch -f first HEAD~3 && + git branch -f second HEAD~3 && + git branch -f third HEAD~1 && + test_commit extra2 fileX && + git commit --amend --fixup=L && + + git rebase -i --autosquash --update-refs primary 2>err && + + test_cmp_rev HEAD~3 refs/heads/first && + test_cmp_rev HEAD~3 refs/heads/second && + test_cmp_rev HEAD~1 refs/heads/third && + test_cmp_rev HEAD refs/heads/no-conflict-branch && + + cat >expect <<-\EOF && + Successfully rebased and updated refs/heads/update-refs. + Updated the following refs with --update-refs: + refs/heads/first + refs/heads/no-conflict-branch + refs/heads/second + refs/heads/third + EOF + + # Clear "Rebasing (X/Y)" progress lines and drop leading tabs. + sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \ + <err >err.trimmed && + test_cmp expect err.trimmed +' + +test_expect_success 'respect user edits to update-ref steps' ' + git checkout -B update-refs-break no-conflict-branch && + git branch -f base HEAD~4 && + git branch -f first HEAD~3 && + git branch -f second HEAD~3 && + git branch -f third HEAD~1 && + git branch -f unseen base && + + # First, we will add breaks to the expected todo file + cat >fake-todo-1 <<-EOF && + pick $(git rev-parse HEAD~3) + break + update-ref refs/heads/second + update-ref refs/heads/first + + pick $(git rev-parse HEAD~2) + pick $(git rev-parse HEAD~1) + update-ref refs/heads/third + + pick $(git rev-parse HEAD) + update-ref refs/heads/no-conflict-branch + EOF + + # Second, we will drop some update-refs commands (and move one) + cat >fake-todo-2 <<-EOF && + update-ref refs/heads/second + + pick $(git rev-parse HEAD~2) + update-ref refs/heads/third + pick $(git rev-parse HEAD~1) + break + + pick $(git rev-parse HEAD) + EOF + + # Third, we will: + # * insert a new one (new-branch), + # * re-add an old one (first), and + # * add a second instance of a previously-stored one (second) + cat >fake-todo-3 <<-EOF && + update-ref refs/heads/unseen + update-ref refs/heads/new-branch + pick $(git rev-parse HEAD) + update-ref refs/heads/first + update-ref refs/heads/second + EOF + + ( + set_replace_editor fake-todo-1 && + git rebase -i --update-refs primary && + + # These branches are currently locked. + for b in first second third no-conflict-branch + do + test_must_fail git branch -f $b base || return 1 + done && + + set_replace_editor fake-todo-2 && + git rebase --edit-todo && + + # These branches are currently locked. + for b in second third + do + test_must_fail git branch -f $b base || return 1 + done && + + # These branches are currently unlocked for checkout. + for b in first no-conflict-branch + do + git worktree add wt-$b $b && + git worktree remove wt-$b || return 1 + done && + + git rebase --continue && + + set_replace_editor fake-todo-3 && + git rebase --edit-todo && + + # These branches are currently locked. + for b in second third first unseen + do + test_must_fail git branch -f $b base || return 1 + done && + + # These branches are currently unlocked for checkout. + for b in no-conflict-branch + do + git worktree add wt-$b $b && + git worktree remove wt-$b || return 1 + done && + + git rebase --continue + ) && + + test_cmp_rev HEAD~2 refs/heads/third && + test_cmp_rev HEAD~1 refs/heads/unseen && + test_cmp_rev HEAD~1 refs/heads/new-branch && + test_cmp_rev HEAD refs/heads/first && + test_cmp_rev HEAD refs/heads/second && + test_cmp_rev HEAD refs/heads/no-conflict-branch +' + +test_expect_success '--update-refs: check failed ref update' ' + git checkout -B update-refs-error no-conflict-branch && + git branch -f base HEAD~4 && + git branch -f first HEAD~3 && + git branch -f second HEAD~2 && + git branch -f third HEAD~1 && + + cat >fake-todo <<-EOF && + pick $(git rev-parse HEAD~3) + break + update-ref refs/heads/first + + pick $(git rev-parse HEAD~2) + update-ref refs/heads/second + + pick $(git rev-parse HEAD~1) + update-ref refs/heads/third + + pick $(git rev-parse HEAD) + update-ref refs/heads/no-conflict-branch + EOF + + ( + set_replace_editor fake-todo && + git rebase -i --update-refs base + ) && + + # At this point, the values of first, second, and third are + # recorded in the update-refs file. We will force-update the + # "second" ref, but "git branch -f" will not work because of + # the lock in the update-refs file. + git rev-parse third >.git/refs/heads/second && + + test_must_fail git rebase --continue 2>err && + grep "update_ref failed for ref '\''refs/heads/second'\''" err && + + cat >expect <<-\EOF && + Updated the following refs with --update-refs: + refs/heads/first + refs/heads/no-conflict-branch + refs/heads/third + Failed to update the following refs with --update-refs: + refs/heads/second + EOF + + # Clear "Rebasing (X/Y)" progress lines and drop leading tabs. + tail -n 6 err >err.last && + sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \ + <err.last >err.trimmed && + test_cmp expect err.trimmed +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged diff --git a/t/t3408-rebase-multi-line.sh b/t/t3408-rebase-multi-line.sh index cde3562..7b4607d 100755 --- a/t/t3408-rebase-multi-line.sh +++ b/t/t3408-rebase-multi-line.sh @@ -5,6 +5,7 @@ test_description='rebasing a commit with multi-line first paragraph.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh index 1e9f783..58371d8 100755 --- a/t/t3412-rebase-root.sh +++ b/t/t3412-rebase-root.sh @@ -31,12 +31,9 @@ test_expect_success 'rebase --root fails with too many args' ' ' test_expect_success 'setup pre-rebase hook' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<EOF && -#!$SHELL_PATH -echo "\$1,\$2" >.git/PRE-REBASE-INPUT -EOF - chmod +x .git/hooks/pre-rebase + test_hook --setup pre-rebase <<-\EOF + echo "$1,$2" >.git/PRE-REBASE-INPUT + EOF ' cat > expect <<EOF 4 @@ -141,12 +138,9 @@ commit work7~5 EOF test_expect_success 'setup pre-rebase hook that fails' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<EOF && -#!$SHELL_PATH -false -EOF - chmod +x .git/hooks/pre-rebase + test_hook --setup --clobber pre-rebase <<-\EOF + false + EOF ' test_expect_success 'pre-rebase hook stops rebase' ' diff --git a/t/t3413-rebase-hook.sh b/t/t3413-rebase-hook.sh index b4acb3b..9fab0d7 100755 --- a/t/t3413-rebase-hook.sh +++ b/t/t3413-rebase-hook.sh @@ -41,12 +41,9 @@ test_expect_success 'rebase -i' ' ' test_expect_success 'setup pre-rebase hook' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<EOF && -#!$SHELL_PATH -echo "\$1,\$2" >.git/PRE-REBASE-INPUT -EOF - chmod +x .git/hooks/pre-rebase + test_hook --setup pre-rebase <<-\EOF + echo "$1,$2" >.git/PRE-REBASE-INPUT + EOF ' test_expect_success 'pre-rebase hook gets correct input (1)' ' @@ -102,12 +99,9 @@ test_expect_success 'pre-rebase hook gets correct input (6)' ' ' test_expect_success 'setup pre-rebase hook that fails' ' - mkdir -p .git/hooks && - cat >.git/hooks/pre-rebase <<EOF && -#!$SHELL_PATH -false -EOF - chmod +x .git/hooks/pre-rebase + test_hook --setup --clobber pre-rebase <<-\EOF + false + EOF ' test_expect_success 'pre-rebase hook stops rebase (1)' ' diff --git a/t/t3416-rebase-onto-threedots.sh b/t/t3416-rebase-onto-threedots.sh index 3716a42..3e04802 100755 --- a/t/t3416-rebase-onto-threedots.sh +++ b/t/t3416-rebase-onto-threedots.sh @@ -129,6 +129,20 @@ test_expect_success 'rebase --keep-base main from topic' ' test_cmp expect actual ' +test_expect_success 'rebase --keep-base main topic from main' ' + git checkout main && + git branch -f topic G && + + git rebase --keep-base main topic && + git rev-parse C >base.expect && + git merge-base main HEAD >base.actual && + test_cmp base.expect base.actual && + + git rev-parse HEAD~2 >actual && + git rev-parse C^0 >expect && + test_cmp expect actual +' + test_expect_success 'rebase --keep-base main from side' ' git reset --hard && git checkout side && @@ -153,6 +167,21 @@ test_expect_success 'rebase -i --keep-base main from topic' ' test_cmp expect actual ' +test_expect_success 'rebase -i --keep-base main topic from main' ' + git checkout main && + git branch -f topic G && + + set_fake_editor && + EXPECT_COUNT=2 git rebase -i --keep-base main topic && + git rev-parse C >base.expect && + git merge-base main HEAD >base.actual && + test_cmp base.expect base.actual && + + git rev-parse HEAD~2 >actual && + git rev-parse C^0 >expect && + test_cmp expect actual +' + test_expect_success 'rebase -i --keep-base main from side' ' git reset --hard && git checkout side && diff --git a/t/t3426-rebase-submodule.sh b/t/t3426-rebase-submodule.sh index 0ad3a07..7a9f112 100755 --- a/t/t3426-rebase-submodule.sh +++ b/t/t3426-rebase-submodule.sh @@ -35,6 +35,7 @@ git_rebase_interactive () { ls -1pR * >>actual && test_cmp expect actual && set_fake_editor && + mkdir .git/info && echo "fake-editor.sh" >.git/info/exclude && may_only_be_test_must_fail "$2" && $2 git rebase -i "$1" diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index 43c82d9..f351701 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -292,9 +292,9 @@ test_expect_success 'post-rewrite hook and fixups work for merges' ' git commit --fixup HEAD same2.t && fixup="$(git rev-parse HEAD)" && - mkdir -p .git/hooks && - test_when_finished "rm .git/hooks/post-rewrite" && - echo "cat >actual" | write_script .git/hooks/post-rewrite && + test_hook post-rewrite <<-\EOF && + cat >actual + EOF test_tick && git rebase -i --autosquash -r HEAD^^^ && diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index 8617efa..1f4cfc3 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -66,8 +66,7 @@ test_expect_success 'cherry-pick after renaming branch' ' git checkout rename2 && git cherry-pick added && - test $(git rev-parse HEAD^) = $(git rev-parse rename2) && - test -f opos && + test_cmp_rev rename2 HEAD^ && grep "Add extra line at the end" opos && git reflog -1 | grep cherry-pick @@ -77,9 +76,9 @@ test_expect_success 'revert after renaming branch' ' git checkout rename1 && git revert added && - test $(git rev-parse HEAD^) = $(git rev-parse rename1) && - test -f spoo && - ! grep "Add extra line at the end" spoo && + test_cmp_rev rename1 HEAD^ && + test_path_is_file spoo && + test_cmp_rev initial:oops HEAD:spoo && git reflog -1 | grep revert ' @@ -159,6 +158,7 @@ test_expect_success 'cherry-pick works with dirty renamed file' ' ' test_expect_success 'advice from failed revert' ' + test_when_finished "git reset --hard" && test_commit --no-tag "add dream" dream dream && dream_oid=$(git rev-parse --short HEAD) && cat <<-EOF >expected && @@ -174,4 +174,40 @@ test_expect_success 'advice from failed revert' ' test_must_fail git revert HEAD^ 2>actual && test_cmp expected actual ' + +test_expect_success 'identification of reverted commit (default)' ' + test_commit to-ident && + test_when_finished "git reset --hard to-ident" && + git checkout --detach to-ident && + git revert --no-edit HEAD && + git cat-file commit HEAD >actual.raw && + grep "^This reverts " actual.raw >actual && + echo "This reverts commit $(git rev-parse HEAD^)." >expect && + test_cmp expect actual +' + +test_expect_success 'identification of reverted commit (--reference)' ' + git checkout --detach to-ident && + git revert --reference --no-edit HEAD && + git cat-file commit HEAD >actual.raw && + grep "^This reverts " actual.raw >actual && + echo "This reverts commit $(git show -s --pretty=reference HEAD^)." >expect && + test_cmp expect actual +' + +test_expect_success 'identification of reverted commit (revert.reference)' ' + git checkout --detach to-ident && + git -c revert.reference=true revert --no-edit HEAD && + git cat-file commit HEAD >actual.raw && + grep "^This reverts " actual.raw >actual && + echo "This reverts commit $(git show -s --pretty=reference HEAD^)." >expect && + test_cmp expect actual +' + +test_expect_success 'cherry-pick is unaware of --reference (for now)' ' + test_when_finished "git reset --hard" && + test_must_fail git cherry-pick --reference HEAD 2>actual && + grep "^usage: git cherry-pick" actual +' + test_done diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 979e843..f32799e 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -12,6 +12,7 @@ test_description='test cherry-pick and revert with conflicts GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh pristine_detach () { @@ -558,6 +559,7 @@ test_expect_success 'cherry-pick preserves sparse-checkout' ' echo \"/*\" >.git/info/sparse-checkout git read-tree --reset -u HEAD rm .git/info/sparse-checkout" && + mkdir .git/info && echo /unrelated >.git/info/sparse-checkout && git read-tree --reset -u HEAD && test_must_fail git cherry-pick -Xours picked>actual && diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh index 034ec01..08580fd 100755 --- a/t/t3602-rm-sparse-checkout.sh +++ b/t/t3602-rm-sparse-checkout.sh @@ -30,7 +30,7 @@ test_expect_success 'setup' " for opt in "" -f --dry-run do test_expect_success "rm${opt:+ $opt} does not remove sparse entries" ' - git sparse-checkout set a && + git sparse-checkout set --no-cone a && test_must_fail git rm $opt b 2>stderr && test_cmp b_error_and_hint stderr && git ls-files --error-unmatch b @@ -118,7 +118,7 @@ test_expect_success 'can remove files from non-sparse dir' ' test_commit w/f && test_commit x/y/f && - git sparse-checkout set w !/x y/ && + git sparse-checkout set --no-cone w !/x y/ && git rm w/f.t x/y/f.t 2>stderr && test_must_be_empty stderr ' @@ -128,7 +128,7 @@ test_expect_success 'refuse to remove non-skip-worktree file from sparse dir' ' git sparse-checkout disable && mkdir -p x/y/z && test_commit x/y/z/f && - git sparse-checkout set !/x y/ !x/y/z && + git sparse-checkout set --no-cone !/x y/ !x/y/z && git update-index --no-skip-worktree x/y/z/f.t && test_must_fail git rm x/y/z/f.t 2>stderr && diff --git a/t/t3700-add.sh b/t/t3700-add.sh index b1f90ba..8689b48 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -8,6 +8,8 @@ test_description='Test of git add, including the -- option.' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-unique-files.sh + # Test the file mode "$1" of the file "$2" in the index. test_mode_in_index () { case "$(git ls-files -s "$2")" in @@ -34,6 +36,32 @@ test_expect_success \ 'Test that "git add -- -q" works' \ 'touch -- -q && git add -- -q' +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' + +test_expect_success 'git add: core.fsyncmethod=batch' " + test_create_unique_files 2 4 files_base_dir1 && + GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION add -- ./files_base_dir1/ && + git ls-files --stage files_base_dir1/ | + test_parse_ls_files_stage_oids >added_files_oids && + + # We created 2 subdirs with 4 files each (8 files total) above + test_line_count = 8 added_files_oids && + git cat-file --batch-check='%(objectname)' <added_files_oids >added_files_actual && + test_cmp added_files_oids added_files_actual +" + +test_expect_success 'git update-index: core.fsyncmethod=batch' " + test_create_unique_files 2 4 files_base_dir2 && + find files_base_dir2 ! -type d -print | xargs git $BATCH_CONFIGURATION update-index --add -- && + git ls-files --stage files_base_dir2 | + test_parse_ls_files_stage_oids >added_files2_oids && + + # We created 2 subdirs with 4 files each (8 files total) above + test_line_count = 8 added_files2_oids && + git cat-file --batch-check='%(objectname)' <added_files2_oids >added_files2_actual && + test_cmp added_files2_oids added_files2_actual +" + test_expect_success \ 'git add: Test that executable bit is not used if core.filemode=0' \ 'git config core.filemode 0 && diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 94537a6..b354fb3 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -103,6 +103,15 @@ test_expect_success 'status works (commit)' ' grep "+1/-0 *+2/-0 file" output ' +test_expect_success 'update can stage deletions' ' + >to-delete && + git add to-delete && + rm to-delete && + test_write_lines u t "" | git add -i && + git ls-files to-delete >output && + test_must_be_empty output +' + test_expect_success 'setup expected' ' cat >expected <<-\EOF index 180b47c..b6f2c08 100644 @@ -538,7 +547,15 @@ test_expect_success 'split hunk "add -p (edit)"' ' ! grep "^+15" actual ' -test_expect_failure 'split hunk "add -p (no, yes, edit)"' ' +test_expect_success 'setup ADD_I_USE_BUILTIN check' ' + result=success && + if ! test_have_prereq ADD_I_USE_BUILTIN + then + result=failure + fi +' + +test_expect_$result 'split hunk "add -p (no, yes, edit)"' ' test_write_lines 5 10 20 21 30 31 40 50 60 >test && git reset && # test sequence is s(plit), n(o), y(es), e(dit) @@ -562,7 +579,7 @@ test_expect_success 'split hunk with incomplete line at end' ' test_must_fail git grep --cached before ' -test_expect_failure 'edit, adding lines to the first hunk' ' +test_expect_$result 'edit, adding lines to the first hunk' ' test_write_lines 10 11 20 30 40 50 51 60 >test && git reset && tr _ " " >patch <<-EOF && diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh index 9560904..2bade9e 100755 --- a/t/t3705-add-sparse-checkout.sh +++ b/t/t3705-add-sparse-checkout.sh @@ -166,7 +166,7 @@ test_expect_success 'do not warn when pathspec matches dense entries' ' test_expect_success 'git add fails outside of sparse-checkout definition' ' test_when_finished git sparse-checkout disable && test_commit a && - git sparse-checkout init && + git sparse-checkout init --no-cone && git sparse-checkout set a && echo >>sparse_entry && @@ -208,7 +208,7 @@ test_expect_success 'add obeys advice.updateSparsePath' ' ' test_expect_success 'add allows sparse entries with --sparse' ' - git sparse-checkout set a && + git sparse-checkout set --no-cone a && echo modified >sparse_entry && test_must_fail git add sparse_entry && test_sparse_entry_unchanged && diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 42638b1..2a4c3fd 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-unique-files.sh test_expect_success 'usage on cmd and subcommand invalid option' ' test_expect_code 129 git stash --invalid-option 2>usage && @@ -302,6 +303,18 @@ test_expect_success 'apply -q is quiet' ' test_must_be_empty output.out ' +test_expect_success 'apply --index -q is quiet' ' + # Added file, deleted file, modified file all staged for commit + echo foo >new-file && + echo test >file && + git add new-file file && + git rm other-file && + + git stash && + git stash apply --index -q >output.out 2>&1 && + test_must_be_empty output.out +' + test_expect_success 'save -q is quiet' ' git stash save --quiet >output.out 2>&1 && test_must_be_empty output.out @@ -332,6 +345,27 @@ test_expect_success 'drop -q is quiet' ' test_must_be_empty output.out ' +test_expect_success 'stash push -q --staged refreshes the index' ' + git reset --hard && + echo test >file && + git add file && + git stash push -q --staged && + git diff-files >output.out && + test_must_be_empty output.out +' + +test_expect_success 'stash apply -q --index refreshes the index' ' + echo test >other-file && + git add other-file && + echo another-change >other-file && + git diff-files >expect && + git stash && + + git stash apply -q --index && + git diff-files >actual && + test_cmp expect actual +' + test_expect_success 'stash -k' ' echo bar3 >file && echo bar4 >file2 && @@ -1377,6 +1411,25 @@ test_expect_success 'stash handles skip-worktree entries nicely' ' git rev-parse --verify refs/stash:A.t ' + +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' + +test_expect_success 'stash with core.fsyncmethod=batch' " + test_create_unique_files 2 4 files_base_dir && + GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION stash push -u -- ./files_base_dir/ && + + # The files were untracked, so use the third parent, + # which contains the untracked files + git ls-tree -r stash^3 -- ./files_base_dir/ | + test_parse_ls_tree_oids >stashed_files_oids && + + # We created 2 dirs with 4 files each (8 files total) above + test_line_count = 8 stashed_files_oids && + git cat-file --batch-check='%(objectname)' <stashed_files_oids >stashed_files_actual && + test_cmp stashed_files_oids stashed_files_actual +" + + test_expect_success 'git stash succeeds despite directory/file change' ' test_create_repo directory_file_switch_v1 && ( diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 750aee1..056e922 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -542,6 +542,39 @@ test_expect_success 'diff-tree --stdin with log formatting' ' test_cmp expect actual ' +test_expect_success 'diff-tree --stdin with pathspec' ' + cat >expect <<-EOF && + Third + + dir/sub + Second + + dir/sub + EOF + git rev-list master^ | + git diff-tree -r --stdin --name-only --format=%s dir >actual && + test_cmp expect actual +' + +test_expect_success 'show A B ... -- <pathspec>' ' + # side touches dir/sub, file0, and file3 + # master^ touches dir/sub, and file1 + # master^^ touches dir/sub, file0, and file2 + git show --name-only --format="<%s>" side master^ master^^ -- dir >actual && + cat >expect <<-\EOF && + <Side> + + dir/sub + <Third> + + dir/sub + <Second> + + dir/sub + EOF + test_cmp expect actual +' + test_expect_success 'diff -I<regex>: setup' ' git checkout master && test_seq 50 >file0 && diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 7dc5a5c..fbec8ad 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -926,11 +926,40 @@ test_expect_success 'format-patch --numstat should produce a patch' ' ' test_expect_success 'format-patch -- <path>' ' - git format-patch main..side -- file 2>error && - ! grep "Use .--" error + rm -f *.patch && + git checkout -b pathspec main && + + echo file_a 1 >file_a && + echo file_b 1 >file_b && + git add file_a file_b && + git commit -m pathspec_initial && + + echo file_a 2 >>file_a && + git add file_a && + git commit -m pathspec_a && + + echo file_b 2 >>file_b && + git add file_b && + git commit -m pathspec_b && + + echo file_a 3 >>file_a && + echo file_b 3 >>file_b && + git add file_a file_b && + git commit -m pathspec_ab && + + cat >expect <<-\EOF && + 0001-pathspec_initial.patch + 0002-pathspec_a.patch + 0003-pathspec_ab.patch + EOF + + git format-patch main..pathspec -- file_a >output && + test_cmp expect output && + ! grep file_b *.patch ' test_expect_success 'format-patch --ignore-if-in-upstream HEAD' ' + git checkout side && git format-patch --ignore-if-in-upstream HEAD ' diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh index 1219f8b..858a552 100755 --- a/t/t4020-diff-external.sh +++ b/t/t4020-diff-external.sh @@ -206,17 +206,17 @@ test_expect_success 'GIT_EXTERNAL_DIFF path counter/total' ' ' test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' ' + test_when_finished "git rm -f file.ext" && touch file.ext && git add file.ext && echo with extension > file.ext && cat >expect <<-EOF && - file.ext file $(git rev-parse --verify HEAD:file) 100644 file.ext $(test_oid zero) 100644 + file.ext EOF GIT_EXTERNAL_DIFF=echo git diff file.ext >out && - cut -d" " -f1,3- <out >actual && - git update-index --force-remove file.ext && - rm file.ext + basename $(cut -d" " -f2 <out) >actual && + test_cmp expect actual ' echo "#!$SHELL_PATH" >fake-diff.sh diff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh index 9be65fd..1219aa2 100755 --- a/t/t4021-format-patch-numbered.sh +++ b/t/t4021-format-patch-numbered.sh @@ -5,6 +5,7 @@ test_description='Format-patch numbering options' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh index 295da98..40164ae 100755 --- a/t/t4027-diff-submodule.sh +++ b/t/t4027-diff-submodule.sh @@ -2,6 +2,7 @@ test_description='difference in submodules' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh diff --git a/t/t4028-format-patch-mime-headers.sh b/t/t4028-format-patch-mime-headers.sh index 204ba67..60cb819 100755 --- a/t/t4028-format-patch-mime-headers.sh +++ b/t/t4028-format-patch-mime-headers.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='format-patch mime headers and extra headers do not conflict' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'create commit with utf-8 body' ' diff --git a/t/t4036-format-patch-signer-mime.sh b/t/t4036-format-patch-signer-mime.sh index 98d9713..48655bc 100755 --- a/t/t4036-format-patch-signer-mime.sh +++ b/t/t4036-format-patch-signer-mime.sh @@ -2,6 +2,7 @@ test_description='format-patch -s should force MIME encoding as needed' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t4039-diff-assume-unchanged.sh b/t/t4039-diff-assume-unchanged.sh index 0eb0314..78090e6 100755 --- a/t/t4039-diff-assume-unchanged.sh +++ b/t/t4039-diff-assume-unchanged.sh @@ -2,6 +2,7 @@ test_description='diff with assume-unchanged entries' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # external diff has been tested in t4020-diff-external.sh diff --git a/t/t4044-diff-index-unique-abbrev.sh b/t/t4044-diff-index-unique-abbrev.sh index 4701796..29e49d2 100755 --- a/t/t4044-diff-index-unique-abbrev.sh +++ b/t/t4044-diff-index-unique-abbrev.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test unique sha1 abbreviation on "index from..to" line' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4055-diff-context.sh b/t/t4055-diff-context.sh index 741e080..73048d0 100755 --- a/t/t4055-diff-context.sh +++ b/t/t4055-diff-context.sh @@ -5,6 +5,7 @@ test_description='diff.context configuration' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4066-diff-emit-delay.sh b/t/t4066-diff-emit-delay.sh index a1de63b..0ecb391 100755 --- a/t/t4066-diff-emit-delay.sh +++ b/t/t4066-diff-emit-delay.sh @@ -4,6 +4,7 @@ test_description='test combined/stat/moved interaction' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This test covers a weird 3-way interaction between "--cc -p", which will run diff --git a/t/t4122-apply-symlink-inside.sh b/t/t4122-apply-symlink-inside.sh index aa52de4..9696537 100755 --- a/t/t4122-apply-symlink-inside.sh +++ b/t/t4122-apply-symlink-inside.sh @@ -4,6 +4,7 @@ test_description='apply to deeper directory without getting fooled with symlink' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t4126-apply-empty.sh b/t/t4126-apply-empty.sh index 33860d3..ece9fae 100755 --- a/t/t4126-apply-empty.sh +++ b/t/t4126-apply-empty.sh @@ -2,7 +2,6 @@ test_description='apply empty' - TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh index f6db5a7..ed94c90 100755 --- a/t/t4128-apply-root.sh +++ b/t/t4128-apply-root.sh @@ -2,6 +2,7 @@ test_description='apply same filename' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4140-apply-ita.sh b/t/t4140-apply-ita.sh index c614eaf..b375aca 100755 --- a/t/t4140-apply-ita.sh +++ b/t/t4140-apply-ita.sh @@ -2,6 +2,7 @@ test_description='git apply of i-t-a file' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 159fae8..cdad4b6 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -315,12 +315,10 @@ test_expect_success 'am --patch-format=hg applies hg patch' ' ' test_expect_success 'am with applypatch-msg hook' ' - test_when_finished "rm -f .git/hooks/applypatch-msg" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/applypatch-msg <<-\EOF && + test_hook applypatch-msg <<-\EOF && cat "$1" >actual-msg && echo hook-message >"$1" EOF @@ -335,12 +333,10 @@ test_expect_success 'am with applypatch-msg hook' ' ' test_expect_success 'am with failing applypatch-msg hook' ' - test_when_finished "rm -f .git/hooks/applypatch-msg" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/applypatch-msg <<-\EOF && + test_hook applypatch-msg <<-\EOF && exit 1 EOF test_must_fail git am patch1 && @@ -350,12 +346,10 @@ test_expect_success 'am with failing applypatch-msg hook' ' ' test_expect_success 'am with pre-applypatch hook' ' - test_when_finished "rm -f .git/hooks/pre-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/pre-applypatch <<-\EOF && + test_hook pre-applypatch <<-\EOF && git diff first >diff.actual exit 0 EOF @@ -368,12 +362,10 @@ test_expect_success 'am with pre-applypatch hook' ' ' test_expect_success 'am with failing pre-applypatch hook' ' - test_when_finished "rm -f .git/hooks/pre-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/pre-applypatch <<-\EOF && + test_hook pre-applypatch <<-\EOF && exit 1 EOF test_must_fail git am patch1 && @@ -383,12 +375,10 @@ test_expect_success 'am with failing pre-applypatch hook' ' ' test_expect_success 'am with post-applypatch hook' ' - test_when_finished "rm -f .git/hooks/post-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/post-applypatch <<-\EOF && + test_hook post-applypatch <<-\EOF && git rev-parse HEAD >head.actual git diff second >diff.actual exit 0 @@ -403,12 +393,10 @@ test_expect_success 'am with post-applypatch hook' ' ' test_expect_success 'am with failing post-applypatch hook' ' - test_when_finished "rm -f .git/hooks/post-applypatch" && rm -fr .git/rebase-apply && git reset --hard && git checkout first && - mkdir -p .git/hooks && - write_script .git/hooks/post-applypatch <<-\EOF && + test_hook post-applypatch <<-\EOF && git rev-parse HEAD >head.actual exit 1 EOF diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index 9f8c76d..7025cfd 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -365,9 +365,6 @@ test_expect_success 'set up an unresolved merge' ' test_might_fail git config --unset rerere.autoupdate && git reset --hard && git checkout version2 && - fifth=$(git rev-parse fifth) && - echo "$fifth branch fifth of ." | - git fmt-merge-msg >msg && ancestor=$(git merge-base version2 fifth) && test_must_fail git merge-recursive "$ancestor" -- HEAD fifth && diff --git a/t/t4202-log.sh b/t/t4202-log.sh index be07407..6e66352 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1992,10 +1992,13 @@ test_expect_success GPG 'log --show-signature for merged tag with GPG failure' ' git tag -s -m signed_tag_msg signed_tag_fail && git checkout plain-fail && git merge --no-ff -m msg signed_tag_fail && - TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual && - grep "^merged tag" actual && - grep "^No signature" actual && - ! grep "^gpg: Signature made" actual + if ! test_have_prereq VALGRIND + then + TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual && + grep "^merged tag" actual && + grep "^No signature" actual && + ! grep "^gpg: Signature made" actual + fi ' test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' ' diff --git a/t/t4206-log-follow-harder-copies.sh b/t/t4206-log-follow-harder-copies.sh index 4871a5d..33ecf82 100755 --- a/t/t4206-log-follow-harder-copies.sh +++ b/t/t4206-log-follow-harder-copies.sh @@ -6,6 +6,8 @@ test_description='Test --follow should always find copies hard in git log. ' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff.sh diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index b870942..36ac6af 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -8,6 +8,7 @@ test_description='Test for "git log --decorate" colors' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t4212-log-corrupt.sh b/t/t4212-log-corrupt.sh index 0244888..30a2198 100755 --- a/t/t4212-log-corrupt.sh +++ b/t/t4212-log-corrupt.sh @@ -2,6 +2,7 @@ test_description='git log with invalid commit headers' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4217-log-limit.sh b/t/t4217-log-limit.sh new file mode 100755 index 0000000..6e01e26 --- /dev/null +++ b/t/t4217-log-limit.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +test_description='git log with filter options limiting the output' + +. ./test-lib.sh + +test_expect_success 'setup test' ' + git init && + echo a >file && + git add file && + GIT_COMMITTER_DATE="2021-02-01 00:00" git commit -m init && + echo a >>file && + git add file && + GIT_COMMITTER_DATE="2022-02-01 00:00" git commit -m first && + echo a >>file && + git add file && + GIT_COMMITTER_DATE="2021-03-01 00:00" git commit -m second && + echo a >>file && + git add file && + GIT_COMMITTER_DATE="2022-03-01 00:00" git commit -m third +' + +test_expect_success 'git log --since-as-filter=...' ' + git log --since-as-filter="2022-01-01" --format=%s >actual && + cat >expect <<-\EOF && + third + first + EOF + test_cmp expect actual +' + +test_expect_success 'git log --children --since-as-filter=...' ' + git log --children --since-as-filter="2022-01-01" --format=%s >actual && + cat >expect <<-\EOF && + third + first + EOF + test_cmp expect actual +' + +test_done diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh new file mode 100755 index 0000000..f091259 --- /dev/null +++ b/t/t4301-merge-tree-write-tree.sh @@ -0,0 +1,240 @@ +#!/bin/sh + +test_description='git merge-tree --write-tree' + +. ./test-lib.sh + +# This test is ort-specific +if test "$GIT_TEST_MERGE_ALGORITHM" != "ort" +then + skip_all="GIT_TEST_MERGE_ALGORITHM != ort" + test_done +fi + +test_expect_success setup ' + test_write_lines 1 2 3 4 5 >numbers && + echo hello >greeting && + echo foo >whatever && + git add numbers greeting whatever && + test_tick && + git commit -m initial && + + git branch side1 && + git branch side2 && + git branch side3 && + + git checkout side1 && + test_write_lines 1 2 3 4 5 6 >numbers && + echo hi >greeting && + echo bar >whatever && + git add numbers greeting whatever && + test_tick && + git commit -m modify-stuff && + + git checkout side2 && + test_write_lines 0 1 2 3 4 5 >numbers && + echo yo >greeting && + git rm whatever && + mkdir whatever && + >whatever/empty && + git add numbers greeting whatever/empty && + test_tick && + git commit -m other-modifications && + + git checkout side3 && + git mv numbers sequence && + test_tick && + git commit -m rename-numbers && + + git switch --orphan unrelated && + >something-else && + git add something-else && + test_tick && + git commit -m first-commit +' + +test_expect_success 'Clean merge' ' + TREE_OID=$(git merge-tree --write-tree side1 side3) && + q_to_tab <<-EOF >expect && + 100644 blob $(git rev-parse side1:greeting)Qgreeting + 100644 blob $(git rev-parse side1:numbers)Qsequence + 100644 blob $(git rev-parse side1:whatever)Qwhatever + EOF + + git ls-tree $TREE_OID >actual && + test_cmp expect actual +' + +test_expect_success 'Content merge and a few conflicts' ' + git checkout side1^0 && + test_must_fail git merge side2 && + expected_tree=$(git rev-parse AUTO_MERGE) && + + # We will redo the merge, while we are still in a conflicted state! + git ls-files -u >conflicted-file-info && + test_when_finished "git reset --hard" && + + test_expect_code 1 git merge-tree --write-tree side1 side2 >RESULT && + actual_tree=$(head -n 1 RESULT) && + + # Due to differences of e.g. "HEAD" vs "side1", the results will not + # exactly match. Dig into individual files. + + # Numbers should have three-way merged cleanly + test_write_lines 0 1 2 3 4 5 6 >expect && + git show ${actual_tree}:numbers >actual && + test_cmp expect actual && + + # whatever and whatever~<branch> should have same HASHES + git rev-parse ${expected_tree}:whatever ${expected_tree}:whatever~HEAD >expect && + git rev-parse ${actual_tree}:whatever ${actual_tree}:whatever~side1 >actual && + test_cmp expect actual && + + # greeting should have a merge conflict + git show ${expected_tree}:greeting >tmp && + sed -e s/HEAD/side1/ tmp >expect && + git show ${actual_tree}:greeting >actual && + test_cmp expect actual +' + +test_expect_success 'Barf on misspelled option, with exit code other than 0 or 1' ' + # Mis-spell with single "s" instead of double "s" + test_expect_code 129 git merge-tree --write-tree --mesages FOOBAR side1 side2 2>expect && + + grep "error: unknown option.*mesages" expect +' + +test_expect_success 'Barf on too many arguments' ' + test_expect_code 129 git merge-tree --write-tree side1 side2 invalid 2>expect && + + grep "^usage: git merge-tree" expect +' + +anonymize_hash() { + sed -e "s/[0-9a-f]\{40,\}/HASH/g" "$@" +} + +test_expect_success 'test conflict notices and such' ' + test_expect_code 1 git merge-tree --write-tree --name-only side1 side2 >out && + anonymize_hash out >actual && + + # Expected results: + # "greeting" should merge with conflicts + # "numbers" should merge cleanly + # "whatever" has *both* a modify/delete and a file/directory conflict + cat <<-EOF >expect && + HASH + greeting + whatever~side1 + + Auto-merging greeting + CONFLICT (content): Merge conflict in greeting + Auto-merging numbers + CONFLICT (file/directory): directory in the way of whatever from side1; moving it to whatever~side1 instead. + CONFLICT (modify/delete): whatever~side1 deleted in side2 and modified in side1. Version side1 of whatever~side1 left in tree. + EOF + + test_cmp expect actual +' + +for opt in $(git merge-tree --git-completion-helper-all) +do + if test $opt = "--trivial-merge" || test $opt = "--write-tree" + then + continue + fi + + test_expect_success "usage: --trivial-merge is incompatible with $opt" ' + test_expect_code 128 git merge-tree --trivial-merge $opt side1 side2 side3 + ' +done + +test_expect_success 'Just the conflicted files without the messages' ' + test_expect_code 1 git merge-tree --write-tree --no-messages --name-only side1 side2 >out && + anonymize_hash out >actual && + + test_write_lines HASH greeting whatever~side1 >expect && + + test_cmp expect actual +' + +test_expect_success 'Check conflicted oids and modes without messages' ' + test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out && + anonymize_hash out >actual && + + # Compare the basic output format + q_to_tab >expect <<-\EOF && + HASH + 100644 HASH 1Qgreeting + 100644 HASH 2Qgreeting + 100644 HASH 3Qgreeting + 100644 HASH 1Qwhatever~side1 + 100644 HASH 2Qwhatever~side1 + EOF + + test_cmp expect actual && + + # Check the actual hashes against the `ls-files -u` output too + tail -n +2 out | sed -e s/side1/HEAD/ >actual && + test_cmp conflicted-file-info actual +' + +test_expect_success 'NUL terminated conflicted file "lines"' ' + git checkout -b tweak1 side1 && + test_write_lines zero 1 2 3 4 5 6 >numbers && + git add numbers && + git mv numbers "Αυτά μου φαίνονται κινέζικα" && + git commit -m "Renamed numbers" && + + test_expect_code 1 git merge-tree --write-tree -z tweak1 side2 >out && + anonymize_hash out >actual && + printf "\\n" >>actual && + + # Expected results: + # "greeting" should merge with conflicts + # "whatever" has *both* a modify/delete and a file/directory conflict + # "Αυτά μου φαίνονται κινέζικα" should have a conflict + echo HASH | lf_to_nul >expect && + + q_to_tab <<-EOF | lf_to_nul >>expect && + 100644 HASH 1Qgreeting + 100644 HASH 2Qgreeting + 100644 HASH 3Qgreeting + 100644 HASH 1Qwhatever~tweak1 + 100644 HASH 2Qwhatever~tweak1 + 100644 HASH 1QΑυτά μου φαίνονται κινέζικα + 100644 HASH 2QΑυτά μου φαίνονται κινέζικα + 100644 HASH 3QΑυτά μου φαίνονται κινέζικα + + EOF + + q_to_nul <<-EOF >>expect && + 1QgreetingQAuto-mergingQAuto-merging greeting + Q1QgreetingQCONFLICT (contents)QCONFLICT (content): Merge conflict in greeting + Q2Qwhatever~tweak1QwhateverQCONFLICT (file/directory)QCONFLICT (file/directory): directory in the way of whatever from tweak1; moving it to whatever~tweak1 instead. + Q1Qwhatever~tweak1QCONFLICT (modify/delete)QCONFLICT (modify/delete): whatever~tweak1 deleted in side2 and modified in tweak1. Version tweak1 of whatever~tweak1 left in tree. + Q1QΑυτά μου φαίνονται κινέζικαQAuto-mergingQAuto-merging Αυτά μου φαίνονται κινέζικα + Q1QΑυτά μου φαίνονται κινέζικαQCONFLICT (contents)QCONFLICT (content): Merge conflict in Αυτά μου φαίνονται κινέζικα + Q + EOF + + test_cmp expect actual +' + +test_expect_success 'error out by default for unrelated histories' ' + test_expect_code 128 git merge-tree --write-tree side1 unrelated 2>error && + + grep "refusing to merge unrelated histories" error +' + +test_expect_success 'can override merge of unrelated histories' ' + git merge-tree --write-tree --allow-unrelated-histories side1 unrelated >tree && + TREE=$(cat tree) && + + git rev-parse side1:numbers side1:greeting side1:whatever unrelated:something-else >expect && + git rev-parse $TREE:numbers $TREE:greeting $TREE:whatever $TREE:something-else >actual && + + test_cmp expect actual +' + +test_done diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 7f8d2ab..eaa0b22 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -24,6 +24,7 @@ commit id embedding: ' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh SUBSTFORMAT=%H%n @@ -143,6 +144,7 @@ test_expect_success 'populate workdir' ' test_expect_success \ 'add ignored file' \ 'echo ignore me >a/ignored && + mkdir .git/info && echo ignored export-ignore >.git/info/attributes' test_expect_success 'add files to repository' ' @@ -157,7 +159,8 @@ test_expect_success 'setup export-subst' ' ' test_expect_success 'create bare clone' ' - git clone --bare . bare.git && + git clone --template= --bare . bare.git && + mkdir bare.git/info && cp .git/info/attributes bare.git/info/attributes ' @@ -339,21 +342,21 @@ test_expect_success 'only enabled filters are available remotely' ' test_cmp_bin remote.bar config.bar ' -test_expect_success GZIP 'git archive --format=tgz' ' +test_expect_success 'git archive --format=tgz' ' git archive --format=tgz HEAD >j.tgz ' -test_expect_success GZIP 'git archive --format=tar.gz' ' +test_expect_success 'git archive --format=tar.gz' ' git archive --format=tar.gz HEAD >j1.tar.gz && test_cmp_bin j.tgz j1.tar.gz ' -test_expect_success GZIP 'infer tgz from .tgz filename' ' +test_expect_success 'infer tgz from .tgz filename' ' git archive --output=j2.tgz HEAD && test_cmp_bin j.tgz j2.tgz ' -test_expect_success GZIP 'infer tgz from .tar.gz filename' ' +test_expect_success 'infer tgz from .tar.gz filename' ' git archive --output=j3.tar.gz HEAD && test_cmp_bin j.tgz j3.tar.gz ' @@ -363,17 +366,33 @@ test_expect_success GZIP 'extract tgz file' ' test_cmp_bin b.tar j.tar ' -test_expect_success GZIP 'remote tar.gz is allowed by default' ' +test_expect_success 'remote tar.gz is allowed by default' ' git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && test_cmp_bin j.tgz remote.tar.gz ' -test_expect_success GZIP 'remote tar.gz can be disabled' ' +test_expect_success 'remote tar.gz can be disabled' ' git config tar.tar.gz.remote false && test_must_fail git archive --remote=. --format=tar.gz HEAD \ >remote.tar.gz ' +test_expect_success GZIP 'git archive --format=tgz (external gzip)' ' + test_config tar.tgz.command "gzip -cn" && + git archive --format=tgz HEAD >external_gzip.tgz +' + +test_expect_success GZIP 'git archive --format=tar.gz (external gzip)' ' + test_config tar.tar.gz.command "gzip -cn" && + git archive --format=tar.gz HEAD >external_gzip.tar.gz && + test_cmp_bin external_gzip.tgz external_gzip.tar.gz +' + +test_expect_success GZIP 'extract tgz file (external gzip)' ' + gzip -d -c <external_gzip.tgz >external_gzip.tar && + test_cmp_bin b.tar external_gzip.tar +' + test_expect_success 'archive and :(glob)' ' git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual && cat >expect <<EOF && diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index 712ae52..2f6eef5 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -2,6 +2,7 @@ test_description='git archive attribute tests' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh SUBSTFORMAT='%H (%h)%n' @@ -20,6 +21,7 @@ extract_tar_to_dir () { test_expect_success 'setup' ' echo ignored >ignored && + mkdir .git/info && echo ignored export-ignore >>.git/info/attributes && git add ignored && @@ -46,7 +48,8 @@ test_expect_success 'setup' ' git commit -m. && - git clone --bare . bare && + git clone --template= --bare . bare && + mkdir bare/info && cp .git/info/attributes bare/info/attributes ' diff --git a/t/t5002-archive-attr-pattern.sh b/t/t5002-archive-attr-pattern.sh index a66b5ba..78ab75f 100755 --- a/t/t5002-archive-attr-pattern.sh +++ b/t/t5002-archive-attr-pattern.sh @@ -3,6 +3,7 @@ test_description='git archive attribute pattern tests' TEST_PASSES_SANITIZE_LEAK=true +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh test_expect_exists() { @@ -15,6 +16,7 @@ test_expect_missing() { test_expect_success 'setup' ' echo ignored >ignored && + mkdir .git/info && echo ignored export-ignore >>.git/info/attributes && git add ignored && @@ -54,7 +56,8 @@ test_expect_success 'setup' ' git commit -m. && - git clone --bare . bare && + git clone --template= --bare . bare && + mkdir bare/info && cp .git/info/attributes bare/info/attributes ' diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index d726964..fc499cd 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -2,6 +2,7 @@ test_description='git archive --format=zip test' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh SUBSTFORMAT=%H%n @@ -121,6 +122,7 @@ test_expect_success 'prepare file list' ' test_expect_success \ 'add ignored file' \ 'echo ignore me >a/ignored && + mkdir .git/info && echo ignored export-ignore >.git/info/attributes' test_expect_success 'add files to repository' ' @@ -139,7 +141,8 @@ test_expect_success 'setup export-subst and diff attributes' ' ' test_expect_success 'create bare clone' ' - git clone --bare . bare.git && + git clone --template= --bare . bare.git && + mkdir bare.git/info && cp .git/info/attributes bare.git/info/attributes && # Recreate our changes to .git/config rather than just copying it, as # we do not want to clobber core.bare or other settings. @@ -206,6 +209,26 @@ test_expect_success 'git archive --format=zip --add-file' ' check_zip with_untracked check_added with_untracked untracked untracked +test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' ' + if test_have_prereq FUNNYNAMES + then + PATHNAME="pathname with : colon" + else + PATHNAME="pathname without colon" + fi && + git archive --format=zip >with_file_with_content.zip \ + --add-virtual-file=\""$PATHNAME"\": \ + --add-virtual-file=hello:world $EMPTY_TREE && + test_when_finished "rm -rf tmp-unpack" && + mkdir tmp-unpack && ( + cd tmp-unpack && + "$GIT_UNZIP" ../with_file_with_content.zip && + test_path_is_file hello && + test_path_is_file "$PATHNAME" && + test world = $(cat hello) + ) +' + test_expect_success 'git archive --format=zip --add-file twice' ' echo untracked >untracked && git archive --format=zip --prefix=one/ --add-file=untracked \ diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index a11d612..f8a0f30 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -161,22 +161,27 @@ test_expect_success 'pack-objects with bogus arguments' ' ' check_unpack () { + local packname="$1" && + local object_list="$2" && + local git_config="$3" && test_when_finished "rm -rf git2" && - git init --bare git2 && - git -C git2 unpack-objects -n <"$1".pack && - git -C git2 unpack-objects <"$1".pack && - (cd .git && find objects -type f -print) | - while read path - do - cmp git2/$path .git/$path || { - echo $path differs. - return 1 - } - done + git $git_config init --bare git2 && + ( + git $git_config -C git2 unpack-objects -n <"$packname".pack && + git $git_config -C git2 unpack-objects <"$packname".pack && + git $git_config -C git2 cat-file --batch-check="%(objectname)" + ) <"$object_list" >current && + cmp "$object_list" current } test_expect_success 'unpack without delta' ' - check_unpack test-1-${packname_1} + check_unpack test-1-${packname_1} obj-list +' + +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' + +test_expect_success 'unpack without delta (core.fsyncmethod=batch)' ' + check_unpack test-1-${packname_1} obj-list "$BATCH_CONFIGURATION" ' test_expect_success 'pack with REF_DELTA' ' @@ -185,7 +190,11 @@ test_expect_success 'pack with REF_DELTA' ' ' test_expect_success 'unpack with REF_DELTA' ' - check_unpack test-2-${packname_2} + check_unpack test-2-${packname_2} obj-list +' + +test_expect_success 'unpack with REF_DELTA (core.fsyncmethod=batch)' ' + check_unpack test-2-${packname_2} obj-list "$BATCH_CONFIGURATION" ' test_expect_success 'pack with OFS_DELTA' ' @@ -195,7 +204,11 @@ test_expect_success 'pack with OFS_DELTA' ' ' test_expect_success 'unpack with OFS_DELTA' ' - check_unpack test-3-${packname_3} + check_unpack test-3-${packname_3} obj-list +' + +test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' ' + check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION" ' test_expect_success 'compare delta flavors' ' diff --git a/t/t5301-sliding-window.sh b/t/t5301-sliding-window.sh index 76f9798..3ccaaeb 100755 --- a/t/t5301-sliding-window.sh +++ b/t/t5301-sliding-window.sh @@ -4,6 +4,8 @@ # test_description='mmap sliding window tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success \ diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh index 41e6dc4..2926e8d 100755 --- a/t/t5303-pack-corruption-resilience.sh +++ b/t/t5303-pack-corruption-resilience.sh @@ -4,6 +4,8 @@ # test_description='resilience to pack corruptions with redundant objects' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Note: the test objects are created with knowledge of their pack encoding diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh index 693b241..655cafa 100755 --- a/t/t5308-pack-detect-duplicates.sh +++ b/t/t5308-pack-detect-duplicates.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='handling of duplicate objects in incoming packfiles' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pack.sh diff --git a/t/t5309-pack-delta-cycles.sh b/t/t5309-pack-delta-cycles.sh index 55b7876..4e910c5 100755 --- a/t/t5309-pack-delta-cycles.sh +++ b/t/t5309-pack-delta-cycles.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test index-pack handling of delta cycles in packfiles' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pack.sh diff --git a/t/t5313-pack-bounds-checks.sh b/t/t5313-pack-bounds-checks.sh index 535313e..cc4cfaa 100755 --- a/t/t5313-pack-bounds-checks.sh +++ b/t/t5313-pack-bounds-checks.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='bounds-checking of access to mmapped on-disk file formats' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh clear_base () { diff --git a/t/t5314-pack-cycle-detection.sh b/t/t5314-pack-cycle-detection.sh index 0aec861..73a2417 100755 --- a/t/t5314-pack-cycle-detection.sh +++ b/t/t5314-pack-cycle-detection.sh @@ -49,9 +49,9 @@ Then no matter which order we start looking at the packs in, we know that we will always find a delta for "file", because its lookup will always come immediately after the lookup for "dummy". ' -. ./test-lib.sh - +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh # Create a pack containing the tree $1 and blob $1:file, with # the latter stored as a delta against $2:file. diff --git a/t/t5316-pack-delta-depth.sh b/t/t5316-pack-delta-depth.sh index e904500..eb4ef3d 100755 --- a/t/t5316-pack-delta-depth.sh +++ b/t/t5316-pack-delta-depth.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='pack-objects breaks long cross-pack delta chains' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # This mirrors a repeated push setup: diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 33b740ce..bb633c9 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -10,9 +10,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME # Test blob:none filter. test_expect_success 'setup r1' ' - echo "{print \$1}" >print_1.awk && - echo "{print \$2}" >print_2.awk && - git init r1 && for n in 1 2 3 4 5 do @@ -22,10 +19,13 @@ test_expect_success 'setup r1' ' done ' +parse_verify_pack_blob_oid () { + awk '{print $1}' - +} + test_expect_success 'verify blob count in normal packfile' ' - git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \ - >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 | + test_parse_ls_files_stage_oids | sort >expected && git -C r1 pack-objects --revs --stdout >all.pack <<-EOF && @@ -35,7 +35,7 @@ test_expect_success 'verify blob count in normal packfile' ' git -C r1 verify-pack -v ../all.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -54,12 +54,12 @@ test_expect_success 'verify blob:none packfile has no blobs' ' test_expect_success 'verify normal and blob:none packfiles have same commits/trees' ' git -C r1 verify-pack -v ../all.pack >verify_result && grep -E "commit|tree" verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >expected && git -C r1 verify-pack -v ../filter.pack >verify_result && grep -E "commit|tree" verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -123,8 +123,8 @@ test_expect_success 'setup r2' ' ' test_expect_success 'verify blob count in normal packfile' ' - git -C r2 ls-files -s large.1000 large.10000 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r2 ls-files -s large.1000 large.10000 | + test_parse_ls_files_stage_oids | sort >expected && git -C r2 pack-objects --revs --stdout >all.pack <<-EOF && @@ -134,7 +134,7 @@ test_expect_success 'verify blob count in normal packfile' ' git -C r2 verify-pack -v ../all.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -161,8 +161,8 @@ test_expect_success 'verify blob:limit=1000' ' ' test_expect_success 'verify blob:limit=1001' ' - git -C r2 ls-files -s large.1000 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r2 ls-files -s large.1000 | + test_parse_ls_files_stage_oids | sort >expected && git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF && @@ -172,15 +172,15 @@ test_expect_success 'verify blob:limit=1001' ' git -C r2 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed ' test_expect_success 'verify blob:limit=10001' ' - git -C r2 ls-files -s large.1000 large.10000 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r2 ls-files -s large.1000 large.10000 | + test_parse_ls_files_stage_oids | sort >expected && git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF && @@ -190,15 +190,15 @@ test_expect_success 'verify blob:limit=10001' ' git -C r2 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed ' test_expect_success 'verify blob:limit=1k' ' - git -C r2 ls-files -s large.1000 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r2 ls-files -s large.1000 | + test_parse_ls_files_stage_oids | sort >expected && git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF && @@ -208,15 +208,15 @@ test_expect_success 'verify blob:limit=1k' ' git -C r2 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed ' test_expect_success 'verify explicitly specifying oversized blob in input' ' - git -C r2 ls-files -s large.1000 large.10000 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r2 ls-files -s large.1000 large.10000 | + test_parse_ls_files_stage_oids | sort >expected && echo HEAD >objects && @@ -226,15 +226,15 @@ test_expect_success 'verify explicitly specifying oversized blob in input' ' git -C r2 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed ' test_expect_success 'verify blob:limit=1m' ' - git -C r2 ls-files -s large.1000 large.10000 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r2 ls-files -s large.1000 large.10000 | + test_parse_ls_files_stage_oids | sort >expected && git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF && @@ -244,7 +244,7 @@ test_expect_success 'verify blob:limit=1m' ' git -C r2 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -253,12 +253,12 @@ test_expect_success 'verify blob:limit=1m' ' test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' ' git -C r2 verify-pack -v ../all.pack >verify_result && grep -E "commit|tree" verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >expected && git -C r2 verify-pack -v ../filter.pack >verify_result && grep -E "commit|tree" verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -289,9 +289,8 @@ test_expect_success 'setup r3' ' ' test_expect_success 'verify blob count in normal packfile' ' - git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \ - >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 | + test_parse_ls_files_stage_oids | sort >expected && git -C r3 pack-objects --revs --stdout >all.pack <<-EOF && @@ -301,7 +300,7 @@ test_expect_success 'verify blob count in normal packfile' ' git -C r3 verify-pack -v ../all.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -342,9 +341,8 @@ test_expect_success 'setup r4' ' ' test_expect_success 'verify blob count in normal packfile' ' - git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \ - >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 | + test_parse_ls_files_stage_oids | sort >expected && git -C r4 pack-objects --revs --stdout >all.pack <<-EOF && @@ -354,19 +352,19 @@ test_expect_success 'verify blob count in normal packfile' ' git -C r4 verify-pack -v ../all.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed ' test_expect_success 'verify sparse:oid=OID' ' - git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 | + test_parse_ls_files_stage_oids | sort >expected && git -C r4 ls-files -s pattern >staged && - oid=$(awk -f print_2.awk staged) && + oid=$(test_parse_ls_files_stage_oids <staged) && git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF && HEAD EOF @@ -374,15 +372,15 @@ test_expect_success 'verify sparse:oid=OID' ' git -C r4 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed ' test_expect_success 'verify sparse:oid=oid-ish' ' - git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 | + test_parse_ls_files_stage_oids | sort >expected && git -C r4 pack-objects --revs --stdout --filter=sparse:oid=main:pattern >filter.pack <<-EOF && @@ -392,7 +390,7 @@ test_expect_success 'verify sparse:oid=oid-ish' ' git -C r4 verify-pack -v ../filter.pack >verify_result && grep blob verify_result | - awk -f print_1.awk | + parse_verify_pack_blob_oid | sort >observed && test_cmp expected observed @@ -402,9 +400,8 @@ test_expect_success 'verify sparse:oid=oid-ish' ' # This models previously omitted objects that we did not receive. test_expect_success 'setup r1 - delete loose blobs' ' - git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \ - >ls_files_result && - awk -f print_2.awk ls_files_result | + git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 | + test_parse_ls_files_stage_oids | sort >expected && for id in `cat expected | sed "s|..|&/|"` diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index fbf0d64..be0b564 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -361,13 +361,14 @@ test_expect_success 'replace-objects invalidates commit-graph' ' test_expect_success 'commit grafts invalidate commit-graph' ' cd "$TRASH_DIRECTORY" && test_when_finished rm -rf graft && - git clone full graft && + git clone --template= full graft && ( cd graft && git commit-graph write --reachable && test_path_is_file .git/objects/info/commit-graph && H1=$(git rev-parse --verify HEAD~1) && H3=$(git rev-parse --verify HEAD~3) && + mkdir .git/info && echo "$H1 $H3" >.git/info/grafts && git -c core.commitGraph=false log >expect && git -c core.commitGraph=true log >actual && diff --git a/t/t5320-delta-islands.sh b/t/t5320-delta-islands.sh index fea92a5..124d476 100755 --- a/t/t5320-delta-islands.sh +++ b/t/t5320-delta-islands.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='exercise delta islands' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # returns true iff $1 is a delta based on $2 diff --git a/t/t5321-pack-large-objects.sh b/t/t5321-pack-large-objects.sh index 8a56d98..70770fe 100755 --- a/t/t5321-pack-large-objects.sh +++ b/t/t5321-pack-large-objects.sh @@ -6,6 +6,8 @@ test_description='git pack-object with "large" deltas ' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pack.sh diff --git a/t/t5322-pack-objects-sparse.sh b/t/t5322-pack-objects-sparse.sh index d39958c..770695c 100755 --- a/t/t5322-pack-objects-sparse.sh +++ b/t/t5322-pack-objects-sparse.sh @@ -4,6 +4,7 @@ test_description='pack-objects object selection using sparse algorithm' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup repo' ' diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh new file mode 100755 index 0000000..8968f7a --- /dev/null +++ b/t/t5329-pack-objects-cruft.sh @@ -0,0 +1,741 @@ +#!/bin/sh + +test_description='cruft pack related pack-objects tests' +. ./test-lib.sh + +objdir=.git/objects +packdir=$objdir/pack + +basic_cruft_pack_tests () { + expire="$1" + + test_expect_success "unreachable loose objects are packed (expire $expire)" ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit base && + git repack -Ad && + test_commit loose && + + test-tool chmtime +2000 "$objdir/$(test_oid_to_path \ + $(git rev-parse loose:loose.t))" && + test-tool chmtime +1000 "$objdir/$(test_oid_to_path \ + $(git rev-parse loose^{tree}))" && + + ( + git rev-list --objects --no-object-names base..loose | + while read oid + do + path="$objdir/$(test_oid_to_path "$oid")" && + printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" + done | + sort -k1 + ) >expect && + + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + cruft="$(echo $keep | git pack-objects --cruft \ + --cruft-expiration="$expire" $packdir/pack)" && + test-tool pack-mtimes "pack-$cruft.mtimes" >actual && + + test_cmp expect actual + ) + ' + + test_expect_success "unreachable packed objects are packed (expire $expire)" ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit packed && + git repack -Ad && + test_commit other && + + git rev-list --objects --no-object-names packed.. >objects && + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + other="$(git pack-objects --delta-base-offset \ + $packdir/pack <objects)" && + git prune-packed && + + test-tool chmtime --get -100 "$packdir/pack-$other.pack" >expect && + + cruft="$(git pack-objects --cruft --cruft-expiration="$expire" $packdir/pack <<-EOF + $keep + -pack-$other.pack + EOF + )" && + test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && + + cut -d" " -f2 <actual.raw | sort -u >actual && + + test_cmp expect actual + ) + ' + + test_expect_success "unreachable cruft objects are repacked (expire $expire)" ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit packed && + git repack -Ad && + test_commit other && + + git rev-list --objects --no-object-names packed.. >objects && + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + + cruft_a="$(echo $keep | git pack-objects --cruft --cruft-expiration="$expire" $packdir/pack)" && + git prune-packed && + cruft_b="$(git pack-objects --cruft --cruft-expiration="$expire" $packdir/pack <<-EOF + $keep + -pack-$cruft_a.pack + EOF + )" && + + test-tool pack-mtimes "pack-$cruft_a.mtimes" >expect.raw && + test-tool pack-mtimes "pack-$cruft_b.mtimes" >actual.raw && + + sort <expect.raw >expect && + sort <actual.raw >actual && + + test_cmp expect actual + ) + ' + + test_expect_success "multiple cruft packs (expire $expire)" ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + git repack -Ad && + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + + test_commit cruft && + loose="$objdir/$(test_oid_to_path $(git rev-parse cruft))" && + + # generate three copies of the cruft object in different + # cruft packs, each with a unique mtime: + # - one expired (1000 seconds ago) + # - two non-expired (one 1000 seconds in the future, + # one 1500 seconds in the future) + test-tool chmtime =-1000 "$loose" && + git pack-objects --cruft $packdir/pack-A <<-EOF && + $keep + EOF + test-tool chmtime =+1000 "$loose" && + git pack-objects --cruft $packdir/pack-B <<-EOF && + $keep + -$(basename $(ls $packdir/pack-A-*.pack)) + EOF + test-tool chmtime =+1500 "$loose" && + git pack-objects --cruft $packdir/pack-C <<-EOF && + $keep + -$(basename $(ls $packdir/pack-A-*.pack)) + -$(basename $(ls $packdir/pack-B-*.pack)) + EOF + + # ensure the resulting cruft pack takes the most recent + # mtime among all copies + cruft="$(git pack-objects --cruft \ + --cruft-expiration="$expire" \ + $packdir/pack <<-EOF + $keep + -$(basename $(ls $packdir/pack-A-*.pack)) + -$(basename $(ls $packdir/pack-B-*.pack)) + -$(basename $(ls $packdir/pack-C-*.pack)) + EOF + )" && + + test-tool pack-mtimes "$(basename $(ls $packdir/pack-C-*.mtimes))" >expect.raw && + test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && + + sort expect.raw >expect && + sort actual.raw >actual && + test_cmp expect actual + ) + ' + + test_expect_success "cruft packs tolerate missing trees (expire $expire)" ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + test_commit cruft && + + tree="$(git rev-parse cruft^{tree})" && + + git reset --hard reachable && + git tag -d cruft && + git reflog expire --all --expire=all && + + # remove the unreachable tree, but leave the commit + # which has it as its root tree intact + rm -fr "$objdir/$(test_oid_to_path "$tree")" && + + git repack -Ad && + basename $(ls $packdir/pack-*.pack) >in && + git pack-objects --cruft --cruft-expiration="$expire" \ + $packdir/pack <in + ) + ' + + test_expect_success "cruft packs tolerate missing blobs (expire $expire)" ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + test_commit cruft && + + blob="$(git rev-parse cruft:cruft.t)" && + + git reset --hard reachable && + git tag -d cruft && + git reflog expire --all --expire=all && + + # remove the unreachable blob, but leave the commit (and + # the root tree of that commit) intact + rm -fr "$objdir/$(test_oid_to_path "$blob")" && + + git repack -Ad && + basename $(ls $packdir/pack-*.pack) >in && + git pack-objects --cruft --cruft-expiration="$expire" \ + $packdir/pack <in + ) + ' +} + +basic_cruft_pack_tests never +basic_cruft_pack_tests 2.weeks.ago + +test_expect_success 'cruft tags rescue tagged objects' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit packed && + git repack -Ad && + + test_commit tagged && + git tag -a annotated -m tag && + + git rev-list --objects --no-object-names packed.. >objects && + while read oid + do + test-tool chmtime -1000 \ + "$objdir/$(test_oid_to_path $oid)" + done <objects && + + test-tool chmtime -500 \ + "$objdir/$(test_oid_to_path $(git rev-parse annotated))" && + + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + cruft="$(echo $keep | git pack-objects --cruft \ + --cruft-expiration=750.seconds.ago \ + $packdir/pack)" && + test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && + cut -f1 -d" " <actual.raw | sort >actual && + + ( + cat objects && + git rev-parse annotated + ) >expect.raw && + sort <expect.raw >expect && + + test_cmp expect actual && + cat actual + ) +' + +test_expect_success 'cruft commits rescue parents, trees' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit packed && + git repack -Ad && + + test_commit old && + test_commit new && + + git rev-list --objects --no-object-names packed..new >objects && + while read object + do + test-tool chmtime -1000 \ + "$objdir/$(test_oid_to_path $object)" + done <objects && + test-tool chmtime +500 "$objdir/$(test_oid_to_path \ + $(git rev-parse HEAD))" && + + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + cruft="$(echo $keep | git pack-objects --cruft \ + --cruft-expiration=750.seconds.ago \ + $packdir/pack)" && + test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && + + cut -d" " -f1 <actual.raw | sort >actual && + sort <objects >expect && + + test_cmp expect actual + ) +' + +test_expect_success 'cruft trees rescue sub-trees, blobs' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit packed && + git repack -Ad && + + mkdir -p dir/sub && + echo foo >foo && + echo bar >dir/bar && + echo baz >dir/sub/baz && + + test_tick && + git add . && + git commit -m "pruned" && + + test-tool chmtime -1000 "$objdir/$(test_oid_to_path $(git rev-parse HEAD))" && + test-tool chmtime -1000 "$objdir/$(test_oid_to_path $(git rev-parse HEAD^{tree}))" && + test-tool chmtime -1000 "$objdir/$(test_oid_to_path $(git rev-parse HEAD:foo))" && + test-tool chmtime -500 "$objdir/$(test_oid_to_path $(git rev-parse HEAD:dir))" && + test-tool chmtime -1000 "$objdir/$(test_oid_to_path $(git rev-parse HEAD:dir/bar))" && + test-tool chmtime -1000 "$objdir/$(test_oid_to_path $(git rev-parse HEAD:dir/sub))" && + test-tool chmtime -1000 "$objdir/$(test_oid_to_path $(git rev-parse HEAD:dir/sub/baz))" && + + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + cruft="$(echo $keep | git pack-objects --cruft \ + --cruft-expiration=750.seconds.ago \ + $packdir/pack)" && + test-tool pack-mtimes "pack-$cruft.mtimes" >actual.raw && + cut -f1 -d" " <actual.raw | sort >actual && + + git rev-parse HEAD:dir HEAD:dir/bar HEAD:dir/sub HEAD:dir/sub/baz >expect.raw && + sort <expect.raw >expect && + + test_cmp expect actual + ) +' + +test_expect_success 'expired objects are pruned' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit packed && + git repack -Ad && + + test_commit pruned && + + git rev-list --objects --no-object-names packed..pruned >objects && + while read object + do + test-tool chmtime -1000 \ + "$objdir/$(test_oid_to_path $object)" + done <objects && + + keep="$(basename "$(ls $packdir/pack-*.pack)")" && + cruft="$(echo $keep | git pack-objects --cruft \ + --cruft-expiration=750.seconds.ago \ + $packdir/pack)" && + + test-tool pack-mtimes "pack-$cruft.mtimes" >actual && + test_must_be_empty actual + ) +' + +test_expect_success 'repack --cruft generates a cruft pack' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + git branch -M main && + git checkout --orphan other && + test_commit unreachable && + + git checkout main && + git branch -D other && + git tag -d unreachable && + # objects are not cruft if they are contained in the reflogs + git reflog expire --all --expire=all && + + git rev-list --objects --all --no-object-names >reachable.raw && + git cat-file --batch-all-objects --batch-check="%(objectname)" >objects && + sort <reachable.raw >reachable && + comm -13 reachable objects >unreachable && + + git repack --cruft -d && + + cruft=$(basename $(ls $packdir/pack-*.mtimes) .mtimes) && + pack=$(basename $(ls $packdir/pack-*.pack | grep -v $cruft) .pack) && + + git show-index <$packdir/$pack.idx >actual.raw && + cut -f2 -d" " actual.raw | sort >actual && + test_cmp reachable actual && + + git show-index <$packdir/$cruft.idx >actual.raw && + cut -f2 -d" " actual.raw | sort >actual && + test_cmp unreachable actual + ) +' + +test_expect_success 'loose objects mtimes upsert others' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + git repack -Ad && + git branch -M main && + + git checkout --orphan other && + test_commit cruft && + # incremental repack, leaving existing objects loose (so + # they can be "freshened") + git repack && + + tip="$(git rev-parse cruft)" && + path="$objdir/$(test_oid_to_path "$tip")" && + test-tool chmtime --get +1000 "$path" >expect && + + git checkout main && + git branch -D other && + git tag -d cruft && + git reflog expire --all --expire=all && + + git repack --cruft -d && + + mtimes="$(basename $(ls $packdir/pack-*.mtimes))" && + test-tool pack-mtimes "$mtimes" >actual.raw && + grep "$tip" actual.raw | cut -d" " -f2 >actual && + test_cmp expect actual + ) +' + +test_expect_success 'expiring cruft objects with git gc' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + git branch -M main && + git checkout --orphan other && + test_commit unreachable && + + git checkout main && + git branch -D other && + git tag -d unreachable && + # objects are not cruft if they are contained in the reflogs + git reflog expire --all --expire=all && + + git rev-list --objects --all --no-object-names >reachable.raw && + git cat-file --batch-all-objects --batch-check="%(objectname)" >objects && + sort <reachable.raw >reachable && + comm -13 reachable objects >unreachable && + + # Write a cruft pack containing all unreachable objects. + git gc --cruft --prune="01-01-1980" && + + mtimes=$(ls .git/objects/pack/pack-*.mtimes) && + test_path_is_file $mtimes && + + # Prune all unreachable objects from the cruft pack. + git gc --cruft --prune=now && + + git cat-file --batch-all-objects --batch-check="%(objectname)" >objects && + + comm -23 unreachable objects >removed && + test_cmp unreachable removed && + test_path_is_missing $mtimes + ) +' + +test_expect_success 'cruft packs are not included in geometric repack' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + git repack -Ad && + git branch -M main && + + git checkout --orphan other && + test_commit cruft && + git repack -d && + + git checkout main && + git branch -D other && + git tag -d cruft && + git reflog expire --all --expire=all && + + git repack --cruft && + + find $packdir -type f | sort >before && + git repack --geometric=2 -d && + find $packdir -type f | sort >after && + + test_cmp before after + ) +' + +test_expect_success 'repack --geometric collects once-cruft objects' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + git repack -Ad && + git branch -M main && + + git checkout --orphan other && + git rm -rf . && + test_commit --no-tag cruft && + cruft="$(git rev-parse HEAD)" && + + git checkout main && + git branch -D other && + git reflog expire --all --expire=all && + + # Pack the objects created in the previous step into a cruft + # pack. Intentionally leave loose copies of those objects + # around so we can pick them up in a subsequent --geometric + # reapack. + git repack --cruft && + + # Now make those objects reachable, and ensure that they are + # packed into the new pack created via a --geometric repack. + git update-ref refs/heads/other $cruft && + + # Without this object, the set of unpacked objects is exactly + # the set of objects already in the cruft pack. Tweak that set + # to ensure we do not overwrite the cruft pack entirely. + test_commit reachable2 && + + find $packdir -name "pack-*.idx" | sort >before && + git repack --geometric=2 -d && + find $packdir -name "pack-*.idx" | sort >after && + + { + git rev-list --objects --no-object-names $cruft && + git rev-list --objects --no-object-names reachable..reachable2 + } >want.raw && + sort want.raw >want && + + pack=$(comm -13 before after) && + git show-index <$pack >objects.raw && + + cut -d" " -f2 objects.raw | sort >got && + + test_cmp want got + ) +' + +test_expect_success 'cruft repack with no reachable objects' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit base && + git repack -ad && + + base="$(git rev-parse base)" && + + git for-each-ref --format="delete %(refname)" >in && + git update-ref --stdin <in && + git reflog expire --all --expire=all && + rm -fr .git/index && + + git repack --cruft -d && + + git cat-file -t $base + ) +' + +test_expect_success 'cruft repack ignores --max-pack-size' ' + git init max-pack-size && + ( + cd max-pack-size && + test_commit base && + # two cruft objects which exceed the maximum pack size + test-tool genrandom foo 1048576 | git hash-object --stdin -w && + test-tool genrandom bar 1048576 | git hash-object --stdin -w && + git repack --cruft --max-pack-size=1M && + find $packdir -name "*.mtimes" >cruft && + test_line_count = 1 cruft && + test-tool pack-mtimes "$(basename "$(cat cruft)")" >objects && + test_line_count = 2 objects + ) +' + +test_expect_success 'cruft repack ignores pack.packSizeLimit' ' + ( + cd max-pack-size && + # repack everything back together to remove the existing cruft + # pack (but to keep its objects) + git repack -adk && + git -c pack.packSizeLimit=1M repack --cruft && + # ensure the same post condition is met when --max-pack-size + # would otherwise be inferred from the configuration + find $packdir -name "*.mtimes" >cruft && + test_line_count = 1 cruft && + test-tool pack-mtimes "$(basename "$(cat cruft)")" >objects && + test_line_count = 2 objects + ) +' + +test_expect_success 'cruft repack respects repack.cruftWindow' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit base && + + GIT_TRACE2_EVENT=$(pwd)/event.trace \ + git -c pack.window=1 -c repack.cruftWindow=2 repack \ + --cruft --window=3 && + + grep "pack-objects.*--window=2.*--cruft" event.trace + ) +' + +test_expect_success 'cruft repack respects --window by default' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit base && + + GIT_TRACE2_EVENT=$(pwd)/event.trace \ + git -c pack.window=2 repack --cruft --window=3 && + + grep "pack-objects.*--window=3.*--cruft" event.trace + ) +' + +test_expect_success 'cruft repack respects --quiet' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit base && + GIT_PROGRESS_DELAY=0 git repack --cruft --quiet 2>err && + test_must_be_empty err + ) +' + +test_expect_success 'cruft --local drops unreachable objects' ' + git init alternate && + git init repo && + test_when_finished "rm -fr alternate repo" && + + test_commit -C alternate base && + # Pack all objects in alterate so that the cruft repack in "repo" sees + # the object it dropped due to `--local` as packed. Otherwise this + # object would not appear packed anywhere (since it is not packed in + # alternate and likewise not part of the cruft pack in the other repo + # because of `--local`). + git -C alternate repack -ad && + + ( + cd repo && + + object="$(git -C ../alternate rev-parse HEAD:base.t)" && + git -C ../alternate cat-file -p $object >contents && + + # Write some reachable objects and two unreachable ones: one + # that the alternate has and another that is unique. + test_commit other && + git hash-object -w -t blob contents && + cruft="$(echo cruft | git hash-object -w -t blob --stdin)" && + + ( cd ../alternate/.git/objects && pwd ) \ + >.git/objects/info/alternates && + + test_path_is_file $objdir/$(test_oid_to_path $cruft) && + test_path_is_file $objdir/$(test_oid_to_path $object) && + + git repack -d --cruft --local && + + test-tool pack-mtimes "$(basename $(ls $packdir/pack-*.mtimes))" \ + >objects && + ! grep $object objects && + grep $cruft objects + ) +' + +test_expect_success 'MIDX bitmaps tolerate reachable cruft objects' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + test_commit reachable && + test_commit cruft && + unreachable="$(git rev-parse cruft)" && + + git reset --hard $unreachable^ && + git tag -d cruft && + git reflog expire --all --expire=all && + + git repack --cruft -d && + + # resurrect the unreachable object via a new commit. the + # new commit will get selected for a bitmap, but be + # missing one of its parents from the selected packs. + git reset --hard $unreachable && + test_commit resurrect && + + git repack --write-midx --write-bitmap-index --geometric=2 -d + ) +' + +test_expect_success 'cruft objects are freshend via loose' ' + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + echo "cruft" >contents && + blob="$(git hash-object -w -t blob contents)" && + loose="$objdir/$(test_oid_to_path $blob)" && + + test_commit base && + + git repack --cruft -d && + + test_path_is_missing "$loose" && + test-tool pack-mtimes "$(basename "$(ls $packdir/pack-*.mtimes)")" >cruft && + grep "$blob" cruft && + + # write the same object again + git hash-object -w -t blob contents && + + test_path_is_file "$loose" + ) +' + +test_done diff --git a/t/t5330-no-lazy-fetch-with-commit-graph.sh b/t/t5330-no-lazy-fetch-with-commit-graph.sh new file mode 100755 index 0000000..2cc7fd7 --- /dev/null +++ b/t/t5330-no-lazy-fetch-with-commit-graph.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +test_description='test for no lazy fetch with the commit-graph' + +. ./test-lib.sh + +test_expect_success 'setup: prepare a repository with a commit' ' + git init with-commit && + test_commit -C with-commit the-commit && + oid=$(git -C with-commit rev-parse HEAD) +' + +test_expect_success 'setup: prepare a repository with commit-graph contains the commit' ' + git init with-commit-graph && + echo "$(pwd)/with-commit/.git/objects" \ + >with-commit-graph/.git/objects/info/alternates && + # create a ref that points to the commit in alternates + git -C with-commit-graph update-ref refs/ref_to_the_commit "$oid" && + # prepare some other objects to commit-graph + test_commit -C with-commit-graph something && + git -c gc.writeCommitGraph=true -C with-commit-graph gc && + test_path_is_file with-commit-graph/.git/objects/info/commit-graph +' + +test_expect_success 'setup: change the alternates to what without the commit' ' + git init --bare without-commit && + git -C with-commit-graph cat-file -e $oid && + echo "$(pwd)/without-commit/objects" \ + >with-commit-graph/.git/objects/info/alternates && + test_must_fail git -C with-commit-graph cat-file -e $oid +' + +test_expect_success 'fetch any commit from promisor with the usage of the commit graph' ' + # setup promisor and prepare any commit to fetch + git -C with-commit-graph remote add origin "$(pwd)/with-commit" && + git -C with-commit-graph config remote.origin.promisor true && + git -C with-commit-graph config remote.origin.partialclonefilter blob:none && + test_commit -C with-commit any-commit && + anycommit=$(git -C with-commit rev-parse HEAD) && + GIT_TRACE="$(pwd)/trace.txt" \ + git -C with-commit-graph fetch origin $anycommit 2>err && + ! grep "fatal: promisor-remote: unable to fork off fetch subprocess" err && + grep "git fetch origin" trace.txt >actual && + test_line_count = 1 actual +' + +test_done diff --git a/t/t5351-unpack-large-objects.sh b/t/t5351-unpack-large-objects.sh new file mode 100755 index 0000000..f785cb0 --- /dev/null +++ b/t/t5351-unpack-large-objects.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# +# Copyright (c) 2022 Han Xin +# + +test_description='git unpack-objects with large objects' + +. ./test-lib.sh + +prepare_dest () { + test_when_finished "rm -rf dest.git" && + git init --bare dest.git && + git -C dest.git config core.bigFileThreshold "$1" +} + +test_expect_success "create large objects (1.5 MB) and PACK" ' + test-tool genrandom foo 1500000 >big-blob && + test_commit --append foo big-blob && + test-tool genrandom bar 1500000 >big-blob && + test_commit --append bar big-blob && + PACK=$(echo HEAD | git pack-objects --revs pack) && + git verify-pack -v pack-$PACK.pack >out && + sed -n -e "s/^\([0-9a-f][0-9a-f]*\).*\(commit\|tree\|blob\).*/\1/p" \ + <out >obj-list +' + +test_expect_success 'set memory limitation to 1MB' ' + GIT_ALLOC_LIMIT=1m && + export GIT_ALLOC_LIMIT +' + +test_expect_success 'unpack-objects failed under memory limitation' ' + prepare_dest 2m && + test_must_fail git -C dest.git unpack-objects <pack-$PACK.pack 2>err && + grep "fatal: attempting to allocate" err +' + +test_expect_success 'unpack-objects works with memory limitation in dry-run mode' ' + prepare_dest 2m && + git -C dest.git unpack-objects -n <pack-$PACK.pack && + test_stdout_line_count = 0 find dest.git/objects -type f && + test_dir_is_empty dest.git/objects/pack +' + +test_expect_success 'unpack big object in stream' ' + prepare_dest 1m && + git -C dest.git unpack-objects <pack-$PACK.pack && + test_dir_is_empty dest.git/objects/pack +' + +check_fsync_events () { + local trace="$1" && + shift && + + cat >expect && + sed -n \ + -e '/^{"event":"data",.*"category":"fsync",/ { + s/.*"category":"fsync",//; + s/}$//; + p; + }' \ + <"$trace" >actual && + test_cmp expect actual +} + +BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' + +test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' ' + prepare_dest 1m && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ + GIT_TEST_FSYNC=true \ + git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack && + check_fsync_events trace2.txt <<-\EOF && + "key":"fsync/writeout-only","value":"6" + "key":"fsync/hardware-flush","value":"1" + EOF + + test_dir_is_empty dest.git/objects/pack && + git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current && + cmp obj-list current +' + +test_expect_success 'do not unpack existing large objects' ' + prepare_dest 1m && + git -C dest.git index-pack --stdin <pack-$PACK.pack && + git -C dest.git unpack-objects <pack-$PACK.pack && + + # The destination came up with the exact same pack... + DEST_PACK=$(echo dest.git/objects/pack/pack-*.pack) && + test_cmp pack-$PACK.pack $DEST_PACK && + + # ...and wrote no loose objects + test_stdout_line_count = 0 find dest.git/objects -type f ! -name "pack-*" +' + +test_done diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 6012cc8..001b7a1 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -20,45 +20,37 @@ test_expect_success setup ' git clone --bare ./. victim.git && GIT_DIR=victim.git git update-ref refs/heads/tofail $commit1 && git update-ref refs/heads/main $commit1 && - git update-ref refs/heads/tofail $commit0 -' + git update-ref refs/heads/tofail $commit0 && -cat >victim.git/hooks/pre-receive <<'EOF' -#!/bin/sh -printf %s "$@" >>$GIT_DIR/pre-receive.args -cat - >$GIT_DIR/pre-receive.stdin -echo STDOUT pre-receive -echo STDERR pre-receive >&2 -EOF -chmod u+x victim.git/hooks/pre-receive + test_hook --setup -C victim.git pre-receive <<-\EOF && + printf %s "$@" >>$GIT_DIR/pre-receive.args + cat - >$GIT_DIR/pre-receive.stdin + echo STDOUT pre-receive + echo STDERR pre-receive >&2 + EOF -cat >victim.git/hooks/update <<'EOF' -#!/bin/sh -echo "$@" >>$GIT_DIR/update.args -read x; printf %s "$x" >$GIT_DIR/update.stdin -echo STDOUT update $1 -echo STDERR update $1 >&2 -test "$1" = refs/heads/main || exit -EOF -chmod u+x victim.git/hooks/update + test_hook --setup -C victim.git update <<-\EOF && + echo "$@" >>$GIT_DIR/update.args + read x; printf %s "$x" >$GIT_DIR/update.stdin + echo STDOUT update $1 + echo STDERR update $1 >&2 + test "$1" = refs/heads/main || exit + EOF -cat >victim.git/hooks/post-receive <<'EOF' -#!/bin/sh -printf %s "$@" >>$GIT_DIR/post-receive.args -cat - >$GIT_DIR/post-receive.stdin -echo STDOUT post-receive -echo STDERR post-receive >&2 -EOF -chmod u+x victim.git/hooks/post-receive + test_hook --setup -C victim.git post-receive <<-\EOF && + printf %s "$@" >>$GIT_DIR/post-receive.args + cat - >$GIT_DIR/post-receive.stdin + echo STDOUT post-receive + echo STDERR post-receive >&2 + EOF -cat >victim.git/hooks/post-update <<'EOF' -#!/bin/sh -echo "$@" >>$GIT_DIR/post-update.args -read x; printf %s "$x" >$GIT_DIR/post-update.stdin -echo STDOUT post-update -echo STDERR post-update >&2 -EOF -chmod u+x victim.git/hooks/post-update + test_hook --setup -C victim.git post-update <<-\EOF + echo "$@" >>$GIT_DIR/post-update.args + read x; printf %s "$x" >$GIT_DIR/post-update.stdin + echo STDOUT post-update + echo STDERR post-update >&2 + EOF +' test_expect_success push ' test_must_fail git send-pack --force ./victim.git \ @@ -136,7 +128,7 @@ test_expect_success 'send-pack stderr contains hook messages' ' ' test_expect_success 'pre-receive hook that forgets to read its input' ' - write_script victim.git/hooks/pre-receive <<-\EOF && + test_hook --clobber -C victim.git pre-receive <<-\EOF && exit 0 EOF rm -f victim.git/hooks/update victim.git/hooks/post-update && diff --git a/t/t5402-post-merge-hook.sh b/t/t5402-post-merge-hook.sh index 3e5e19c..915af2d 100755 --- a/t/t5402-post-merge-hook.sh +++ b/t/t5402-post-merge-hook.sh @@ -25,13 +25,15 @@ test_expect_success setup ' GIT_DIR=clone2/.git git update-index --add a ' -for clone in 1 2; do - cat >clone${clone}/.git/hooks/post-merge <<'EOF' -#!/bin/sh -echo $@ >> $GIT_DIR/post-merge.args -EOF - chmod u+x clone${clone}/.git/hooks/post-merge -done +test_expect_success 'setup clone hooks' ' + test_when_finished "rm -f hook" && + cat >hook <<-\EOF && + echo $@ >>$GIT_DIR/post-merge.args + EOF + + test_hook --setup -C clone1 post-merge <hook && + test_hook --setup -C clone2 post-merge <hook +' test_expect_success 'post-merge does not run for up-to-date ' ' GIT_DIR=clone1/.git git merge $commit0 && diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index d118181..978f240 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -10,8 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success setup ' - mkdir -p .git/hooks && - write_script .git/hooks/post-checkout <<-\EOF && + test_hook --setup post-checkout <<-\EOF && echo "$@" >.git/post-checkout.args EOF test_commit one && diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh index 5c509db..dcbeb42 100755 --- a/t/t5406-remote-rejects.sh +++ b/t/t5406-remote-rejects.sh @@ -5,7 +5,7 @@ test_description='remote push rejects are reported by client' . ./test-lib.sh test_expect_success 'setup' ' - write_script .git/hooks/update <<-\EOF && + test_hook update <<-\EOF && exit 1 EOF echo 1 >file && diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 6da8d76..5f3ff05 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -17,15 +17,13 @@ test_expect_success 'setup' ' git checkout A^0 && test_commit E bar E && test_commit F foo F && - git checkout main -' + git checkout main && -cat >.git/hooks/post-rewrite <<EOF -#!/bin/sh -echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args -cat > "$TRASH_DIRECTORY"/post-rewrite.data -EOF -chmod u+x .git/hooks/post-rewrite + test_hook --setup post-rewrite <<-EOF + echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args + cat > "$TRASH_DIRECTORY"/post-rewrite.data + EOF +' clear_hook_input () { rm -f post-rewrite.args post-rewrite.data diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh index 9f1a483..fa5de45 100755 --- a/t/t5409-colorize-remote-messages.sh +++ b/t/t5409-colorize-remote-messages.sh @@ -5,7 +5,7 @@ test_description='remote messages are colorized on the client' . ./test-lib.sh test_expect_success 'setup' ' - write_script .git/hooks/update <<-\EOF && + test_hook --setup update <<-\EOF && echo error: error echo ERROR: also highlighted echo hint: hint diff --git a/t/t5411-proc-receive-hook.sh b/t/t5411-proc-receive-hook.sh index 98b0e81..92cf52c 100755 --- a/t/t5411-proc-receive-hook.sh +++ b/t/t5411-proc-receive-hook.sh @@ -36,7 +36,7 @@ setup_upstream_and_workbench () { TAG=$(git -C workbench rev-parse v123) && # setup pre-receive hook - write_script upstream.git/hooks/pre-receive <<-\EOF && + test_hook --setup -C upstream.git pre-receive <<-\EOF && exec >&2 echo "# pre-receive hook" while read old new ref @@ -46,7 +46,7 @@ setup_upstream_and_workbench () { EOF # setup post-receive hook - write_script upstream.git/hooks/post-receive <<-\EOF && + test_hook --setup -C upstream.git post-receive <<-\EOF && exec >&2 echo "# post-receive hook" while read old new ref diff --git a/t/t5411/once-0010-report-status-v1.sh b/t/t5411/once-0010-report-status-v1.sh index 297b109..f9ffb01 100644 --- a/t/t5411/once-0010-report-status-v1.sh +++ b/t/t5411/once-0010-report-status-v1.sh @@ -3,7 +3,7 @@ test_expect_success "setup receive.procReceiveRefs" ' ' test_expect_success "setup proc-receive hook" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic1" \ diff --git a/t/t5411/test-0002-pre-receive-declined.sh b/t/t5411/test-0002-pre-receive-declined.sh index 0c3490c..98a9d13 100644 --- a/t/t5411/test-0002-pre-receive-declined.sh +++ b/t/t5411/test-0002-pre-receive-declined.sh @@ -1,6 +1,6 @@ test_expect_success "setup pre-receive hook ($PROTOCOL)" ' mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && - write_script "$upstream/hooks/pre-receive" <<-EOF + test_hook -C "$upstream" --clobber pre-receive <<-\EOF exit 1 EOF ' @@ -21,7 +21,7 @@ test_expect_success "git-push is declined ($PROTOCOL)" ' EOF test_cmp expect actual && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs -C "$upstream" <<-\EOF <COMMIT-A> refs/heads/main EOF ' diff --git a/t/t5411/test-0003-pre-receive-declined--porcelain.sh b/t/t5411/test-0003-pre-receive-declined--porcelain.sh index 2393b04..67ca6dc 100644 --- a/t/t5411/test-0003-pre-receive-declined--porcelain.sh +++ b/t/t5411/test-0003-pre-receive-declined--porcelain.sh @@ -1,6 +1,6 @@ test_expect_success "setup pre-receive hook ($PROTOCOL/porcelain)" ' mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" && - write_script "$upstream/hooks/pre-receive" <<-EOF + test_hook -C "$upstream" --clobber pre-receive <<-\EOF exit 1 EOF ' diff --git a/t/t5411/test-0013-bad-protocol.sh b/t/t5411/test-0013-bad-protocol.sh index c08a00d..8d22e17 100644 --- a/t/t5411/test-0013-bad-protocol.sh +++ b/t/t5411/test-0013-bad-protocol.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --version 2 EOF @@ -40,7 +40,7 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-version EOF @@ -65,13 +65,13 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO grep "remote: fatal: die with the --die-read-version option" out-$test_count && grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count && - test_cmp_refs -C "$upstream" <<-EOF + test_cmp_refs -C "$upstream" <<-\EOF <COMMIT-A> refs/heads/main EOF ' test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-version EOF @@ -102,7 +102,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT ' test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-commands EOF @@ -132,7 +132,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT ' test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-push-options EOF @@ -164,7 +164,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $ ' test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-report EOF @@ -194,7 +194,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO ' test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v EOF @@ -236,7 +236,7 @@ test_expect_success "cleanup ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok" @@ -269,7 +269,7 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "xx refs/for/main/topic" diff --git a/t/t5411/test-0014-bad-protocol--porcelain.sh b/t/t5411/test-0014-bad-protocol--porcelain.sh index 3eaa597..298a3d1 100644 --- a/t/t5411/test-0014-bad-protocol--porcelain.sh +++ b/t/t5411/test-0014-bad-protocol--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --version 2 EOF @@ -40,7 +40,7 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porc ' test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-version EOF @@ -71,7 +71,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO ' test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-version EOF @@ -102,7 +102,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT ' test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-commands EOF @@ -132,7 +132,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT ' test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-read-push-options EOF @@ -164,7 +164,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $ ' test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v --die-write-report EOF @@ -194,7 +194,7 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO ' test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v EOF @@ -236,7 +236,7 @@ test_expect_success "cleanup ($PROTOCOL/porcelain)" ' ' test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok" @@ -270,7 +270,7 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" ' ' test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "xx refs/for/main/topic" diff --git a/t/t5411/test-0020-report-ng.sh b/t/t5411/test-0020-report-ng.sh index e915dbc..6347c96 100644 --- a/t/t5411/test-0020-report-ng.sh +++ b/t/t5411/test-0020-report-ng.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic" @@ -31,7 +31,7 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic error msg" diff --git a/t/t5411/test-0021-report-ng--porcelain.sh b/t/t5411/test-0021-report-ng--porcelain.sh index 2a392e0..502b34f 100644 --- a/t/t5411/test-0021-report-ng--porcelain.sh +++ b/t/t5411/test-0021-report-ng--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic" @@ -32,7 +32,7 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/por ' test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ng refs/for/main/topic error msg" diff --git a/t/t5411/test-0022-report-unexpect-ref.sh b/t/t5411/test-0022-report-unexpect-ref.sh index f7a494b..7744392 100644 --- a/t/t5411/test-0022-report-unexpect-ref.sh +++ b/t/t5411/test-0022-report-unexpect-ref.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" diff --git a/t/t5411/test-0023-report-unexpect-ref--porcelain.sh b/t/t5411/test-0023-report-unexpect-ref--porcelain.sh index 63c479e..6d116ef 100644 --- a/t/t5411/test-0023-report-unexpect-ref--porcelain.sh +++ b/t/t5411/test-0023-report-unexpect-ref--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" diff --git a/t/t5411/test-0024-report-unknown-ref.sh b/t/t5411/test-0024-report-unknown-ref.sh index af055aa..619ca2f 100644 --- a/t/t5411/test-0024-report-unknown-ref.sh +++ b/t/t5411/test-0024-report-unknown-ref.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0025-report-unknown-ref--porcelain.sh b/t/t5411/test-0025-report-unknown-ref--porcelain.sh index 99601ca..8b3f5d0 100644 --- a/t/t5411/test-0025-report-unknown-ref--porcelain.sh +++ b/t/t5411/test-0025-report-unknown-ref--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0026-push-options.sh b/t/t5411/test-0026-push-options.sh index fec5f95..6dfc7b1 100644 --- a/t/t5411/test-0026-push-options.sh +++ b/t/t5411/test-0026-push-options.sh @@ -1,6 +1,6 @@ test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL)" ' git -C "$upstream" config receive.advertisePushOptions false && - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" @@ -31,7 +31,7 @@ test_expect_success "enable push options ($PROTOCOL)" ' ' test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ --version 0 \ @@ -75,7 +75,7 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL) ' test_expect_success "restore proc-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok 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 8fb75a8..768880b 100644 --- a/t/t5411/test-0027-push-options--porcelain.sh +++ b/t/t5411/test-0027-push-options--porcelain.sh @@ -1,6 +1,6 @@ test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL/porcelain)" ' git -C "$upstream" config receive.advertisePushOptions false && - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" @@ -32,7 +32,7 @@ test_expect_success "enable push options ($PROTOCOL/porcelain)" ' ' test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ --version 0 \ @@ -78,7 +78,7 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/ ' test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0030-report-ok.sh b/t/t5411/test-0030-report-ok.sh index a3a6278..0f190a6 100644 --- a/t/t5411/test-0030-report-ok.sh +++ b/t/t5411/test-0030-report-ok.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0031-report-ok--porcelain.sh b/t/t5411/test-0031-report-ok--porcelain.sh index 0e17538..7ec3981 100644 --- a/t/t5411/test-0031-report-ok--porcelain.sh +++ b/t/t5411/test-0031-report-ok--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" diff --git a/t/t5411/test-0032-report-with-options.sh b/t/t5411/test-0032-report-with-options.sh index 988a430..07733b9 100644 --- a/t/t5411/test-0032-report-with-options.sh +++ b/t/t5411/test-0032-report-with-options.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "option refname refs/pull/123/head" \ @@ -30,7 +30,7 @@ test_expect_success "proc-receive: report option without matching ok ($PROTOCOL) ' test_expect_success "setup proc-receive hook (option refname, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -62,7 +62,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -95,7 +95,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO ' test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -129,7 +129,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL) ' test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -161,7 +161,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL) ' test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/a/b/c/topic" \ diff --git a/t/t5411/test-0033-report-with-options--porcelain.sh b/t/t5411/test-0033-report-with-options--porcelain.sh index daacb3d..2e1831b 100644 --- a/t/t5411/test-0033-report-with-options--porcelain.sh +++ b/t/t5411/test-0033-report-with-options--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "option refname refs/pull/123/head" \ @@ -31,7 +31,7 @@ test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/ ' test_expect_success "setup proc-receive hook (option refname, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -64,7 +64,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" ' test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -99,7 +99,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO ' test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -134,7 +134,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/ ' test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -167,7 +167,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" ' test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -202,7 +202,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/ ' test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/a/b/c/topic" \ diff --git a/t/t5411/test-0034-report-ft.sh b/t/t5411/test-0034-report-ft.sh index 73a47d1..0e37535 100644 --- a/t/t5411/test-0034-report-ft.sh +++ b/t/t5411/test-0034-report-ft.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (ft, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0035-report-ft--porcelain.sh b/t/t5411/test-0035-report-ft--porcelain.sh index c350201..b9a0518 100644 --- a/t/t5411/test-0035-report-ft--porcelain.sh +++ b/t/t5411/test-0035-report-ft--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (fall-through, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-\EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh b/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh index 8c8a6c1..889e970 100644 --- a/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +++ b/t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh @@ -14,7 +14,7 @@ test_expect_success "setup git config for remote-tracking of special refs" ' ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -87,7 +87,7 @@ test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -162,7 +162,7 @@ test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh b/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh index bc44810..1e523b1 100644 --- a/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +++ b/t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -58,7 +58,7 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ @@ -119,7 +119,7 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for ' test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/main/topic" \ diff --git a/t/t5411/test-0038-report-mixed-refs.sh b/t/t5411/test-0038-report-mixed-refs.sh index e63fe7b..4c70e84 100644 --- a/t/t5411/test-0038-report-mixed-refs.sh +++ b/t/t5411/test-0038-report-mixed-refs.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/next/topic2" \ diff --git a/t/t5411/test-0039-report-mixed-refs--porcelain.sh b/t/t5411/test-0039-report-mixed-refs--porcelain.sh index 99d17b7..40f4c5b 100644 --- a/t/t5411/test-0039-report-mixed-refs--porcelain.sh +++ b/t/t5411/test-0039-report-mixed-refs--porcelain.sh @@ -1,5 +1,5 @@ test_expect_success "setup proc-receive hook ($PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/for/next/topic2" \ diff --git a/t/t5411/test-0040-process-all-refs.sh b/t/t5411/test-0040-process-all-refs.sh index 2f405ad..7ae3851 100644 --- a/t/t5411/test-0040-process-all-refs.sh +++ b/t/t5411/test-0040-process-all-refs.sh @@ -17,7 +17,7 @@ test_expect_success "setup upstream branches ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ diff --git a/t/t5411/test-0041-process-all-refs--porcelain.sh b/t/t5411/test-0041-process-all-refs--porcelain.sh index c884057..02e1e08 100644 --- a/t/t5411/test-0041-process-all-refs--porcelain.sh +++ b/t/t5411/test-0041-process-all-refs--porcelain.sh @@ -17,7 +17,7 @@ test_expect_success "setup upstream branches ($PROTOCOL/porcelain)" ' ' test_expect_success "setup proc-receive hook ($PROTOCOL/porcelain)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ diff --git a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh index 31989f0..7efdfe5 100644 --- a/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +++ b/t/t5411/test-0050-proc-receive-refs-with-modifiers.sh @@ -9,7 +9,7 @@ test_expect_success "config receive.procReceiveRefs with modifiers ($PROTOCOL)" ' test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ @@ -70,7 +70,7 @@ test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" ' ' test_expect_success "setup proc-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/proc-receive" <<-EOF + test_hook -C "$upstream" --clobber proc-receive <<-EOF printf >&2 "# proc-receive hook\n" test-tool proc-receive -v \ -r "ok refs/heads/main" \ diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh index a3c0101..195fc64 100755 --- a/t/t5503-tagfollow.sh +++ b/t/t5503-tagfollow.sh @@ -160,68 +160,4 @@ test_expect_success 'new clone fetch main and tags' ' test_cmp expect actual ' -test_expect_success 'atomic fetch with failing backfill' ' - git init clone3 && - - # We want to test whether a failure when backfilling tags correctly - # aborts the complete transaction when `--atomic` is passed: we should - # neither create the branch nor should we create the tag when either - # one of both fails to update correctly. - # - # To trigger failure we simply abort when backfilling a tag. - write_script clone3/.git/hooks/reference-transaction <<-\EOF && - while read oldrev newrev reference - do - if test "$reference" = refs/tags/tag1 - then - exit 1 - fi - done - EOF - - test_must_fail git -C clone3 fetch --atomic .. $B:refs/heads/something && - test_must_fail git -C clone3 rev-parse --verify refs/heads/something && - test_must_fail git -C clone3 rev-parse --verify refs/tags/tag2 -' - -test_expect_success 'atomic fetch with backfill should use single transaction' ' - git init clone4 && - - # Fetching with the `--atomic` flag should update all references in a - # single transaction, including backfilled tags. We thus expect to see - # a single reference transaction for the created branch and tags. - cat >expected <<-EOF && - prepared - $ZERO_OID $B refs/heads/something - $ZERO_OID $S refs/tags/tag2 - $ZERO_OID $T refs/tags/tag1 - committed - $ZERO_OID $B refs/heads/something - $ZERO_OID $S refs/tags/tag2 - $ZERO_OID $T refs/tags/tag1 - EOF - - write_script clone4/.git/hooks/reference-transaction <<-\EOF && - ( echo "$*" && cat ) >>actual - EOF - - git -C clone4 fetch --atomic .. $B:refs/heads/something && - test_cmp expected clone4/actual -' - -test_expect_success 'backfill failure causes command to fail' ' - git init clone5 && - - # Create a tag that is nested below the tag we are about to fetch via - # the backfill mechanism. This causes a D/F conflict when backfilling - # and should thus cause the command to fail. - empty_blob=$(git -C clone5 hash-object -w --stdin </dev/null) && - git -C clone5 update-ref refs/tags/tag1/nested $empty_blob && - - test_must_fail git -C clone5 fetch .. $B:refs/heads/something && - test $B = $(git -C clone5 rev-parse --verify refs/heads/something) && - test $S = $(git -C clone5 rev-parse --verify tag2) && - test_must_fail git -C clone5 rev-parse --verify tag1 -' - test_done diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index c90cf47..6c7370f 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -78,6 +78,40 @@ test_expect_success 'add another remote' ' ) ' +test_expect_success 'setup bare clone for server' ' + git clone --bare "file://$(pwd)/one" srv.bare && + git -C srv.bare config --local uploadpack.allowfilter 1 && + git -C srv.bare config --local uploadpack.allowanysha1inwant 1 +' + +test_expect_success 'filters for promisor remotes are listed by git remote -v' ' + test_when_finished "rm -rf pc" && + git clone --filter=blob:none "file://$(pwd)/srv.bare" pc && + git -C pc remote -v >out && + grep "srv.bare (fetch) \[blob:none\]" out && + + git -C pc config remote.origin.partialCloneFilter object:type=commit && + git -C pc remote -v >out && + grep "srv.bare (fetch) \[object:type=commit\]" out +' + +test_expect_success 'filters should not be listed for non promisor remotes (remote -v)' ' + test_when_finished "rm -rf pc" && + git clone one pc && + git -C pc remote -v >out && + ! grep "(fetch) \[.*\]" out +' + +test_expect_success 'filters are listed by git remote -v only' ' + test_when_finished "rm -rf pc" && + git clone --filter=blob:none "file://$(pwd)/srv.bare" pc && + git -C pc remote >out && + ! grep "\[blob:none\]" out && + + git -C pc remote show >out && + ! grep "\[blob:none\]" out +' + test_expect_success 'check remote-tracking' ' ( cd test && @@ -268,6 +302,52 @@ test_expect_success 'show' ' ) ' +cat >expect <<EOF +* remote origin + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one + HEAD branch: main + Remote branches: + main skipped + side tracked + Local branches configured for 'git pull': + ahead merges with remote main + main merges with remote main + Local refs configured for 'git push': + main pushes to main (local out of date) + main pushes to upstream (create) +EOF + +test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --unset-all --fixed-value remote.origin.fetch ^refs/heads/main" && + git -C test config --add remote.origin.fetch ^refs/heads/main && + git -C test remote show origin >output && + test_cmp expect output +' + +cat >expect <<EOF +* remote origin + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one + HEAD branch: main + Remote branches: + main new (next fetch will store in remotes/origin) + side stale (use 'git remote prune' to remove) + Local branches configured for 'git pull': + ahead merges with remote main + main merges with remote main + Local refs configured for 'git push': + main pushes to main (local out of date) + main pushes to upstream (create) +EOF + +test_expect_failure 'show stale with negative refspecs' ' + test_when_finished "git -C test config --unset-all --fixed-value remote.origin.fetch ^refs/heads/side" && + git -C test config --add remote.origin.fetch ^refs/heads/side && + git -C test remote show origin >output && + test_cmp expect output +' + cat >test/expect <<EOF * remote origin Fetch URL: $(pwd)/one @@ -923,11 +1003,12 @@ test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' ' test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' - git clone one six && + git clone --template= one six && origin_url=$(pwd)/one && ( cd six && git remote rm origin && + mkdir .git/branches && echo "$origin_url#main" >.git/branches/origin && git remote rename origin origin && test_path_is_missing .git/branches/origin && @@ -938,10 +1019,11 @@ test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' ' test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' ' - git clone one seven && + git clone --template= one seven && ( cd seven && git remote rm origin && + mkdir .git/branches && echo "quux#foom" > .git/branches/origin && git remote rename origin origin && test_path_is_missing .git/branches/origin && diff --git a/t/t5506-remote-groups.sh b/t/t5506-remote-groups.sh index 8f150c0..5bac03e 100755 --- a/t/t5506-remote-groups.sh +++ b/t/t5506-remote-groups.sh @@ -4,6 +4,7 @@ test_description='git remote group handling' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh mark() { diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 48e14e2..b45879a 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -273,7 +273,7 @@ test_expect_success 'fetch --atomic executes a single reference transaction only EOF rm -f atomic/actual && - write_script atomic/.git/hooks/reference-transaction <<-\EOF && + test_hook -C atomic reference-transaction <<-\EOF && ( echo "$*" && cat ) >>actual EOF @@ -306,7 +306,7 @@ test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' EOF rm -f atomic/actual && - write_script atomic/.git/hooks/reference-transaction <<-\EOF && + test_hook -C atomic/.git reference-transaction <<-\EOF && ( echo "$*" && cat ) >>actual exit 1 EOF @@ -334,7 +334,7 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' ' test_line_count = 2 atomic/.git/FETCH_HEAD && cp atomic/.git/FETCH_HEAD expected && - write_script atomic/.git/hooks/reference-transaction <<-\EOF && + test_hook -C atomic reference-transaction <<-\EOF && exit 1 EOF @@ -343,35 +343,6 @@ test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' ' test_cmp expected atomic/.git/FETCH_HEAD ' -test_expect_success 'fetch --atomic --prune executes a single reference transaction only' ' - test_when_finished "rm -rf \"$D\"/atomic" && - - cd "$D" && - git branch scheduled-for-deletion && - git clone . atomic && - git branch -D scheduled-for-deletion && - git branch new-branch && - head_oid=$(git rev-parse HEAD) && - - # Fetching with the `--atomic` flag should update all references in a - # single transaction. - cat >expected <<-EOF && - prepared - $ZERO_OID $ZERO_OID refs/remotes/origin/scheduled-for-deletion - $ZERO_OID $head_oid refs/remotes/origin/new-branch - committed - $ZERO_OID $ZERO_OID refs/remotes/origin/scheduled-for-deletion - $ZERO_OID $head_oid refs/remotes/origin/new-branch - EOF - - write_script atomic/.git/hooks/reference-transaction <<-\EOF && - ( echo "$*" && cat ) >>actual - EOF - - git -C atomic fetch --atomic --prune origin && - test_cmp expected atomic/actual -' - test_expect_success '--refmap="" ignores configured refspec' ' cd "$TRASH_DIRECTORY" && git clone "$D" remote-refs && @@ -882,7 +853,11 @@ test_configured_prune_type () { then new_cmdline=$cmdline_setup else - new_cmdline=$(printf "%s" "$cmdline" | perl -pe 's[origin(?!/)]["'"$remote_url"'"]g') + new_cmdline=$(perl -e ' + my ($cmdline, $url) = @ARGV; + $cmdline =~ s[origin(?!/)][quotemeta($url)]ge; + print $cmdline; + ' -- "$cmdline" "$remote_url") fi if test "$fetch_prune_tags" = 'true' || diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index f53f588..20d063f 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -15,6 +15,10 @@ generate_references () { done } +test_expect_success 'dies when no remote found' ' + test_must_fail git ls-remote +' + test_expect_success setup ' >file && git add file && @@ -30,7 +34,8 @@ test_expect_success setup ' git show-ref -d >refs && sed -e "s/ / /" refs >>expected.all && - git remote add self "$(pwd)/.git" + git remote add self "$(pwd)/.git" && + git remote add self2 "." ' test_expect_success 'ls-remote --tags .git' ' @@ -83,11 +88,17 @@ test_expect_success 'ls-remote --sort="-refname" --tags self' ' test_cmp expect actual ' -test_expect_success 'dies when no remote specified and no default remotes found' ' +test_expect_success 'dies when no remote specified, multiple remotes found, and no default specified' ' test_must_fail git ls-remote ' -test_expect_success 'use "origin" when no remote specified' ' +test_expect_success 'succeeds when no remote specified but only one found' ' + test_when_finished git remote add self2 "." && + git remote remove self2 && + git ls-remote +' + +test_expect_success 'use "origin" when no remote specified and multiple found' ' URL="$(pwd)/.git" && echo "From $URL" >exp_err && diff --git a/t/t5513-fetch-track.sh b/t/t5513-fetch-track.sh index 65d1e05..c46c4db 100755 --- a/t/t5513-fetch-track.sh +++ b/t/t5513-fetch-track.sh @@ -2,6 +2,7 @@ test_description='fetch follows remote-tracking branches correctly' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5515-fetch-merge-logic.sh b/t/t5515-fetch-merge-logic.sh index 320d267..c100a80 100755 --- a/t/t5515-fetch-merge-logic.sh +++ b/t/t5515-fetch-merge-logic.sh @@ -14,6 +14,7 @@ export GIT_TEST_PROTOCOL_VERSION GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh build_script () { diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 3137eb8..f3356f9 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -12,25 +12,24 @@ This test checks the following functionality: * --porcelain output format * hiderefs * reflogs +* URL validation ' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh D=$(pwd) mk_empty () { repo_name="$1" - rm -fr "$repo_name" && - mkdir "$repo_name" && - ( - cd "$repo_name" && - git init && - git config receive.denyCurrentBranch warn && - mv .git/hooks .git/hooks-disabled - ) + test_when_finished "rm -rf \"$repo_name\"" && + test_path_is_missing "$repo_name" && + git init --template= "$repo_name" && + mkdir "$repo_name"/.git/hooks && + git -C "$repo_name" config receive.denyCurrentBranch warn } mk_test () { @@ -59,41 +58,29 @@ mk_test () { mk_test_with_hooks() { repo_name=$1 mk_test "$@" && - ( - cd "$repo_name" && - mkdir .git/hooks && - cd .git/hooks && - - cat >pre-receive <<-'EOF' && - #!/bin/sh - cat - >>pre-receive.actual - EOF - - cat >update <<-'EOF' && - #!/bin/sh - printf "%s %s %s\n" "$@" >>update.actual - EOF - - cat >post-receive <<-'EOF' && - #!/bin/sh - cat - >>post-receive.actual - EOF - - cat >post-update <<-'EOF' && - #!/bin/sh - for ref in "$@" - do - printf "%s\n" "$ref" >>post-update.actual - done - EOF - - chmod +x pre-receive update post-receive post-update - ) + test_hook -C "$repo_name" pre-receive <<-'EOF' && + cat - >>pre-receive.actual + EOF + + test_hook -C "$repo_name" update <<-'EOF' && + printf "%s %s %s\n" "$@" >>update.actual + EOF + + test_hook -C "$repo_name" post-receive <<-'EOF' && + cat - >>post-receive.actual + EOF + + test_hook -C "$repo_name" post-update <<-'EOF' + for ref in "$@" + do + printf "%s\n" "$ref" >>post-update.actual + done + EOF } mk_child() { - rm -rf "$2" && - git clone "$1" "$2" + test_when_finished "rm -rf \"$2\"" && + git clone --template= "$1" "$2" } check_push_result () { @@ -197,32 +184,32 @@ grep_wrote () { grep 'write_pack_file/wrote.*"value":"'$1'"' $2 } -test_expect_success 'push with negotiation' ' - # Without negotiation +test_expect_success 'push without negotiation' ' mk_empty testrepo && git push testrepo $the_first_commit:refs/remotes/origin/first_commit && test_commit -C testrepo unrelated_commit && git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && - echo now pushing without negotiation && + test_when_finished "rm event" && GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 push testrepo refs/heads/main:refs/remotes/origin/main && - grep_wrote 5 event && # 2 commits, 2 trees, 1 blob + grep_wrote 5 event # 2 commits, 2 trees, 1 blob +' - # Same commands, but with negotiation - rm event && +test_expect_success 'push with negotiation' ' mk_empty testrepo && git push testrepo $the_first_commit:refs/remotes/origin/first_commit && test_commit -C testrepo unrelated_commit && git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && + test_when_finished "rm event" && GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main && grep_wrote 2 event # 1 commit, 1 tree ' test_expect_success 'push with negotiation proceeds anyway even if negotiation fails' ' - rm event && mk_empty testrepo && git push testrepo $the_first_commit:refs/remotes/origin/first_commit && test_commit -C testrepo unrelated_commit && git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit && + test_when_finished "rm event" && GIT_TEST_PROTOCOL_VERSION=0 GIT_TRACE2_EVENT="$(pwd)/event" \ git -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err && grep_wrote 5 event && # 2 commits, 2 trees, 1 blob @@ -614,6 +601,26 @@ test_expect_success 'branch.*.pushremote config order is irrelevant' ' check_push_result two_repo $the_commit heads/main ' +test_expect_success 'push rejects empty branch name entries' ' + mk_test one_repo heads/main && + test_config remote.one.url one_repo && + test_config branch..remote one && + test_config branch..merge refs/heads/ && + test_config branch.main.remote one && + test_config branch.main.merge refs/heads/main && + test_must_fail git push 2>err && + grep "bad config variable .branch\.\." err +' + +test_expect_success 'push ignores "branch." config without subsection' ' + mk_test one_repo heads/main && + test_config remote.one.url one_repo && + test_config branch.autoSetupMerge true && + test_config branch.main.remote one && + test_config branch.main.merge refs/heads/main && + git push +' + test_expect_success 'push with dry-run' ' mk_test testrepo heads/main && @@ -668,7 +675,6 @@ test_expect_success 'push does not update local refs on failure' ' mk_test testrepo heads/main && mk_child testrepo child && - mkdir testrepo/.git/hooks && echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive && chmod +x testrepo/.git/hooks/pre-receive && ( @@ -933,6 +939,7 @@ test_expect_success 'fetch with branches' ' mk_empty testrepo && git branch second $the_first_commit && git checkout second && + mkdir testrepo/.git/branches && echo ".." > testrepo/.git/branches/branch1 && ( cd testrepo && @@ -946,6 +953,7 @@ test_expect_success 'fetch with branches' ' test_expect_success 'fetch with branches containing #' ' mk_empty testrepo && + mkdir testrepo/.git/branches && echo "..#second" > testrepo/.git/branches/branch2 && ( cd testrepo && @@ -960,7 +968,11 @@ test_expect_success 'fetch with branches containing #' ' test_expect_success 'push with branches' ' mk_empty testrepo && git checkout second && + + test_when_finished "rm -rf .git/branches" && + mkdir .git/branches && echo "testrepo" > .git/branches/branch1 && + git push branch1 && ( cd testrepo && @@ -972,7 +984,11 @@ test_expect_success 'push with branches' ' test_expect_success 'push with branches containing #' ' mk_empty testrepo && + + test_when_finished "rm -rf .git/branches" && + mkdir .git/branches && echo "testrepo#branch3" > .git/branches/branch2 && + git push branch2 && ( cd testrepo && @@ -1330,7 +1346,7 @@ done test_expect_success 'fetch follows tags by default' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && ( cd src && @@ -1340,6 +1356,7 @@ test_expect_success 'fetch follows tags by default' ' sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 | sort -k 3 >../expect ) && + test_when_finished "rm -rf dst" && git init dst && ( cd dst && @@ -1365,8 +1382,9 @@ test_expect_success 'peeled advertisements are not considered ref tips' ' test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1389,8 +1407,9 @@ test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' test_expect_success 'with no remote.$name.push, it is not used as refmap' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1411,8 +1430,9 @@ test_expect_success 'with no remote.$name.push, it is not used as refmap' ' test_expect_success 'with no remote.$name.push, upstream mapping is used' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1440,8 +1460,9 @@ test_expect_success 'with no remote.$name.push, upstream mapping is used' ' test_expect_success 'push does not follow tags by default' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1463,8 +1484,9 @@ test_expect_success 'push does not follow tags by default' ' test_expect_success 'push --follow-tags only pushes relevant tags' ' mk_test testrepo heads/main && - rm -fr src dst && + test_when_finished "rm -rf src" && git init src && + test_when_finished "rm -rf dst" && git init --bare dst && ( cd src && @@ -1502,9 +1524,9 @@ EOF ' test_expect_success 'pushing a tag pushes the tagged object' ' - rm -rf dst.git && blob=$(echo unreferenced | git hash-object -w --stdin) && git tag -m foo tag-of-blob $blob && + test_when_finished "rm -rf dst.git" && git init --bare dst.git && git push dst.git tag-of-blob && # the receiving index-pack should have noticed @@ -1515,7 +1537,7 @@ test_expect_success 'pushing a tag pushes the tagged object' ' ' test_expect_success 'push into bare respects core.logallrefupdates' ' - rm -rf dst.git && + test_when_finished "rm -rf dst.git" && git init --bare dst.git && git -C dst.git config core.logallrefupdates true && @@ -1533,7 +1555,7 @@ test_expect_success 'push into bare respects core.logallrefupdates' ' ' test_expect_success 'fetch into bare respects core.logallrefupdates' ' - rm -rf dst.git && + test_when_finished "rm -rf dst.git" && git init --bare dst.git && ( cd dst.git && @@ -1554,6 +1576,7 @@ test_expect_success 'fetch into bare respects core.logallrefupdates' ' ' test_expect_success 'receive.denyCurrentBranch = updateInstead' ' + mk_empty testrepo && git push testrepo main && ( cd testrepo && @@ -1656,7 +1679,7 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' ' ) && # (5) push into void - rm -fr void && + test_when_finished "rm -rf void" && git init void && ( cd void && @@ -1678,26 +1701,23 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' ' ' test_expect_success 'updateInstead with push-to-checkout hook' ' - rm -fr testrepo && + test_when_finished "rm -rf testrepo" && git init testrepo && - ( - cd testrepo && - git pull .. main && - git reset --hard HEAD^^ && - git tag initial && - git config receive.denyCurrentBranch updateInstead && - write_script .git/hooks/push-to-checkout <<-\EOF - echo >&2 updating from $(git rev-parse HEAD) - echo >&2 updating to "$1" - - git update-index -q --refresh && - git read-tree -u -m HEAD "$1" || { - status=$? - echo >&2 read-tree failed - exit $status - } - EOF - ) && + git -C testrepo pull .. main && + git -C testrepo reset --hard HEAD^^ && + git -C testrepo tag initial && + git -C testrepo config receive.denyCurrentBranch updateInstead && + test_hook -C testrepo push-to-checkout <<-\EOF && + echo >&2 updating from $(git rev-parse HEAD) + echo >&2 updating to "$1" + + git update-index -q --refresh && + git read-tree -u -m HEAD "$1" || { + status=$? + echo >&2 read-tree failed + exit $status + } + EOF # Try pushing into a pristine git push testrepo main && @@ -1740,35 +1760,32 @@ test_expect_success 'updateInstead with push-to-checkout hook' ' ) && # push into void - rm -fr void && + test_when_finished "rm -rf void" && git init void && - ( - cd void && - git config receive.denyCurrentBranch updateInstead && - write_script .git/hooks/push-to-checkout <<-\EOF - if git rev-parse --quiet --verify HEAD - then - has_head=yes - echo >&2 updating from $(git rev-parse HEAD) - else - has_head=no - echo >&2 pushing into void - fi - echo >&2 updating to "$1" - - git update-index -q --refresh && - case "$has_head" in - yes) - git read-tree -u -m HEAD "$1" ;; - no) - git read-tree -u -m "$1" ;; - esac || { - status=$? - echo >&2 read-tree failed - exit $status - } - EOF - ) && + git -C void config receive.denyCurrentBranch updateInstead && + test_hook -C void push-to-checkout <<-\EOF && + if git rev-parse --quiet --verify HEAD + then + has_head=yes + echo >&2 updating from $(git rev-parse HEAD) + else + has_head=no + echo >&2 pushing into void + fi + echo >&2 updating to "$1" + + git update-index -q --refresh && + case "$has_head" in + yes) + git read-tree -u -m HEAD "$1" ;; + no) + git read-tree -u -m "$1" ;; + esac || { + status=$? + echo >&2 read-tree failed + exit $status + } + EOF git push void main && ( @@ -1829,4 +1846,57 @@ test_expect_success 'refuse to push a hidden ref, and make sure do not pollute t test_dir_is_empty testrepo/.git/objects/pack ' +test_expect_success LIBCURL 'fetch warns or fails when using username:password' ' + message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" && + test_must_fail git -c transfer.credentialsInUrl=allow fetch https://username:password@localhost 2>err && + ! grep "$message" err && + + test_must_fail git -c transfer.credentialsInUrl=warn fetch https://username:password@localhost 2>err && + grep "warning: $message" err >warnings && + test_line_count = 3 warnings && + + test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:password@localhost 2>err && + grep "fatal: $message" err >warnings && + test_line_count = 1 warnings && + + test_must_fail git -c transfer.credentialsInUrl=die fetch https://username:@localhost 2>err && + grep "fatal: $message" err >warnings && + test_line_count = 1 warnings +' + + +test_expect_success LIBCURL 'push warns or fails when using username:password' ' + message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" && + test_must_fail git -c transfer.credentialsInUrl=allow push https://username:password@localhost 2>err && + ! grep "$message" err && + + test_must_fail git -c transfer.credentialsInUrl=warn push https://username:password@localhost 2>err && + grep "warning: $message" err >warnings && + test_must_fail git -c transfer.credentialsInUrl=die push https://username:password@localhost 2>err && + grep "fatal: $message" err >warnings && + test_line_count = 1 warnings +' + +test_expect_success 'push with config push.useBitmaps' ' + mk_test testrepo heads/main && + git checkout main && + test_unconfig push.useBitmaps && + GIT_TRACE2_EVENT="$PWD/default" \ + git push testrepo main:test && + test_subcommand git pack-objects --all-progress-implied --revs --stdout \ + --thin --delta-base-offset -q <default && + + test_config push.useBitmaps true && + GIT_TRACE2_EVENT="$PWD/true" \ + git push testrepo main:test2 && + test_subcommand git pack-objects --all-progress-implied --revs --stdout \ + --thin --delta-base-offset -q <true && + + test_config push.useBitmaps false && + GIT_TRACE2_EVENT="$PWD/false" \ + git push testrepo main:test3 && + test_subcommand git pack-objects --all-progress-implied --revs --stdout \ + --thin --delta-base-offset -q --no-use-bitmap-index <false +' + test_done diff --git a/t/t5518-fetch-exit-status.sh b/t/t5518-fetch-exit-status.sh index 5c4ac25..c131200 100755 --- a/t/t5518-fetch-exit-status.sh +++ b/t/t5518-fetch-exit-status.sh @@ -8,6 +8,7 @@ test_description='fetch exit status test' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh index 66cfcb0..264de29 100755 --- a/t/t5521-pull-options.sh +++ b/t/t5521-pull-options.sh @@ -233,7 +233,7 @@ test_expect_success 'git pull --no-verify flag passed to merge' ' git init src && test_commit -C src one && git clone src dst && - write_script dst/.git/hooks/commit-msg <<-\EOF && + test_hook -C dst commit-msg <<-\EOF && false EOF test_commit -C src two && @@ -245,7 +245,7 @@ test_expect_success 'git pull --no-verify --verify passed to merge' ' git init src && test_commit -C src one && git clone src dst && - write_script dst/.git/hooks/commit-msg <<-\EOF && + test_hook -C dst commit-msg <<-\EOF && false EOF test_commit -C src two && diff --git a/t/t5524-pull-msg.sh b/t/t5524-pull-msg.sh index b2be360..56716e2 100755 --- a/t/t5524-pull-msg.sh +++ b/t/t5524-pull-msg.sh @@ -2,6 +2,7 @@ test_description='git pull message generation' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh dollar='$Dollar' diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index 43dada8..a301b56 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -1125,4 +1125,31 @@ test_expect_success 'fetch --recurse-submodules updates name-conflicted, unpopul ) ' +test_expect_success 'fetch --all with --recurse-submodules' ' + test_when_finished "rm -fr src_clone" && + git clone --recurse-submodules src src_clone && + ( + cd src_clone && + git config submodule.recurse true && + git config fetch.parallel 0 && + git fetch --all 2>../fetch-log + ) && + grep "^Fetching submodule sub$" fetch-log >fetch-subs && + test_line_count = 1 fetch-subs +' + +test_expect_success 'fetch --all with --recurse-submodules with multiple' ' + test_when_finished "rm -fr src_clone" && + git clone --recurse-submodules src src_clone && + ( + cd src_clone && + git remote add secondary ../src && + git config submodule.recurse true && + git config fetch.parallel 0 && + git fetch --all 2>../fetch-log + ) && + grep "Fetching submodule sub" fetch-log >fetch-subs && + test_line_count = 2 fetch-subs +' + test_done diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh index f280e00..284e20f 100755 --- a/t/t5528-push-default.sh +++ b/t/t5528-push-default.sh @@ -94,13 +94,88 @@ test_expect_success '"upstream" does not push when remotes do not match' ' test_must_fail git push parent2 ' -test_expect_success 'push from/to new branch with upstream, matching and simple' ' +test_expect_success '"current" does not push when multiple remotes and none origin' ' + git checkout main && + test_config push.default current && + test_commit current-multi && + test_must_fail git push +' + +test_expect_success '"current" pushes when remote explicitly specified' ' + git checkout main && + test_config push.default current && + test_commit current-specified && + git push parent1 +' + +test_expect_success '"current" pushes to origin when no remote specified among multiple' ' + git checkout main && + test_config remote.origin.url repo1 && + test_config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && + test_commit current-origin && + test_push_success current main +' + +test_expect_success '"current" pushes to single remote even when not specified' ' + git checkout main && + test_when_finished git remote add parent1 repo1 && + git remote remove parent1 && + test_commit current-implied && + test_push_success current main repo2 +' + +test_expect_success 'push from/to new branch with non-defaulted remote fails with upstream, matching, current and simple ' ' git checkout -b new-branch && test_push_failure simple && test_push_failure matching && + test_push_failure upstream && + test_push_failure current +' + +test_expect_success 'push from/to new branch fails with upstream and simple ' ' + git checkout -b new-branch-1 && + test_config branch.new-branch-1.remote parent1 && + test_push_failure simple && test_push_failure upstream ' +# The behavior here is surprising but not entirely wrong: +# - the current branch is used to determine the target remote +# - the "matching" push default pushes matching branches, *ignoring* the +# current new branch as it does not have upstream tracking +# - the default push succeeds +# +# A previous test expected this to fail, but for the wrong reasons: +# it expected a fail becaause the branch is new and cannot be pushed, but +# in fact it was failing because of an ambiguous remote +# +test_expect_failure 'push from/to new branch fails with matching ' ' + git checkout -b new-branch-2 && + test_config branch.new-branch-2.remote parent1 && + test_push_failure matching +' + +test_expect_success 'push from/to branch with tracking fails with nothing ' ' + git checkout -b tracked-branch && + test_config branch.tracked-branch.remote parent1 && + test_config branch.tracked-branch.merge refs/heads/tracked-branch && + test_push_failure nothing +' + +test_expect_success 'push from/to new branch succeeds with upstream if push.autoSetupRemote' ' + git checkout -b new-branch-a && + test_config push.autoSetupRemote true && + test_config branch.new-branch-a.remote parent1 && + test_push_success upstream new-branch-a +' + +test_expect_success 'push from/to new branch succeeds with simple if push.autoSetupRemote' ' + git checkout -b new-branch-c && + test_config push.autoSetupRemote true && + test_config branch.new-branch-c.remote parent1 && + test_push_success simple new-branch-c +' + test_expect_success '"matching" fails if none match' ' git init --bare empty && test_must_fail git push empty : 2>actual && diff --git a/t/t5532-fetch-proxy.sh b/t/t5532-fetch-proxy.sh index 9c27986..d664912 100755 --- a/t/t5532-fetch-proxy.sh +++ b/t/t5532-fetch-proxy.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='fetching via git:// using core.gitproxy' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup remote repo' ' diff --git a/t/t5534-push-signed.sh b/t/t5534-push-signed.sh index 24d374a..7c0a148 100755 --- a/t/t5534-push-signed.sh +++ b/t/t5534-push-signed.sh @@ -35,8 +35,7 @@ test_expect_success setup ' test_expect_success 'unsigned push does not send push certificate' ' prepare_dst && - mkdir -p dst/.git/hooks && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -52,8 +51,7 @@ test_expect_success 'unsigned push does not send push certificate' ' test_expect_success 'talking with a receiver without push certificate support' ' prepare_dst && - mkdir -p dst/.git/hooks && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -69,22 +67,19 @@ test_expect_success 'talking with a receiver without push certificate support' ' test_expect_success 'push --signed fails with a receiver without push certificate support' ' prepare_dst && - mkdir -p dst/.git/hooks && test_must_fail git push --signed dst noop ff +noff 2>err && test_i18ngrep "the receiving end does not support" err ' test_expect_success 'push --signed=1 is accepted' ' prepare_dst && - mkdir -p dst/.git/hooks && test_must_fail git push --signed=1 dst noop ff +noff 2>err && test_i18ngrep "the receiving end does not support" err ' test_expect_success GPG 'no certificate for a signed push with no update' ' prepare_dst && - mkdir -p dst/.git/hooks && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && if test -n "${GIT_PUSH_CERT-}" then git cat-file blob $GIT_PUSH_CERT >../push-cert @@ -96,9 +91,8 @@ test_expect_success GPG 'no certificate for a signed push with no update' ' test_expect_success GPG 'signed push sends push certificate' ' prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -139,10 +133,9 @@ test_expect_success GPG 'signed push sends push certificate' ' test_expect_success GPGSSH 'ssh signed push sends push certificate' ' prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -223,9 +216,8 @@ test_expect_success GPG 'inconsistent push options in signed push not allowed' ' test_expect_success GPG 'fail without key and heed user.signingkey' ' prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -273,9 +265,8 @@ test_expect_success GPG 'fail without key and heed user.signingkey' ' test_expect_success GPGSM 'fail without key and heed user.signingkey x509' ' test_config gpg.format x509 && prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -326,10 +317,9 @@ test_expect_success GPGSM 'fail without key and heed user.signingkey x509' ' test_expect_success GPGSSH 'fail without key and heed user.signingkey ssh' ' test_config gpg.format ssh && prepare_dst && - mkdir -p dst/.git/hooks && git -C dst config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && git -C dst config receive.certnonceseed sekrit && - write_script dst/.git/hooks/post-receive <<-\EOF && + test_hook -C dst post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh index 11d5ea5..10e9a7f 100755 --- a/t/t5537-fetch-shallow.sh +++ b/t/t5537-fetch-shallow.sh @@ -161,6 +161,27 @@ test_expect_success 'fetch --update-shallow' ' ) ' +test_expect_success 'fetch --update-shallow into a repo with submodules' ' + git init a-submodule && + test_commit -C a-submodule foo && + + test_when_finished "rm -rf repo-with-sub" && + git init repo-with-sub && + git -C repo-with-sub submodule add ../a-submodule a-submodule && + git -C repo-with-sub commit -m "added submodule" && + git -C repo-with-sub fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* +' + +test_expect_success 'fetch --update-shallow a commit that is also a shallow point into a repo with submodules' ' + test_when_finished "rm -rf repo-with-sub" && + git init repo-with-sub && + git -C repo-with-sub submodule add ../a-submodule a-submodule && + git -C repo-with-sub commit -m "added submodule" && + + SHALLOW=$(cat shallow/.git/shallow) && + git -C repo-with-sub fetch --update-shallow ../shallow/.git "$SHALLOW":refs/heads/a-shallow +' + test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' ' ( cd shallow && diff --git a/t/t5540-http-push-webdav.sh b/t/t5540-http-push-webdav.sh index b0dbacf..37db3de 100755 --- a/t/t5540-http-push-webdav.sh +++ b/t/t5540-http-push-webdav.sh @@ -42,7 +42,9 @@ test_expect_success 'setup remote repository' ' git clone --bare test_repo test_repo.git && cd test_repo.git && git --bare update-server-info && - mv hooks/post-update.sample hooks/post-update && + test_hook --setup post-update <<-\EOF && + exec git update-server-info + EOF ORIG_HEAD=$(git rev-parse --verify HEAD) && cd - && mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index 8ca50f8..fbad2d5 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -80,6 +80,25 @@ test_expect_success 'push to remote repository (standard)' ' test $HEAD = $(git rev-parse --verify HEAD)) ' +test_expect_success 'push to remote repository (standard) with sending Accept-Language' ' + cat >exp <<-\EOF && + => Send header: Accept-Language: ko-KR, *;q=0.9 + => Send header: Accept-Language: ko-KR, *;q=0.9 + EOF + + cd "$ROOT_PATH"/test_repo_clone && + : >path_lang && + git add path_lang && + test_tick && + git commit -m path_lang && + HEAD=$(git rev-parse --verify HEAD) && + GIT_TRACE_CURL=true LANGUAGE="ko_KR.UTF-8" git push -v -v 2>err && + ! grep "Expect: 100-continue" err && + + grep "=> Send header: Accept-Language:" err >err.language && + test_cmp exp err.language +' + test_expect_success 'push already up-to-date' ' git push ' @@ -96,18 +115,18 @@ test_expect_success 'create and delete remote branch' ' test_must_fail git show-ref --verify refs/remotes/origin/dev ' -cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF -#!/bin/sh -exit 1 -EOF -chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" +test_expect_success 'setup rejected update hook' ' + test_hook --setup -C "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" update <<-\EOF && + exit 1 + EOF -cat >exp <<EOF -remote: error: hook declined to update refs/heads/dev2 -To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git - ! [remote rejected] dev2 -> dev2 (hook declined) -error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git' -EOF + cat >exp <<-EOF + remote: error: hook declined to update refs/heads/dev2 + To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git + ! [remote rejected] dev2 -> dev2 (hook declined) + error: failed to push some refs to '\''http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'\'' + EOF +' test_expect_success 'rejected update prints status' ' cd "$ROOT_PATH"/test_repo_clone && @@ -419,10 +438,7 @@ test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' ' ' test_expect_success GPG 'push with post-receive to inspect certificate' ' - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && - mkdir -p hooks && - write_script hooks/post-receive <<-\EOF && + test_hook -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git post-receive <<-\EOF && # discard the update list cat >/dev/null # record the push certificate @@ -437,8 +453,9 @@ test_expect_success GPG 'push with post-receive to inspect certificate' ' NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus} NONCE=${GIT_PUSH_CERT_NONCE-nononce} E_O_F - EOF - + EOF + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && git config receive.certnonceseed sekrit && git config receive.certnonceslop 30 ) && diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh index bfee461..7043112 100755 --- a/t/t5543-atomic-push.sh +++ b/t/t5543-atomic-push.sh @@ -162,16 +162,10 @@ test_expect_success 'atomic push obeys update hook preventing a branch to be pus test_commit two && git push --mirror up ) && - ( - cd upstream && - HOOKDIR="$(git rev-parse --git-dir)/hooks" && - HOOK="$HOOKDIR/update" && - mkdir -p "$HOOKDIR" && - write_script "$HOOK" <<-\EOF - # only allow update to main from now on - test "$1" = "refs/heads/main" - EOF - ) && + test_hook -C upstream update <<-\EOF && + # only allow update to main from now on + test "$1" = "refs/heads/main" + EOF ( cd workbench && git checkout main && diff --git a/t/t5544-pack-objects-hook.sh b/t/t5544-pack-objects-hook.sh index dd5f44d..54f54f8 100755 --- a/t/t5544-pack-objects-hook.sh +++ b/t/t5544-pack-objects-hook.sh @@ -56,7 +56,12 @@ test_expect_success 'hook does not run from repo config' ' ! grep "hook running" stderr && test_path_is_missing .git/hook.args && test_path_is_missing .git/hook.stdin && - test_path_is_missing .git/hook.stdout + test_path_is_missing .git/hook.stdout && + + # check that global config is used instead + test_config_global uploadpack.packObjectsHook ./hook && + git clone --no-local . dst2.git 2>stderr && + grep "hook running" stderr ' test_expect_success 'hook works with partial clone' ' diff --git a/t/t5547-push-quarantine.sh b/t/t5547-push-quarantine.sh index faaa51c..1876fb3 100755 --- a/t/t5547-push-quarantine.sh +++ b/t/t5547-push-quarantine.sh @@ -5,7 +5,7 @@ test_description='check quarantine of objects during push' test_expect_success 'create picky dest repo' ' git init --bare dest.git && - write_script dest.git/hooks/pre-receive <<-\EOF + test_hook --setup -C dest.git pre-receive <<-\EOF while read old new ref; do test "$(git log -1 --format=%s $new)" = reject && exit 1 done @@ -60,7 +60,7 @@ test_expect_success 'push to repo path with path separator (colon)' ' test_expect_success 'updating a ref from quarantine is forbidden' ' git init --bare update.git && - write_script update.git/hooks/pre-receive <<-\EOF && + test_hook -C update.git pre-receive <<-\EOF && read old new refname git update-ref refs/heads/unrelated $new exit 1 diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh index f11ff57..6282728 100755 --- a/t/t5548-push-porcelain.sh +++ b/t/t5548-push-porcelain.sh @@ -168,7 +168,7 @@ run_git_push_porcelain_output_test() { ' test_expect_success "prepare pre-receive hook ($PROTOCOL)" ' - write_script "$upstream/hooks/pre-receive" <<-EOF + test_hook --setup -C "$upstream" pre-receive <<-EOF exit 1 EOF ' diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index 2592039..d7cf85f 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -25,16 +25,17 @@ test_expect_success 'setup repository' ' git commit -m two ' +setup_post_update_server_info_hook () { + test_hook --setup -C "$1" post-update <<-\EOF && + exec git update-server-info + EOF + git -C "$1" update-server-info +} + test_expect_success 'create http-accessible bare repository with loose objects' ' cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git config core.bare true && - mkdir -p hooks && - write_script "hooks/post-update" <<-\EOF && - exec git update-server-info - EOF - hooks/post-update - ) && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config core.bare true && + setup_post_update_server_info_hook "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && git push public main:main ' @@ -62,13 +63,7 @@ test_expect_success 'create password-protected repository' ' test_expect_success 'create empty remote repository' ' git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && - (cd "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && - mkdir -p hooks && - write_script "hooks/post-update" <<-\EOF && - exec git update-server-info - EOF - hooks/post-update - ) + setup_post_update_server_info_hook "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" ' test_expect_success 'empty dumb HTTP repository has default hash algorithm' ' @@ -374,7 +369,7 @@ ja;q=0.95, zh;q=0.94, sv;q=0.93, pt;q=0.92, nb;q=0.91, *;q=0.90" \ ko_KR.EUC-KR:en_US.UTF-8:fr_CA:de.UTF-8@euro:sr@latin:ja:zh:sv:pt:nb ' -test_expect_success 'git client does not send an empty Accept-Language' ' +test_expect_success 'git client send an empty Accept-Language' ' GIT_TRACE_CURL=true LANGUAGE= git ls-remote "$HTTPD_URL/dumb/repo.git" 2>stderr && ! grep "^=> Send header: Accept-Language:" stderr ' @@ -427,7 +422,8 @@ test_expect_success 'set up evil alternates scheme' ' sha1=$(git -C "$victim" rev-parse HEAD) && evil=$HTTPD_DOCUMENT_ROOT_PATH/evil.git && - git init --bare "$evil" && + git init --template= --bare "$evil" && + mkdir "$evil/info" && # do this by hand to avoid object existence check printf "%s\\t%s\\n" $sha1 refs/heads/main >"$evil/info/refs" ' diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index f92c79c..245532d 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -31,6 +31,7 @@ test_expect_success 'clone http repository' ' > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 > Accept: */* > Accept-Encoding: ENCODINGS + > Accept-Language: ko-KR, *;q=0.9 > Pragma: no-cache < HTTP/1.1 200 OK < Pragma: no-cache @@ -40,13 +41,15 @@ test_expect_success 'clone http repository' ' > Accept-Encoding: ENCODINGS > Content-Type: application/x-git-upload-pack-request > Accept: application/x-git-upload-pack-result + > Accept-Language: ko-KR, *;q=0.9 > Content-Length: xxx < HTTP/1.1 200 OK < Pragma: no-cache < Cache-Control: no-cache, max-age=0, must-revalidate < Content-Type: application/x-git-upload-pack-result EOF - GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 \ + + GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \ git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err && test_cmp file clone/file && tr '\''\015'\'' Q <err | @@ -94,7 +97,10 @@ test_expect_success 'clone http repository' ' test_cmp exp actual.smudged && grep "Accept-Encoding:.*gzip" actual >actual.gzip && - test_line_count = 2 actual.gzip + test_line_count = 2 actual.gzip && + + grep "Accept-Language: ko-KR, *" actual >actual.language && + test_line_count = 2 actual.language fi ' @@ -567,4 +573,11 @@ test_expect_success 'client falls back from v2 to v0 to match server' ' grep symref=HEAD:refs/heads/ trace ' +test_expect_success 'passing hostname resolution information works' ' + BOGUS_HOST=gitbogusexamplehost.invalid && + BOGUS_HTTPD_URL=$HTTPD_PROTO://$BOGUS_HOST:$LIB_HTTPD_PORT && + test_must_fail git ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null && + git -c "http.curloptResolve=$BOGUS_HOST:$LIB_HTTPD_PORT:127.0.0.1" ls-remote "$BOGUS_HTTPD_URL/smart/repo.git" >/dev/null +' + test_done diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh index 96d6ecc..a11b20e 100755 --- a/t/t5571-pre-push-hook.sh +++ b/t/t5571-pre-push-hook.sh @@ -6,16 +6,11 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -# Setup hook that always succeeds -HOOKDIR="$(git rev-parse --git-dir)/hooks" -HOOK="$HOOKDIR/pre-push" -mkdir -p "$HOOKDIR" -write_script "$HOOK" <<EOF -cat >actual -exit 0 -EOF - test_expect_success 'setup' ' + test_hook pre-push <<-\EOF && + cat >actual + EOF + git config push.default upstream && git init --bare repo1 && git remote add parent1 repo1 && @@ -28,15 +23,16 @@ test_expect_success 'setup' ' git push parent1 HEAD:foreign && test_cmp expect actual ' -write_script "$HOOK" <<EOF -cat >actual -exit 1 -EOF COMMIT1="$(git rev-parse HEAD)" export COMMIT1 test_expect_success 'push with failing hook' ' + test_hook pre-push <<-\EOF && + cat >actual && + exit 1 + EOF + test_commit two && cat >expect <<-EOF && HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero) @@ -55,13 +51,13 @@ test_expect_success '--no-verify bypasses hook' ' COMMIT2="$(git rev-parse HEAD)" export COMMIT2 -write_script "$HOOK" <<'EOF' -echo "$1" >actual -echo "$2" >>actual -cat >>actual -EOF - test_expect_success 'push with hook' ' + test_hook --setup pre-push <<-\EOF && + echo "$1" >actual + echo "$2" >>actual + cat >>actual + EOF + cat >expect <<-EOF && parent1 repo1 @@ -136,7 +132,9 @@ test_expect_success 'set up many-ref tests' ' ' test_expect_success 'sigpipe does not cause pre-push hook failure' ' - echo "exit 0" | write_script "$HOOK" && + test_hook --clobber pre-push <<-\EOF && + exit 0 + EOF git push parent1 "refs/heads/b/*:refs/heads/b/*" ' diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index fa6b4cc..a35396f 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -107,6 +107,32 @@ test_expect_success " --[no-]recurse-submodule and submodule.recurse" ' test_path_is_file super/sub/merge_strategy_4.t ' +test_expect_success "fetch.recurseSubmodules option triggers recursive fetch (but not recursive update)" ' + test_commit -C child merge_strategy_5 && + # Omit the parent commit, otherwise this passes with the + # default "pull" behavior. + + git -C super -c fetch.recursesubmodules=true pull --no-rebase && + # Check that the submodule commit was fetched + sub_oid=$(git -C child rev-parse HEAD) && + git -C super/sub cat-file -e $sub_oid && + # Check that the submodule worktree did not update + ! test_path_is_file super/sub/merge_strategy_5.t +' + +test_expect_success "fetch.recurseSubmodules takes precedence over submodule.recurse" ' + test_commit -C child merge_strategy_6 && + # Omit the parent commit, otherwise this passes with the + # default "pull" behavior. + + git -C super -c submodule.recurse=false -c fetch.recursesubmodules=true pull --no-rebase && + # Check that the submodule commit was fetched + sub_oid=$(git -C child rev-parse HEAD) && + git -C super/sub cat-file -e $sub_oid && + # Check that the submodule worktree did not update + ! test_path_is_file super/sub/merge_strategy_6.t +' + test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' ' # This tests the following scenario : # - local submodule has new commits diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 34b3df4..c814afa 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -13,6 +13,7 @@ Unless the directory already exists, in which case we clean up only what we wrote. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh corrupt_repo () { diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 83c24fc..cf3be05 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -71,6 +71,29 @@ test_expect_success 'clone respects GIT_WORK_TREE' ' ' +test_expect_success LIBCURL 'clone warns or fails when using username:password' ' + message="URL '\''https://username:<redacted>@localhost/'\'' uses plaintext credentials" && + test_must_fail git -c transfer.credentialsInUrl=allow clone https://username:password@localhost attempt1 2>err && + ! grep "$message" err && + + test_must_fail git -c transfer.credentialsInUrl=warn clone https://username:password@localhost attempt2 2>err && + grep "warning: $message" err >warnings && + test_line_count = 2 warnings && + + test_must_fail git -c transfer.credentialsInUrl=die clone https://username:password@localhost attempt3 2>err && + grep "fatal: $message" err >warnings && + test_line_count = 1 warnings && + + test_must_fail git -c transfer.credentialsInUrl=die clone https://username:@localhost attempt3 2>err && + grep "fatal: $message" err >warnings && + test_line_count = 1 warnings +' + +test_expect_success LIBCURL 'clone does not detect username:password when it is https://username@domain:port/' ' + test_must_fail git -c transfer.credentialsInUrl=warn clone https://username@localhost:8080 attempt3 2>err && + ! grep "uses plaintext credentials" err +' + test_expect_success 'clone from hooks' ' test_create_repo r0 && @@ -79,12 +102,10 @@ test_expect_success 'clone from hooks' ' cd .. && git init r1 && cd r1 && - cat >.git/hooks/pre-commit <<-\EOF && - #!/bin/sh + test_hook pre-commit <<-\EOF && git clone ../r0 ../r2 exit 1 EOF - chmod u+x .git/hooks/pre-commit && : >file && git add file && test_must_fail git commit -m invoke-hook && diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh index 7d63365..38b850c 100755 --- a/t/t5605-clone-local.sh +++ b/t/t5605-clone-local.sh @@ -21,7 +21,9 @@ test_expect_success 'preparing origin repository' ' git bundle create b2.bundle main && mkdir dir && cp b1.bundle dir/b3 && - cp b1.bundle b4 + cp b1.bundle b4 && + git branch not-main main && + git bundle create b5.bundle not-main ' test_expect_success 'local clone without .git suffix' ' @@ -83,11 +85,19 @@ test_expect_success 'bundle clone from b4.bundle that does not exist' ' test_must_fail git clone b4.bundle bb ' -test_expect_success 'bundle clone with nonexistent HEAD' ' +test_expect_success 'bundle clone with nonexistent HEAD (match default)' ' git clone b2.bundle b2 && (cd b2 && git fetch && - test_must_fail git rev-parse --verify refs/heads/main) + git rev-parse --verify refs/heads/main) +' + +test_expect_success 'bundle clone with nonexistent HEAD (no match default)' ' + git clone b5.bundle b5 && + (cd b5 && + git fetch && + test_must_fail git rev-parse --verify refs/heads/main && + test_must_fail git rev-parse --verify refs/heads/not-main) ' test_expect_success 'clone empty repository' ' @@ -141,4 +151,13 @@ test_expect_success 'cloning locally respects "-u" for fetching refs' ' test_must_fail git clone --bare -u false a should_not_work.git ' +test_expect_success 'local clone from repo with corrupt refs fails gracefully' ' + git init corrupt && + test_commit -C corrupt one && + echo a >corrupt/.git/refs/heads/topic && + + test_must_fail git clone corrupt working 2>err && + grep "has a null OID" err +' + test_done diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 34469b6..4a3778d 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -166,6 +166,85 @@ test_expect_success 'manual prefetch of missing objects' ' test_line_count = 0 observed.oids ' +# create new commits in "src" repo to establish a history on file.4.txt +# and push to "srv.bare". +test_expect_success 'push new commits to server for file.4.txt' ' + for x in a b c d e f + do + echo "Mod file.4.txt $x" >src/file.4.txt && + if list_contains "a,b" "$x"; then + printf "%10000s" X >>src/file.4.txt + fi && + if list_contains "c,d" "$x"; then + printf "%20000s" X >>src/file.4.txt + fi && + git -C src add file.4.txt && + git -C src commit -m "mod $x" || return 1 + done && + git -C src push -u srv main +' + +# Do partial fetch to fetch smaller files; then verify that without --refetch +# applying a new filter does not refetch missing large objects. Then use +# --refetch to apply the new filter on existing commits. Test it under both +# protocol v2 & v0. +test_expect_success 'apply a different filter using --refetch' ' + git -C pc1 fetch --filter=blob:limit=999 origin && + git -C pc1 rev-list --quiet --objects --missing=print \ + main..origin/main >observed && + test_line_count = 4 observed && + + git -C pc1 fetch --filter=blob:limit=19999 --refetch origin && + git -C pc1 rev-list --quiet --objects --missing=print \ + main..origin/main >observed && + test_line_count = 2 observed && + + git -c protocol.version=0 -C pc1 fetch --filter=blob:limit=29999 \ + --refetch origin && + git -C pc1 rev-list --quiet --objects --missing=print \ + main..origin/main >observed && + test_line_count = 0 observed +' + +test_expect_success 'fetch --refetch works with a shallow clone' ' + git clone --no-checkout --depth=1 --filter=blob:none "file://$(pwd)/srv.bare" pc1s && + git -C pc1s rev-list --objects --missing=print HEAD >observed && + test_line_count = 6 observed && + + GIT_TRACE=1 git -C pc1s fetch --filter=blob:limit=999 --refetch origin && + git -C pc1s rev-list --objects --missing=print HEAD >observed && + test_line_count = 6 observed +' + +test_expect_success 'fetch --refetch triggers repacking' ' + GIT_TRACE2_CONFIG_PARAMS=gc.autoPackLimit,maintenance.incremental-repack.auto && + export GIT_TRACE2_CONFIG_PARAMS && + + GIT_TRACE2_EVENT="$PWD/trace1.event" \ + git -C pc1 fetch --refetch origin && + test_subcommand git maintenance run --auto --no-quiet <trace1.event && + grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace1.event && + grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace1.event && + + GIT_TRACE2_EVENT="$PWD/trace2.event" \ + git -c protocol.version=0 \ + -c gc.autoPackLimit=0 \ + -c maintenance.incremental-repack.auto=1234 \ + -C pc1 fetch --refetch origin && + test_subcommand git maintenance run --auto --no-quiet <trace2.event && + grep \"param\":\"gc.autopacklimit\",\"value\":\"0\" trace2.event && + grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace2.event && + + GIT_TRACE2_EVENT="$PWD/trace3.event" \ + git -c protocol.version=0 \ + -c gc.autoPackLimit=1234 \ + -c maintenance.incremental-repack.auto=0 \ + -C pc1 fetch --refetch origin && + test_subcommand git maintenance run --auto --no-quiet <trace3.event && + grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace3.event && + grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"0\" trace3.event +' + test_expect_success 'partial clone with transfer.fsckobjects=1 works with submodules' ' test_create_repo submodule && test_commit -C submodule mycommit && @@ -225,7 +304,7 @@ test_expect_success 'use fsck before and after manually fetching a missing subtr # Auto-fetch all remaining trees and blobs with --missing=error git -C dst rev-list --missing=error --objects main >fetched_objects && - test_line_count = 70 fetched_objects && + test_line_count = 88 fetched_objects && awk -f print_1.awk fetched_objects | xargs -n1 git -C dst cat-file -t >fetched_types && diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 00ce9ae..5d42a35 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -250,6 +250,65 @@ test_expect_success 'bare clone propagates empty default branch' ' grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD ' +test_expect_success 'clone propagates unborn HEAD from non-empty repo' ' + test_when_finished "rm -rf file_unborn_parent file_unborn_child" && + + git init file_unborn_parent && + ( + cd file_unborn_parent && + git checkout -b branchwithstuff && + test_commit --no-tag stuff && + git symbolic-ref HEAD refs/heads/mydefaultbranch + ) && + + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ + git -c init.defaultBranch=main -c protocol.version=2 \ + clone "file://$(pwd)/file_unborn_parent" \ + file_unborn_child 2>stderr && + grep "refs/heads/mydefaultbranch" file_unborn_child/.git/HEAD && + grep "warning: remote HEAD refers to nonexistent ref" stderr +' + +test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' ' + test_when_finished "rm -rf file_unborn_parent file_unborn_child.git" && + + git init file_unborn_parent && + ( + cd file_unborn_parent && + git checkout -b branchwithstuff && + test_commit --no-tag stuff && + git symbolic-ref HEAD refs/heads/mydefaultbranch + ) && + + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ + git -c init.defaultBranch=main -c protocol.version=2 \ + clone --bare "file://$(pwd)/file_unborn_parent" \ + file_unborn_child.git 2>stderr && + grep "refs/heads/mydefaultbranch" file_unborn_child.git/HEAD && + ! grep "warning:" stderr +' + +test_expect_success 'defaulted HEAD uses remote branch if available' ' + test_when_finished "rm -rf file_unborn_parent file_unborn_child" && + + git init file_unborn_parent && + ( + cd file_unborn_parent && + git config lsrefs.unborn ignore && + git checkout -b branchwithstuff && + test_commit --no-tag stuff && + git symbolic-ref HEAD refs/heads/mydefaultbranch + ) && + + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ + git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \ + clone "file://$(pwd)/file_unborn_parent" \ + file_unborn_child 2>stderr && + grep "refs/heads/branchwithstuff" file_unborn_child/.git/HEAD && + test_path_is_file file_unborn_child/stuff.t && + ! grep "warning:" stderr +' + test_expect_success 'fetch with file:// using protocol v2' ' test_when_finished "rm -f log" && diff --git a/t/t5812-proto-disable-http.sh b/t/t5812-proto-disable-http.sh index af8772f..d8da5f5 100755 --- a/t/t5812-proto-disable-http.sh +++ b/t/t5812-proto-disable-http.sh @@ -16,7 +16,7 @@ test_expect_success 'create git-accessible repo' ' test_proto "smart http" http "$HTTPD_URL/smart/repo.git" -test_expect_success 'curl redirects respect whitelist' ' +test_expect_success 'http(s) transport respects GIT_ALLOW_PROTOCOL' ' test_must_fail env GIT_ALLOW_PROTOCOL=http:https \ GIT_SMART_HTTP=0 \ git clone "$HTTPD_URL/ftp-redir/repo.git" 2>stderr && diff --git a/t/t5815-submodule-protos.sh b/t/t5815-submodule-protos.sh index 06f55a1..4d5956c 100755 --- a/t/t5815-submodule-protos.sh +++ b/t/t5815-submodule-protos.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='test protocol whitelisting with submodules' +test_description='test protocol filtering with submodules' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-proto-disable.sh @@ -36,7 +36,7 @@ test_expect_success 'update of ext not allowed' ' test_must_fail git -C dst submodule update ext-module ' -test_expect_success 'user can override whitelist' ' +test_expect_success 'user can filter protocols with GIT_ALLOW_PROTOCOL' ' GIT_ALLOW_PROTOCOL=ext git -C dst submodule update ext-module ' diff --git a/t/t5900-repo-selection.sh b/t/t5900-repo-selection.sh index 14e59c5..a84faac 100755 --- a/t/t5900-repo-selection.sh +++ b/t/t5900-repo-selection.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='selecting remote repo in ambiguous cases' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh reset() { diff --git a/t/t6001-rev-list-graft.sh b/t/t6001-rev-list-graft.sh index 7294147..16635ec 100755 --- a/t/t6001-rev-list-graft.sh +++ b/t/t6001-rev-list-graft.sh @@ -99,6 +99,7 @@ do " test_expect_success 'with grafts' " + mkdir -p .git/info && echo '$B0 $A2' >.git/info/grafts && check $type $B2 -- $B2 $B1 $B0 $A2 $A1 $A0 " diff --git a/t/t6002-rev-list-bisect.sh b/t/t6002-rev-list-bisect.sh index b95a021..162cf50 100755 --- a/t/t6002-rev-list-bisect.sh +++ b/t/t6002-rev-list-bisect.sh @@ -4,6 +4,7 @@ # test_description='Tests git rev-list --bisect functionality' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions diff --git a/t/t6003-rev-list-topo-order.sh b/t/t6003-rev-list-topo-order.sh index 24d1836..1f7d7dd 100755 --- a/t/t6003-rev-list-topo-order.sh +++ b/t/t6003-rev-list-topo-order.sh @@ -5,6 +5,7 @@ test_description='Tests git rev-list --topo-order functionality' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions diff --git a/t/t6005-rev-list-count.sh b/t/t6005-rev-list-count.sh index e960049..0729f80 100755 --- a/t/t6005-rev-list-count.sh +++ b/t/t6005-rev-list-count.sh @@ -2,6 +2,7 @@ test_description='git rev-list --max-count and --skip test' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index 24b34ad..e1abc5c 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -5,6 +5,7 @@ test_description='rev-list/rev-parse --glob' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh commit () { diff --git a/t/t6020-bundle-misc.sh b/t/t6020-bundle-misc.sh index ed95d19..8332051 100755 --- a/t/t6020-bundle-misc.sh +++ b/t/t6020-bundle-misc.sh @@ -122,6 +122,8 @@ format_and_save_expect () { sed -e 's/Z$//' >expect } +HASH_MESSAGE="The bundle uses this hash algorithm: $GIT_DEFAULT_HASH" + # (C) (D, pull/1/head, topic/1) # o --- o # / \ (L) @@ -194,11 +196,12 @@ test_expect_success 'create bundle from special rev: main^!' ' git bundle verify special-rev.bdl | make_user_friendly_and_stable_output >actual && - format_and_save_expect <<-\EOF && + format_and_save_expect <<-EOF && The bundle contains this ref: <COMMIT-P> refs/heads/main The bundle requires this ref: <COMMIT-O> Z + $HASH_MESSAGE EOF test_cmp expect actual && @@ -215,12 +218,13 @@ test_expect_success 'create bundle with --max-count option' ' git bundle verify max-count.bdl | make_user_friendly_and_stable_output >actual && - format_and_save_expect <<-\EOF && + format_and_save_expect <<-EOF && The bundle contains these 2 refs: <COMMIT-P> refs/heads/main <TAG-1> refs/tags/v1 The bundle requires this ref: <COMMIT-O> Z + $HASH_MESSAGE EOF test_cmp expect actual && @@ -240,7 +244,7 @@ test_expect_success 'create bundle with --since option' ' git bundle verify since.bdl | make_user_friendly_and_stable_output >actual && - format_and_save_expect <<-\EOF && + format_and_save_expect <<-EOF && The bundle contains these 5 refs: <COMMIT-P> refs/heads/main <COMMIT-N> refs/heads/release @@ -250,6 +254,7 @@ test_expect_success 'create bundle with --since option' ' The bundle requires these 2 refs: <COMMIT-M> Z <COMMIT-K> Z + $HASH_MESSAGE EOF test_cmp expect actual && @@ -267,11 +272,12 @@ test_expect_success 'create bundle 1 - no prerequisites' ' EOF git bundle create stdin-1.bdl --stdin <input && - cat >expect <<-\EOF && + format_and_save_expect <<-EOF && The bundle contains these 2 refs: <COMMIT-D> refs/heads/topic/1 <COMMIT-H> refs/heads/topic/2 The bundle records a complete history. + $HASH_MESSAGE EOF # verify bundle, which has no prerequisites @@ -308,13 +314,14 @@ test_expect_success 'create bundle 2 - has prerequisites' ' --stdin \ release <input && - format_and_save_expect <<-\EOF && + format_and_save_expect <<-EOF && The bundle contains this ref: <COMMIT-N> refs/heads/release The bundle requires these 3 refs: <COMMIT-D> Z <COMMIT-E> Z <COMMIT-G> Z + $HASH_MESSAGE EOF git bundle verify 2.bdl | @@ -367,13 +374,14 @@ test_expect_success 'create bundle 3 - two refs, same object' ' --stdin \ main HEAD <input && - format_and_save_expect <<-\EOF && + format_and_save_expect <<-EOF && The bundle contains these 2 refs: <COMMIT-P> refs/heads/main <COMMIT-P> HEAD The bundle requires these 2 refs: <COMMIT-M> Z <COMMIT-K> Z + $HASH_MESSAGE EOF git bundle verify 3.bdl | @@ -409,12 +417,13 @@ test_expect_success 'create bundle 4 - with tags' ' --stdin \ --all <input && - cat >expect <<-\EOF && + cat >expect <<-EOF && The bundle contains these 3 refs: <TAG-1> refs/tags/v1 <TAG-2> refs/tags/v2 <TAG-3> refs/tags/v3 The bundle records a complete history. + $HASH_MESSAGE EOF git bundle verify 4.bdl | @@ -510,8 +519,9 @@ do <TAG-2> refs/tags/v2 <TAG-3> refs/tags/v3 <COMMIT-P> HEAD - The bundle uses this filter: $filter The bundle records a complete history. + $HASH_MESSAGE + The bundle uses this filter: $filter EOF test_cmp expect actual && diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 5382e5d..83931d4 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -1025,4 +1025,32 @@ test_expect_success 'bisect visualize with a filename with dash and space' ' git bisect visualize -p -- "-hello 2" ' +test_expect_success 'bisect state output with multiple good commits' ' + git bisect reset && + git bisect start >output && + grep "waiting for both good and bad commits" output && + git bisect log >output && + grep "waiting for both good and bad commits" output && + git bisect good "$HASH1" >output && + grep "waiting for bad commit, 1 good commit known" output && + git bisect log >output && + grep "waiting for bad commit, 1 good commit known" output && + git bisect good "$HASH2" >output && + grep "waiting for bad commit, 2 good commits known" output && + git bisect log >output && + grep "waiting for bad commit, 2 good commits known" output +' + +test_expect_success 'bisect state output with bad commit' ' + git bisect reset && + git bisect start >output && + grep "waiting for both good and bad commits" output && + git bisect log >output && + grep "waiting for both good and bad commits" output && + git bisect bad "$HASH4" >output && + grep -F "waiting for good commit(s), bad commit known" output && + git bisect log >output && + grep -F "waiting for good commit(s), bad commit known" output +' + test_done diff --git a/t/t6100-rev-list-in-order.sh b/t/t6100-rev-list-in-order.sh index e934bc2..88ed7bd 100755 --- a/t/t6100-rev-list-in-order.sh +++ b/t/t6100-rev-list-in-order.sh @@ -2,6 +2,7 @@ test_description='rev-list testing in-commit-order' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup a commit history with trees, blobs' ' diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh index c571fa5..d20723d 100755 --- a/t/t6101-rev-parse-parents.sh +++ b/t/t6101-rev-parse-parents.sh @@ -8,6 +8,8 @@ test_description='Test git rev-parse with different parent options' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh test_cmp_rev_output () { @@ -25,6 +27,7 @@ test_expect_success 'setup' ' git merge -m next --allow-unrelated-histories start2 && test_commit final && + mkdir .git/info && test_seq 40 | while read i do diff --git a/t/t6110-rev-list-sparse.sh b/t/t6110-rev-list-sparse.sh index 13c1da5..ddefc7f 100755 --- a/t/t6110-rev-list-sparse.sh +++ b/t/t6110-rev-list-sparse.sh @@ -4,6 +4,7 @@ test_description='operations that cull histories in unusual ways' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t6114-keep-packs.sh b/t/t6114-keep-packs.sh index 9239d8a..44246f8 100755 --- a/t/t6114-keep-packs.sh +++ b/t/t6114-keep-packs.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='rev-list with .keep packs' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t6131-pathspec-icase.sh b/t/t6131-pathspec-icase.sh index 39fc3f6..770cce0 100755 --- a/t/t6131-pathspec-icase.sh +++ b/t/t6131-pathspec-icase.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test case insensitive pathspec limiting' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh if test_have_prereq CASE_INSENSITIVE_FS diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index 8ff1d76..9fdafeb 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -195,6 +195,7 @@ test_expect_success 'multiple exclusions' ' ' test_expect_success 't_e_i() exclude case #8' ' + test_when_finished "rm -fr case8" && git init case8 && ( cd case8 && @@ -244,4 +245,184 @@ test_expect_success 'grep --untracked PATTERN :(exclude)*FILE' ' test_cmp expect-grep actual-grep ' +# Depending on the command, all negative pathspec needs to subtract +# either from the full tree, or from the current directory. +# +# The sample tree checked out at this point has: +# file +# sub/file +# sub/file2 +# sub/sub/file +# sub/sub/sub/file +# sub2/file +# +# but there may also be some cruft that interferes with "git clean" +# and "git add" tests. + +test_expect_success 'archive with all negative' ' + git reset --hard && + git clean -f && + git -C sub archive --format=tar HEAD -- ":!sub/" >archive && + "$TAR" tf archive >actual && + cat >expect <<-\EOF && + file + file2 + EOF + test_cmp expect actual +' + +test_expect_success 'add with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + git clean -f && + test_when_finished "git reset --hard $H" && + for path in file sub/file sub/sub/file sub2/file + do + echo smudge >>"$path" || return 1 + done && + git -C sub add -- ":!sub/" && + git diff --name-only --no-renames --cached >actual && + cat >expect <<-\EOF && + file + sub/file + sub2/file + EOF + test_cmp expect actual && + git diff --name-only --no-renames >actual && + echo sub/sub/file >expect && + test_cmp expect actual +' + +test_expect_success 'add -p with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + git clean -f && + test_when_finished "git reset --hard $H" && + for path in file sub/file sub/sub/file sub2/file + do + echo smudge >>"$path" || return 1 + done && + yes | git -C sub add -p -- ":!sub/" && + git diff --name-only --no-renames --cached >actual && + cat >expect <<-\EOF && + file + sub/file + sub2/file + EOF + test_cmp expect actual && + git diff --name-only --no-renames >actual && + echo sub/sub/file >expect && + test_cmp expect actual +' + +test_expect_success 'clean with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + test_when_finished "git reset --hard $H && git clean -f" && + git clean -f && + for path in file9 sub/file9 sub/sub/file9 sub2/file9 + do + echo cruft >"$path" || return 1 + done && + git -C sub clean -f -- ":!sub" && + test_path_is_file file9 && + test_path_is_missing sub/file9 && + test_path_is_file sub/sub/file9 && + test_path_is_file sub2/file9 +' + +test_expect_success 'commit with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + test_when_finished "git reset --hard $H" && + for path in file sub/file sub/sub/file sub2/file + do + echo smudge >>"$path" || return 1 + done && + git -C sub commit -m sample -- ":!sub/" && + git diff --name-only --no-renames HEAD^ HEAD >actual && + cat >expect <<-\EOF && + file + sub/file + sub2/file + EOF + test_cmp expect actual && + git diff --name-only --no-renames HEAD >actual && + echo sub/sub/file >expect && + test_cmp expect actual +' + +test_expect_success 'reset with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + test_when_finished "git reset --hard $H" && + for path in file sub/file sub/sub/file sub2/file + do + echo smudge >>"$path" && + git add "$path" || return 1 + done && + git -C sub reset --quiet -- ":!sub/" && + git diff --name-only --no-renames --cached >actual && + echo sub/sub/file >expect && + test_cmp expect actual +' + +test_expect_success 'grep with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + test_when_finished "git reset --hard $H" && + for path in file sub/file sub/sub/file sub2/file + do + echo "needle $path" >>"$path" || return 1 + done && + git -C sub grep -h needle -- ":!sub/" >actual && + cat >expect <<-\EOF && + needle sub/file + EOF + test_cmp expect actual +' + +test_expect_success 'ls-files with all negative' ' + git reset --hard && + git -C sub ls-files -- ":!sub/" >actual && + cat >expect <<-\EOF && + file + file2 + EOF + test_cmp expect actual +' + +test_expect_success 'rm with all negative' ' + git reset --hard && + test_when_finished "git reset --hard" && + git -C sub rm -r --cached -- ":!sub/" >actual && + git diff --name-only --no-renames --diff-filter=D --cached >actual && + cat >expect <<-\EOF && + sub/file + sub/file2 + EOF + test_cmp expect actual +' + +test_expect_success 'stash with all negative' ' + H=$(git rev-parse HEAD) && + git reset --hard $H && + test_when_finished "git reset --hard $H" && + for path in file sub/file sub/sub/file sub2/file + do + echo smudge >>"$path" || return 1 + done && + git -C sub stash push -m sample -- ":!sub/" && + git diff --name-only --no-renames HEAD >actual && + echo sub/sub/file >expect && + test_cmp expect actual && + git stash show --name-only >actual && + cat >expect <<-\EOF && + file + sub/file + sub2/file + EOF + test_cmp expect actual +' + test_done diff --git a/t/t6403-merge-file.sh b/t/t6403-merge-file.sh index 2f421d9..1a70823 100755 --- a/t/t6403-merge-file.sh +++ b/t/t6403-merge-file.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='RCS merge replacement: merge-file' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t6417-merge-ours-theirs.sh b/t/t6417-merge-ours-theirs.sh index 62d1406..482b73a 100755 --- a/t/t6417-merge-ours-theirs.sh +++ b/t/t6417-merge-ours-theirs.sh @@ -4,6 +4,7 @@ test_description='Merge-recursive ours and theirs variants' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t6422-merge-rename-corner-cases.sh b/t/t6422-merge-rename-corner-cases.sh index bf4ce3c..9b65768 100755 --- a/t/t6422-merge-rename-corner-cases.sh +++ b/t/t6422-merge-rename-corner-cases.sh @@ -6,6 +6,7 @@ test_description="recursive merge corner cases w/ renames but not criss-crosses" GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh index 479db32..99baf77 100755 --- a/t/t6423-merge-rename-directories.sh +++ b/t/t6423-merge-rename-directories.sh @@ -5199,6 +5199,111 @@ test_expect_success '12k: Directory rename with sibling causes rename-to-self' ' ) ' +# Testcase 12l, Both sides rename a directory into the other side, both add +# a file which after directory renames are the same filename +# Commit O: sub1/file, sub2/other +# Commit A: sub3/file, sub2/{other, new_add_add_file_1} +# Commit B: sub1/{file, newfile}, sub1/sub2/{other, new_add_add_file_2} +# +# In words: +# A: sub1/ -> sub3/, add sub2/new_add_add_file_1 +# B: sub2/ -> sub1/sub2, add sub1/newfile, add sub1/sub2/new_add_add_file_2 +# +# Expected: sub3/{file, newfile, sub2/other} +# CONFLICT (add/add): sub1/sub2/new_add_add_file +# +# Note that sub1/newfile is not extraneous. Directory renames are only +# detected if they are needed, and they are only needed if the old directory +# had a new file added on the opposite side of history. So sub1/newfile +# is needed for there to be a sub1/ -> sub3/ rename. + +test_setup_12l () { + test_create_repo 12l_$1 && + ( + cd 12l_$1 && + + mkdir sub1 sub2 + echo file >sub1/file && + echo other >sub2/other && + git add sub1 sub2 && + git commit -m "O" && + + git branch O && + git branch A && + git branch B && + + git checkout A && + git mv sub1 sub3 && + echo conflicting >sub2/new_add_add_file && + git add sub2 && + test_tick && + git add -u && + git commit -m "A" && + + git checkout B && + echo dissimilar >sub2/new_add_add_file && + echo brand >sub1/newfile && + git add sub1 sub2 && + git mv sub2 sub1 && + test_tick && + git commit -m "B" + ) +} + +test_expect_merge_algorithm failure success '12l (B into A): Rename into each other + add/add conflict' ' + test_setup_12l BintoA && + ( + cd 12l_BintoA && + + git checkout -q A^0 && + + test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 && + + test_stdout_line_count = 5 git ls-files -s && + + git rev-parse >actual \ + :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \ + :2:sub1/sub2/new_add_add_file \ + :3:sub1/sub2/new_add_add_file && + git rev-parse >expect \ + O:sub1/file B:sub1/newfile O:sub2/other \ + A:sub2/new_add_add_file \ + B:sub1/sub2/new_add_add_file && + test_cmp expect actual && + + git ls-files -o >actual && + test_write_lines actual expect >expect && + test_cmp expect actual + ) +' + +test_expect_merge_algorithm failure success '12l (A into B): Rename into each other + add/add conflict' ' + test_setup_12l AintoB && + ( + cd 12l_AintoB && + + git checkout -q B^0 && + + test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 && + + test_stdout_line_count = 5 git ls-files -s && + + git rev-parse >actual \ + :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \ + :2:sub1/sub2/new_add_add_file \ + :3:sub1/sub2/new_add_add_file && + git rev-parse >expect \ + O:sub1/file B:sub1/newfile O:sub2/other \ + B:sub1/sub2/new_add_add_file \ + A:sub2/new_add_add_file && + test_cmp expect actual && + + git ls-files -o >actual && + test_write_lines actual expect >expect && + test_cmp expect actual + ) +' + ########################################################################### # SECTION 13: Checking informational and conflict messages # diff --git a/t/t6424-merge-unrelated-index-changes.sh b/t/t6424-merge-unrelated-index-changes.sh index 89dd544..b6e424a 100755 --- a/t/t6424-merge-unrelated-index-changes.sh +++ b/t/t6424-merge-unrelated-index-changes.sh @@ -71,7 +71,9 @@ test_expect_success 'ff update' ' git merge E^0 && test_must_fail git rev-parse HEAD:random_file && - test "$(git diff --name-only --cached E)" = "random_file" + test "$(git diff --name-only --cached E)" = "random_file" && + test_path_is_file random_file && + git rev-parse --verify :random_file ' test_expect_success 'ff update, important file modified' ' @@ -83,6 +85,8 @@ test_expect_success 'ff update, important file modified' ' git add subdir/e && test_must_fail git merge E^0 && + test_path_is_file subdir/e && + git rev-parse --verify :subdir/e && test_path_is_missing .git/MERGE_HEAD ' @@ -93,6 +97,8 @@ test_expect_success 'resolve, trivial' ' touch random_file && git add random_file && test_must_fail git merge -s resolve C^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -103,6 +109,8 @@ test_expect_success 'resolve, non-trivial' ' touch random_file && git add random_file && test_must_fail git merge -s resolve D^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -113,6 +121,8 @@ test_expect_success 'recursive' ' touch random_file && git add random_file && test_must_fail git merge -s recursive C^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -145,9 +155,12 @@ test_expect_success 'recursive, when file has staged changes not matching HEAD n mkdir subdir && test_seq 1 10 >subdir/a && git add subdir/a && + git rev-parse --verify :subdir/a >expect && # We have staged changes; merge should error out test_must_fail git merge -s recursive E^0 2>err && + git rev-parse --verify :subdir/a >actual && + test_cmp expect actual && test_i18ngrep "changes to the following files would be overwritten" err ' @@ -158,9 +171,12 @@ test_expect_success 'recursive, when file has staged changes matching what a mer mkdir subdir && test_seq 1 11 >subdir/a && git add subdir/a && + git rev-parse --verify :subdir/a >expect && # We have staged changes; merge should error out test_must_fail git merge -s recursive E^0 2>err && + git rev-parse --verify :subdir/a >actual && + test_cmp expect actual && test_i18ngrep "changes to the following files would be overwritten" err ' @@ -171,7 +187,9 @@ test_expect_success 'octopus, unrelated file touched' ' touch random_file && git add random_file && test_must_fail git merge C^0 D^0 && - test_path_is_missing .git/MERGE_HEAD + test_path_is_missing .git/MERGE_HEAD && + git rev-parse --verify :random_file && + test_path_exists random_file ' test_expect_success 'octopus, related file removed' ' @@ -181,6 +199,8 @@ test_expect_success 'octopus, related file removed' ' git rm b && test_must_fail git merge C^0 D^0 && + test_path_is_missing b && + test_must_fail git rev-parse --verify :b && test_path_is_missing .git/MERGE_HEAD ' @@ -189,8 +209,12 @@ test_expect_success 'octopus, related file modified' ' git checkout B^0 && echo 12 >>a && git add a && + git rev-parse --verify :a >expect && test_must_fail git merge C^0 D^0 && + test_path_is_file a && + git rev-parse --verify :a >actual && + test_cmp expect actual && test_path_is_missing .git/MERGE_HEAD ' @@ -201,6 +225,8 @@ test_expect_success 'ours' ' touch random_file && git add random_file && test_must_fail git merge -s ours C^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' @@ -211,6 +237,8 @@ test_expect_success 'subtree' ' touch random_file && git add random_file && test_must_fail git merge -s subtree E^0 && + test_path_is_file random_file && + git rev-parse --verify :random_file && test_path_is_missing .git/MERGE_HEAD ' diff --git a/t/t6428-merge-conflicts-sparse.sh b/t/t6428-merge-conflicts-sparse.sh index 142c9aa..064be1b 100755 --- a/t/t6428-merge-conflicts-sparse.sh +++ b/t/t6428-merge-conflicts-sparse.sh @@ -87,7 +87,7 @@ test_expect_success 'conflicting entries written to worktree even if sparse' ' test_path_is_file numerals && git sparse-checkout init && - git sparse-checkout set README && + git sparse-checkout set --no-cone README && test_path_is_file README && test_path_is_missing numerals && @@ -123,7 +123,7 @@ test_expect_success 'present-despite-SKIP_WORKTREE handled reasonably' ' test_path_is_file numerals && git sparse-checkout init && - git sparse-checkout set README && + git sparse-checkout set --no-cone README && test_path_is_file README && test_path_is_missing numerals && diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh index f2bc8a7..e1ce919 100755 --- a/t/t6429-merge-sequence-rename-caching.sh +++ b/t/t6429-merge-sequence-rename-caching.sh @@ -760,7 +760,7 @@ test_expect_success 'avoid assuming we detected renames' ' test_must_fail git -c merge.renameLimit=1 rebase upstream && git ls-files -u >actual && - ! test_file_is_empty actual + test_line_count = 2 actual ) ' diff --git a/t/t6435-merge-sparse.sh b/t/t6435-merge-sparse.sh index 74562e1..fde4aa3 100755 --- a/t/t6435-merge-sparse.sh +++ b/t/t6435-merge-sparse.sh @@ -2,6 +2,7 @@ test_description='merge with sparse files' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh # test_file $filename $content @@ -26,6 +27,7 @@ test_expect_success 'setup' ' git rm modify_delete && test_commit_this ours && git config core.sparseCheckout true && + mkdir .git/info && echo "/checked-out" >.git/info/sparse-checkout && git reset --hard && test_must_fail git merge theirs diff --git a/t/t6437-submodule-merge.sh b/t/t6437-submodule-merge.sh index 178413c..c253bf7 100755 --- a/t/t6437-submodule-merge.sh +++ b/t/t6437-submodule-merge.sh @@ -133,7 +133,7 @@ test_expect_success 'merging should conflict for non fast-forward' ' (cd merge-search && git checkout -b test-nonforward b && (cd sub && - git rev-parse sub-d > ../expect) && + git rev-parse --short sub-d > ../expect) && if test "$GIT_TEST_MERGE_ALGORITHM" = ort then test_must_fail git merge c >actual diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index c202126..cd6c533 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -101,12 +101,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' ' EOF git init pre-auto-gc-hook && + test_hook -C pre-auto-gc-hook pre-auto-gc <<-\EOF && + echo >&2 no gc for you && + exit 1 + EOF ( cd pre-auto-gc-hook && - write_script ".git/hooks/pre-auto-gc" <<-\EOF && - echo >&2 no gc for you && - exit 1 - EOF git config gc.auto 3 && git config gc.autoDetach false && @@ -128,14 +128,12 @@ test_expect_success 'pre-auto-gc hook can stop auto gc' ' See "git help gc" for manual housekeeping. EOF - ( - cd pre-auto-gc-hook && - write_script ".git/hooks/pre-auto-gc" <<-\EOF && - echo >&2 will gc for you && - exit 0 - EOF - git gc --auto >../out.actual 2>../err.actual - ) && + test_hook -C pre-auto-gc-hook --clobber pre-auto-gc <<-\EOF && + echo >&2 will gc for you && + exit 0 + EOF + + git -C pre-auto-gc-hook gc --auto >out.actual 2>err.actual && test_must_be_empty out.actual && test_cmp err.expect err.actual diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 963356b..a402908 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -4,6 +4,25 @@ test_description='git mv in subdirs' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-diff-data.sh +test_expect_success 'mv -f refreshes updated index entry' ' + echo test >bar && + git add bar && + git commit -m test && + + echo foo >foo && + git add foo && + + # Wait one second to ensure ctime of rename will differ from original + # file creation ctime. + sleep 1 && + git mv -f foo bar && + git reset --merge HEAD && + + # Verify the index has been reset + git diff-files >out && + test_must_be_empty out +' + test_expect_success 'prepare reference tree' ' mkdir path0 path1 && COPYING_test_data >path0/COPYING && diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 1d3d2ac..71fe296 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -4,6 +4,18 @@ test_description='git mv in sparse working trees' . ./test-lib.sh +setup_sparse_checkout () { + mkdir folder1 && + touch folder1/file1 && + git add folder1 && + git sparse-checkout set --cone sub +} + +cleanup_sparse_checkout () { + git sparse-checkout disable && + git reset --hard +} + test_expect_success 'setup' " mkdir -p sub/dir sub/dir2 && touch a b c sub/d sub/dir/e sub/dir2/e && @@ -27,7 +39,7 @@ test_expect_success 'setup' " test_expect_success 'mv refuses to move sparse-to-sparse' ' test_when_finished rm -f e && git reset --hard && - git sparse-checkout set a && + git sparse-checkout set --no-cone a && touch b && test_must_fail git mv b e 2>stderr && cat sparse_error_header >expect && @@ -196,6 +208,7 @@ test_expect_success 'can move files to non-sparse dir' ' ' test_expect_success 'refuse to move file to non-skip-worktree sparse path' ' + test_when_finished "cleanup_sparse_checkout" && git reset --hard && git sparse-checkout init --no-cone && git sparse-checkout set a !/x y/ !x/y/z && @@ -206,4 +219,75 @@ test_expect_success 'refuse to move file to non-skip-worktree sparse path' ' test_cmp expect stderr ' +test_expect_success 'refuse to move out-of-cone directory without --sparse' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + + test_must_fail git mv folder1 sub 2>stderr && + cat sparse_error_header >expect && + echo folder1/file1 >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_expect_success 'can move out-of-cone directory with --sparse' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + + git mv --sparse folder1 sub 2>stderr && + test_must_be_empty stderr && + + test_path_is_dir sub/folder1 && + test_path_is_file sub/folder1/file1 +' + +test_expect_success 'refuse to move out-of-cone file without --sparse' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + + test_must_fail git mv folder1/file1 sub 2>stderr && + cat sparse_error_header >expect && + echo folder1/file1 >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr +' + +test_expect_success 'can move out-of-cone file with --sparse' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + + git mv --sparse folder1/file1 sub 2>stderr && + test_must_be_empty stderr && + + test_path_is_file sub/file1 +' + +test_expect_success 'refuse to move sparse file to existing destination' ' + test_when_finished "cleanup_sparse_checkout" && + mkdir folder1 && + touch folder1/file1 && + touch sub/file1 && + git add folder1 sub/file1 && + git sparse-checkout set --cone sub && + + test_must_fail git mv --sparse folder1/file1 sub 2>stderr && + echo "fatal: destination exists, source=folder1/file1, destination=sub/file1" >expect && + test_cmp expect stderr +' + +test_expect_success 'move sparse file to existing destination with --force and --sparse' ' + test_when_finished "cleanup_sparse_checkout" && + mkdir folder1 && + touch folder1/file1 && + touch sub/file1 && + echo "overwrite" >folder1/file1 && + git add folder1 sub/file1 && + git sparse-checkout set --cone sub && + + git mv --sparse --force folder1/file1 sub 2>stderr && + test_must_be_empty stderr && + echo "overwrite" >expect && + test_cmp expect sub/file1 +' + test_done diff --git a/t/t7008-filter-branch-null-sha1.sh b/t/t7008-filter-branch-null-sha1.sh index 9ba9f24..93fbc92 100755 --- a/t/t7008-filter-branch-null-sha1.sh +++ b/t/t7008-filter-branch-null-sha1.sh @@ -1,6 +1,7 @@ #!/bin/sh test_description='filter-branch removal of trees with null sha1' + . ./test-lib.sh test_expect_success 'setup: base commits' ' diff --git a/t/t7011-skip-worktree-reading.sh b/t/t7011-skip-worktree-reading.sh index 1761a2b..4adac5a 100755 --- a/t/t7011-skip-worktree-reading.sh +++ b/t/t7011-skip-worktree-reading.sh @@ -5,6 +5,7 @@ test_description='skip-worktree bit test' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >expect.full <<EOF diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh index cb9f1a6..cd5c20f 100755 --- a/t/t7012-skip-worktree-writing.sh +++ b/t/t7012-skip-worktree-writing.sh @@ -151,7 +151,7 @@ test_expect_success 'stash restore in sparse checkout' ' git stash push && - git sparse-checkout set subdir && + git sparse-checkout set --no-cone subdir && # Ensure after sparse-checkout we only have expected files cat >expect <<-EOF && diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh index c1f0d95..8929ef4 100755 --- a/t/t7063-status-untracked-cache.sh +++ b/t/t7063-status-untracked-cache.sh @@ -86,7 +86,7 @@ test_expect_success 'core.untrackedCache is unset' ' ' test_expect_success 'setup' ' - git init worktree && + git init --template= worktree && cd worktree && mkdir done dtwo dthree && touch one two three done/one dtwo/two dthree/three && @@ -94,6 +94,7 @@ test_expect_success 'setup' ' test-tool chmtime =-300 done dtwo dthree && test-tool chmtime =-300 . && git add one two done/one && + mkdir .git/info && : >.git/info/exclude && git update-index --untracked-cache && test_oid_cache <<-EOF diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index d054260..22477f3 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -462,14 +462,40 @@ test_expect_success 'resetting an unmodified path is a no-op' ' git diff-index --cached --exit-code HEAD ' +test_reset_refreshes_index () { + + # To test whether the index is refreshed in `git reset --mixed` with + # the given options, create a scenario where we clearly see different + # results depending on whether the refresh occurred or not. + + # Step 0: start with a clean index + git reset --hard HEAD && + + # Step 1: remove file2, but only in the index (no change to worktree) + git rm --cached file2 && + + # Step 2: reset index & leave worktree unchanged from HEAD + git $1 reset $2 --mixed HEAD && + + # Step 3: verify whether the index is refreshed by checking whether + # file2 still has staged changes in the index differing from HEAD (if + # the refresh occurred, there should be no such changes) + git diff-files >output.log && + test_must_be_empty output.log +} + test_expect_success '--mixed refreshes the index' ' - cat >expect <<-\EOF && - Unstaged changes after reset: - M file2 - EOF - echo 123 >>file2 && - git reset --mixed HEAD >output && - test_cmp expect output + # Verify default behavior (without --[no-]refresh or reset.refresh) + test_reset_refreshes_index && + + # With --quiet + test_reset_refreshes_index "" --quiet +' + +test_expect_success '--mixed --[no-]refresh sets refresh behavior' ' + # Verify that --[no-]refresh controls index refresh + test_reset_refreshes_index "" --refresh && + ! test_reset_refreshes_index "" --no-refresh ' test_expect_success '--mixed preserves skip-worktree' ' diff --git a/t/t7113-post-index-change-hook.sh b/t/t7113-post-index-change-hook.sh index a21781d..58e55a7 100755 --- a/t/t7113-post-index-change-hook.sh +++ b/t/t7113-post-index-change-hook.sh @@ -17,8 +17,7 @@ test_expect_success 'setup' ' ' test_expect_success 'test status, add, commit, others trigger hook without flags set' ' - mkdir -p .git/hooks && - write_script .git/hooks/post-index-change <<-\EOF && + test_hook post-index-change <<-\EOF && if test "$1" -eq 1; then echo "Invalid combination of flags passed to hook; updated_workdir is set." >testfailure exit 1 @@ -63,7 +62,7 @@ test_expect_success 'test status, add, commit, others trigger hook without flags ' test_expect_success 'test checkout and reset trigger the hook' ' - write_script .git/hooks/post-index-change <<-\EOF && + test_hook post-index-change <<-\EOF && if test "$1" -eq 1 && test "$2" -eq 1; then echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure exit 1 @@ -106,7 +105,7 @@ test_expect_success 'test checkout and reset trigger the hook' ' ' test_expect_success 'test reset --mixed and update-index triggers the hook' ' - write_script .git/hooks/post-index-change <<-\EOF && + test_hook post-index-change <<-\EOF && if test "$1" -eq 1 && test "$2" -eq 1; then echo "Invalid combination of flags passed to hook; updated_workdir and updated_skipworktree are both set." >testfailure exit 1 diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 000e055..6cc0746 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -670,6 +670,39 @@ test_expect_success 'submodule update --init skips submodule with update=none' ' ) ' +test_expect_success 'submodule update with pathspec warns against uninitialized ones' ' + test_when_finished "rm -fr selective" && + git clone super selective && + ( + cd selective && + git submodule init submodule && + + git submodule update submodule 2>err && + ! grep "Submodule path .* not initialized" err && + + git submodule update rebasing 2>err && + grep "Submodule path .rebasing. not initialized" err && + + test_path_exists submodule/.git && + test_path_is_missing rebasing/.git + ) + +' + +test_expect_success 'submodule update without pathspec updates only initialized ones' ' + test_when_finished "rm -fr selective" && + git clone super selective && + ( + cd selective && + git submodule init submodule && + git submodule update 2>err && + test_path_exists submodule/.git && + test_path_is_missing rebasing/.git && + ! grep "Submodule path .* not initialized" err + ) + +' + test_expect_success 'submodule update continues after checkout error' ' (cd super && git reset --hard HEAD && @@ -1041,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' git submodule update --rebase --quiet >out 2>err && test_must_be_empty out && test_must_be_empty err && - git submodule update --rebase -v >out 2>err && + git submodule update --rebase >out 2>err && test_file_not_empty out && test_must_be_empty err ) @@ -1083,4 +1116,66 @@ test_expect_success 'submodule update --filter sets partial clone settings' ' test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter ' +# NEEDSWORK: Clean up the tests so that we can reuse the test setup. +# Don't reuse the existing repos because the earlier tests have +# intentionally disruptive configurations. +test_expect_success 'setup clean recursive superproject' ' + git init bottom && + test_commit -C bottom "bottom" && + git init middle && + git -C middle submodule add ../bottom bottom && + git -C middle commit -m "middle" && + git init top && + git -C top submodule add ../middle middle && + git -C top commit -m "top" && + git clone --recurse-submodules top top-clean +' + +test_expect_success 'submodule update should skip unmerged submodules' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + # Create an upstream commit in each repo, starting with bottom + test_commit -C bottom upstream_commit && + # Create middle commit + git -C middle/bottom fetch && + git -C middle/bottom checkout -f FETCH_HEAD && + git -C middle add bottom && + git -C middle commit -m "upstream_commit" && + # Create top commit + git -C top/middle fetch && + git -C top/middle checkout -f FETCH_HEAD && + git -C top add middle && + git -C top commit -m "upstream_commit" && + + # Create a downstream conflict + test_commit -C top-cloned/middle/bottom downstream_commit && + git -C top-cloned/middle add bottom && + git -C top-cloned/middle commit -m "downstream_commit" && + git -C top-cloned/middle fetch --recurse-submodules origin && + test_must_fail git -C top-cloned/middle merge origin/main && + + # Make the update of "middle" a no-op, otherwise we error out + # because of its unmerged state + test_config -C top-cloned submodule.middle.update !true && + git -C top-cloned submodule update --recursive 2>actual.err && + cat >expect.err <<-\EOF && + Skipping unmerged submodule middle/bottom + EOF + test_cmp expect.err actual.err +' + +test_expect_success 'submodule update --recursive skip submodules with strategy=none' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + test_commit -C top-cloned/middle/bottom downstream_commit && + git -C top-cloned/middle config submodule.bottom.update none && + git -C top-cloned submodule update --recursive 2>actual.err && + cat >expect.err <<-\EOF && + Skipping submodule '\''middle/bottom'\'' + EOF + test_cmp expect.err actual.err +' + test_done diff --git a/t/t7418-submodule-sparse-gitmodules.sh b/t/t7418-submodule-sparse-gitmodules.sh index f87e524..57d7ab3 100755 --- a/t/t7418-submodule-sparse-gitmodules.sh +++ b/t/t7418-submodule-sparse-gitmodules.sh @@ -31,8 +31,9 @@ test_expect_success 'sparse checkout setup which hides .gitmodules' ' test_tick && git commit -m "Add submodule" ) && - git clone upstream super && + git clone --template= upstream super && (cd super && + mkdir .git/info && cat >.git/info/sparse-checkout <<-\EOF && /* !/.gitmodules diff --git a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh index 606d8d0..ad1eb64 100755 --- a/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh +++ b/t/t7503-pre-commit-and-pre-merge-commit-hooks.sh @@ -7,37 +7,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -HOOKDIR="$(git rev-parse --git-dir)/hooks" -PRECOMMIT="$HOOKDIR/pre-commit" -PREMERGE="$HOOKDIR/pre-merge-commit" - -# Prepare sample scripts that write their $0 to actual_hooks -test_expect_success 'sample script setup' ' - mkdir -p "$HOOKDIR" && - write_script "$HOOKDIR/success.sample" <<-\EOF && - echo $0 >>actual_hooks - exit 0 - EOF - write_script "$HOOKDIR/fail.sample" <<-\EOF && - echo $0 >>actual_hooks - exit 1 - EOF - write_script "$HOOKDIR/non-exec.sample" <<-\EOF && - echo $0 >>actual_hooks - exit 1 - EOF - chmod -x "$HOOKDIR/non-exec.sample" && - write_script "$HOOKDIR/require-prefix.sample" <<-\EOF && - echo $0 >>actual_hooks - test $GIT_PREFIX = "success/" - EOF - write_script "$HOOKDIR/check-author.sample" <<-\EOF - echo $0 >>actual_hooks - test "$GIT_AUTHOR_NAME" = "New Author" && - test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" - EOF -' - test_expect_success 'root commit' ' echo "root" >file && git add file && @@ -96,10 +65,16 @@ test_expect_success '--no-verify with no hook (merge)' ' test_path_is_missing actual_hooks ' +setup_success_hook () { + test_when_finished "rm -f actual_hooks expected_hooks" && + echo "$1" >expected_hooks && + test_hook "$1" <<-EOF + echo $1 >>actual_hooks + EOF +} + test_expect_success 'with succeeding hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" && - cp "$HOOKDIR/success.sample" "$PRECOMMIT" && - echo "$PRECOMMIT" >expected_hooks && + setup_success_hook "pre-commit" && echo "more" >>file && git add file && git commit -m "more" && @@ -107,9 +82,7 @@ test_expect_success 'with succeeding hook' ' ' test_expect_success 'with succeeding hook (merge)' ' - test_when_finished "rm -f \"$PREMERGE\" expected_hooks actual_hooks" && - cp "$HOOKDIR/success.sample" "$PREMERGE" && - echo "$PREMERGE" >expected_hooks && + setup_success_hook "pre-merge-commit" && git checkout side && git merge -m "merge main" main && git checkout main && @@ -117,17 +90,14 @@ test_expect_success 'with succeeding hook (merge)' ' ' test_expect_success 'automatic merge fails; both hooks are available' ' - test_when_finished "rm -f \"$PREMERGE\" \"$PRECOMMIT\"" && - test_when_finished "rm -f expected_hooks actual_hooks" && - test_when_finished "git checkout main" && - cp "$HOOKDIR/success.sample" "$PREMERGE" && - cp "$HOOKDIR/success.sample" "$PRECOMMIT" && + setup_success_hook "pre-commit" && + setup_success_hook "pre-merge-commit" && git checkout conflicting-a && test_must_fail git merge -m "merge conflicting-b" conflicting-b && test_path_is_missing actual_hooks && - echo "$PRECOMMIT" >expected_hooks && + echo "pre-commit" >expected_hooks && echo a+b >conflicting && git add conflicting && git commit -m "resolve conflict" && @@ -135,8 +105,7 @@ test_expect_success 'automatic merge fails; both hooks are available' ' ' test_expect_success '--no-verify with succeeding hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && - cp "$HOOKDIR/success.sample" "$PRECOMMIT" && + setup_success_hook "pre-commit" && echo "even more" >>file && git add file && git commit --no-verify -m "even more" && @@ -144,8 +113,7 @@ test_expect_success '--no-verify with succeeding hook' ' ' test_expect_success '--no-verify with succeeding hook (merge)' ' - test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && - cp "$HOOKDIR/success.sample" "$PREMERGE" && + setup_success_hook "pre-merge-commit" && git branch -f side side-orig && git checkout side && git merge --no-verify -m "merge main" main && @@ -153,10 +121,19 @@ test_expect_success '--no-verify with succeeding hook (merge)' ' test_path_is_missing actual_hooks ' +setup_failing_hook () { + test_when_finished "rm -f actual_hooks" && + test_hook "$1" <<-EOF + echo $1-failing-hook >>actual_hooks + exit 1 + EOF +} + test_expect_success 'with failing hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" && - cp "$HOOKDIR/fail.sample" "$PRECOMMIT" && - echo "$PRECOMMIT" >expected_hooks && + setup_failing_hook "pre-commit" && + test_when_finished "rm -f expected_hooks" && + echo "pre-commit-failing-hook" >expected_hooks && + echo "another" >>file && git add file && test_must_fail git commit -m "another" && @@ -164,8 +141,7 @@ test_expect_success 'with failing hook' ' ' test_expect_success '--no-verify with failing hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && - cp "$HOOKDIR/fail.sample" "$PRECOMMIT" && + setup_failing_hook "pre-commit" && echo "stuff" >>file && git add file && git commit --no-verify -m "stuff" && @@ -173,9 +149,8 @@ test_expect_success '--no-verify with failing hook' ' ' test_expect_success 'with failing hook (merge)' ' - test_when_finished "rm -f \"$PREMERGE\" expected_hooks actual_hooks" && - cp "$HOOKDIR/fail.sample" "$PREMERGE" && - echo "$PREMERGE" >expected_hooks && + setup_failing_hook "pre-merge-commit" && + echo "pre-merge-commit-failing-hook" >expected_hooks && git checkout side && test_must_fail git merge -m "merge main" main && git checkout main && @@ -183,8 +158,8 @@ test_expect_success 'with failing hook (merge)' ' ' test_expect_success '--no-verify with failing hook (merge)' ' - test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && - cp "$HOOKDIR/fail.sample" "$PREMERGE" && + setup_failing_hook "pre-merge-commit" && + git branch -f side side-orig && git checkout side && git merge --no-verify -m "merge main" main && @@ -192,9 +167,18 @@ test_expect_success '--no-verify with failing hook (merge)' ' test_path_is_missing actual_hooks ' +setup_non_exec_hook () { + test_when_finished "rm -f actual_hooks" && + test_hook "$1" <<-\EOF && + echo non-exec >>actual_hooks + exit 1 + EOF + test_hook --disable "$1" +} + + test_expect_success POSIXPERM 'with non-executable hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && - cp "$HOOKDIR/non-exec.sample" "$PRECOMMIT" && + setup_non_exec_hook "pre-commit" && echo "content" >>file && git add file && git commit -m "content" && @@ -202,8 +186,7 @@ test_expect_success POSIXPERM 'with non-executable hook' ' ' test_expect_success POSIXPERM '--no-verify with non-executable hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" actual_hooks" && - cp "$HOOKDIR/non-exec.sample" "$PRECOMMIT" && + setup_non_exec_hook "pre-commit" && echo "more content" >>file && git add file && git commit --no-verify -m "more content" && @@ -211,8 +194,7 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook' ' ' test_expect_success POSIXPERM 'with non-executable hook (merge)' ' - test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && - cp "$HOOKDIR/non-exec.sample" "$PREMERGE" && + setup_non_exec_hook "pre-merge" && git branch -f side side-orig && git checkout side && git merge -m "merge main" main && @@ -221,8 +203,7 @@ test_expect_success POSIXPERM 'with non-executable hook (merge)' ' ' test_expect_success POSIXPERM '--no-verify with non-executable hook (merge)' ' - test_when_finished "rm -f \"$PREMERGE\" actual_hooks" && - cp "$HOOKDIR/non-exec.sample" "$PREMERGE" && + setup_non_exec_hook "pre-merge" && git branch -f side side-orig && git checkout side && git merge --no-verify -m "merge main" main && @@ -230,10 +211,18 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook (merge)' ' test_path_is_missing actual_hooks ' +setup_require_prefix_hook () { + test_when_finished "rm -f expected_hooks" && + echo require-prefix >expected_hooks && + test_hook pre-commit <<-\EOF + echo require-prefix >>actual_hooks + test $GIT_PREFIX = "success/" + EOF +} + test_expect_success 'with hook requiring GIT_PREFIX' ' - test_when_finished "rm -rf \"$PRECOMMIT\" expected_hooks actual_hooks success" && - cp "$HOOKDIR/require-prefix.sample" "$PRECOMMIT" && - echo "$PRECOMMIT" >expected_hooks && + test_when_finished "rm -rf actual_hooks success" && + setup_require_prefix_hook && echo "more content" >>file && git add file && mkdir success && @@ -245,9 +234,8 @@ test_expect_success 'with hook requiring GIT_PREFIX' ' ' test_expect_success 'with failing hook requiring GIT_PREFIX' ' - test_when_finished "rm -rf \"$PRECOMMIT\" expected_hooks actual_hooks fail" && - cp "$HOOKDIR/require-prefix.sample" "$PRECOMMIT" && - echo "$PRECOMMIT" >expected_hooks && + test_when_finished "rm -rf actual_hooks fail" && + setup_require_prefix_hook && echo "more content" >>file && git add file && mkdir fail && @@ -259,13 +247,23 @@ test_expect_success 'with failing hook requiring GIT_PREFIX' ' test_cmp expected_hooks actual_hooks ' +setup_require_author_hook () { + test_when_finished "rm -f expected_hooks actual_hooks" && + echo check-author >expected_hooks && + test_hook pre-commit <<-\EOF + echo check-author >>actual_hooks + test "$GIT_AUTHOR_NAME" = "New Author" && + test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com" + EOF +} + + test_expect_success 'check the author in hook' ' - test_when_finished "rm -f \"$PRECOMMIT\" expected_hooks actual_hooks" && - cp "$HOOKDIR/check-author.sample" "$PRECOMMIT" && + setup_require_author_hook && cat >expected_hooks <<-EOF && - $PRECOMMIT - $PRECOMMIT - $PRECOMMIT + check-author + check-author + check-author EOF test_must_fail git commit --allow-empty -m "by a.u.thor" && ( diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh index bba58f0..a39de8c 100755 --- a/t/t7504-commit-msg-hook.sh +++ b/t/t7504-commit-msg-hook.sh @@ -54,15 +54,11 @@ test_expect_success '--no-verify with no hook (editor)' ' ' -# now install hook that always succeeds -HOOKDIR="$(git rev-parse --git-dir)/hooks" -HOOK="$HOOKDIR/commit-msg" -mkdir -p "$HOOKDIR" -cat > "$HOOK" <<EOF -#!/bin/sh -exit 0 -EOF -chmod +x "$HOOK" +test_expect_success 'setup: commit-msg hook that always succeeds' ' + test_hook --setup commit-msg <<-\EOF + exit 0 + EOF +' test_expect_success 'with succeeding hook' ' @@ -98,11 +94,11 @@ test_expect_success '--no-verify with succeeding hook (editor)' ' ' -# now a hook that fails -cat > "$HOOK" <<EOF -#!/bin/sh -exit 1 -EOF +test_expect_success 'setup: commit-msg hook that always fails' ' + test_hook --clobber commit-msg <<-\EOF + exit 1 + EOF +' commit_msg_is () { test "$(git log --pretty=format:%s%b -1)" = "$1" @@ -176,8 +172,12 @@ test_expect_success 'merge bypasses failing hook with --no-verify' ' commit_msg_is "Merge branch '\''main'\'' into newbranch" ' +test_expect_success 'setup: commit-msg hook made non-executable' ' + git_dir="$(git rev-parse --git-dir)" && + chmod -x "$git_dir/hooks/commit-msg" +' + -chmod -x "$HOOK" test_expect_success POSIXPERM 'with non-executable hook' ' echo "content" >file && @@ -212,13 +212,12 @@ test_expect_success POSIXPERM '--no-verify with non-executable hook (editor)' ' ' -# now a hook that edits the commit message -cat > "$HOOK" <<'EOF' -#!/bin/sh -echo "new message" > "$1" -exit 0 -EOF -chmod +x "$HOOK" +test_expect_success 'setup: commit-msg hook that edits the commit message' ' + test_hook --clobber commit-msg <<-\EOF + echo "new message" >"$1" + exit 0 + EOF +' test_expect_success 'hook edits commit message' ' diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh index e39c809..2128142 100755 --- a/t/t7505-prepare-commit-msg-hook.sh +++ b/t/t7505-prepare-commit-msg-hook.sh @@ -47,25 +47,19 @@ test_expect_success 'with no hook' ' ' -# set up fake editor for interactive editing -cat > fake-editor <<'EOF' -#!/bin/sh -exit 0 -EOF -chmod +x fake-editor - -## Not using test_set_editor here so we can easily ensure the editor variable -## is only set for the editor tests -FAKE_EDITOR="$(pwd)/fake-editor" -export FAKE_EDITOR +test_expect_success 'setup fake editor for interactive editing' ' + write_script fake-editor <<-\EOF && + exit 0 + EOF -# now install hook that always succeeds and adds a message -HOOKDIR="$(git rev-parse --git-dir)/hooks" -HOOK="$HOOKDIR/prepare-commit-msg" -mkdir -p "$HOOKDIR" -echo "#!$SHELL_PATH" > "$HOOK" -cat >> "$HOOK" <<'EOF' + ## Not using test_set_editor here so we can easily ensure the editor variable + ## is only set for the editor tests + FAKE_EDITOR="$(pwd)/fake-editor" && + export FAKE_EDITOR +' +test_expect_success 'setup prepare-commit-msg hook' ' + test_hook --setup prepare-commit-msg <<\EOF GIT_DIR=$(git rev-parse --git-dir) if test -d "$GIT_DIR/rebase-merge" then @@ -103,7 +97,7 @@ else fi exit 0 EOF -chmod +x "$HOOK" +' echo dummy template > "$(git rev-parse --git-dir)/template" @@ -265,10 +259,11 @@ test_expect_success 'with hook and editor (cherry-pick)' ' test "$(git log -1 --pretty=format:%s)" = merge ' -cat > "$HOOK" <<'EOF' -#!/bin/sh -exit 1 -EOF +test_expect_success 'setup: commit-msg hook that always fails' ' + test_hook --setup --clobber prepare-commit-msg <<-\EOF + exit 1 + EOF +' test_expect_success 'with failing hook' ' @@ -296,9 +291,9 @@ test_expect_success 'with failing hook (merge)' ' git checkout -B other HEAD@{1} && echo "more" >> file && git add file && - rm -f "$HOOK" && + test_hook --remove prepare-commit-msg && git commit -m other && - write_script "$HOOK" <<-EOF && + test_hook --setup prepare-commit-msg <<-\EOF && exit 1 EOF git checkout - && diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index fffc571..8348e3a 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -26,7 +26,7 @@ dirty_repo () { } write_integration_script () { - write_script .git/hooks/fsmonitor-test<<-\EOF + test_hook --setup --clobber fsmonitor-test<<-\EOF if test "$#" -ne 2 then echo "$0: exactly 2 arguments expected" @@ -55,8 +55,39 @@ test_lazy_prereq UNTRACKED_CACHE ' test $ret -ne 1 ' +# Test that we detect and disallow repos that are incompatible with FSMonitor. +test_expect_success 'incompatible bare repo' ' + test_when_finished "rm -rf ./bare-clone actual expect" && + git init --bare bare-clone && + + test_must_fail \ + git -C ./bare-clone -c core.fsmonitor=foo \ + update-index --fsmonitor 2>actual && + grep "bare repository .* is incompatible with fsmonitor" actual && + + test_must_fail \ + git -C ./bare-clone -c core.fsmonitor=true \ + update-index --fsmonitor 2>actual && + grep "bare repository .* is incompatible with fsmonitor" actual +' + +test_expect_success FSMONITOR_DAEMON 'run fsmonitor-daemon in bare repo' ' + test_when_finished "rm -rf ./bare-clone actual" && + git init --bare bare-clone && + test_must_fail git -C ./bare-clone fsmonitor--daemon run 2>actual && + grep "bare repository .* is incompatible with fsmonitor" actual +' + +test_expect_success MINGW,FSMONITOR_DAEMON 'run fsmonitor-daemon in virtual repo' ' + test_when_finished "rm -rf ./fake-virtual-clone actual" && + git init fake-virtual-clone && + test_must_fail git -C ./fake-virtual-clone \ + -c core.virtualfilesystem=true \ + fsmonitor--daemon run 2>actual && + grep "virtual repository .* is incompatible with fsmonitor" actual +' + test_expect_success 'setup' ' - mkdir -p .git/hooks && : >tracked && : >modified && mkdir dir1 && @@ -108,7 +139,7 @@ EOF # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook fsmonitor-test<<-\EOF && printf "last_update_token\0" EOF git update-index --fsmonitor && @@ -169,7 +200,7 @@ EOF # test that newly added files are marked valid test_expect_success 'newly added files are marked valid' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --setup --clobber fsmonitor-test<<-\EOF && printf "last_update_token\0" EOF git add new && @@ -210,7 +241,7 @@ EOF # test that *only* files returned by the integration script get flagged as invalid test_expect_success '*only* files returned by the integration script get flagged as invalid' ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --clobber fsmonitor-test<<-\EOF && printf "last_update_token\0" printf "dir1/modified\0" EOF @@ -231,7 +262,7 @@ test_expect_success 'refresh_index() invalidates fsmonitor cache' ' dirty_repo && write_integration_script && git add . && - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --clobber fsmonitor-test<<-\EOF && EOF git commit -m "to reset" && git reset HEAD~1 && @@ -280,7 +311,7 @@ do # Make sure it's actually skipping the check for modified and untracked # (if enabled) files unless it is told about them. test_expect_success "status doesn't detect unreported modifications" ' - write_script .git/hooks/fsmonitor-test<<-\EOF && + test_hook --clobber fsmonitor-test<<-\EOF && printf "last_update_token\0" :>marker EOF @@ -322,7 +353,6 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' test_create_repo dot-git && ( cd dot-git && - mkdir -p .git/hooks && : >tracked && test-tool chmtime =-60 tracked && : >modified && @@ -414,14 +444,14 @@ test_expect_success 'status succeeds with sparse index' ' git -C sparse sparse-checkout init --cone --sparse-index && git -C sparse sparse-checkout set dir1 dir2 && - write_script .git/hooks/fsmonitor-test <<-\EOF && + test_hook --clobber fsmonitor-test <<-\EOF && printf "last_update_token\0" EOF git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test && git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test && check_sparse_index_behavior ! && - write_script .git/hooks/fsmonitor-test <<-\EOF && + test_hook --clobber fsmonitor-test <<-\EOF && printf "last_update_token\0" printf "dir1/modified\0" EOF @@ -439,7 +469,7 @@ test_expect_success 'status succeeds with sparse index' ' # This one modifies outside the sparse-checkout definition # and hence we expect to expand the sparse-index. - write_script .git/hooks/fsmonitor-test <<-\EOF && + test_hook --clobber fsmonitor-test <<-\EOF && printf "last_update_token\0" printf "dir1a/modified\0" EOF diff --git a/t/t7520-ignored-hook-warning.sh b/t/t7520-ignored-hook-warning.sh index 634fb7f..dc57526 100755 --- a/t/t7520-ignored-hook-warning.sh +++ b/t/t7520-ignored-hook-warning.sh @@ -5,10 +5,7 @@ test_description='ignored hook warning' . ./test-lib.sh test_expect_success setup ' - hookdir="$(git rev-parse --git-dir)/hooks" && - hook="$hookdir/pre-commit" && - mkdir -p "$hookdir" && - write_script "$hook" <<-\EOF + test_hook --setup pre-commit <<-\EOF exit 0 EOF ' @@ -19,20 +16,20 @@ test_expect_success 'no warning if hook is not ignored' ' ' test_expect_success POSIXPERM 'warning if hook is ignored' ' - chmod -x "$hook" && + test_hook --disable pre-commit && git commit --allow-empty -m "even more" 2>message && test_i18ngrep -e "hook was ignored" message ' test_expect_success POSIXPERM 'no warning if advice.ignoredHook set to false' ' test_config advice.ignoredHook false && - chmod -x "$hook" && + test_hook --disable pre-commit && git commit --allow-empty -m "even more" 2>message && test_i18ngrep ! -e "hook was ignored" message ' test_expect_success 'no warning if unset advice.ignoredHook and hook removed' ' - rm -f "$hook" && + test_hook --remove pre-commit && test_unconfig advice.ignoredHook && git commit --allow-empty -m "even more" 2>message && test_i18ngrep ! -e "hook was ignored" message diff --git a/t/t7524-commit-summary.sh b/t/t7524-commit-summary.sh new file mode 100755 index 0000000..47b2f1d --- /dev/null +++ b/t/t7524-commit-summary.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +test_description='git commit summary' +. ./test-lib.sh + +test_expect_success 'setup' ' + test_seq 101 200 >file && + git add file && + git commit -m initial && + git tag initial +' + +test_expect_success 'commit summary ignores rewrites' ' + git reset --hard initial && + test_seq 200 300 >file && + + git diff --stat >diffstat && + git diff --stat --break-rewrites >diffstatrewrite && + + # make sure this scenario is a detectable rewrite + ! test_cmp_bin diffstat diffstatrewrite && + + git add file && + git commit -m second >actual && + + grep "1 file" <actual >actual.total && + grep "1 file" <diffstat >diffstat.total && + test_cmp diffstat.total actual.total +' + +test_done diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh new file mode 100755 index 0000000..56c0dff --- /dev/null +++ b/t/t7527-builtin-fsmonitor.sh @@ -0,0 +1,1002 @@ +#!/bin/sh + +test_description='built-in file system watcher' + +. ./test-lib.sh + +if ! test_have_prereq FSMONITOR_DAEMON +then + skip_all="fsmonitor--daemon is not supported on this platform" + test_done +fi + +stop_daemon_delete_repo () { + r=$1 && + test_might_fail git -C $r fsmonitor--daemon stop && + rm -rf $1 +} + +start_daemon () { + r= tf= t2= tk= && + + while test "$#" -ne 0 + do + case "$1" in + -C) + r="-C ${2?}" + shift + ;; + --tf) + tf="${2?}" + shift + ;; + --t2) + t2="${2?}" + shift + ;; + --tk) + tk="${2?}" + shift + ;; + -*) + BUG "error: unknown option: '$1'" + ;; + *) + BUG "error: unbound argument: '$1'" + ;; + esac + shift + done && + + ( + if test -n "$tf" + then + GIT_TRACE_FSMONITOR="$tf" + export GIT_TRACE_FSMONITOR + fi && + + if test -n "$t2" + then + GIT_TRACE2_PERF="$t2" + export GIT_TRACE2_PERF + fi && + + if test -n "$tk" + then + GIT_TEST_FSMONITOR_TOKEN="$tk" + export GIT_TEST_FSMONITOR_TOKEN + fi && + + git $r fsmonitor--daemon start && + git $r fsmonitor--daemon status + ) +} + +# Is a Trace2 data event present with the given catetory and key? +# We do not care what the value is. +# +have_t2_data_event () { + c=$1 && + k=$2 && + + grep -e '"event":"data".*"category":"'"$c"'".*"key":"'"$k"'"' +} + +test_expect_success 'explicit daemon start and stop' ' + test_when_finished "stop_daemon_delete_repo test_explicit" && + + git init test_explicit && + start_daemon -C test_explicit && + + git -C test_explicit fsmonitor--daemon stop && + test_must_fail git -C test_explicit fsmonitor--daemon status +' + +test_expect_success 'implicit daemon start' ' + test_when_finished "stop_daemon_delete_repo test_implicit" && + + git init test_implicit && + test_must_fail git -C test_implicit fsmonitor--daemon status && + + # query will implicitly start the daemon. + # + # for test-script simplicity, we send a V1 timestamp rather than + # a V2 token. either way, the daemon response to any query contains + # a new V2 token. (the daemon may complain that we sent a V1 request, + # but this test case is only concerned with whether the daemon was + # implicitly started.) + + GIT_TRACE2_EVENT="$PWD/.git/trace" \ + test-tool -C test_implicit fsmonitor-client query --token 0 >actual && + nul_to_q <actual >actual.filtered && + grep "builtin:" actual.filtered && + + # confirm that a daemon was started in the background. + # + # since the mechanism for starting the background daemon is platform + # dependent, just confirm that the foreground command received a + # response from the daemon. + + have_t2_data_event fsm_client query/response-length <.git/trace && + + git -C test_implicit fsmonitor--daemon status && + git -C test_implicit fsmonitor--daemon stop && + test_must_fail git -C test_implicit fsmonitor--daemon status +' + +# Verify that the daemon has shutdown. Spin a few seconds to +# make the test a little more robust during CI testing. +# +# We're looking for an implicit shutdown, such as when we delete or +# rename the ".git" directory. Our delete/rename will cause a file +# system event that the daemon will see and the daemon will +# auto-shutdown as soon as it sees it. But this is racy with our `git +# fsmonitor--daemon status` commands (and we cannot use a cookie file +# here to help us). So spin a little and give the daemon a chance to +# see the event. (This is primarily for underpowered CI build/test +# machines (where it might take a moment to wake and reschedule the +# daemon process) to avoid false alarms during test runs.) +# +IMPLICIT_TIMEOUT=5 + +verify_implicit_shutdown () { + r=$1 && + + k=0 && + while test "$k" -lt $IMPLICIT_TIMEOUT + do + git -C $r fsmonitor--daemon status || return 0 + + sleep 1 + k=$(( $k + 1 )) + done && + + return 1 +} + +test_expect_success 'implicit daemon stop (delete .git)' ' + test_when_finished "stop_daemon_delete_repo test_implicit_1" && + + git init test_implicit_1 && + + start_daemon -C test_implicit_1 && + + # deleting the .git directory will implicitly stop the daemon. + rm -rf test_implicit_1/.git && + + # [1] Create an empty .git directory so that the following Git + # command will stay relative to the `-C` directory. + # + # Without this, the Git command will override the requested + # -C argument and crawl out to the containing Git source tree. + # This would make the test result dependent upon whether we + # were using fsmonitor on our development worktree. + # + mkdir test_implicit_1/.git && + + verify_implicit_shutdown test_implicit_1 +' + +test_expect_success 'implicit daemon stop (rename .git)' ' + test_when_finished "stop_daemon_delete_repo test_implicit_2" && + + git init test_implicit_2 && + + start_daemon -C test_implicit_2 && + + # renaming the .git directory will implicitly stop the daemon. + mv test_implicit_2/.git test_implicit_2/.xxx && + + # See [1] above. + # + mkdir test_implicit_2/.git && + + verify_implicit_shutdown test_implicit_2 +' + +# File systems on Windows may or may not have shortnames. +# This is a volume-specific setting on modern systems. +# "C:/" drives are required to have them enabled. Other +# hard drives default to disabled. +# +# This is a crude test to see if shortnames are enabled +# on the volume containing the test directory. It is +# crude, but it does not require elevation like `fsutil`. +# +test_lazy_prereq SHORTNAMES ' + mkdir .foo && + test -d "FOO~1" +' + +# Here we assume that the shortname of ".git" is "GIT~1". +test_expect_success MINGW,SHORTNAMES 'implicit daemon stop (rename GIT~1)' ' + test_when_finished "stop_daemon_delete_repo test_implicit_1s" && + + git init test_implicit_1s && + + start_daemon -C test_implicit_1s && + + # renaming the .git directory will implicitly stop the daemon. + # this moves {.git, GIT~1} to {.gitxyz, GITXYZ~1}. + # the rename-from FS Event will contain the shortname. + # + mv test_implicit_1s/GIT~1 test_implicit_1s/.gitxyz && + + # See [1] above. + # this moves {.gitxyz, GITXYZ~1} to {.git, GIT~1}. + mv test_implicit_1s/.gitxyz test_implicit_1s/.git && + + verify_implicit_shutdown test_implicit_1s +' + +# Here we first create a file with LONGNAME of "GIT~1" before +# we create the repo. This will cause the shortname of ".git" +# to be "GIT~2". +test_expect_success MINGW,SHORTNAMES 'implicit daemon stop (rename GIT~2)' ' + test_when_finished "stop_daemon_delete_repo test_implicit_1s2" && + + mkdir test_implicit_1s2 && + echo HELLO >test_implicit_1s2/GIT~1 && + git init test_implicit_1s2 && + + test_path_is_file test_implicit_1s2/GIT~1 && + test_path_is_dir test_implicit_1s2/GIT~2 && + + start_daemon -C test_implicit_1s2 && + + # renaming the .git directory will implicitly stop the daemon. + # the rename-from FS Event will contain the shortname. + # + mv test_implicit_1s2/GIT~2 test_implicit_1s2/.gitxyz && + + # See [1] above. + mv test_implicit_1s2/.gitxyz test_implicit_1s2/.git && + + verify_implicit_shutdown test_implicit_1s2 +' + +test_expect_success 'cannot start multiple daemons' ' + test_when_finished "stop_daemon_delete_repo test_multiple" && + + git init test_multiple && + + start_daemon -C test_multiple && + + test_must_fail git -C test_multiple fsmonitor--daemon start 2>actual && + grep "fsmonitor--daemon is already running" actual && + + git -C test_multiple fsmonitor--daemon stop && + test_must_fail git -C test_multiple fsmonitor--daemon status +' + +# These tests use the main repo in the trash directory + +test_expect_success 'setup' ' + >tracked && + >modified && + >delete && + >rename && + mkdir dir1 && + >dir1/tracked && + >dir1/modified && + >dir1/delete && + >dir1/rename && + mkdir dir2 && + >dir2/tracked && + >dir2/modified && + >dir2/delete && + >dir2/rename && + mkdir dirtorename && + >dirtorename/a && + >dirtorename/b && + + cat >.gitignore <<-\EOF && + .gitignore + expect* + actual* + flush* + trace* + EOF + + mkdir -p T1/T2/T3/T4 && + echo 1 >T1/F1 && + echo 1 >T1/T2/F1 && + echo 1 >T1/T2/T3/F1 && + echo 1 >T1/T2/T3/T4/F1 && + echo 2 >T1/F2 && + echo 2 >T1/T2/F2 && + echo 2 >T1/T2/T3/F2 && + echo 2 >T1/T2/T3/T4/F2 && + + git -c core.fsmonitor=false add . && + test_tick && + git -c core.fsmonitor=false commit -m initial && + + git config core.fsmonitor true +' + +# The test already explicitly stopped (or tried to stop) the daemon. +# This is here in case something else fails first. +# +redundant_stop_daemon () { + test_might_fail git fsmonitor--daemon stop +} + +test_expect_success 'update-index implicitly starts daemon' ' + test_when_finished redundant_stop_daemon && + + test_must_fail git fsmonitor--daemon status && + + GIT_TRACE2_EVENT="$PWD/.git/trace_implicit_1" \ + git update-index --fsmonitor && + + git fsmonitor--daemon status && + test_might_fail git fsmonitor--daemon stop && + + # Confirm that the trace2 log contains a record of the + # daemon starting. + test_subcommand git fsmonitor--daemon start <.git/trace_implicit_1 +' + +test_expect_success 'status implicitly starts daemon' ' + test_when_finished redundant_stop_daemon && + + test_must_fail git fsmonitor--daemon status && + + GIT_TRACE2_EVENT="$PWD/.git/trace_implicit_2" \ + git status >actual && + + git fsmonitor--daemon status && + test_might_fail git fsmonitor--daemon stop && + + # Confirm that the trace2 log contains a record of the + # daemon starting. + test_subcommand git fsmonitor--daemon start <.git/trace_implicit_2 +' + +edit_files () { + echo 1 >modified && + echo 2 >dir1/modified && + echo 3 >dir2/modified && + >dir1/untracked +} + +delete_files () { + rm -f delete && + rm -f dir1/delete && + rm -f dir2/delete +} + +create_files () { + echo 1 >new && + echo 2 >dir1/new && + echo 3 >dir2/new +} + +rename_files () { + mv rename renamed && + mv dir1/rename dir1/renamed && + mv dir2/rename dir2/renamed +} + +file_to_directory () { + rm -f delete && + mkdir delete && + echo 1 >delete/new +} + +directory_to_file () { + rm -rf dir1 && + echo 1 >dir1 +} + +move_directory_contents_deeper() { + mkdir T1/_new_ && + mv T1/[A-Z]* T1/_new_ +} + +move_directory_up() { + mv T1/T2/T3 T1 +} + +move_directory() { + mv T1/T2/T3 T1/T2/NewT3 +} + +# The next few test cases confirm that our fsmonitor daemon sees each type +# of OS filesystem notification that we care about. At this layer we just +# ensure we are getting the OS notifications and do not try to confirm what +# is reported by `git status`. +# +# We run a simple query after modifying the filesystem just to introduce +# a bit of a delay so that the trace logging from the daemon has time to +# get flushed to disk. +# +# We `reset` and `clean` at the bottom of each test (and before stopping the +# daemon) because these commands might implicitly restart the daemon. + +clean_up_repo_and_stop_daemon () { + git reset --hard HEAD && + git clean -fd && + test_might_fail git fsmonitor--daemon stop && + rm -f .git/trace +} + +test_expect_success 'edit some files' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + edit_files && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: dir1/modified$" .git/trace && + grep "^event: dir2/modified$" .git/trace && + grep "^event: modified$" .git/trace && + grep "^event: dir1/untracked$" .git/trace +' + +test_expect_success 'create some files' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + create_files && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: dir1/new$" .git/trace && + grep "^event: dir2/new$" .git/trace && + grep "^event: new$" .git/trace +' + +test_expect_success 'delete some files' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + delete_files && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: dir1/delete$" .git/trace && + grep "^event: dir2/delete$" .git/trace && + grep "^event: delete$" .git/trace +' + +test_expect_success 'rename some files' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + rename_files && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: dir1/rename$" .git/trace && + grep "^event: dir2/rename$" .git/trace && + grep "^event: rename$" .git/trace && + grep "^event: dir1/renamed$" .git/trace && + grep "^event: dir2/renamed$" .git/trace && + grep "^event: renamed$" .git/trace +' + +test_expect_success 'rename directory' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + mv dirtorename dirrenamed && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: dirtorename/*$" .git/trace && + grep "^event: dirrenamed/*$" .git/trace +' + +test_expect_success 'file changes to directory' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + file_to_directory && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: delete$" .git/trace && + grep "^event: delete/new$" .git/trace +' + +test_expect_success 'directory changes to a file' ' + test_when_finished clean_up_repo_and_stop_daemon && + + start_daemon --tf "$PWD/.git/trace" && + + directory_to_file && + + test-tool fsmonitor-client query --token 0 && + + grep "^event: dir1$" .git/trace +' + +# The next few test cases exercise the token-resync code. When filesystem +# drops events (because of filesystem velocity or because the daemon isn't +# polling fast enough), we need to discard the cached data (relative to the +# current token) and start collecting events under a new token. +# +# the 'test-tool fsmonitor-client flush' command can be used to send a +# "flush" message to a running daemon and ask it to do a flush/resync. + +test_expect_success 'flush cached data' ' + test_when_finished "stop_daemon_delete_repo test_flush" && + + git init test_flush && + + start_daemon -C test_flush --tf "$PWD/.git/trace_daemon" --tk true && + + # The daemon should have an initial token with no events in _0 and + # then a few (probably platform-specific number of) events in _1. + # These should both have the same <token_id>. + + test-tool -C test_flush fsmonitor-client query --token "builtin:test_00000001:0" >actual_0 && + nul_to_q <actual_0 >actual_q0 && + + >test_flush/file_1 && + >test_flush/file_2 && + + test-tool -C test_flush fsmonitor-client query --token "builtin:test_00000001:0" >actual_1 && + nul_to_q <actual_1 >actual_q1 && + + grep "file_1" actual_q1 && + + # Force a flush. This will change the <token_id>, reset the <seq_nr>, and + # flush the file data. Then create some events and ensure that the file + # again appears in the cache. It should have the new <token_id>. + + test-tool -C test_flush fsmonitor-client flush >flush_0 && + nul_to_q <flush_0 >flush_q0 && + grep "^builtin:test_00000002:0Q/Q$" flush_q0 && + + test-tool -C test_flush fsmonitor-client query --token "builtin:test_00000002:0" >actual_2 && + nul_to_q <actual_2 >actual_q2 && + + grep "^builtin:test_00000002:0Q$" actual_q2 && + + >test_flush/file_3 && + + test-tool -C test_flush fsmonitor-client query --token "builtin:test_00000002:0" >actual_3 && + nul_to_q <actual_3 >actual_q3 && + + grep "file_3" actual_q3 +' + +# The next few test cases create repos where the .git directory is NOT +# inside the one of the working directory. That is, where .git is a file +# that points to a directory elsewhere. This happens for submodules and +# non-primary worktrees. + +test_expect_success 'setup worktree base' ' + git init wt-base && + echo 1 >wt-base/file1 && + git -C wt-base add file1 && + git -C wt-base commit -m "c1" +' + +test_expect_success 'worktree with .git file' ' + git -C wt-base worktree add ../wt-secondary && + + start_daemon -C wt-secondary \ + --tf "$PWD/trace_wt_secondary" \ + --t2 "$PWD/trace2_wt_secondary" && + + git -C wt-secondary fsmonitor--daemon stop && + test_must_fail git -C wt-secondary fsmonitor--daemon status +' + +# NEEDSWORK: Repeat one of the "edit" tests on wt-secondary and +# confirm that we get the same events and behavior -- that is, that +# fsmonitor--daemon correctly watches BOTH the working directory and +# the external GITDIR directory and behaves the same as when ".git" +# is a directory inside the working directory. + +test_expect_success 'cleanup worktrees' ' + stop_daemon_delete_repo wt-secondary && + stop_daemon_delete_repo wt-base +' + +# The next few tests perform arbitrary/contrived file operations and +# confirm that status is correct. That is, that the data (or lack of +# data) from fsmonitor doesn't cause incorrect results. And doesn't +# cause incorrect results when the untracked-cache is enabled. + +test_lazy_prereq UNTRACKED_CACHE ' + git update-index --test-untracked-cache +' + +test_expect_success 'Matrix: setup for untracked-cache,fsmonitor matrix' ' + test_unconfig core.fsmonitor && + git update-index --no-fsmonitor && + test_might_fail git fsmonitor--daemon stop +' + +matrix_clean_up_repo () { + git reset --hard HEAD && + git clean -fd +} + +matrix_try () { + uc=$1 && + fsm=$2 && + fn=$3 && + + if test $uc = true && test $fsm = false + then + # The untracked-cache is buggy when FSMonitor is + # DISABLED, so skip the tests for this matrix + # combination. + # + # We've observed random, occasional test failures on + # Windows and MacOS when the UC is turned on and FSM + # is turned off. These are rare, but they do happen + # indicating that it is probably a race condition within + # the untracked cache itself. + # + # It usually happens when a test does F/D trickery and + # then the NEXT test fails because of extra status + # output from stale UC data from the previous test. + # + # Since FSMonitor is not involved in the error, skip + # the tests for this matrix combination. + # + return 0 + fi && + + test_expect_success "Matrix[uc:$uc][fsm:$fsm] $fn" ' + matrix_clean_up_repo && + $fn && + if test $uc = false && test $fsm = false + then + git status --porcelain=v1 >.git/expect.$fn + else + git status --porcelain=v1 >.git/actual.$fn && + test_cmp .git/expect.$fn .git/actual.$fn + fi + ' +} + +uc_values="false" +test_have_prereq UNTRACKED_CACHE && uc_values="false true" +for uc_val in $uc_values +do + if test $uc_val = false + then + test_expect_success "Matrix[uc:$uc_val] disable untracked cache" ' + git config core.untrackedcache false && + git update-index --no-untracked-cache + ' + else + test_expect_success "Matrix[uc:$uc_val] enable untracked cache" ' + git config core.untrackedcache true && + git update-index --untracked-cache + ' + fi + + fsm_values="false true" + for fsm_val in $fsm_values + do + if test $fsm_val = false + then + test_expect_success "Matrix[uc:$uc_val][fsm:$fsm_val] disable fsmonitor" ' + test_unconfig core.fsmonitor && + git update-index --no-fsmonitor && + test_might_fail git fsmonitor--daemon stop + ' + else + test_expect_success "Matrix[uc:$uc_val][fsm:$fsm_val] enable fsmonitor" ' + git config core.fsmonitor true && + git fsmonitor--daemon start && + git update-index --fsmonitor + ' + fi + + matrix_try $uc_val $fsm_val edit_files + matrix_try $uc_val $fsm_val delete_files + matrix_try $uc_val $fsm_val create_files + matrix_try $uc_val $fsm_val rename_files + matrix_try $uc_val $fsm_val file_to_directory + matrix_try $uc_val $fsm_val directory_to_file + + matrix_try $uc_val $fsm_val move_directory_contents_deeper + matrix_try $uc_val $fsm_val move_directory_up + matrix_try $uc_val $fsm_val move_directory + + if test $fsm_val = true + then + test_expect_success "Matrix[uc:$uc_val][fsm:$fsm_val] disable fsmonitor at end" ' + test_unconfig core.fsmonitor && + git update-index --no-fsmonitor && + test_might_fail git fsmonitor--daemon stop + ' + fi + done +done + +# Test Unicode UTF-8 characters in the pathname of the working +# directory root. Use of "*A()" routines rather than "*W()" routines +# on Windows can sometimes lead to odd failures. +# +u1=$(printf "u_c3_a6__\xC3\xA6") +u2=$(printf "u_e2_99_ab__\xE2\x99\xAB") +u_values="$u1 $u2" +for u in $u_values +do + test_expect_success "unicode in repo root path: $u" ' + test_when_finished "stop_daemon_delete_repo $u" && + + git init "$u" && + echo 1 >"$u"/file1 && + git -C "$u" add file1 && + git -C "$u" config core.fsmonitor true && + + start_daemon -C "$u" && + git -C "$u" status >actual && + grep "new file: file1" actual + ' +done + +# Test fsmonitor interaction with submodules. +# +# If we start the daemon in the super, it will see FS events for +# everything in the working directory cone and this includes any +# files/directories contained *within* the submodules. +# +# A `git status` at top level will get events for items within the +# submodule and ignore them, since they aren't named in the index +# of the super repo. This makes the fsmonitor response a little +# noisy, but it doesn't alter the correctness of the state of the +# super-proper. +# +# When we have submodules, `git status` normally does a recursive +# status on each of the submodules and adds a summary row for any +# dirty submodules. (See the "S..." bits in porcelain V2 output.) +# +# It is therefore important that the top level status not be tricked +# by the FSMonitor response to skip those recursive calls. That is, +# even if FSMonitor says that the mtime of the submodule directory +# hasn't changed and it could be implicitly marked valid, we must +# not take that shortcut. We need to force the recusion into the +# submodule so that we get a summary of the status *within* the +# submodule. + +create_super () { + super="$1" && + + git init "$super" && + echo x >"$super/file_1" && + echo y >"$super/file_2" && + echo z >"$super/file_3" && + mkdir "$super/dir_1" && + echo a >"$super/dir_1/file_11" && + echo b >"$super/dir_1/file_12" && + mkdir "$super/dir_1/dir_2" && + echo a >"$super/dir_1/dir_2/file_21" && + echo b >"$super/dir_1/dir_2/file_22" && + git -C "$super" add . && + git -C "$super" commit -m "initial $super commit" +} + +create_sub () { + sub="$1" && + + git init "$sub" && + echo x >"$sub/file_x" && + echo y >"$sub/file_y" && + echo z >"$sub/file_z" && + mkdir "$sub/dir_x" && + echo a >"$sub/dir_x/file_a" && + echo b >"$sub/dir_x/file_b" && + mkdir "$sub/dir_x/dir_y" && + echo a >"$sub/dir_x/dir_y/file_a" && + echo b >"$sub/dir_x/dir_y/file_b" && + git -C "$sub" add . && + git -C "$sub" commit -m "initial $sub commit" +} + +my_match_and_clean () { + git -C super --no-optional-locks status --porcelain=v2 >actual.with && + git -C super --no-optional-locks -c core.fsmonitor=false \ + status --porcelain=v2 >actual.without && + test_cmp actual.with actual.without && + + git -C super/dir_1/dir_2/sub reset --hard && + git -C super/dir_1/dir_2/sub clean -d -f +} + +test_expect_success 'submodule always visited' ' + test_when_finished "git -C super fsmonitor--daemon stop; \ + rm -rf super; \ + rm -rf sub" && + + create_super super && + create_sub sub && + + git -C super submodule add ../sub ./dir_1/dir_2/sub && + git -C super commit -m "add sub" && + + start_daemon -C super && + git -C super config core.fsmonitor true && + git -C super update-index --fsmonitor && + git -C super status && + + # Now run pairs of commands w/ and w/o FSMonitor while we make + # some dirt in the submodule and confirm matching output. + + # Completely clean status. + my_match_and_clean && + + # .M S..U + echo z >super/dir_1/dir_2/sub/dir_x/dir_y/foobar_u && + my_match_and_clean && + + # .M S.M. + echo z >super/dir_1/dir_2/sub/dir_x/dir_y/foobar_m && + git -C super/dir_1/dir_2/sub add . && + my_match_and_clean && + + # .M S.M. + echo z >>super/dir_1/dir_2/sub/dir_x/dir_y/file_a && + git -C super/dir_1/dir_2/sub add . && + my_match_and_clean && + + # .M SC.. + echo z >>super/dir_1/dir_2/sub/dir_x/dir_y/file_a && + git -C super/dir_1/dir_2/sub add . && + git -C super/dir_1/dir_2/sub commit -m "SC.." && + my_match_and_clean +' + +# If a submodule has a `sub/.git/` directory (rather than a file +# pointing to the super's `.git/modules/sub`) and `core.fsmonitor` +# turned on in the submodule and the daemon is not yet started in +# the submodule, and someone does a `git submodule absorbgitdirs` +# in the super, Git will recursively invoke `git submodule--helper` +# to do the work and this may try to read the index. This will +# try to start the daemon in the submodule *and* pass (either +# directly or via inheritance) the `--super-prefix` arg to the +# `git fsmonitor--daemon start` command inside the submodule. +# This causes a warning because fsmonitor--daemon does take that +# global arg (see the table in git.c) +# +# This causes a warning when trying to start the daemon that is +# somewhat confusing. It does not seem to hurt anything because +# the fsmonitor code maps the query failure into a trivial response +# and does the work anyway. +# +# It would be nice to silence the warning, however. + +have_t2_error_event () { + log=$1 + msg="fsmonitor--daemon doesnQt support --super-prefix" && + + tr '\047' Q <$1 | grep -e "$msg" +} + +test_expect_success "stray submodule super-prefix warning" ' + test_when_finished "rm -rf super; \ + rm -rf sub; \ + rm super-sub.trace" && + + create_super super && + create_sub sub && + + # Copy rather than submodule add so that we get a .git dir. + cp -R ./sub ./super/dir_1/dir_2/sub && + + git -C super/dir_1/dir_2/sub config core.fsmonitor true && + + git -C super submodule add ../sub ./dir_1/dir_2/sub && + git -C super commit -m "add sub" && + + test_path_is_dir super/dir_1/dir_2/sub/.git && + + GIT_TRACE2_EVENT="$PWD/super-sub.trace" \ + git -C super submodule absorbgitdirs && + + ! have_t2_error_event super-sub.trace +' + +# On a case-insensitive file system, confirm that the daemon +# notices when the .git directory is moved/renamed/deleted +# regardless of how it is spelled in the the FS event. +# That is, does the FS event receive the spelling of the +# operation or does it receive the spelling preserved with +# the file/directory. +# +test_expect_success CASE_INSENSITIVE_FS 'case insensitive+preserving' ' +# test_when_finished "stop_daemon_delete_repo test_insensitive" && + + git init test_insensitive && + + start_daemon -C test_insensitive --tf "$PWD/insensitive.trace" && + + mkdir -p test_insensitive/abc/def && + echo xyz >test_insensitive/ABC/DEF/xyz && + + test_path_is_dir test_insensitive/.git && + test_path_is_dir test_insensitive/.GIT && + + # Rename .git using an alternate spelling to verify that that + # daemon detects it and automatically shuts down. + mv test_insensitive/.GIT test_insensitive/.FOO && + + # See [1] above. + mv test_insensitive/.FOO test_insensitive/.git && + + verify_implicit_shutdown test_insensitive && + + # Verify that events were reported using on-disk spellings of the + # directories and files that we touched. We may or may not get a + # trailing slash on modified directories. + # + egrep "^event: abc/?$" ./insensitive.trace && + egrep "^event: abc/def/?$" ./insensitive.trace && + egrep "^event: abc/def/xyz$" ./insensitive.trace +' + +# The variable "unicode_debug" is defined in the following library +# script to dump information about how the (OS, FS) handles Unicode +# composition. Uncomment the following line if you want to enable it. +# +# unicode_debug=true + +. "$TEST_DIRECTORY/lib-unicode-nfc-nfd.sh" + +# See if the OS or filesystem does NFC/NFD aliasing/munging. +# +# The daemon should err on the side of caution and send BOTH the +# NFC and NFD forms. It does not know the original spelling of +# the pathname (how the user thinks it should be spelled), so +# emit both and let the client decide (when necessary). This is +# similar to "core.precomposeUnicode". +# +test_expect_success !UNICODE_COMPOSITION_SENSITIVE 'Unicode nfc/nfd' ' + test_when_finished "stop_daemon_delete_repo test_unicode" && + + git init test_unicode && + + start_daemon -C test_unicode --tf "$PWD/unicode.trace" && + + # Create a directory using an NFC spelling. + # + mkdir test_unicode/nfc && + mkdir test_unicode/nfc/c_${utf8_nfc} && + + # Create a directory using an NFD spelling. + # + mkdir test_unicode/nfd && + mkdir test_unicode/nfd/d_${utf8_nfd} && + + git -C test_unicode fsmonitor--daemon stop && + + if test_have_prereq UNICODE_NFC_PRESERVED + then + # We should have seen NFC event from OS. + # We should not have synthesized an NFD event. + egrep "^event: nfc/c_${utf8_nfc}/?$" ./unicode.trace && + egrep -v "^event: nfc/c_${utf8_nfd}/?$" ./unicode.trace + else + # We should have seen NFD event from OS. + # We should have synthesized an NFC event. + egrep "^event: nfc/c_${utf8_nfd}/?$" ./unicode.trace && + egrep "^event: nfc/c_${utf8_nfc}/?$" ./unicode.trace + fi && + + # We assume UNICODE_NFD_PRESERVED. + # We should have seen explicit NFD from OS. + # We should have synthesized an NFC event. + egrep "^event: nfd/d_${utf8_nfd}/?$" ./unicode.trace && + egrep "^event: nfd/d_${utf8_nfc}/?$" ./unicode.trace +' + +test_done diff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh new file mode 100755 index 0000000..330d6d6 --- /dev/null +++ b/t/t7609-mergetool--lib.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +test_description='git mergetool + +Testing basic merge tools options' + +. ./test-lib.sh + +test_expect_success 'mergetool --tool=vimdiff creates the expected layout' ' + . "$GIT_BUILD_DIR"/mergetools/vimdiff && + run_unit_tests +' + +test_done diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 770d143..ca45c4c 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -369,10 +369,61 @@ test_expect_success '--write-midx with preferred bitmap tips' ' ) ' +# The first argument is expected to be a filename +# and that file should contain the name of a .idx +# file. Send the list of objects in that .idx file +# into stdout. +get_sorted_objects_from_pack () { + git show-index <$(cat "$1") >raw && + cut -d" " -f2 raw +} + test_expect_success '--write-midx -b packs non-kept objects' ' - GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ - git repack --write-midx -a -b && - test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt + git init repo && + test_when_finished "rm -fr repo" && + ( + cd repo && + + # Create a kept pack-file + test_commit base && + git repack -ad && + find $objdir/pack -name "*.idx" >before && + test_line_count = 1 before && + before_name=$(cat before) && + >${before_name%.idx}.keep && + + # Create a non-kept pack-file + test_commit other && + git repack && + + # Create loose objects + test_commit loose && + + # Repack everything + git repack --write-midx -a -b -d && + + # There should be two pack-files now, the + # old, kept pack and the new, non-kept pack. + find $objdir/pack -name "*.idx" | sort >after && + test_line_count = 2 after && + find $objdir/pack -name "*.keep" >kept && + kept_name=$(cat kept) && + echo ${kept_name%.keep}.idx >kept-idx && + test_cmp before kept-idx && + + # Get object list from the kept pack. + get_sorted_objects_from_pack before >old.objects && + + # Get object list from the one non-kept pack-file + comm -13 before after >new-pack && + test_line_count = 1 new-pack && + get_sorted_objects_from_pack new-pack >new.objects && + + # None of the objects in the new pack should + # exist within the kept pack. + comm -12 old.objects new.objects >shared.objects && + test_must_be_empty shared.objects + ) ' test_expect_success TTY '--quiet disables progress' ' diff --git a/t/t7702-repack-cyclic-alternate.sh b/t/t7702-repack-cyclic-alternate.sh index 93b7486..f3cdb98 100755 --- a/t/t7702-repack-cyclic-alternate.sh +++ b/t/t7702-repack-cyclic-alternate.sh @@ -4,6 +4,8 @@ # test_description='repack involving cyclic alternate' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' diff --git a/t/t7703-repack-geometric.sh b/t/t7703-repack-geometric.sh index bdbbcbf..da87f8b 100755 --- a/t/t7703-repack-geometric.sh +++ b/t/t7703-repack-geometric.sh @@ -7,6 +7,7 @@ test_description='git repack --geometric works correctly' GIT_TEST_MULTI_PACK_INDEX=0 objdir=.git/objects +packdir=$objdir/pack midx=$objdir/pack/multi-pack-index test_expect_success '--geometric with no packs' ' @@ -180,6 +181,34 @@ test_expect_success '--geometric ignores kept packs' ' ) ' +test_expect_success '--geometric ignores --keep-pack packs' ' + git init geometric && + test_when_finished "rm -fr geometric" && + ( + cd geometric && + + # Create two equal-sized packs + test_commit kept && # 3 objects + git repack -d && + test_commit pack && # 3 objects + git repack -d && + + find $objdir/pack -type f -name "*.pack" | sort >packs.before && + git repack --geometric 2 -dm \ + --keep-pack="$(basename "$(head -n 1 packs.before)")" >out && + find $objdir/pack -type f -name "*.pack" | sort >packs.after && + + # Packs should not have changed (only one non-kept pack, no + # loose objects), but $midx should now exist. + grep "Nothing new to pack" out && + test_path_is_file $midx && + + test_cmp packs.before packs.after && + + git fsck + ) +' + test_expect_success '--geometric chooses largest MIDX preferred pack' ' git init geometric && test_when_finished "rm -fr geometric" && @@ -202,4 +231,50 @@ test_expect_success '--geometric chooses largest MIDX preferred pack' ' ) ' +test_expect_success '--geometric with pack.packSizeLimit' ' + git init pack-rewrite && + test_when_finished "rm -fr pack-rewrite" && + ( + cd pack-rewrite && + + test-tool genrandom foo 1048576 >foo && + test-tool genrandom bar 1048576 >bar && + + git add foo bar && + test_tick && + git commit -m base && + + git rev-parse HEAD:foo HEAD:bar >p1.objects && + git rev-parse HEAD HEAD^{tree} >p2.objects && + + # These two packs each contain two objects, so the following + # `--geometric` repack will try to combine them. + p1="$(git pack-objects $packdir/pack <p1.objects)" && + p2="$(git pack-objects $packdir/pack <p2.objects)" && + + # Remove any loose objects in packs, since we do not want extra + # copies around (which would mask over potential object + # corruption issues). + git prune-packed && + + # Both p1 and p2 will be rolled up, but pack-objects will write + # three packs: + # + # - one containing object "foo", + # - another containing object "bar", + # - a final pack containing the commit and tree objects + # (identical to p2 above) + git repack --geometric 2 -d --max-pack-size=1048576 && + + # Ensure `repack` can detect that the third pack it wrote + # (containing just the tree and commit objects) was identical to + # one that was below the geometric split, so that we can save it + # from deletion. + # + # If `repack` fails to do that, we will incorrectly delete p2, + # causing object corruption. + git fsck + ) +' + test_done diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 6935601..0f93799 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -77,6 +77,7 @@ test_expect_success setup ' # Say hello. function hello() { echo "Hello world." + echo "Hello again." } # hello # Still a no-op. @@ -595,6 +596,92 @@ test_expect_success 'grep --files-without-match --quiet' ' test_must_be_empty actual ' +test_expect_success 'grep --max-count 0 (must exit with non-zero)' ' + test_must_fail git grep --max-count 0 foo >actual && + test_must_be_empty actual +' + +test_expect_success 'grep --max-count 3' ' + cat >expected <<-EOF && + file:foo mmap bar + file:foo_mmap bar + file:foo_mmap bar mmap + EOF + git grep --max-count 3 foo >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count -1 (no limit)' ' + cat >expected <<-EOF && + file:foo mmap bar + file:foo_mmap bar + file:foo_mmap bar mmap + file:foo mmap bar_mmap + file:foo_mmap bar mmap baz + EOF + git grep --max-count -1 foo >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count 1 --context 2' ' + cat >expected <<-EOF && + file-foo mmap bar + file:foo_mmap bar + file-foo_mmap bar mmap + EOF + git grep --max-count 1 --context 1 foo_mmap >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count 1 --show-function' ' + cat >expected <<-EOF && + hello.ps1=function hello() { + hello.ps1: echo "Hello world." + EOF + git grep --max-count 1 --show-function Hello hello.ps1 >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count 2 --show-function' ' + cat >expected <<-EOF && + hello.ps1=function hello() { + hello.ps1: echo "Hello world." + hello.ps1: echo "Hello again." + EOF + git grep --max-count 2 --show-function Hello hello.ps1 >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count 1 --count' ' + cat >expected <<-EOF && + hello.ps1:1 + EOF + git grep --max-count 1 --count Hello hello.ps1 >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count 1 (multiple files)' ' + cat >expected <<-EOF && + hello.c:#include <stdio.h> + hello.ps1:# No-op. + EOF + git grep --max-count 1 -e o -- hello.\* >actual && + test_cmp expected actual +' + +test_expect_success 'grep --max-count 1 --context 1 (multiple files)' ' + cat >expected <<-EOF && + hello.c-#include <assert.h> + hello.c:#include <stdio.h> + hello.c- + -- + hello.ps1:# No-op. + hello.ps1-function dummy() {} + EOF + git grep --max-count 1 --context 1 -e o -- hello.\* >actual && + test_cmp expected actual +' + cat >expected <<EOF file:foo mmap bar_mmap EOF diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh index 9047d66..31c66b6 100755 --- a/t/t7812-grep-icase-non-ascii.sh +++ b/t/t7812-grep-icase-non-ascii.sh @@ -2,8 +2,13 @@ test_description='grep icase on non-English locales' +TEST_PASSES_SANITIZE_LEAK=true . ./lib-gettext.sh +doalarm () { + perl -e 'alarm shift; exec @ARGV' -- "$@" +} + test_expect_success GETTEXT_LOCALE 'setup' ' test_write_lines "TILRAUN: Halló Heimur!" >file && git add file && @@ -139,4 +144,10 @@ test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-literal ASCII fro test_cmp expected actual ' +test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep avoid endless loop bug' ' + echo " Halló" >leading-whitespace && + git add leading-whitespace && + doalarm 1 git grep --perl-regexp "^\s" leading-whitespace +' + test_done diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh index a4476dc..3ad8052 100755 --- a/t/t7814-grep-recurse-submodules.sh +++ b/t/t7814-grep-recurse-submodules.sh @@ -6,6 +6,7 @@ This test verifies the recurse-submodules feature correctly greps across submodules. ' +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 @@ -471,8 +472,10 @@ test_expect_failure 'grep --textconv: superproject .gitattributes (from index) d test_expect_failure 'grep --textconv: superproject .git/info/attributes does not affect submodules' ' reset_and_clean && test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && - super_attr="$(git rev-parse --git-path info/attributes)" && + super_info="$(git rev-parse --git-path info)" && + super_attr="$super_info/attributes" && test_when_finished "rm -f \"$super_attr\"" && + mkdir "$super_info" && echo "a diff=d2x" >"$super_attr" && cat >expect <<-\EOF && @@ -516,7 +519,8 @@ test_expect_failure 'grep --textconv correctly reads submodule .git/info/attribu reset_and_clean && test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && - submodule_attr="$(git -C submodule rev-parse --path-format=absolute --git-path info/attributes)" && + submodule_info="$(git -C submodule rev-parse --path-format=absolute --git-path info)" && + submodule_attr="$submodule_info/attributes" && test_when_finished "rm -f \"$submodule_attr\"" && echo "a diff=d2x" >"$submodule_attr" && diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh index a536a62..d7167f5 100755 --- a/t/t8001-annotate.sh +++ b/t/t8001-annotate.sh @@ -4,6 +4,7 @@ test_description='git annotate' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh PROG='git annotate' diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh index ee4fdd8..0147de3 100755 --- a/t/t8002-blame.sh +++ b/t/t8002-blame.sh @@ -4,6 +4,7 @@ test_description='git blame' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh PROG='git blame -c' diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh index b067983..c8266f1 100755 --- a/t/t8007-cat-file-textconv.sh +++ b/t/t8007-cat-file-textconv.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git cat-file textconv support' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >helper <<'EOF' diff --git a/t/t8010-cat-file-filters.sh b/t/t8010-cat-file-filters.sh index 31de4b6..ca04242 100755 --- a/t/t8010-cat-file-filters.sh +++ b/t/t8010-cat-file-filters.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git cat-file filters support' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup ' ' diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh index 90c75db..c3a5f6d 100755 --- a/t/t8012-blame-colors.sh +++ b/t/t8012-blame-colors.sh @@ -4,6 +4,7 @@ test_description='colored git blame' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh PROG='git blame -c' diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 84d0f40..01c74b8 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -4,6 +4,7 @@ test_description='git send-email' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # May be altered later in the test @@ -2288,9 +2289,7 @@ test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' ' ' test_expect_success $PREREQ 'invoke hook' ' - mkdir -p .git/hooks && - - write_script .git/hooks/sendemail-validate <<-\EOF && + test_hook sendemail-validate <<-\EOF && # test that we have the correct environment variable, pwd, and # argument case "$GIT_DIR" in diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index fea41b3..7c5b847 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -8,6 +8,7 @@ test_description='git svn basic tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh prepare_utf8_locale diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh index 8b5681d..52046e6 100755 --- a/t/t9101-git-svn-props.sh +++ b/t/t9101-git-svn-props.sh @@ -4,6 +4,7 @@ # test_description='git svn property tests' + . ./lib-git-svn.sh mkdir import diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh index c7d8e0b..85d7358 100755 --- a/t/t9104-git-svn-follow-parent.sh +++ b/t/t9104-git-svn-follow-parent.sh @@ -4,6 +4,7 @@ # test_description='git svn fetching' + . ./lib-git-svn.sh test_expect_success 'initialize repo' ' diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh index aec45bc..3cab0b9 100755 --- a/t/t9106-git-svn-commit-diff-clobber.sh +++ b/t/t9106-git-svn-commit-diff-clobber.sh @@ -2,6 +2,8 @@ # # Copyright (c) 2006 Eric Wong test_description='git svn commit-diff clobber' + +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'initialize repo' ' diff --git a/t/t9115-git-svn-dcommit-funky-renames.sh b/t/t9115-git-svn-dcommit-funky-renames.sh index 743fbe1..419f055 100755 --- a/t/t9115-git-svn-dcommit-funky-renames.sh +++ b/t/t9115-git-svn-dcommit-funky-renames.sh @@ -5,6 +5,7 @@ test_description='git svn dcommit can commit renames of files with ugly names' +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'load repository with strange names' ' diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index 0a9f1ef..d74d7b2 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -4,6 +4,7 @@ # test_description='git svn log tests' + . ./lib-git-svn.sh test_expect_success 'setup repository and import' ' diff --git a/t/t9122-git-svn-author.sh b/t/t9122-git-svn-author.sh index 9e8fe38..527ba3d 100755 --- a/t/t9122-git-svn-author.sh +++ b/t/t9122-git-svn-author.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git svn authorship' + +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'setup svn repository' ' diff --git a/t/t9127-git-svn-partial-rebuild.sh b/t/t9127-git-svn-partial-rebuild.sh index 2e4789d..97f495b 100755 --- a/t/t9127-git-svn-partial-rebuild.sh +++ b/t/t9127-git-svn-partial-rebuild.sh @@ -4,6 +4,7 @@ # test_description='git svn partial-rebuild tests' + . ./lib-git-svn.sh test_expect_success 'initialize svnrepo' ' diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh index 01e1e8a..185248a 100755 --- a/t/t9129-git-svn-i18n-commitencoding.sh +++ b/t/t9129-git-svn-i18n-commitencoding.sh @@ -4,6 +4,7 @@ test_description='git svn honors i18n.commitEncoding in config' +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh compare_git_head_with () { diff --git a/t/t9139-git-svn-non-utf8-commitencoding.sh b/t/t9139-git-svn-non-utf8-commitencoding.sh index 22d80b0..b7f756b 100755 --- a/t/t9139-git-svn-non-utf8-commitencoding.sh +++ b/t/t9139-git-svn-non-utf8-commitencoding.sh @@ -4,6 +4,7 @@ test_description='git svn refuses to dcommit non-UTF8 messages' +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh # ISO-2022-JP can pass for valid UTF-8, so skipping that in this test diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh index 80cb55f..79c26ed 100755 --- a/t/t9146-git-svn-empty-dirs.sh +++ b/t/t9146-git-svn-empty-dirs.sh @@ -3,6 +3,8 @@ # Copyright (c) 2009 Eric Wong test_description='git svn creates empty directories' + +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'initialize repo' ' diff --git a/t/t9148-git-svn-propset.sh b/t/t9148-git-svn-propset.sh index aebb289..6cc76a0 100755 --- a/t/t9148-git-svn-propset.sh +++ b/t/t9148-git-svn-propset.sh @@ -5,6 +5,7 @@ test_description='git svn propset tests' +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'setup propset via import' ' diff --git a/t/t9160-git-svn-preserve-empty-dirs.sh b/t/t9160-git-svn-preserve-empty-dirs.sh index 36c6b1a..9cf7a14 100755 --- a/t/t9160-git-svn-preserve-empty-dirs.sh +++ b/t/t9160-git-svn-preserve-empty-dirs.sh @@ -9,6 +9,7 @@ This test uses git to clone a Subversion repository that contains empty directories, and checks that corresponding directories are created in the local Git repository with placeholder files.' +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh GIT_REPO=git-svn-repo diff --git a/t/t9162-git-svn-dcommit-interactive.sh b/t/t9162-git-svn-dcommit-interactive.sh index e38d9fa..e2aa8ed 100755 --- a/t/t9162-git-svn-dcommit-interactive.sh +++ b/t/t9162-git-svn-dcommit-interactive.sh @@ -3,6 +3,8 @@ # Copyright (c) 2011 Frédéric Heitzmann test_description='git svn dcommit --interactive series' + +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh test_expect_success 'initialize repo' ' diff --git a/t/t9164-git-svn-dcommit-concurrent.sh b/t/t9164-git-svn-dcommit-concurrent.sh index 8466269..1465156 100755 --- a/t/t9164-git-svn-dcommit-concurrent.sh +++ b/t/t9164-git-svn-dcommit-concurrent.sh @@ -4,6 +4,8 @@ # test_description='concurrent git svn dcommit' + +TEST_FAILS_SANITIZE_LEAK=true . ./lib-git-svn.sh diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh index 1ae4d7c..5841322 100755 --- a/t/t9301-fast-import-notes.sh +++ b/t/t9301-fast-import-notes.sh @@ -7,6 +7,7 @@ test_description='test git fast-import of notes objects' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 7b7a18d..fc99703 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -500,6 +500,13 @@ test_expect_success 'path limiting with import-marks does not lose unmodified fi grep file0 actual ' +test_expect_success 'path limiting works' ' + git fast-export simple -- file >actual && + sed -ne "s/^M .* //p" <actual | sort -u >actual.files && + echo file >expect && + test_cmp expect actual.files +' + test_expect_success 'avoid corrupt stream with non-existent mark' ' test_create_repo avoid_non_existent_mark && ( diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 210ddf0..379b19f 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -221,7 +221,7 @@ test_expect_success 'req_Root (export-all)' \ 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 && sed -ne \$p log | grep "^I LOVE YOU\$"' -test_expect_success 'req_Root failure (export-all w/o whitelist)' \ +test_expect_success 'req_Root failure (export-all w/o directory list)' \ '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)' test_expect_success 'req_Root (everything together)' \ diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index 32814e7..c900231 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -13,6 +13,7 @@ code and message.' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./lib-gitweb.sh # diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh index 8cb582f..81d5625 100755 --- a/t/t9502-gitweb-standalone-parse-output.sh +++ b/t/t9502-gitweb-standalone-parse-output.sh @@ -220,4 +220,18 @@ test_expect_success 'no http-equiv="content-type" in XHTML' ' no_http_equiv_content_type "p=.git;a=tree" ' +proper_doctype() { + gitweb_run "$@" && + grep -F "<!DOCTYPE html [" gitweb.body && + grep "<!ENTITY nbsp" gitweb.body && + grep "<!ENTITY sdot" gitweb.body +} + +test_expect_success 'Proper DOCTYPE with entity declarations' ' + proper_doctype && + proper_doctype "p=.git" && + proper_doctype "p=.git;a=log" && + proper_doctype "p=.git;a=tree" +' + test_done diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh index 806005a..dc88d0e 100755 --- a/t/t9800-git-p4-basic.sh +++ b/t/t9800-git-p4-basic.sh @@ -74,6 +74,91 @@ test_expect_success 'git p4 sync new branch' ' ) ' +# +# Setup as before, and then explicitly sync imported branch, using a +# different ref format. +# +test_expect_success 'git p4 sync existing branch without changes' ' + test_create_repo "$git" && + test_when_finished cleanup_git && + ( + cd "$git" && + test_commit head && + git p4 sync --branch=depot //depot@all && + git p4 sync --branch=refs/remotes/p4/depot >out && + test_i18ngrep "No changes to import!" out + ) +' + +# +# Same as before, relative branch name. +# +test_expect_success 'git p4 sync existing branch with relative name' ' + test_create_repo "$git" && + test_when_finished cleanup_git && + ( + cd "$git" && + test_commit head && + git p4 sync --branch=branch1 //depot@all && + git p4 sync --branch=p4/branch1 >out && + test_i18ngrep "No changes to import!" out + ) +' + +# +# Same as before, with a nested branch path, referenced different ways. +# +test_expect_success 'git p4 sync existing branch with nested path' ' + test_create_repo "$git" && + test_when_finished cleanup_git && + ( + cd "$git" && + test_commit head && + git p4 sync --branch=p4/some/path //depot@all && + git p4 sync --branch=some/path >out && + test_i18ngrep "No changes to import!" out + ) +' + +# +# Same as before, with a full ref path outside the p4/* namespace. +# +test_expect_success 'git p4 sync branch explicit ref without p4 in path' ' + test_create_repo "$git" && + test_when_finished cleanup_git && + ( + cd "$git" && + test_commit head && + git p4 sync --branch=refs/remotes/someremote/depot //depot@all && + git p4 sync --branch=refs/remotes/someremote/depot >out && + test_i18ngrep "No changes to import!" out + ) +' + +test_expect_success 'git p4 sync nonexistent ref' ' + test_create_repo "$git" && + test_when_finished cleanup_git && + ( + cd "$git" && + test_commit head && + git p4 sync --branch=depot //depot@all && + test_must_fail git p4 sync --branch=depot2 2>errs && + test_i18ngrep "Perhaps you never did" errs + ) +' + +test_expect_success 'git p4 sync existing non-p4-imported ref' ' + test_create_repo "$git" && + test_when_finished cleanup_git && + ( + cd "$git" && + test_commit head && + git p4 sync --branch=depot //depot@all && + test_must_fail git p4 sync --branch=refs/heads/master 2>errs && + test_i18ngrep "Perhaps you never did" errs + ) +' + test_expect_success 'clone two dirs' ' ( cd "$cli" && @@ -277,16 +362,21 @@ test_expect_success 'run hook p4-pre-submit before submit' ' git commit -m "add hello.txt" && git config git-p4.skipSubmitEdit true && git p4 submit --dry-run >out && - grep "Would apply" out && - mkdir -p .git/hooks && - write_script .git/hooks/p4-pre-submit <<-\EOF && - exit 0 - EOF + grep "Would apply" out + ) && + test_hook -C "$git" p4-pre-submit <<-\EOF && + exit 0 + EOF + ( + cd "$git" && git p4 submit --dry-run >out && - grep "Would apply" out && - write_script .git/hooks/p4-pre-submit <<-\EOF && - exit 1 - EOF + grep "Would apply" out + ) && + test_hook -C "$git" --clobber p4-pre-submit <<-\EOF && + exit 1 + EOF + ( + cd "$git" && test_must_fail git p4 submit --dry-run >errs 2>&1 && ! grep "Would apply" errs ) diff --git a/t/t9801-git-p4-branch.sh b/t/t9801-git-p4-branch.sh index 50a6f8b..759a14f 100755 --- a/t/t9801-git-p4-branch.sh +++ b/t/t9801-git-p4-branch.sh @@ -129,6 +129,16 @@ test_expect_success 'import depot, branch detection' ' ) ' +test_expect_success 'sync specific detected branch' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" --detect-branches //depot@all && + ( + cd "$git" && + git p4 sync --branch=depot/branch2 >out && + test_i18ngrep "No changes to import!" out + ) +' + test_expect_success 'import depot, branch detection, branchList branch definition' ' test_when_finished cleanup_git && test_create_repo "$git" && diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh index 19073c6..2a6ee2a 100755 --- a/t/t9802-git-p4-filetype.sh +++ b/t/t9802-git-p4-filetype.sh @@ -333,4 +333,38 @@ test_expect_success SYMLINKS 'empty symlink target' ' ) ' +test_expect_success SYMLINKS 'utf-8 with and without BOM in text file' ' + ( + cd "$cli" && + + # some utf8 content + echo some tǣxt >utf8-nobom-test && + + # same utf8 content as before but with bom + echo some tǣxt | sed '\''s/^/\xef\xbb\xbf/'\'' >utf8-bom-test && + + # bom only + dd bs=1 count=3 if=utf8-bom-test of=utf8-bom-empty-test && + + p4 add utf8-nobom-test utf8-bom-test utf8-bom-empty-test && + p4 submit -d "add utf8 test files" + ) && + test_when_finished cleanup_git && + + git p4 clone --dest="$git" //depot@all && + ( + cd "$git" && + git checkout refs/remotes/p4/master && + + echo some tǣxt >utf8-nobom-check && + test_cmp utf8-nobom-check utf8-nobom-test && + + echo some tǣxt | sed '\''s/^/\xef\xbb\xbf/'\'' >utf8-bom-check && + test_cmp utf8-bom-check utf8-bom-test && + + dd bs=1 count=3 if=utf8-bom-check of=utf8-bom-empty-check && + test_cmp utf8-bom-empty-check utf8-bom-empty-test + ) +' + test_done diff --git a/t/t9835-git-p4-metadata-encoding-python2.sh b/t/t9835-git-p4-metadata-encoding-python2.sh new file mode 100755 index 0000000..036bf79 --- /dev/null +++ b/t/t9835-git-p4-metadata-encoding-python2.sh @@ -0,0 +1,213 @@ +#!/bin/sh + +test_description='git p4 metadata encoding + +This test checks that the import process handles inconsistent text +encoding in p4 metadata (author names, commit messages, etc) without +failing, and produces maximally sane output in git.' + +. ./lib-git-p4.sh + +python_target_version='2' + +############################### +## SECTION REPEATED IN t9836 ## +############################### + +# Please note: this test calls "git-p4.py" rather than "git-p4", because the +# latter references a specific path so we can't easily force it to run under +# the python version we need to. + +python_major_version=$(python -V 2>&1 | cut -c 8) +python_target_binary=$(which python$python_target_version) +if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary" +then + mkdir temp_python + PATH="$(pwd)/temp_python:$PATH" && export PATH + ln -s $python_target_binary temp_python/python +fi + +python_major_version=$(python -V 2>&1 | cut -c 8) +if ! test "$python_major_version" = "$python_target_version" +then + skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available" + test_done +fi + +remove_user_cache () { + rm "$HOME/.gitp4-usercache.txt" || true +} + +test_expect_success 'start p4d' ' + start_p4d +' + +test_expect_success 'init depot' ' + ( + cd "$cli" && + + p4_add_user "utf8_author" "ǣuthor" && + P4USER=utf8_author && + touch file1 && + p4 add file1 && + p4 submit -d "first CL has some utf-8 tǣxt" && + + p4_add_user "latin1_author" "$(echo æuthor | + iconv -f utf8 -t latin1)" && + P4USER=latin1_author && + touch file2 && + p4 add file2 && + p4 submit -d "$(echo second CL has some latin-1 tæxt | + iconv -f utf8 -t latin1)" && + + p4_add_user "cp1252_author" "$(echo æuthœr | + iconv -f utf8 -t cp1252)" && + P4USER=cp1252_author && + touch file3 && + p4 add file3 && + p4 submit -d "$(echo third CL has sœme cp-1252 tæxt | + iconv -f utf8 -t cp1252)" && + + p4_add_user "cp850_author" "$(echo Åuthor | + iconv -f utf8 -t cp850)" && + P4USER=cp850_author && + touch file4 && + p4 add file4 && + p4 submit -d "$(echo fourth CL hÅs some cp850 text | + iconv -f utf8 -t cp850)" + ) +' + +test_expect_success 'clone non-utf8 repo with strict encoding' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err && + grep "Decoding perforce metadata failed!" err +' + +test_expect_success 'check utf-8 contents with passthrough strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "some utf-8 tǣxt" actual && + grep "ǣuthor" actual + ) +' + +test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) && + grep "$badly_encoded_in_git" actual && + bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" && + grep "$bad_author_in_git" actual + ) +' + +test_expect_success 'check utf-8 contents with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "some utf-8 tǣxt" actual && + grep "ǣuthor" actual + ) +' + +test_expect_success 'check latin-1 contents with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "some latin-1 tæxt" actual && + grep "æuthor" actual + ) +' + +test_expect_success 'check cp-1252 contents with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "sœme cp-1252 tæxt" actual && + grep "æuthœr" actual + ) +' + +test_expect_success 'check cp850 contents parsed with correct fallback' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "hÅs some cp850 text" actual && + grep "Åuthor" actual + ) +' + +test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "h%8Fs some cp850 text" actual && + grep "%8Futhor" actual + ) +' + +test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$cli" && + P4USER=cp1252_author && + touch file10 && + p4 add file10 && + p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt | + iconv -f utf8 -t cp1252)" + ) && + ( + cd "$git" && + + git p4.py sync --branch=master && + + git log p4/master >actual && + grep "sœme more cp-1252 tæxt" actual && + grep "æuthœr" actual + ) +' + +############################ +## / END REPEATED SECTION ## +############################ + +test_expect_success 'passthrough (latin-1 contents corrupted in git) is the default with python2' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) && + grep "$badly_encoded_in_git" actual + ) +' + +test_done diff --git a/t/t9836-git-p4-metadata-encoding-python3.sh b/t/t9836-git-p4-metadata-encoding-python3.sh new file mode 100755 index 0000000..63350dc --- /dev/null +++ b/t/t9836-git-p4-metadata-encoding-python3.sh @@ -0,0 +1,214 @@ +#!/bin/sh + +test_description='git p4 metadata encoding + +This test checks that the import process handles inconsistent text +encoding in p4 metadata (author names, commit messages, etc) without +failing, and produces maximally sane output in git.' + +. ./lib-git-p4.sh + +python_target_version='3' + +############################### +## SECTION REPEATED IN t9835 ## +############################### + +# Please note: this test calls "git-p4.py" rather than "git-p4", because the +# latter references a specific path so we can't easily force it to run under +# the python version we need to. + +python_major_version=$(python -V 2>&1 | cut -c 8) +python_target_binary=$(which python$python_target_version) +if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary" +then + mkdir temp_python + PATH="$(pwd)/temp_python:$PATH" && export PATH + ln -s $python_target_binary temp_python/python +fi + +python_major_version=$(python -V 2>&1 | cut -c 8) +if ! test "$python_major_version" = "$python_target_version" +then + skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available" + test_done +fi + +remove_user_cache () { + rm "$HOME/.gitp4-usercache.txt" || true +} + +test_expect_success 'start p4d' ' + start_p4d +' + +test_expect_success 'init depot' ' + ( + cd "$cli" && + + p4_add_user "utf8_author" "ǣuthor" && + P4USER=utf8_author && + touch file1 && + p4 add file1 && + p4 submit -d "first CL has some utf-8 tǣxt" && + + p4_add_user "latin1_author" "$(echo æuthor | + iconv -f utf8 -t latin1)" && + P4USER=latin1_author && + touch file2 && + p4 add file2 && + p4 submit -d "$(echo second CL has some latin-1 tæxt | + iconv -f utf8 -t latin1)" && + + p4_add_user "cp1252_author" "$(echo æuthœr | + iconv -f utf8 -t cp1252)" && + P4USER=cp1252_author && + touch file3 && + p4 add file3 && + p4 submit -d "$(echo third CL has sœme cp-1252 tæxt | + iconv -f utf8 -t cp1252)" && + + p4_add_user "cp850_author" "$(echo Åuthor | + iconv -f utf8 -t cp850)" && + P4USER=cp850_author && + touch file4 && + p4 add file4 && + p4 submit -d "$(echo fourth CL hÅs some cp850 text | + iconv -f utf8 -t cp850)" + ) +' + +test_expect_success 'clone non-utf8 repo with strict encoding' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err && + grep "Decoding perforce metadata failed!" err +' + +test_expect_success 'check utf-8 contents with passthrough strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "some utf-8 tǣxt" actual && + grep "ǣuthor" actual + ) +' + +test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) && + grep "$badly_encoded_in_git" actual && + bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" && + grep "$bad_author_in_git" actual + ) +' + +test_expect_success 'check utf-8 contents with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "some utf-8 tǣxt" actual && + grep "ǣuthor" actual + ) +' + +test_expect_success 'check latin-1 contents with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "some latin-1 tæxt" actual && + grep "æuthor" actual + ) +' + +test_expect_success 'check cp-1252 contents with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "sœme cp-1252 tæxt" actual && + grep "æuthœr" actual + ) +' + +test_expect_success 'check cp850 contents parsed with correct fallback' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "hÅs some cp850 text" actual && + grep "Åuthor" actual + ) +' + +test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "h%8Fs some cp850 text" actual && + grep "%8Futhor" actual + ) +' + +test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all && + ( + cd "$cli" && + P4USER=cp1252_author && + touch file10 && + p4 add file10 && + p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt | + iconv -f utf8 -t cp1252)" + ) && + ( + cd "$git" && + + git p4.py sync --branch=master && + + git log p4/master >actual && + grep "sœme more cp-1252 tæxt" actual && + grep "æuthœr" actual + ) +' + +############################ +## / END REPEATED SECTION ## +############################ + + +test_expect_success 'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' ' + test_when_finished cleanup_git && + test_when_finished remove_user_cache && + git p4.py clone --dest="$git" //depot@all && + ( + cd "$git" && + git log >actual && + grep "sœme cp-1252 tæxt" actual && + grep "æuthœr" actual + ) +' + +test_done diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 24117cb..43de868 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1529,28 +1529,45 @@ test_expect_success 'cone mode sparse-checkout completes directory names with sp ) ' -# use FUNNYNAMES to avoid running on Windows, which doesn't permit backslashes or tabs in paths -test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with backslashes and tabs' ' +# use FUNNYNAMES to avoid running on Windows, which doesn't permit tabs in paths +test_expect_success FUNNYNAMES 'cone mode sparse-checkout completes directory names with tabs' ' # reset sparse-checkout git -C sparse-checkout sparse-checkout disable && ( cd sparse-checkout && - mkdir "directory\with\backslashes" && mkdir "$(printf "directory\twith\ttabs")" && - >"directory\with\backslashes/randomfile" && >"$(printf "directory\twith\ttabs")/randomfile" && git add . && - git commit -m "Add directory with backslashes and directory with tabs" && - git sparse-checkout set --cone "directory\with\backslashes" \ + git commit -m "Add directory with tabs" && + git sparse-checkout set --cone \ "$(printf "directory\twith\ttabs")" && test_completion "git sparse-checkout add dir" <<-\EOF && - directory\with\backslashes/ directory with tabs/ EOF - rm -rf "directory\with\backslashes" && rm -rf "$(printf "directory\twith\ttabs")" && git add . && - git commit -m "Remove directory with backslashes and directory with tabs" + git commit -m "Remove directory with tabs" + ) +' + +# use FUNNYNAMES to avoid running on Windows, and !CYGWIN for Cygwin, as neither permit backslashes in paths +test_expect_success FUNNYNAMES,!CYGWIN 'cone mode sparse-checkout completes directory names with backslashes' ' + # reset sparse-checkout + git -C sparse-checkout sparse-checkout disable && + ( + cd sparse-checkout && + mkdir "directory\with\backslashes" && + >"directory\with\backslashes/randomfile" && + git add . && + git commit -m "Add directory with backslashes" && + git sparse-checkout set --cone \ + "directory\with\backslashes" && + test_completion "git sparse-checkout add dir" <<-\EOF && + directory\with\backslashes/ + EOF + rm -rf "directory\with\backslashes" && + git add . && + git commit -m "Remove directory with backslashes" ) ' @@ -2468,6 +2485,13 @@ test_expect_success 'git config - section' ' EOF ' +test_expect_success 'git config - section include, includeIf' ' + test_completion "git config inclu" <<-\EOF + include.Z + includeIf.Z + EOF +' + test_expect_success 'git config - variable name' ' test_completion "git config log.d" <<-\EOF log.date Z @@ -2476,6 +2500,12 @@ test_expect_success 'git config - variable name' ' EOF ' +test_expect_success 'git config - variable name include' ' + test_completion "git config include.p" <<-\EOF + include.path Z + EOF +' + test_expect_success 'git config - value' ' test_completion "git config color.pager " <<-\EOF false Z diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index bbd513b..6a30f57 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -590,7 +590,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirt ' test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' ' - printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmain" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}${c_green}+${c_clear}):AFTER\\nmain" >expected && echo "dirty index" >file && test_when_finished "git reset --hard" && git add -u && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 0f439c9..8c44856 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -329,7 +329,7 @@ test_commit () { else $echo "${3-$1}" >"$indir$file" fi && - git ${indir:+ -C "$indir"} add "$file" && + git ${indir:+ -C "$indir"} add -- "$file" && if test -z "$notick" then test_tick @@ -551,6 +551,82 @@ write_script () { chmod +x "$1" } +# Usage: test_hook [options] <hook-name> <<-\EOF +# +# -C <dir>: +# Run all git commands in directory <dir> +# --setup +# Setup a hook for subsequent tests, i.e. don't remove it in a +# "test_when_finished" +# --clobber +# Overwrite an existing <hook-name>, if it exists. Implies +# --setup (i.e. the "test_when_finished" is assumed to have been +# set up already). +# --disable +# Disable (chmod -x) an existing <hook-name>, which must exist. +# --remove +# Remove (rm -f) an existing <hook-name>, which must exist. +test_hook () { + setup= && + clobber= && + disable= && + remove= && + indir= && + while test $# != 0 + do + case "$1" in + -C) + indir="$2" && + shift + ;; + --setup) + setup=t + ;; + --clobber) + clobber=t + ;; + --disable) + disable=t + ;; + --remove) + remove=t + ;; + -*) + BUG "invalid argument: $1" + ;; + *) + break + ;; + esac && + shift + done && + + git_dir=$(git -C "$indir" rev-parse --absolute-git-dir) && + hook_dir="$git_dir/hooks" && + hook_file="$hook_dir/$1" && + if test -n "$disable$remove" + then + test_path_is_file "$hook_file" && + if test -n "$disable" + then + chmod -x "$hook_file" + elif test -n "$remove" + then + rm -f "$hook_file" + fi && + return 0 + fi && + if test -z "$clobber" + then + test_path_is_missing "$hook_file" + fi && + if test -z "$setup$clobber" + then + test_when_finished "rm \"$hook_file\"" + fi && + write_script "$hook_file" +} + # Use test_set_prereq to tell that a particular prerequisite is available. # The prerequisite can later be checked for in two ways: # @@ -575,8 +651,7 @@ test_set_prereq () { # test_unset_prereq() !*) ;; - # (Temporary?) whitelist of things we can't easily - # pretend not to support + # List of things we can't easily pretend to not support SYMLINKS) ;; # Inspecting whether GIT_TEST_FAIL_PREREQS is on @@ -719,7 +794,7 @@ test_verify_prereq () { } test_expect_failure () { - test_start_ + test_start_ "$@" test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || BUG "not 2 or 3 parameters to test-expect-failure" @@ -727,6 +802,7 @@ test_expect_failure () { export test_prereq if ! test_skip "$@" then + test -n "$test_skip_test_preamble" || say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $2" if test_run_ "$2" expecting_failure then @@ -739,7 +815,7 @@ test_expect_failure () { } test_expect_success () { - test_start_ + test_start_ "$@" test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || BUG "not 2 or 3 parameters to test-expect-success" @@ -747,6 +823,7 @@ test_expect_success () { export test_prereq if ! test_skip "$@" then + test -n "$test_skip_test_preamble" || say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $2" if test_run_ "$2" then @@ -1706,6 +1783,16 @@ test_oid_to_path () { echo "${1%$basename}/$basename" } +# Parse oids from git ls-files --staged output +test_parse_ls_files_stage_oids () { + awk '{print $2}' - +} + +# Parse oids from git ls-tree output +test_parse_ls_tree_oids () { + awk '{print $3}' - +} + # Choose a port number based on the test script's number and store it in # the given variable name, unless that variable already contains a number. test_set_port () { @@ -1789,40 +1876,6 @@ test_subcommand () { } # Check that the given command was invoked as part of the -# trace2-format trace on stdin, but without an exact set of -# arguments. -# -# test_subcommand [!] <command> <args>... < <trace> -# -# For example, to look for an invocation of "git pack-objects" -# with the "--honor-pack-keep" argument, use -# -# GIT_TRACE2_EVENT=event.log git repack ... && -# test_subcommand git pack-objects --honor-pack-keep <event.log -# -# If the first parameter passed is !, this instead checks that -# the given command was not called. -# -test_subcommand_inexact () { - local negate= - if test "$1" = "!" - then - negate=t - shift - fi - - local expr=$(printf '"%s".*' "$@") - expr="${expr%,}" - - if test -n "$negate" - then - ! grep "\"event\":\"child_start\".*\[$expr\]" - else - grep "\"event\":\"child_start\".*\[$expr\]" - fi -} - -# Check that the given command was invoked as part of the # trace2-format trace on stdin. # # test_region [!] <category> <label> git <command> <args>... diff --git a/t/test-lib-github-workflow-markup.sh b/t/test-lib-github-workflow-markup.sh new file mode 100644 index 0000000..9c5339c --- /dev/null +++ b/t/test-lib-github-workflow-markup.sh @@ -0,0 +1,56 @@ +# Library of functions to mark up test scripts' output suitable for +# pretty-printing it in GitHub workflows. +# +# Copyright (c) 2022 Johannes Schindelin +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/ . +# +# The idea is for `test-lib.sh` to source this file when run in GitHub +# workflows; these functions will then override (empty) functions +# that are are called at the appropriate times during the test runs. + +test_skip_test_preamble=t + +start_test_output () { + test -n "$GIT_TEST_TEE_OUTPUT_FILE" || + die "--github-workflow-markup requires --verbose-log" + github_markup_output="${GIT_TEST_TEE_OUTPUT_FILE%.out}.markup" + >$github_markup_output + GIT_TEST_TEE_OFFSET=0 +} + +# No need to override start_test_case_output + +finalize_test_case_output () { + test_case_result=$1 + shift + case "$test_case_result" in + failure) + echo >>$github_markup_output "::error::failed: $this_test.$test_count $1" + ;; + fixed) + echo >>$github_markup_output "::notice::fixed: $this_test.$test_count $1" + ;; + ok) + # Exit without printing the "ok" tests + return + ;; + esac + echo >>$github_markup_output "::group::$test_case_result: $this_test.$test_count $*" + test-tool >>$github_markup_output path-utils skip-n-bytes \ + "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET + echo >>$github_markup_output "::endgroup::" +} + +# No need to override finalize_test_output diff --git a/t/test-lib-junit.sh b/t/test-lib-junit.sh new file mode 100644 index 0000000..79c31c7 --- /dev/null +++ b/t/test-lib-junit.sh @@ -0,0 +1,132 @@ +# Library of functions to format test scripts' output in JUnit XML +# format, to support Git's test suite result to be presented in an +# easily digestible way on Azure Pipelines. +# +# Copyright (c) 2022 Johannes Schindelin +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/ . +# +# The idea is for `test-lib.sh` to source this file when the user asks +# for JUnit XML; these functions will then override (empty) functions +# that are are called at the appropriate times during the test runs. + +start_test_output () { + junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out" + mkdir -p "$junit_xml_dir" + junit_xml_base=${1##*/} + junit_xml_path="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml" + junit_attrs="name=\"${junit_xml_base%.sh}\"" + junit_attrs="$junit_attrs timestamp=\"$(TZ=UTC \ + date +%Y-%m-%dT%H:%M:%S)\"" + write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>" + junit_suite_start=$(test-tool date getnanos) + if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + GIT_TEST_TEE_OFFSET=0 + fi +} + +start_test_case_output () { + junit_start=$(test-tool date getnanos) +} + +finalize_test_case_output () { + test_case_result=$1 + shift + case "$test_case_result" in + ok) + set -- "$*" + ;; + failure) + junit_insert="<failure message=\"not ok $test_count -" + junit_insert="$junit_insert $(xml_attr_encode --no-lf "$1")\">" + junit_insert="$junit_insert $(xml_attr_encode \ + "$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + test-tool path-utils skip-n-bytes \ + "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET + else + printf '%s\n' "$@" | sed 1d + fi)")" + junit_insert="$junit_insert</failure>" + if test -n "$GIT_TEST_TEE_OUTPUT_FILE" + then + junit_insert="$junit_insert<system-err>$(xml_attr_encode \ + "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>" + fi + set -- "$1" " $junit_insert" + ;; + fixed) + set -- "$* (breakage fixed)" + ;; + broken) + set -- "$* (known breakage)" + ;; + skip) + message="$(xml_attr_encode --no-lf "$skipped_reason")" + set -- "$1" " <skipped message=\"$message\" />" + ;; + esac + + junit_attrs="name=\"$(xml_attr_encode --no-lf "$this_test.$test_count $1")\"" + shift + junit_attrs="$junit_attrs classname=\"$this_test\"" + junit_attrs="$junit_attrs time=\"$(test-tool \ + date getnanos $junit_start)\"" + write_junit_xml "$(printf '%s\n' \ + " <testcase $junit_attrs>" "$@" " </testcase>")" + junit_have_testcase=t +} + +finalize_test_output () { + if test -n "$junit_xml_path" + then + test -n "$junit_have_testcase" || { + junit_start=$(test-tool date getnanos) + write_junit_xml_testcase "all tests skipped" + } + + # adjust the overall time + junit_time=$(test-tool date getnanos $junit_suite_start) + sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \ + -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \ + -e '/^ *<\/testsuite/d' \ + <"$junit_xml_path" >"$junit_xml_path.new" + mv "$junit_xml_path.new" "$junit_xml_path" + + write_junit_xml " </testsuite>" "</testsuites>" + write_junit_xml= + fi +} + +write_junit_xml () { + case "$1" in + --truncate) + >"$junit_xml_path" + junit_have_testcase= + shift + ;; + esac + printf '%s\n' "$@" >>"$junit_xml_path" +} + +xml_attr_encode () { + if test "x$1" = "x--no-lf" + then + shift + printf '%s' "$*" | test-tool xml-encode + else + printf '%s\n' "$@" | test-tool xml-encode + fi +} diff --git a/t/test-lib.sh b/t/test-lib.sh index 515b1af..7726d1d 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -57,14 +57,14 @@ fi # # prepend_var VAR : VALUE prepend_var () { - eval "$1=$3\${$1:+${3:+$2}\$$1}" + eval "$1=\"$3\${$1:+${3:+$2}\$$1}\"" } # If [AL]SAN is in effect we want to abort so that we notice # problems. The GIT_SAN_OPTIONS variable can be used to set common # defaults shared between [AL]SAN_OPTIONS. prepend_var GIT_SAN_OPTIONS : abort_on_error=1 -prepend_var GIT_SAN_OPTIONS : strip_path_prefix=\"$GIT_BUILD_DIR/\" +prepend_var GIT_SAN_OPTIONS : strip_path_prefix="$GIT_BUILD_DIR/" # If we were built with ASAN, it may complain about leaks # of program-lifetime variables. Disable it by default to lower @@ -137,6 +137,12 @@ mark_option_requires_arg () { store_arg_to=$2 } +# These functions can be overridden e.g. to output JUnit XML +start_test_output () { :; } +start_test_case_output () { :; } +finalize_test_case_output () { :; } +finalize_test_output () { :; } + parse_option () { local opt="$1" @@ -196,7 +202,10 @@ parse_option () { tee=t ;; --write-junit-xml) - write_junit_xml=t + . "$TEST_DIRECTORY/test-lib-junit.sh" + ;; + --github-workflow-markup) + . "$TEST_DIRECTORY/test-lib-github-workflow-markup.sh" ;; --stress) stress=t ;; @@ -535,9 +544,10 @@ case $GIT_TEST_FSYNC in ;; esac -# Add libc MALLOC and MALLOC_PERTURB test -# only if we are not executing the test with valgrind +# Add libc MALLOC and MALLOC_PERTURB test only if we are not executing +# the test with valgrind and have not compiled with SANITIZE=address. if test -n "$valgrind" || + test -n "$SANITIZE_ADDRESS" || test -n "$TEST_NO_MALLOC_CHECK" then setup_malloc_check () { @@ -663,7 +673,7 @@ exec 6<&0 exec 7>&2 _error_exit () { - finalize_junit_xml + finalize_test_output GIT_EXIT_OK=t exit 1 } @@ -773,58 +783,35 @@ trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP # the test_expect_* functions instead. test_ok_ () { - if test -n "$write_junit_xml" - then - write_junit_xml_testcase "$*" - fi test_success=$(($test_success + 1)) say_color "" "ok $test_count - $@" + finalize_test_case_output ok "$@" } test_failure_ () { - if test -n "$write_junit_xml" - then - junit_insert="<failure message=\"not ok $test_count -" - junit_insert="$junit_insert $(xml_attr_encode "$1")\">" - junit_insert="$junit_insert $(xml_attr_encode \ - "$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE" - then - test-tool path-utils skip-n-bytes \ - "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET - else - printf '%s\n' "$@" | sed 1d - fi)")" - junit_insert="$junit_insert</failure>" - if test -n "$GIT_TEST_TEE_OUTPUT_FILE" - then - junit_insert="$junit_insert<system-err>$(xml_attr_encode \ - "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>" - fi - write_junit_xml_testcase "$1" " $junit_insert" - fi + failure_label=$1 test_failure=$(($test_failure + 1)) say_color error "not ok $test_count - $1" shift printf '%s\n' "$*" | sed -e 's/^/# /' - test "$immediate" = "" || _error_exit + if test -n "$immediate" + then + say_color error "1..$test_count" + _error_exit + fi + finalize_test_case_output failure "$failure_label" "$@" } test_known_broken_ok_ () { - if test -n "$write_junit_xml" - then - write_junit_xml_testcase "$* (breakage fixed)" - fi test_fixed=$(($test_fixed+1)) say_color error "ok $test_count - $@ # TODO known breakage vanished" + finalize_test_case_output fixed "$@" } test_known_broken_failure_ () { - if test -n "$write_junit_xml" - then - write_junit_xml_testcase "$* (known breakage)" - fi test_broken=$(($test_broken+1)) say_color warn "not ok $test_count - $@ # TODO known breakage" + finalize_test_case_output broken "$@" } test_debug () { @@ -1099,10 +1086,7 @@ test_start_ () { test_count=$(($test_count+1)) maybe_setup_verbose maybe_setup_valgrind - if test -n "$write_junit_xml" - then - junit_start=$(test-tool date getnanos) - fi + start_test_case_output "$@" } test_finish_ () { @@ -1153,15 +1137,10 @@ test_skip () { case "$to_skip" in t) - if test -n "$write_junit_xml" - then - message="$(xml_attr_encode "$skipped_reason")" - write_junit_xml_testcase "$1" \ - " <skipped message=\"$message\" />" - fi say_color skip "ok $test_count # skip $1 ($skipped_reason)" : true + finalize_test_case_output skip "$@" ;; *) false @@ -1174,53 +1153,6 @@ test_at_end_hook_ () { : } -write_junit_xml () { - case "$1" in - --truncate) - >"$junit_xml_path" - junit_have_testcase= - shift - ;; - esac - printf '%s\n' "$@" >>"$junit_xml_path" -} - -xml_attr_encode () { - printf '%s\n' "$@" | test-tool xml-encode -} - -write_junit_xml_testcase () { - junit_attrs="name=\"$(xml_attr_encode "$this_test.$test_count $1")\"" - shift - junit_attrs="$junit_attrs classname=\"$this_test\"" - junit_attrs="$junit_attrs time=\"$(test-tool \ - date getnanos $junit_start)\"" - write_junit_xml "$(printf '%s\n' \ - " <testcase $junit_attrs>" "$@" " </testcase>")" - junit_have_testcase=t -} - -finalize_junit_xml () { - if test -n "$write_junit_xml" && test -n "$junit_xml_path" - then - test -n "$junit_have_testcase" || { - junit_start=$(test-tool date getnanos) - write_junit_xml_testcase "all tests skipped" - } - - # adjust the overall time - junit_time=$(test-tool date getnanos $junit_suite_start) - sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \ - -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \ - -e '/^ *<\/testsuite/d' \ - <"$junit_xml_path" >"$junit_xml_path.new" - mv "$junit_xml_path.new" "$junit_xml_path" - - write_junit_xml " </testsuite>" "</testsuites>" - write_junit_xml= - fi -} - test_atexit_cleanup=: test_atexit_handler () { # In a succeeding test script 'test_atexit_handler' is invoked @@ -1243,7 +1175,7 @@ test_done () { # removed, so the commands can access pidfiles and socket files. test_atexit_handler - finalize_junit_xml + finalize_test_output if test -z "$HARNESS_ACTIVE" then @@ -1524,7 +1456,9 @@ remove_trash_directory "$TRASH_DIRECTORY" || { remove_trash=t if test -z "$TEST_NO_CREATE_REPO" then - git init "$TRASH_DIRECTORY" >&3 2>&4 || + git init \ + ${TEST_CREATE_REPO_NO_TEMPLATE:+--template=} \ + "$TRASH_DIRECTORY" >&3 2>&4 || error "cannot run git init" else mkdir -p "$TRASH_DIRECTORY" @@ -1534,22 +1468,7 @@ fi # in subprocesses like git equals our $PWD (for pathname comparisons). cd -P "$TRASH_DIRECTORY" || exit 1 -if test -n "$write_junit_xml" -then - junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out" - mkdir -p "$junit_xml_dir" - junit_xml_base=${0##*/} - junit_xml_path="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml" - junit_attrs="name=\"${junit_xml_base%.sh}\"" - junit_attrs="$junit_attrs timestamp=\"$(TZ=UTC \ - date +%Y-%m-%dT%H:%M:%S)\"" - write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>" - junit_suite_start=$(test-tool date getnanos) - if test -n "$GIT_TEST_TEE_OUTPUT_FILE" - then - GIT_TEST_TEE_OFFSET=0 - fi -fi +start_test_output "$0" # Convenience # A regexp to match 5 and 35 hexdigits @@ -1655,6 +1574,7 @@ esac test_set_prereq REFFILES ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1 +test -z "$NO_CURL" && test_set_prereq LIBCURL test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PTHREADS" && test_set_prereq PTHREADS test -z "$NO_PYTHON" && test_set_prereq PYTHON @@ -1662,6 +1582,7 @@ test -n "$USE_LIBPCRE2" && test_set_prereq PCRE test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK +test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND if test -z "$GIT_TEST_CHECK_CACHE_TREE" then @@ -1841,9 +1762,20 @@ test_lazy_prereq SHA1 ' esac ' +test_lazy_prereq ADD_I_USE_BUILTIN ' + test_bool_env GIT_TEST_ADD_I_USE_BUILTIN true +' + # Ensure that no test accidentally triggers a Git command # that runs the actual maintenance scheduler, affecting a user's # system permanently. # Tests that verify the scheduler integration must set this locally # to avoid errors. GIT_TEST_MAINT_SCHEDULER="none:exit 1" + +# Does this platform support `git fsmonitor--daemon` +# +test_lazy_prereq FSMONITOR_DAEMON ' + git version --build-options >output && + grep "feature: fsmonitor--daemon" output +' |