diff options
49 files changed, 900 insertions, 236 deletions
diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt index 60eed5edcd..7c9a037cc2 100644 --- a/Documentation/MyFirstContribution.txt +++ b/Documentation/MyFirstContribution.txt @@ -1143,11 +1143,25 @@ After a few days, you will hopefully receive a reply to your patchset with some comments. Woohoo! Now you can get back to work. It's good manners to reply to each comment, notifying the reviewer that you have -made the change requested, feel the original is better, or that the comment +made the change suggested, feel the original is better, or that the comment inspired you to do something a new way which is superior to both the original and the suggested change. This way reviewers don't need to inspect your v2 to figure out whether you implemented their comment or not. +Reviewers may ask you about what you wrote in the patchset, either in +the proposed commit log message or in the changes themselves. You +should answer these questions in your response messages, but often the +reason why reviewers asked these questions to understand what you meant +to write is because your patchset needed clarification to be understood. + +Do not be satisfied by just answering their questions in your response +and hear them say that they now understand what you wanted to say. +Update your patches to clarify the points reviewers had trouble with, +and prepare your v2; the words you used to explain your v1 to answer +reviewers' questions may be useful thing to use. Your goal is to make +your v2 clear enough so that it becomes unnecessary for you to give the +same explanation to the next person who reads it. + If you are going to push back on a comment, be polite and explain why you feel your original is better; be prepared that the reviewer may still disagree with you, and the rest of the community may weigh in on one side or the other. As diff --git a/Documentation/RelNotes/2.30.0.txt b/Documentation/RelNotes/2.30.0.txt index 4c5be2dd04..aef8810819 100644 --- a/Documentation/RelNotes/2.30.0.txt +++ b/Documentation/RelNotes/2.30.0.txt @@ -75,6 +75,9 @@ UI, Workflows & Features safely take a parameter that is supposed to be a revision, e.g. "git rev-parse --verify -q --end-of-options $rev". + * The command line completion script (in contrib/) learned to expand + commands that are alias of alias. + Performance, Internal Implementation, Development Support etc. @@ -117,6 +120,14 @@ Performance, Internal Implementation, Development Support etc. * A specialization of hashmap that uses a string as key has been introduced. Hopefully it will see wider use over time. + * "git bisect start/next" in a large span of history spends a lot of + time trying to come up with exactly the half-way point; this can be + optimized by stopping when we see a commit that is close enough to + the half-way point. + + * A lazily defined test prerequisite can now be defined in terms of + another lazily defined test prerequisite. + Fixes since v2.29 ----------------- @@ -237,6 +248,23 @@ Fixes since v2.29 * Fix regression introduced when nvimdiff support in mergetool was added. (merge 12026f46e7 pd/mergetool-nvimdiff later to maint). + * The exchange between receive-pack and proc-receive hook did not + carefully check for errors. + + * The code was not prepared to deal with pack .idx file that is + larger than 4GB. + (merge 81c4c5cf2e jk/4gb-idx later to maint). + + * "git fetch" did not work correctly with nested submodules where the + innermost submodule that is not of interest got updated in the + upstream, which has been corrected. + (merge 1b7ac4e6d4 pk/subsub-fetch-fix later to maint). + + * Since jgit does not yet work with SHA-256 repositories, mark the + tests that uses it not to run unless we are testing with ShA-1 + repositories. + (merge ea699b4adc sg/t5310-jgit-wants-sha1 later to maint). + * Other code cleanup, docfix, build fix, etc. (merge 3e0a5dc9af cc/doc-filter-branch-typofix later to maint). (merge 32c83afc2c cw/ci-ghwf-check-ws-errors later to maint). @@ -254,3 +282,7 @@ Fixes since v2.29 (merge b7e20b4373 mc/typofix later to maint). (merge f6bcd9a8a4 js/test-whitespace-fixes later to maint). (merge 53b67a801b js/test-file-size later to maint). + (merge 970909c2a7 rs/hashwrite-be64 later to maint). + (merge 5a923bb1f0 ma/list-object-filter-opt-msgfix later to maint). + (merge 1c3e412916 rs/archive-plug-leak-refname later to maint). + (merge d44e5267ea rs/plug-diff-cache-leak later to maint). diff --git a/Documentation/config/gc.txt b/Documentation/config/gc.txt index 00ea0a678e..c834e07991 100644 --- a/Documentation/config/gc.txt +++ b/Documentation/config/gc.txt @@ -44,9 +44,9 @@ gc.autoDetach:: gc.bigPackThreshold:: If non-zero, all packs larger than this limit are kept when - `git gc` is run. This is very similar to `--keep-base-pack` + `git gc` is run. This is very similar to `--keep-largest-pack` except that all packs that meet the threshold are kept, not - just the base pack. Defaults to zero. Common unit suffixes of + just the largest pack. Defaults to zero. Common unit suffixes of 'k', 'm', or 'g' are supported. + Note that if the number of kept packs is more than gc.autoPackLimit, @@ -57,7 +57,7 @@ gc.autoPackLimit and gc.bigPackThreshold should be respected again. If the amount of memory estimated for `git repack` to run smoothly is not available and `gc.bigPackThreshold` is not set, the largest pack will also be excluded (this is the equivalent of running `git gc` with -`--keep-base-pack`). +`--keep-largest-pack`). gc.writeCommitGraph:: If true, then gc will rewrite the commit-graph file when @@ -658,6 +658,7 @@ int write_archive(int argc, const char **argv, const char *prefix, rc = ar->write_archive(ar, &args); string_list_clear_func(&args.extra_files, extra_file_info_clear); + free(args.refname); return rc; } @@ -8,7 +8,7 @@ struct repository; struct archiver_args { struct repository *repo; - const char *refname; + char *refname; const char *prefix; const char *base; size_t baselen; @@ -103,8 +103,10 @@ static int count_interesting_parents(struct commit *commit, unsigned bisect_flag return count; } -static inline int halfway(struct commit_list *p, int nr) +static inline int approx_halfway(struct commit_list *p, int nr) { + int diff; + /* * Don't short-cut something we are not going to return! */ @@ -113,13 +115,22 @@ static inline int halfway(struct commit_list *p, int nr) if (DEBUG_BISECT) return 0; /* - * 2 and 3 are halfway of 5. + * For small number of commits 2 and 3 are halfway of 5, and * 3 is halfway of 6 but 2 and 4 are not. */ - switch (2 * weight(p) - nr) { + diff = 2 * weight(p) - nr; + switch (diff) { case -1: case 0: case 1: return 1; default: + /* + * For large number of commits we are not so strict, it's + * good enough if it's within ~0.1% of the halfway point, + * e.g. 5000 is exactly halfway of 10000, but we consider + * the values [4996, 5004] as halfway as well. + */ + if (abs(diff) < nr / 1024) + return 1; return 0; } } @@ -321,8 +332,9 @@ static struct commit_list *do_find_bisection(struct commit_list *list, weight_set(p, count_distance(p)); clear_distance(list); - /* Does it happen to be at exactly half-way? */ - if (!(bisect_flags & FIND_BISECTION_ALL) && halfway(p, nr)) + /* Does it happen to be at half-way? */ + if (!(bisect_flags & FIND_BISECTION_ALL) && + approx_halfway(p, nr)) return p; counted++; } @@ -362,8 +374,9 @@ static struct commit_list *do_find_bisection(struct commit_list *list, else weight_set(p, weight(q)); - /* Does it happen to be at exactly half-way? */ - if (!(bisect_flags & FIND_BISECTION_ALL) && halfway(p, nr)) + /* Does it happen to be at half-way? */ + if (!(bisect_flags & FIND_BISECTION_ALL) && + approx_halfway(p, nr)) return p; } } diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c index 22b125cf8c..8681031402 100644 --- a/block-sha1/sha1.c +++ b/block-sha1/sha1.c @@ -203,7 +203,7 @@ void blk_SHA1_Init(blk_SHA_CTX *ctx) ctx->H[4] = 0xc3d2e1f0; } -void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) +void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, size_t len) { unsigned int lenW = ctx->size & 63; diff --git a/block-sha1/sha1.h b/block-sha1/sha1.h index 4df6747752..9fb0441b98 100644 --- a/block-sha1/sha1.h +++ b/block-sha1/sha1.h @@ -13,7 +13,7 @@ typedef struct { } blk_SHA_CTX; void blk_SHA1_Init(blk_SHA_CTX *ctx); -void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len); +void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len); void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); #define platform_SHA_CTX blk_SHA_CTX diff --git a/builtin/gc.c b/builtin/gc.c index 3d258b60c2..3e8d76fd5a 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -534,7 +534,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) const char *name; pid_t pid; int daemonized = 0; - int keep_base_pack = -1; + int keep_largest_pack = -1; timestamp_t dummy; struct option builtin_gc_options[] = { @@ -548,7 +548,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) OPT_BOOL_F(0, "force", &force, N_("force running gc even if there may be another gc running"), PARSE_OPT_NOCOMPLETE), - OPT_BOOL(0, "keep-largest-pack", &keep_base_pack, + OPT_BOOL(0, "keep-largest-pack", &keep_largest_pack, N_("repack all other packs except the largest pack")), OPT_END() }; @@ -625,8 +625,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix) } else { struct string_list keep_pack = STRING_LIST_INIT_NODUP; - if (keep_base_pack != -1) { - if (keep_base_pack) + if (keep_largest_pack != -1) { + if (keep_largest_pack) find_base_packs(&keep_pack, 0); } else if (big_pack_threshold) { find_base_packs(&keep_pack, big_pack_threshold); @@ -1253,10 +1253,8 @@ static struct maintenance_task tasks[] = { static int compare_tasks_by_selection(const void *a_, const void *b_) { - const struct maintenance_task *a, *b; - - a = (const struct maintenance_task *)&a_; - b = (const struct maintenance_task *)&b_; + const struct maintenance_task *a = a_; + const struct maintenance_task *b = b_; return b->selected_order - a->selected_order; } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 0d03cb442d..4b8d86e0ad 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1597,7 +1597,7 @@ static void read_v2_anomalous_offsets(struct packed_git *p, /* The address of the 4-byte offset table */ idx1 = (((const uint32_t *)((const uint8_t *)p->index_data + p->crc_offset)) - + p->num_objects /* CRC32 table */ + + (size_t)p->num_objects /* CRC32 table */ ); /* The address of the 8-byte offset table */ diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c index 178e3409b7..3e70f2a4c1 100644 --- a/builtin/pack-redundant.c +++ b/builtin/pack-redundant.c @@ -236,7 +236,7 @@ static struct pack_list * pack_list_difference(const struct pack_list *A, static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2) { - unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step; + size_t p1_off = 0, p2_off = 0, p1_step, p2_step; const unsigned char *p1_base, *p2_base; struct llist_item *p1_hint = NULL, *p2_hint = NULL; const unsigned int hashsz = the_hash_algo->rawsz; @@ -280,7 +280,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2) static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2) { size_t ret = 0; - unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step; + size_t p1_off = 0, p2_off = 0, p1_step, p2_step; const unsigned char *p1_base, *p2_base; const unsigned int hashsz = the_hash_algo->rawsz; @@ -499,7 +499,7 @@ static void scan_alt_odb_packs(void) static struct pack_list * add_pack(struct packed_git *p) { struct pack_list l; - unsigned long off = 0, step; + size_t off = 0, step; const unsigned char *base; if (!p->pack_local && !(alt_odb || verbose)) diff --git a/builtin/pull.c b/builtin/pull.c index 17aa63cd35..1034372f8b 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -345,18 +345,18 @@ static enum rebase_type config_get_rebase(void) return parse_config_rebase("pull.rebase", value, 1); if (opt_verbosity >= 0 && !opt_ff) { - warning(_("Pulling without specifying how to reconcile divergent branches is\n" - "discouraged. You can squelch this message by running one of the following\n" - "commands sometime before your next pull:\n" - "\n" - " git config pull.rebase false # merge (the default strategy)\n" - " git config pull.rebase true # rebase\n" - " git config pull.ff only # fast-forward only\n" - "\n" - "You can replace \"git config\" with \"git config --global\" to set a default\n" - "preference for all repositories. You can also pass --rebase, --no-rebase,\n" - "or --ff-only on the command line to override the configured default per\n" - "invocation.\n")); + advise(_("Pulling without specifying how to reconcile divergent branches is\n" + "discouraged. You can squelch this message by running one of the following\n" + "commands sometime before your next pull:\n" + "\n" + " git config pull.rebase false # merge (the default strategy)\n" + " git config pull.rebase true # rebase\n" + " git config pull.ff only # fast-forward only\n" + "\n" + "You can replace \"git config\" with \"git config --global\" to set a default\n" + "preference for all repositories. You can also pass --rebase, --no-rebase,\n" + "or --ff-only on the command line to override the configured default per\n" + "invocation.\n")); } return REBASE_FALSE; diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index bb9909c52e..f1f0f7bef6 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -977,15 +977,25 @@ static int read_proc_receive_report(struct packet_reader *reader, int new_report = 0; int code = 0; int once = 0; + int response = 0; for (;;) { struct object_id old_oid, new_oid; const char *head; const char *refname; char *p; - - if (packet_reader_read(reader) != PACKET_READ_NORMAL) + enum packet_read_status status; + + status = packet_reader_read(reader); + if (status != PACKET_READ_NORMAL) { + /* Check whether proc-receive exited abnormally */ + if (status == PACKET_READ_EOF && !response) { + strbuf_addstr(errmsg, "proc-receive exited abnormally"); + return -1; + } break; + } + response++; head = reader->line; p = strchr(head, ' '); @@ -1145,31 +1155,49 @@ static int run_proc_receive_hook(struct command *commands, if (use_push_options) strbuf_addstr(&cap, " push-options"); if (cap.len) { - packet_write_fmt(proc.in, "version=1%c%s\n", '\0', cap.buf + 1); + code = packet_write_fmt_gently(proc.in, "version=1%c%s\n", '\0', cap.buf + 1); strbuf_release(&cap); } else { - packet_write_fmt(proc.in, "version=1\n"); + code = packet_write_fmt_gently(proc.in, "version=1\n"); } - packet_flush(proc.in); + if (!code) + code = packet_flush_gently(proc.in); - for (;;) { - int linelen; + if (!code) + for (;;) { + int linelen; + enum packet_read_status status; - if (packet_reader_read(&reader) != PACKET_READ_NORMAL) - break; + status = packet_reader_read(&reader); + if (status != PACKET_READ_NORMAL) { + /* Check whether proc-receive exited abnormally */ + if (status == PACKET_READ_EOF) + code = -1; + break; + } - if (reader.pktlen > 8 && starts_with(reader.line, "version=")) { - version = atoi(reader.line + 8); - linelen = strlen(reader.line); - if (linelen < reader.pktlen) { - const char *feature_list = reader.line + linelen + 1; - if (parse_feature_request(feature_list, "push-options")) - hook_use_push_options = 1; + if (reader.pktlen > 8 && starts_with(reader.line, "version=")) { + version = atoi(reader.line + 8); + linelen = strlen(reader.line); + if (linelen < reader.pktlen) { + const char *feature_list = reader.line + linelen + 1; + if (parse_feature_request(feature_list, "push-options")) + hook_use_push_options = 1; + } } } + + if (code) { + strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook"); + goto cleanup; } - if (version != 1) { + switch (version) { + case 0: + /* fallthrough */ + case 1: + break; + default: strbuf_addf(&errmsg, "proc-receive version '%d' is not supported", version); code = -1; @@ -1180,20 +1208,36 @@ static int run_proc_receive_hook(struct command *commands, for (cmd = commands; cmd; cmd = cmd->next) { if (!cmd->run_proc_receive || cmd->skip_update || cmd->error_string) continue; - packet_write_fmt(proc.in, "%s %s %s", - oid_to_hex(&cmd->old_oid), - oid_to_hex(&cmd->new_oid), - cmd->ref_name); + code = packet_write_fmt_gently(proc.in, "%s %s %s", + oid_to_hex(&cmd->old_oid), + oid_to_hex(&cmd->new_oid), + cmd->ref_name); + if (code) + break; + } + if (!code) + code = packet_flush_gently(proc.in); + if (code) { + strbuf_addstr(&errmsg, "fail to write commands to proc-receive hook"); + goto cleanup; } - packet_flush(proc.in); /* Send push options */ if (hook_use_push_options) { struct string_list_item *item; - for_each_string_list_item(item, push_options) - packet_write_fmt(proc.in, "%s", item->string); - packet_flush(proc.in); + for_each_string_list_item(item, push_options) { + code = packet_write_fmt_gently(proc.in, "%s", item->string); + if (code) + break; + } + if (!code) + code = packet_flush_gently(proc.in); + if (code) { + strbuf_addstr(&errmsg, + "fail to write push-options to proc-receive hook"); + goto cleanup; + } } /* Read result from proc-receive */ diff --git a/builtin/stash.c b/builtin/stash.c index 24ddb1bffa..e1f8235fdd 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -419,7 +419,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, ret = apply_cached(&out); strbuf_release(&out); if (ret) - return error(_("conflicts in index." + return error(_("conflicts in index. " "Try without --index.")); discard_cache(); diff --git a/builtin/worktree.c b/builtin/worktree.c index ce56fdaaa9..197fd24a55 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -304,9 +304,9 @@ static void check_candidate_path(const char *path, } if (locked) - die(_("'%s' is a missing but locked worktree;\nuse '%s -f -f' to override, or 'unlock' and 'prune' or 'remove' to clear"), cmd, path); + die(_("'%s' is a missing but locked worktree;\nuse '%s -f -f' to override, or 'unlock' and 'prune' or 'remove' to clear"), path, cmd); else - die(_("'%s' is a missing but already registered worktree;\nuse '%s -f' to override, or 'prune' or 'remove' to clear"), cmd, path); + die(_("'%s' is a missing but already registered worktree;\nuse '%s -f' to override, or 'prune' or 'remove' to clear"), path, cmd); } static int add_worktree(const char *path, const char *refname, @@ -1960,7 +1960,6 @@ int stat_validity_check(struct stat_validity *sv, const char *path); void stat_validity_update(struct stat_validity *sv, int fd); int versioncmp(const char *s1, const char *s2); -void sleep_millisec(int millisec); /* * Create a directory and (if share is nonzero) adjust its permissions diff --git a/ci/print-test-failures.sh b/ci/print-test-failures.sh index 92a983a265..c70d6cdbf2 100755 --- a/ci/print-test-failures.sh +++ b/ci/print-test-failures.sh @@ -48,7 +48,7 @@ do ;; github-actions) mkdir -p failed-test-artifacts - echo "::set-env name=FAILED_TEST_ARTIFACTS::t/failed-test-artifacts" + echo "FAILED_TEST_ARTIFACTS=t/failed-test-artifacts" >>$GITHUB_ENV cp "${TEST_EXIT%.exit}.out" failed-test-artifacts/ tar czf failed-test-artifacts/"$test_name".trash.tar.gz "$trash_dir" continue diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 7c81e4ba49..1ed03623cd 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1120,26 +1120,44 @@ __git_pretty_aliases () # __git_aliased_command requires 1 argument __git_aliased_command () { - local word cmdline=$(__git config --get "alias.$1") - for word in $cmdline; do - case "$word" in - \!gitk|gitk) - echo "gitk" - return - ;; - \!*) : shell command alias ;; - -*) : option ;; - *=*) : setting env ;; - git) : git itself ;; - \(\)) : skip parens of shell function definition ;; - {) : skip start of shell helper function ;; - :) : skip null command ;; - \'*) : skip opening quote after sh -c ;; - *) - echo "$word" + local cur=$1 last list word cmdline + + while [[ -n "$cur" ]]; do + if [[ "$list" == *" $cur "* ]]; then + # loop detected return - esac + fi + + cmdline=$(__git config --get "alias.$cur") + list=" $cur $list" + last=$cur + cur= + + for word in $cmdline; do + case "$word" in + \!gitk|gitk) + cur="gitk" + break + ;; + \!*) : shell command alias ;; + -*) : option ;; + *=*) : setting env ;; + git) : git itself ;; + \(\)) : skip parens of shell function definition ;; + {) : skip start of shell helper function ;; + :) : skip null command ;; + \'*) : skip opening quote after sh -c ;; + *) + cur="$word" + break + esac + done done + + cur=$last + if [[ "$cur" != "$1" ]]; then + echo "$cur" + fi } # Check whether one of the given words is present on the command line, diff --git a/csum-file.h b/csum-file.h index f9cbd317fb..e54d53d1d0 100644 --- a/csum-file.h +++ b/csum-file.h @@ -62,4 +62,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data) hashwrite(f, &data, sizeof(data)); } +static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data) +{ + data = htonll(data); + hashwrite(f, &data, sizeof(data)); + return sizeof(data); +} + #endif diff --git a/diff-lib.c b/diff-lib.c index 082e249fc3..b73cc1859a 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -606,10 +606,12 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt) repo_init_revisions(opt->repo, &revs, NULL); copy_pathspec(&revs.prune_data, &opt->pathspec); + diff_setup_done(&revs.diffopt); revs.diffopt = *opt; if (diff_cache(&revs, tree_oid, NULL, 1)) exit(128); + clear_pathspec(&revs.prune_data); return 0; } diff --git a/git-compat-util.h b/git-compat-util.h index adfea06897..7d509c5022 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1354,4 +1354,6 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr)) #endif /* !__GNUC__ */ +void sleep_millisec(int millisec); + #endif diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index defd3dfd10..d2d1c81caf 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -35,7 +35,7 @@ const char *list_object_filter_config_name(enum list_objects_filter_choice c) /* not a real filter type; just the count of all filters */ break; } - BUG("list_object_filter_choice_name: invalid argument '%d'", c); + BUG("list_object_filter_config_name: invalid argument '%d'", c); } /* @@ -785,9 +785,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off if (!(offset >> 31)) continue; - hashwrite_be32(f, offset >> 32); - hashwrite_be32(f, offset & 0xffffffffUL); - written += 2 * sizeof(uint32_t); + written += hashwrite_be64(f, offset); nr_large_offset--; } @@ -975,8 +973,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * chunk_offsets[i]); hashwrite_be32(f, chunk_ids[i]); - hashwrite_be32(f, chunk_offsets[i] >> 32); - hashwrite_be32(f, chunk_offsets[i]); + hashwrite_be64(f, chunk_offsets[i]); written += MIDX_CHUNKLOOKUP_WIDTH; } @@ -970,7 +970,7 @@ static int notes_display_config(const char *k, const char *v, void *cb) if (*load_refs && !strcmp(k, "notes.displayref")) { if (!v) - config_error_nonbool(k); + return config_error_nonbool(k); string_list_add_refs_by_glob(&display_notes_refs, v); } diff --git a/pack-check.c b/pack-check.c index dad6d8ae7f..4b089fe8ec 100644 --- a/pack-check.c +++ b/pack-check.c @@ -39,7 +39,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, } while (len); index_crc = p->index_data; - index_crc += 2 + 256 + p->num_objects * (the_hash_algo->rawsz/4) + nr; + index_crc += 2 + 256 + (size_t)p->num_objects * (the_hash_algo->rawsz/4) + nr; return data_crc != ntohl(*index_crc); } @@ -164,7 +164,7 @@ static int verify_packfile(struct repository *r, int verify_pack_index(struct packed_git *p) { - off_t index_size; + size_t len; const unsigned char *index_base; git_hash_ctx ctx; unsigned char hash[GIT_MAX_RAWSZ]; @@ -172,14 +172,14 @@ int verify_pack_index(struct packed_git *p) if (open_pack_index(p)) return error("packfile %s index not opened", p->pack_name); - index_size = p->index_size; index_base = p->index_data; + len = p->index_size - the_hash_algo->rawsz; /* Verify SHA1 sum of the index file */ the_hash_algo->init_fn(&ctx); - the_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz)); + the_hash_algo->update_fn(&ctx, index_base, len); the_hash_algo->final_fn(hash, &ctx); - if (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz)) + if (!hasheq(hash, index_base + len)) err = error("Packfile index for %s hash mismatch", p->pack_name); return err; diff --git a/pack-revindex.c b/pack-revindex.c index d28a7e43d0..ecdde39cf4 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -130,7 +130,7 @@ static void create_pack_revindex(struct packed_git *p) if (p->index_version > 1) { const uint32_t *off_32 = - (uint32_t *)(index + 8 + p->num_objects * (hashsz + 4)); + (uint32_t *)(index + 8 + (size_t)p->num_objects * (hashsz + 4)); const uint32_t *off_64 = off_32 + p->num_objects; for (i = 0; i < num_ent; i++) { const uint32_t off = ntohl(*off_32++); diff --git a/pack-write.c b/pack-write.c index 23e19cc1ec..3513665e1e 100644 --- a/pack-write.c +++ b/pack-write.c @@ -151,13 +151,10 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec while (nr_large_offset) { struct pack_idx_entry *obj = *list++; uint64_t offset = obj->offset; - uint32_t split[2]; if (!need_large_offset(offset, opts)) continue; - split[0] = htonl(offset >> 32); - split[1] = htonl(offset & 0xffffffff); - hashwrite(f, split, 8); + hashwrite_be64(f, offset); nr_large_offset--; } } diff --git a/packfile.c b/packfile.c index 0929ebe4fc..9702b1218b 100644 --- a/packfile.c +++ b/packfile.c @@ -148,7 +148,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, * - hash of the packfile * - file checksum */ - if (idx_size != 4 * 256 + nr * (hashsz + 4) + hashsz + hashsz) + if (idx_size != st_add(4 * 256 + hashsz + hashsz, st_mult(nr, hashsz + 4))) return error("wrong index v1 file size in %s", path); } else if (version == 2) { /* @@ -164,10 +164,10 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, * variable sized table containing 8-byte entries * for offsets larger than 2^31. */ - unsigned long min_size = 8 + 4*256 + nr*(hashsz + 4 + 4) + hashsz + hashsz; - unsigned long max_size = min_size; + size_t min_size = st_add(8 + 4*256 + hashsz + hashsz, st_mult(nr, hashsz + 4 + 4)); + size_t max_size = min_size; if (nr) - max_size += (nr - 1)*8; + max_size = st_add(max_size, st_mult(nr - 1, 8)); if (idx_size < min_size || idx_size > max_size) return error("wrong index v2 file size in %s", path); if (idx_size != min_size && @@ -1933,14 +1933,14 @@ off_t nth_packed_object_offset(const struct packed_git *p, uint32_t n) const unsigned int hashsz = the_hash_algo->rawsz; index += 4 * 256; if (p->index_version == 1) { - return ntohl(*((uint32_t *)(index + (hashsz + 4) * n))); + return ntohl(*((uint32_t *)(index + (hashsz + 4) * (size_t)n))); } else { uint32_t off; - index += 8 + p->num_objects * (hashsz + 4); + index += 8 + (size_t)p->num_objects * (hashsz + 4); off = ntohl(*((uint32_t *)(index + 4 * n))); if (!(off & 0x80000000)) return off; - index += p->num_objects * 4 + (off & 0x7fffffff) * 8; + index += (size_t)p->num_objects * 4 + (off & 0x7fffffff) * 8; check_pack_index_ptr(p, index); return get_be64(index); } diff --git a/submodule.c b/submodule.c index b3bb59f066..eef5204e64 100644 --- a/submodule.c +++ b/submodule.c @@ -499,12 +499,6 @@ void prepare_submodule_repo_env(struct strvec *out) DEFAULT_GIT_DIR_ENVIRONMENT); } -static void prepare_submodule_repo_env_in_gitdir(struct strvec *out) -{ - prepare_submodule_repo_env_no_git_dir(out); - strvec_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT); -} - /* * Initialize a repository struct for a submodule based on the provided 'path'. * @@ -1455,8 +1449,8 @@ static int get_next_submodule(struct child_process *cp, if (task->repo) { struct strbuf submodule_prefix = STRBUF_INIT; child_process_init(cp); - cp->dir = task->repo->gitdir; - prepare_submodule_repo_env_in_gitdir(&cp->env_array); + cp->dir = task->repo->worktree; + prepare_submodule_repo_env(&cp->env_array); cp->git_cmd = 1; if (!spf->quiet) strbuf_addf(err, _("Fetching submodule %s%s\n"), @@ -1505,9 +1499,9 @@ static int get_next_submodule(struct child_process *cp, spf->prefix, task->sub->path); child_process_init(cp); - prepare_submodule_repo_env_in_gitdir(&cp->env_array); + prepare_submodule_repo_env(&cp->env_array); cp->git_cmd = 1; - cp->dir = task->repo->gitdir; + cp->dir = task->repo->worktree; strvec_init(&cp->args); strvec_pushv(&cp->args, spf->args.v); diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c index 42164d9898..cc08506cf0 100644 --- a/t/helper/test-proc-receive.c +++ b/t/helper/test-proc-receive.c @@ -10,8 +10,11 @@ static const char *proc_receive_usage[] = { NULL }; -static int die_version; -static int die_readline; +static int die_read_version; +static int die_write_version; +static int die_read_commands; +static int die_read_push_options; +static int die_write_report; static int no_push_options; static int use_atomic; static int use_push_options; @@ -33,14 +36,23 @@ struct command { static void proc_receive_verison(struct packet_reader *reader) { int server_version = 0; + if (die_read_version) + die("die with the --die-read-version option"); + for (;;) { int linelen; if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; + /* Ignore version negotiation for version 0 */ + if (version == 0) + continue; + if (reader->pktlen > 8 && starts_with(reader->line, "version=")) { server_version = atoi(reader->line+8); + if (server_version != 1) + die("bad protocol version: %d", server_version); linelen = strlen(reader->line); if (linelen < reader->pktlen) { const char *feature_list = reader->line + linelen + 1; @@ -52,12 +64,13 @@ static void proc_receive_verison(struct packet_reader *reader) { } } - if (server_version != 1 || die_version) - die("bad protocol version: %d", server_version); + if (die_write_version) + die("die with the --die-write-version option"); - packet_write_fmt(1, "version=%d%c%s\n", - version, '\0', - use_push_options && !no_push_options ? "push-options": ""); + if (version != 0) + packet_write_fmt(1, "version=%d%c%s\n", + version, '\0', + use_push_options && !no_push_options ? "push-options": ""); packet_flush(1); } @@ -75,11 +88,13 @@ static void proc_receive_read_commands(struct packet_reader *reader, if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; + if (die_read_commands) + die("die with the --die-read-commands option"); + if (parse_oid_hex(reader->line, &old_oid, &p) || *p++ != ' ' || parse_oid_hex(p, &new_oid, &p) || - *p++ != ' ' || - die_readline) + *p++ != ' ') die("protocol error: expected 'old new ref', got '%s'", reader->line); refname = p; @@ -99,6 +114,9 @@ static void proc_receive_read_push_options(struct packet_reader *reader, if (no_push_options || !use_push_options) return; + if (die_read_push_options) + die("die with the --die-read-push-options option"); + while (1) { if (packet_reader_read(reader) != PACKET_READ_NORMAL) break; @@ -117,10 +135,16 @@ int cmd__proc_receive(int argc, const char **argv) struct option options[] = { OPT_BOOL(0, "no-push-options", &no_push_options, "disable push options"), - OPT_BOOL(0, "die-version", &die_version, - "die during version negotiation"), - OPT_BOOL(0, "die-readline", &die_readline, - "die when readline"), + OPT_BOOL(0, "die-read-version", &die_read_version, + "die when reading version"), + OPT_BOOL(0, "die-write-version", &die_write_version, + "die when writing version"), + OPT_BOOL(0, "die-read-commands", &die_read_commands, + "die when reading commands"), + OPT_BOOL(0, "die-read-push-options", &die_read_push_options, + "die when reading push-options"), + OPT_BOOL(0, "die-write-report", &die_write_report, + "die when writing report"), OPT_STRING_LIST('r', "return", &returns, "old/new/ref/status/msg", "return of results"), OPT__VERBOSE(&verbose, "be verbose"), @@ -136,7 +160,7 @@ int cmd__proc_receive(int argc, const char **argv) usage_msg_opt("Too many arguments.", proc_receive_usage, options); packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE | - PACKET_READ_DIE_ON_ERR_PACKET); + PACKET_READ_GENTLE_ON_EOF); sigchain_push(SIGPIPE, SIG_IGN); proc_receive_verison(&reader); @@ -166,6 +190,8 @@ int cmd__proc_receive(int argc, const char **argv) fprintf(stderr, "proc-receive> %s\n", item->string); } + if (die_write_report) + die("die with the --die-write-report option"); if (returns.nr) for_each_string_list_item(item, &returns) packet_write_fmt(1, "%s\n", item->string); diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 22489c24dc..f4ba2e8c85 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -840,6 +840,27 @@ then exit 1 fi +test_lazy_prereq NESTED_INNER ' + >inner && + rm -f outer +' +test_lazy_prereq NESTED_PREREQ ' + >outer && + test_have_prereq NESTED_INNER && + echo "can create new file in cwd" >file && + test -f outer && + test ! -f inner +' +test_expect_success NESTED_PREREQ 'evaluating nested lazy prereqs dont interfere with each other' ' + nestedworks=yes +' + +if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" && test "$nestedworks" != yes +then + say 'bug in test framework: nested lazy prerequisites do not work' + exit 1 +fi + test_expect_success 'lazy prereqs do not turn off tracing' " run_sub_test_lib_test lazy-prereq-and-tracing \ 'lazy prereqs and -x' -v -x <<-\\EOF && diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index ebb8e1aecb..b4a9158307 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -91,11 +91,11 @@ test_expect_failure 'ignore .git/ with invalid config' ' test_expect_success 'early config and onbranch' ' echo "[broken" >broken && - test_with_config "[includeif \"onbranch:master\"]path=../broken" + test_with_config "[includeif \"onbranch:topic\"]path=../broken" ' test_expect_success 'onbranch config outside of git repo' ' - test_config_global includeIf.onbranch:master.path non-existent && + test_config_global includeIf.onbranch:topic.path non-existent && nongit git help ' diff --git a/t/t2106-update-index-assume-unchanged.sh b/t/t2106-update-index-assume-unchanged.sh index 99d858c6b7..2d450daf5c 100755 --- a/t/t2106-update-index-assume-unchanged.sh +++ b/t/t2106-update-index-assume-unchanged.sh @@ -5,20 +5,23 @@ test_description='git update-index --assume-unchanged test. . ./test-lib.sh -test_expect_success 'setup' \ - ': >file && - git add file && - git commit -m initial && - git branch other && - echo upstream >file && - git add file && - git commit -m upstream' +test_expect_success 'setup' ' + : >file && + git add file && + git commit -m initial && + git branch other && + echo upstream >file && + git add file && + git commit -m upstream +' -test_expect_success 'do not switch branches with dirty file' \ - 'git reset --hard && - git checkout other && - echo dirt >file && - git update-index --assume-unchanged file && - test_must_fail git checkout master' +test_expect_success 'do not switch branches with dirty file' ' + git reset --hard && + git checkout other && + echo dirt >file && + git update-index --assume-unchanged file && + test_must_fail git checkout - 2>err && + test_i18ngrep overwritten err +' test_done diff --git a/t/t3040-subprojects-basic.sh b/t/t3040-subprojects-basic.sh index b81eb5fd6f..6abdcbbc94 100755 --- a/t/t3040-subprojects-basic.sh +++ b/t/t3040-subprojects-basic.sh @@ -79,7 +79,4 @@ test_expect_success 'checkout in superproject' ' git diff-index --exit-code --raw --cached save -- sub1 ' -# just interesting what happened... -# git diff --name-status -M save master - test_done diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index 8f43303007..ca60faf480 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -672,6 +672,11 @@ test_expect_success 'notes.displayRef respects order' ' test_cmp expect-both-reversed actual ' +test_expect_success 'notes.displayRef with no value handled gracefully' ' + test_must_fail git -c notes.displayRef log -0 --notes && + test_must_fail git -c notes.displayRef diff-tree --notes HEAD +' + test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ git log -2 >actual && diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 1e56696e4f..b06fc36159 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -12,7 +12,7 @@ Initial setup: one - two - three - four (conflict-branch) / - A - B - C - D - E (master) + A - B - C - D - E (primary) | \ | F - G - H (branch1) | \ @@ -30,6 +30,7 @@ Initial setup: . "$TEST_DIRECTORY"/lib-rebase.sh test_expect_success 'setup' ' + git switch -C primary && test_commit A file1 && test_commit B file1 && test_commit C file2 && @@ -65,7 +66,7 @@ SHELL= export SHELL test_expect_success 'rebase --keep-empty' ' - git checkout -b emptybranch master && + git checkout -b emptybranch primary && git commit --allow-empty -m "empty" && git rebase --keep-empty -i HEAD~2 && git log --oneline >actual && @@ -86,7 +87,7 @@ test_expect_success 'rebase -i with empty todo list' ' ' test_expect_success 'rebase -i with the exec command' ' - git checkout master && + git checkout primary && ( set_fake_editor && FAKE_LINES="1 exec_>touch-one @@ -103,12 +104,12 @@ test_expect_success 'rebase -i with the exec command' ' test_path_is_file touch-three && test_path_is_file "touch-file name with spaces" && test_path_is_file touch-after-semicolon && - test_cmp_rev master HEAD && + test_cmp_rev primary HEAD && rm -f touch-* ' test_expect_success 'rebase -i with the exec command runs from tree root' ' - git checkout master && + git checkout primary && mkdir subdir && (cd subdir && set_fake_editor && FAKE_LINES="1 exec_>touch-subdir" \ @@ -121,7 +122,7 @@ test_expect_success 'rebase -i with the exec command runs from tree root' ' test_expect_success 'rebase -i with exec allows git commands in subdirs' ' test_when_finished "rm -rf subdir" && test_when_finished "git rebase --abort ||:" && - git checkout master && + git checkout primary && mkdir subdir && (cd subdir && set_fake_editor && FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \ @@ -139,13 +140,13 @@ test_expect_success 'rebase -i sets work tree properly' ' ' test_expect_success 'rebase -i with the exec command checks tree cleanness' ' - git checkout master && + git checkout primary && ( set_fake_editor && test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \ git rebase -i HEAD^ ) && - test_cmp_rev master^ HEAD && + test_cmp_rev primary^ HEAD && git reset --hard && git rebase --continue ' @@ -168,7 +169,7 @@ test_expect_success 'rebase -x with newline in command fails' ' ' test_expect_success 'rebase -i with exec of inexistent command' ' - git checkout master && + git checkout primary && test_when_finished "git rebase --abort" && ( set_fake_editor && @@ -259,8 +260,8 @@ test_expect_success 'stop on conflicting pick' ' >>>>>>> $commit (G) EOF git tag new-branch1 && - test_must_fail git rebase -i master && - test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && + test_must_fail git rebase -i primary && + test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" && test_cmp expect .git/rebase-merge/patch && test_cmp expect2 file1 && test "$(git diff --name-status | @@ -287,7 +288,7 @@ test_expect_success 'abort' ' test_expect_success 'abort with error when new base cannot be checked out' ' git rm --cached file1 && git commit -m "remove file in base" && - test_must_fail git rebase -i master > output 2>&1 && + test_must_fail git rebase -i primary > output 2>&1 && test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \ output && test_i18ngrep "file1" output && @@ -301,7 +302,7 @@ test_expect_success 'retain authorship' ' test_tick && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && git tag twerp && - git rebase -i --onto master HEAD^ && + git rebase -i --onto primary HEAD^ && git show HEAD | grep "^Author: Twerp Snog" ' @@ -336,10 +337,10 @@ test_expect_success 'squash' ' ( set_fake_editor && FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ - git rebase -i --onto master HEAD~2 + git rebase -i --onto primary HEAD~2 ) && test B = $(cat file7) && - test_cmp_rev HEAD^ master + test_cmp_rev HEAD^ primary ' test_expect_success 'retain authorship when squashing' ' @@ -366,12 +367,12 @@ test_expect_failure REBASE_P 'exchange two commits with -p' ' ' test_expect_success REBASE_P 'preserve merges with -p' ' - git checkout -b to-be-preserved master^ && + git checkout -b to-be-preserved primary^ && : > unrelated-file && git add unrelated-file && test_tick && git commit -m "unrelated" && - git checkout -b another-branch master && + git checkout -b another-branch primary && echo B > file1 && test_tick && git commit -m J file1 && @@ -394,7 +395,7 @@ test_expect_success REBASE_P 'preserve merges with -p' ' git commit -m M file1 && git checkout -b to-be-rebased && test_tick && - git rebase -i -p --onto branch1 master && + git rebase -i -p --onto branch1 primary && git update-index --refresh && git diff-files --quiet && git diff-index --quiet --cached HEAD -- && @@ -437,7 +438,7 @@ test_expect_success '--continue tries to commit' ' ' test_expect_success 'verbose flag is heeded, even after --continue' ' - git reset --hard master@{1} && + git reset --hard primary@{1} && test_tick && test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && echo resolved > file1 && @@ -802,7 +803,7 @@ test_expect_success 'rebase -i continue with unstaged submodule' ' ' test_expect_success 'avoid unnecessary reset' ' - git checkout master && + git checkout primary && git reset --hard && test-tool chmtime =123456789 file3 && git update-index --refresh && @@ -814,14 +815,14 @@ test_expect_success 'avoid unnecessary reset' ' ' test_expect_success 'reword' ' - git checkout -b reword-branch master && + git checkout -b reword-branch primary && ( set_fake_editor && FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \ git rebase -i A && git show HEAD | grep "E changed" && - test $(git rev-parse master) != $(git rev-parse HEAD) && - test_cmp_rev master^ HEAD^ && + test $(git rev-parse primary) != $(git rev-parse HEAD) && + test_cmp_rev primary^ HEAD^ && FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \ git rebase -i A && git show HEAD^ | grep "D changed" && @@ -918,7 +919,7 @@ test_expect_success 'rebase-i history with funny messages' ' ' test_expect_success 'prepare for rebase -i --exec' ' - git checkout master && + git checkout primary && git checkout -b execute && test_commit one_exec main.txt one_exec && test_commit two_exec main.txt two_exec && @@ -1027,7 +1028,7 @@ test_expect_success 'rebase -i --exec without <CMD>' ' git reset --hard execute && test_must_fail git rebase -i --exec 2>actual && test_i18ngrep "requires a value" actual && - git checkout master + git checkout primary ' test_expect_success 'rebase -i --root re-order and drop commits' ' @@ -1079,7 +1080,7 @@ test_expect_success 'rebase -i --root fixup root commit' ' test_expect_success 'rebase -i --root reword original root commit' ' test_when_finished "test_might_fail git rebase --abort" && - git checkout -b reword-original-root-branch master && + git checkout -b reword-original-root-branch primary && ( set_fake_editor && FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \ @@ -1091,7 +1092,7 @@ test_expect_success 'rebase -i --root reword original root commit' ' test_expect_success 'rebase -i --root reword new root commit' ' test_when_finished "test_might_fail git rebase --abort" && - git checkout -b reword-now-root-branch master && + git checkout -b reword-now-root-branch primary && ( set_fake_editor && FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \ @@ -1251,7 +1252,7 @@ test_expect_success 'rebase -i error on commits with \ in message' ' ' test_expect_success 'short commit ID setup' ' - test_when_finished "git checkout master" && + test_when_finished "git checkout primary" && git checkout --orphan collide && git rm -rf . && ( @@ -1292,7 +1293,7 @@ test_expect_success 'short commit ID collide' ' t3404_collider sha1:ac4f2ee t3404_collider sha256:16697 EOF - test_when_finished "reset_rebase && git checkout master" && + test_when_finished "reset_rebase && git checkout primary" && git checkout collide && colliding_id=$(test_oid t3404_collision) && hexsz=$(test_oid hexsz) && @@ -1416,11 +1417,11 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' rebase_setup_and_clean () { test_when_finished " - git checkout master && + git checkout primary && test_might_fail git branch -D $1 && test_might_fail git rebase --abort " && - git checkout -b $1 ${2:-master} + git checkout -b $1 ${2:-primary} } test_expect_success 'drop' ' @@ -1451,7 +1452,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) To avoid this message, use "drop" to explicitly remove a commit. EOF test_config rebase.missingCommitsCheck warn && @@ -1469,8 +1470,8 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2) To avoid this message, use "drop" to explicitly remove a commit. Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. @@ -1512,11 +1513,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ig test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. EOF head -n4 expect >expect.2 && @@ -1546,11 +1547,11 @@ test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = wa test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' ' cat >expect <<-EOF && - error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) Warning: some commits may have been dropped accidentally. Dropped commits (newer to older): - - $(git rev-list --pretty=oneline --abbrev-commit -1 master) - - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary) + - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4) To avoid this message, use "drop" to explicitly remove a commit. Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings. @@ -1635,7 +1636,7 @@ test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and e ( set_cat_todo_editor && test_must_fail git rebase -i --exec "git show HEAD" \ - --autosquash master >actual + --autosquash primary >actual ) && test_cmp expected actual ' @@ -1646,7 +1647,7 @@ test_expect_success 'static check of bad command' ' set_fake_editor && test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \ git rebase -i --root 2>actual && - test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \ + test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \ actual && test_i18ngrep "You can fix this with .git rebase --edit-todo.." \ actual && @@ -1798,13 +1799,13 @@ test_expect_success 'todo has correct onto hash' ' ' test_expect_success 'ORIG_HEAD is updated correctly' ' - test_when_finished "git checkout master && git branch -D test-orig-head" && + test_when_finished "git checkout primary && git branch -D test-orig-head" && git checkout -b test-orig-head A && git commit --allow-empty -m A1 && git commit --allow-empty -m A2 && git commit --allow-empty -m A3 && git commit --allow-empty -m A4 && - git rebase master && + git rebase primary && test_cmp_rev ORIG_HEAD test-orig-head@{1} ' diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 8bdaa0a693..47f0e2889d 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -877,13 +877,13 @@ test_expect_success 'rename empty' ' test_expect_success 'combined diff with autocrlf conversion' ' git reset --hard && - echo >x hello && - git commit -m "one side" x && + test_commit "one side" x hello one-side && git checkout HEAD^ && echo >x goodbye && git commit -m "the other side" x && git config core.autocrlf true && - test_must_fail git merge master && + test_must_fail git merge one-side >actual && + test_i18ngrep "Automatic merge failed" actual && git diff >actual.raw && sed -e "1,/^@@@/d" actual.raw >actual && diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index 8318781d2b..1d40fcad39 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -277,7 +277,7 @@ test_expect_success 'pack with missing parent' ' git pack-objects --stdout --revs <revs >/dev/null ' -test_expect_success JGIT 'we can read jgit bitmaps' ' +test_expect_success JGIT,SHA1 'we can read jgit bitmaps' ' git clone --bare . compat-jgit.git && ( cd compat-jgit.git && @@ -287,7 +287,7 @@ test_expect_success JGIT 'we can read jgit bitmaps' ' ) ' -test_expect_success JGIT 'jgit can read our bitmaps' ' +test_expect_success JGIT,SHA1 'jgit can read our bitmaps' ' git clone --bare . compat-us.git && ( cd compat-us.git && diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh index 521a347710..344d13f61a 100644 --- a/t/t5411/common-functions.sh +++ b/t/t5411/common-functions.sh @@ -42,7 +42,7 @@ create_commits_in () { make_user_friendly_and_stable_output () { sed \ -e "s/ *\$//" \ - -e "s/ */ /g" \ + -e "s/ */ /g" \ -e "s/'/\"/g" \ -e "s/ / /g" \ -e "s/$A/<COMMIT-A>/g" \ @@ -54,3 +54,8 @@ make_user_friendly_and_stable_output () { -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \ -e "/^error: / d" } + +filter_out_user_friendly_and_stable_output () { + make_user_friendly_and_stable_output | + sed -n ${1+"$@"} +} diff --git a/t/t5411/test-0000-standard-git-push.sh b/t/t5411/test-0000-standard-git-push.sh index 2b04b49367..47b058af7e 100644 --- a/t/t5411/test-0000-standard-git-push.sh +++ b/t/t5411/test-0000-standard-git-push.sh @@ -36,11 +36,10 @@ test_expect_success "git-push --atomic ($PROTOCOL)" ' main \ $B:refs/heads/next \ >out 2>&1 && - make_user_friendly_and_stable_output <out | - sed -n \ - -e "/^To / { s/ */ /g; p; }" \ - -e "/^ ! / { s/ */ /g; p; }" \ - >actual && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && cat >expect <<-EOF && To <URL/of/upstream.git> ! [rejected] main -> main (non-fast-forward) diff --git a/t/t5411/test-0001-standard-git-push--porcelain.sh b/t/t5411/test-0001-standard-git-push--porcelain.sh index 747307f8da..bbead12bbb 100644 --- a/t/t5411/test-0001-standard-git-push--porcelain.sh +++ b/t/t5411/test-0001-standard-git-push--porcelain.sh @@ -37,16 +37,15 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" ' main \ $B:refs/heads/next \ >out 2>&1 && - make_user_friendly_and_stable_output <out | - sed -n \ - -e "s/^# GETTEXT POISON #//" \ - -e "/^To / { s/ */ /g; p; }" \ - -e "/^! / { s/ */ /g; p; }" \ - >actual && + filter_out_user_friendly_and_stable_output \ + -e "s/^# GETTEXT POISON #//" \ + -e "/^To / { p; }" \ + -e "/^! / { p; }" \ + <out >actual && cat >expect <<-EOF && To <URL/of/upstream.git> - ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward) - ! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed) + ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward) + ! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed) EOF test_cmp expect actual && git -C "$upstream" show-ref >out && diff --git a/t/t5411/test-0013-bad-protocol.sh b/t/t5411/test-0013-bad-protocol.sh index 854c3e884a..b9be12be77 100644 --- a/t/t5411/test-0013-bad-protocol.sh +++ b/t/t5411/test-0013-bad-protocol.sh @@ -16,7 +16,8 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" ' # Check status report for git-push sed -n \ - -e "/^To / { p; n; p; }" \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ <actual >actual-report && cat >expect <<-EOF && To <URL/of/upstream.git> @@ -41,32 +42,98 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" ' test_cmp expect actual ' -test_expect_success "setup proc-receive hook (hook --die-version, $PROTOCOL)" ' +test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n" - test-tool proc-receive -v --die-version + test-tool proc-receive -v --die-read-version EOF ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push : refs/for/main/topic(A) -test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" ' +test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL)" ' test_must_fail git -C workbench push origin \ HEAD:refs/for/main/topic \ >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-version + EOF +' +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-commands + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && cat >expect <<-EOF && - remote: # pre-receive hook - remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic - remote: # proc-receive hook - remote: fatal: bad protocol version: 1 - remote: error: proc-receive version "0" is not supported To <URL/of/upstream.git> ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) EOF test_cmp expect actual && + grep "remote: fatal: die with the --die-read-commands option" out && git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && @@ -76,23 +143,65 @@ test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" test_cmp expect actual ' -test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" ' +test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n" - test-tool proc-receive -v --die-readline + test-tool proc-receive -v --die-read-push-options EOF ' # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push : refs/for/main/topic(A) -test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" ' +test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL)" ' + git -C "$upstream" config receive.advertisePushOptions true && test_must_fail git -C workbench push origin \ + -o reviewers=user1,user2 \ HEAD:refs/for/main/topic \ >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-push-options option" out && + + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-report + EOF +' - grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual && +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL)" ' + test_must_fail git -C workbench push origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; }" \ + -e "/^ ! / { p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook) + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-report option" out && git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && @@ -130,6 +239,7 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" ' ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -173,6 +283,7 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" ' ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -208,6 +319,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" ' ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status) EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && diff --git a/t/t5411/test-0014-bad-protocol--porcelain.sh b/t/t5411/test-0014-bad-protocol--porcelain.sh index 88c56311da..fdb4569109 100644 --- a/t/t5411/test-0014-bad-protocol--porcelain.sh +++ b/t/t5411/test-0014-bad-protocol--porcelain.sh @@ -42,6 +42,175 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porc test_cmp expect actual ' +test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-version + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-version + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-version option" out && + grep "remote: error: fail to negotiate version with proc-receive hook" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-commands + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-commands option" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-read-push-options + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL/porcelain)" ' + git -C "$upstream" config receive.advertisePushOptions true && + test_must_fail git -C workbench push --porcelain origin \ + -o reviewers=user1,user2 \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-read-push-options option" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + +test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v --die-write-report + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push : refs/for/main/topic(A) +test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL/porcelain)" ' + test_must_fail git -C workbench push --porcelain origin \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + filter_out_user_friendly_and_stable_output \ + -e "/^To / { p; n; p; n; p; }" \ + <out >actual && + cat >expect <<-EOF && + To <URL/of/upstream.git> + ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook) + Done + EOF + test_cmp expect actual && + grep "remote: fatal: die with the --die-write-report option" out && + + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + EOF + test_cmp expect actual +' + test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" ' write_script "$upstream/hooks/proc-receive" <<-EOF printf >&2 "# proc-receive hook\n" @@ -71,6 +240,7 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain) Done EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -84,7 +254,6 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain) # Refs of workbench: main(A) tags/v123 test_expect_success "cleanup ($PROTOCOL/porcelain)" ' git -C "$upstream" update-ref -d refs/heads/next - ' test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" ' @@ -115,6 +284,7 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" ' Done EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && @@ -151,6 +321,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porce Done EOF test_cmp expect actual && + git -C "$upstream" show-ref >out && make_user_friendly_and_stable_output <out >actual && cat >expect <<-EOF && diff --git a/t/t5411/test-0026-push-options.sh b/t/t5411/test-0026-push-options.sh index d414be87d0..e88edb16a4 100644 --- a/t/t5411/test-0026-push-options.sh +++ b/t/t5411/test-0026-push-options.sh @@ -32,6 +32,66 @@ test_expect_success "enable push options ($PROTOCOL)" ' git -C "$upstream" config receive.advertisePushOptions true ' +test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + --version 0 \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push -o ... : next(A) refs/for/main/topic +test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL)" ' + git -C workbench push \ + --atomic \ + -o issue=123 \ + -o reviewer=user1 \ + origin \ + HEAD:refs/heads/next \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: proc-receive> ok refs/for/main/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + To <URL/of/upstream.git> + * [new branch] HEAD -> next + * [new reference] HEAD -> refs/for/main/topic + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + <COMMIT-A> refs/heads/next + EOF + test_cmp expect actual +' + +test_expect_success "restore proc-receive hook ($PROTOCOL)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) next(A) +# Refs of workbench: main(A) tags/v123 +test_expect_success "cleanup ($PROTOCOL)" ' + git -C "$upstream" update-ref -d refs/heads/next +' + # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push -o ... : next(A) refs/for/main/topic diff --git a/t/t5411/test-0027-push-options--porcelain.sh b/t/t5411/test-0027-push-options--porcelain.sh index d5d0dcb172..3a6561b5ea 100644 --- a/t/t5411/test-0027-push-options--porcelain.sh +++ b/t/t5411/test-0027-push-options--porcelain.sh @@ -33,6 +33,68 @@ test_expect_success "enable push options ($PROTOCOL/porcelain)" ' git -C "$upstream" config receive.advertisePushOptions true ' +test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + --version 0 \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) +# Refs of workbench: main(A) tags/v123 +# git push -o ... : next(A) refs/for/main/topic +test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/porcelain)" ' + git -C workbench push \ + --porcelain \ + --atomic \ + -o issue=123 \ + -o reviewer=user1 \ + origin \ + HEAD:refs/heads/next \ + HEAD:refs/for/main/topic \ + >out 2>&1 && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + remote: # pre-receive hook + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: # proc-receive hook + remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + remote: proc-receive> ok refs/for/main/topic + remote: # post-receive hook + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next + remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic + To <URL/of/upstream.git> + * HEAD:refs/heads/next [new branch] + * HEAD:refs/for/main/topic [new reference] + Done + EOF + test_cmp expect actual && + git -C "$upstream" show-ref >out && + make_user_friendly_and_stable_output <out >actual && + cat >expect <<-EOF && + <COMMIT-A> refs/heads/main + <COMMIT-A> refs/heads/next + EOF + test_cmp expect actual +' + +test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" ' + write_script "$upstream/hooks/proc-receive" <<-EOF + printf >&2 "# proc-receive hook\n" + test-tool proc-receive -v \ + -r "ok refs/for/main/topic" + EOF +' + +# Refs of upstream : main(A) next(A) +# Refs of workbench: main(A) tags/v123 +test_expect_success "cleanup ($PROTOCOL/porcelain)" ' + git -C "$upstream" update-ref -d refs/heads/next +' + # Refs of upstream : main(A) # Refs of workbench: main(A) tags/v123 # git push -o ... : next(A) refs/for/main/topic diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index dd8e423d25..a7f6f9fdd6 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -719,4 +719,67 @@ test_expect_success 'fetch new submodule commit intermittently referenced by sup ) ' +add_commit_push () { + dir="$1" + msg="$2" + shift 2 + git -C "$dir" add "$@" && + git -C "$dir" commit -a -m "$msg" && + git -C "$dir" push +} + +compare_refs_in_dir () { + fail= && + if test "x$1" = 'x!' + then + fail='!' && + shift + fi && + git -C "$1" rev-parse --verify "$2" >expect && + git -C "$3" rev-parse --verify "$4" >actual && + eval $fail test_cmp expect actual +} + + +test_expect_success 'setup nested submodule fetch test' ' + # does not depend on any previous test setups + + for repo in outer middle inner + do + ( + git init --bare $repo && + git clone $repo ${repo}_content && + echo "$repo" >"${repo}_content/file" && + add_commit_push ${repo}_content "initial" file + ) || return 1 + done && + + git clone outer A && + git -C A submodule add "$pwd/middle" && + git -C A/middle/ submodule add "$pwd/inner" && + add_commit_push A/middle/ "adding inner sub" .gitmodules inner && + add_commit_push A/ "adding middle sub" .gitmodules middle && + + git clone outer B && + git -C B/ submodule update --init middle && + + compare_refs_in_dir A HEAD B HEAD && + compare_refs_in_dir A/middle HEAD B/middle HEAD && + test -f B/file && + test -f B/middle/file && + ! test -f B/middle/inner/file && + + echo "change on inner repo of A" >"A/middle/inner/file" && + add_commit_push A/middle/inner "change on inner" file && + add_commit_push A/middle "change on inner" inner && + add_commit_push A "change on inner" middle +' + +test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' ' + # depends on previous test for setup + + git -C B/ fetch && + compare_refs_in_dir A origin/master B origin/master +' + test_done diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index c5c4ea5fc0..6774e9d86f 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -29,8 +29,11 @@ test_expect_success 'setup' ' test_expect_success 'pull.rebase not set' ' git reset --hard c0 && - git pull . c1 2>err && - test_i18ngrep "Pulling without specifying how to reconcile" err + git -c color.advice=always pull . c1 2>err && + test_decode_color <err >decoded && + test_i18ngrep "<YELLOW>hint: " decoded && + test_i18ngrep "Pulling without specifying how to reconcile" decoded + ' test_expect_success 'pull.rebase not set and pull.ff=true' ' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 2be9190425..5c01c75d40 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2195,6 +2195,25 @@ test_expect_success 'complete files' ' test_completion "git add mom" "momified" ' +test_expect_success "simple alias" ' + test_config alias.co checkout && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + +test_expect_success "recursive alias" ' + test_config alias.co checkout && + test_config alias.cod "co --detached" && + test_completion "git cod m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && test_completion "git co m" <<-\EOF diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 59bbf75e83..7ba3011b90 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -423,7 +423,7 @@ write_script () { # - Explicitly using test_have_prereq. # # - Implicitly by specifying the prerequisite tag in the calls to -# test_expect_{success,failure,code}. +# test_expect_{success,failure} and test_external{,_without_stderr}. # # The single parameter is the prerequisite tag (a simple word, in all # capital letters by convention). @@ -474,15 +474,15 @@ test_lazy_prereq () { test_run_lazy_prereq_ () { script=' -mkdir -p "$TRASH_DIRECTORY/prereq-test-dir" && +mkdir -p "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" && ( - cd "$TRASH_DIRECTORY/prereq-test-dir" &&'"$2"' + cd "$TRASH_DIRECTORY/prereq-test-dir-'"$1"'" &&'"$2"' )' say >&3 "checking prerequisite: $1" say >&3 "$script" test_eval_ "$script" eval_ret=$? - rm -rf "$TRASH_DIRECTORY/prereq-test-dir" + rm -rf "$TRASH_DIRECTORY/prereq-test-dir-$1" if test "$eval_ret" = 0; then say >&3 "prerequisite $1 ok" else |