]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ab/reflog-prep'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Jan 2022 19:52:52 +0000 (11:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Jan 2022 19:52:52 +0000 (11:52 -0800)
Code refactoring in the reflog part of refs API.

* ab/reflog-prep:
  reflog + refs-backend: move "verbose" out of the backend
  refs files-backend: assume cb->newlog if !EXPIRE_REFLOGS_DRY_RUN
  reflog: reduce scope of "struct rev_info"
  reflog expire: don't use lookup_commit_reference_gently()
  reflog expire: refactor & use "tip_commit" only for UE_NORMAL
  reflog expire: use "switch" over enum values
  reflog: change one->many worktree->refnames to use a string_list
  reflog expire: narrow scope of "cb" in cmd_reflog_expire()
  reflog delete: narrow scope of "cmd" passed to count_reflog_ent()

320 files changed:
Documentation/RelNotes/2.35.0.txt
Documentation/config/gpg.txt
Documentation/git-am.txt
Documentation/git-apply.txt
Documentation/git-clone.txt
Documentation/git-fmt-merge-msg.txt
Documentation/git-format-patch.txt
Documentation/git-ls-files.txt
Documentation/git-merge.txt
Documentation/git-repack.txt
Documentation/git-sparse-checkout.txt
Makefile
apply.c
apply.h
builtin/am.c
builtin/clean.c
builtin/clone.c
builtin/fast-export.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/log.c
builtin/ls-files.c
builtin/merge.c
builtin/prune.c
builtin/pull.c
builtin/receive-pack.c
builtin/repack.c
builtin/rm.c
builtin/sparse-checkout.c
builtin/stash.c
cache.h
common-main.c
config.mak.dev
contrib/mw-to-git/t/t9365-continuing-queries.sh
contrib/subtree/t/t7900-subtree.sh
daemon.c
diff.c
dir.c
dir.h
environment.c
fmt-merge-msg.c
fmt-merge-msg.h
git-compat-util.h
git-p4.py
grep.c
grep.h
help.c
object-file.c
object-store.h
object.c
po/README.md
refs.c
refs/debug.c
refs/files-backend.c
refs/packed-backend.c
refs/packed-backend.h
refs/refs-internal.h
repository.c
repository.h
revision.c
revision.h
sequencer.c
setup.c
symlinks.c
t/Makefile
t/annotate-tests.sh
t/chainlint.sed
t/chainlint/arithmetic-expansion.expect
t/chainlint/bash-array.expect
t/chainlint/blank-line.expect
t/chainlint/blank-line.test
t/chainlint/block-comment.expect [new file with mode: 0644]
t/chainlint/block-comment.test [new file with mode: 0644]
t/chainlint/block.expect
t/chainlint/block.test
t/chainlint/broken-chain.expect
t/chainlint/broken-chain.test
t/chainlint/case-comment.expect [new file with mode: 0644]
t/chainlint/case-comment.test [new file with mode: 0644]
t/chainlint/case.expect
t/chainlint/case.test
t/chainlint/close-nested-and-parent-together.expect
t/chainlint/close-subshell.expect
t/chainlint/command-substitution.expect
t/chainlint/comment.expect
t/chainlint/complex-if-in-cuddled-loop.expect
t/chainlint/complex-if-in-cuddled-loop.test
t/chainlint/cuddled-if-then-else.expect
t/chainlint/cuddled-if-then-else.test
t/chainlint/cuddled-loop.expect
t/chainlint/cuddled-loop.test
t/chainlint/cuddled.expect
t/chainlint/cuddled.test
t/chainlint/exit-loop.expect
t/chainlint/exit-subshell.expect
t/chainlint/for-loop.expect
t/chainlint/for-loop.test
t/chainlint/here-doc-close-subshell.expect
t/chainlint/here-doc-multi-line-command-subst.expect
t/chainlint/here-doc-multi-line-string.expect
t/chainlint/here-doc.expect
t/chainlint/here-doc.test
t/chainlint/if-in-loop.expect
t/chainlint/if-in-loop.test
t/chainlint/if-then-else.expect
t/chainlint/if-then-else.test
t/chainlint/incomplete-line.expect
t/chainlint/inline-comment.expect
t/chainlint/loop-in-if.expect
t/chainlint/loop-in-if.test
t/chainlint/multi-line-nested-command-substitution.expect
t/chainlint/multi-line-string.expect
t/chainlint/multi-line-string.test
t/chainlint/negated-one-liner.expect
t/chainlint/nested-cuddled-subshell.expect
t/chainlint/nested-here-doc.expect
t/chainlint/nested-subshell-comment.expect
t/chainlint/nested-subshell-comment.test
t/chainlint/nested-subshell.expect
t/chainlint/nested-subshell.test
t/chainlint/not-heredoc.expect [new file with mode: 0644]
t/chainlint/not-heredoc.test [new file with mode: 0644]
t/chainlint/one-liner.expect
t/chainlint/one-liner.test
t/chainlint/p4-filespec.expect
t/chainlint/pipe.expect
t/chainlint/pipe.test
t/chainlint/semicolon.expect
t/chainlint/semicolon.test
t/chainlint/subshell-here-doc.expect
t/chainlint/subshell-here-doc.test
t/chainlint/subshell-one-liner.expect
t/chainlint/t7900-subtree.expect
t/chainlint/t7900-subtree.test
t/chainlint/while-loop.expect
t/chainlint/while-loop.test
t/helper/test-read-cache.c
t/helper/test-ref-store.c
t/helper/test-trace2.c
t/lib-pager.sh
t/perf/p0005-status.sh
t/perf/p0006-read-tree-checkout.sh
t/perf/p0007-write-cache.sh
t/perf/p0100-globbing.sh
t/perf/p1400-update-ref.sh
t/perf/p1451-fsck-skip-list.sh
t/perf/p3400-rebase.sh
t/perf/p4002-diff-color-moved.sh [new file with mode: 0755]
t/perf/p5302-pack-index.sh
t/perf/p5303-many-packs.sh
t/perf/p7519-fsmonitor.sh
t/perf/perf-lib.sh
t/t0005-signals.sh
t/t0008-ignores.sh
t/t0011-hashmap.sh
t/t0020-crlf.sh
t/t0021-conversion.sh
t/t0026-eol-config.sh
t/t0060-path-utils.sh
t/t0069-oidtree.sh
t/t0095-bloom.sh
t/t0410-partial-clone.sh
t/t1006-cat-file.sh
t/t1010-mktree.sh
t/t1020-subdirectory.sh
t/t1050-large.sh
t/t1091-sparse-checkout-builtin.sh
t/t1092-sparse-checkout-compatibility.sh
t/t1300-config.sh
t/t1400-update-ref.sh
t/t1403-show-ref.sh
t/t1410-reflog.sh
t/t1512-rev-parse-disambiguation.sh
t/t1700-split-index.sh
t/t2004-checkout-cache-temp.sh
t/t2012-checkout-last.sh
t/t2102-update-index-symlinks.sh
t/t2103-update-index-ignore-missing.sh
t/t2200-add-update.sh
t/t2201-add-update-typechange.sh
t/t2203-add-intent.sh
t/t2501-cwd-empty.sh [new file with mode: 0755]
t/t3005-ls-files-relative.sh
t/t3070-wildmatch.sh
t/t3202-show-branch.sh
t/t3303-notes-subtrees.sh
t/t3305-notes-fanout.sh
t/t3402-rebase-merge.sh
t/t3404-rebase-interactive.sh
t/t3417-rebase-whitespace-fix.sh
t/t3501-revert-cherry-pick.sh
t/t3508-cherry-pick-many-commits.sh
t/t3600-rm.sh
t/t3700-add.sh
t/t3705-add-sparse-checkout.sh
t/t3903-stash.sh
t/t3920-crlf-messages.sh
t/t4001-diff-rename.sh
t/t4012-diff-binary.sh
t/t4013-diff-various.sh
t/t4014-format-patch.sh
t/t4015-diff-whitespace.sh
t/t4018-diff-funcname.sh
t/t4019-diff-wserror.sh
t/t4023-diff-rename-typechange.sh
t/t4024-diff-optimize-common.sh
t/t4025-hunk-header.sh
t/t4038-diff-combined.sh
t/t4046-diff-unmerged.sh
t/t4049-diff-stat-count.sh
t/t4052-stat-output.sh
t/t4057-diff-combined-paths.sh
t/t4105-apply-fuzz.sh
t/t4106-apply-stdin.sh
t/t4116-apply-reverse.sh
t/t4117-apply-reject.sh
t/t4118-apply-empty-context.sh
t/t4123-apply-shrink.sh
t/t4124-apply-ws-rule.sh
t/t4125-apply-ws-fuzz.sh
t/t4126-apply-empty.sh
t/t4127-apply-same-fn.sh
t/t4138-apply-ws-expansion.sh
t/t4150-am.sh
t/t4151-am-abort.sh
t/t4202-log.sh
t/t4204-patch-id.sh
t/t4205-log-pretty-formats.sh
t/t4211-line-log.sh
t/t4212-log-corrupt.sh
t/t4216-log-bloom.sh
t/t5000-tar-tree.sh
t/t5003-archive-zip.sh
t/t5004-archive-corner-cases.sh
t/t5100-mailinfo.sh
t/t5300-pack-object.sh
t/t5302-pack-index.sh
t/t5306-pack-nobase.sh
t/t5307-pack-missing-commit.sh
t/t5310-pack-bitmaps.sh
t/t5316-pack-delta-depth.sh
t/t5317-pack-objects-filter-objects.sh
t/t5318-commit-graph.sh
t/t5319-multi-pack-index.sh
t/t5322-pack-objects-sparse.sh
t/t5325-reverse-index.sh
t/t5500-fetch-pack.sh
t/t5502-quickfetch.sh
t/t5505-remote.sh
t/t5510-fetch.sh
t/t5515-fetch-merge-logic.sh
t/t5516-fetch-push.sh
t/t5540-http-push-webdav.sh
t/t5550-http-fetch-dumb.sh
t/t5552-skipping-fetch-negotiator.sh
t/t5553-set-upstream.sh
t/t5562-http-backend-content-length.sh
t/t5570-git-daemon.sh
t/t5571-pre-push-hook.sh
t/t5611-clone-config.sh
t/t5616-partial-clone.sh
t/t5702-protocol-v2.sh
t/t6005-rev-list-count.sh
t/t6009-rev-list-parent.sh
t/t6019-rev-list-ancestry-path.sh
t/t6060-merge-index.sh
t/t6101-rev-parse-parents.sh
t/t6112-rev-list-filters-objects.sh
t/t6120-describe.sh
t/t6132-pathspec-exclude.sh
t/t6200-fmt-merge-msg.sh
t/t6300-for-each-ref.sh
t/t6406-merge-attr.sh
t/t6407-merge-binary.sh
t/t6409-merge-subtree.sh
t/t6411-merge-filemode.sh
t/t6412-merge-large-rename.sh
t/t6416-recursive-corner-cases.sh
t/t6417-merge-ours-theirs.sh
t/t6430-merge-recursive.sh
t/t6600-test-reach.sh
t/t7004-tag.sh
t/t7010-setup.sh
t/t7110-reset-merge.sh
t/t7501-commit-basic-functionality.sh
t/t7505-prepare-commit-msg-hook.sh
t/t7512-status-help.sh
t/t7513-interpret-trailers.sh
t/t7519-status-fsmonitor.sh
t/t7600-merge.sh
t/t7602-merge-octopus-many.sh
t/t7603-merge-reduce-heads.sh
t/t7700-repack.sh
t/t7810-grep.sh
t/t7812-grep-icase-non-ascii.sh
t/t8002-blame.sh
t/t8003-blame-corner-cases.sh
t/t8014-blame-ignore-fuzzy.sh
t/t9104-git-svn-follow-parent.sh
t/t9107-git-svn-migrate.sh
t/t9130-git-svn-authors-file.sh
t/t9134-git-svn-ignore-paths.sh
t/t9138-git-svn-authors-prog.sh
t/t9146-git-svn-empty-dirs.sh
t/t9147-git-svn-include-paths.sh
t/t9152-svn-empty-dirs-after-gc.sh
t/t9304-fast-import-marks.sh
t/t9350-fast-export.sh
t/t9400-git-cvsserver-server.sh
t/t9800-git-p4-basic.sh
t/t9810-git-p4-rcs.sh
t/t9818-git-p4-block.sh
t/t9902-completion.sh
t/test-lib-functions.sh
tmp-objdir.c
tmp-objdir.h
unpack-trees.c
unpack-trees.h
upload-pack.c
wt-status.c

index 217334c9345e692e1f4700a542571886dd9c63b7..ff90dd4776592d334bfbf9fcfc763a1862ce6bc6 100644 (file)
@@ -58,6 +58,28 @@ UI, Workflows & Features
  * "git name-rev" has been tweaked to give output that is shorter and
    easier to understand.
 
+ * "git apply" has been taught to ignore a message without a patch
+   with the "--allow-empty" option.  It also learned to honor the
+   "--quiet" option given from the command line.
+
+ * The "init" and "set" subcommands in "git sparse-checkout" have been
+   unified for a better user experience and performance.
+
+ * Many git commands that deal with working tree files try to remove a
+   directory that becomes empty (i.e. "git switch" from a branch that
+   has the directory to another branch that does not would attempt
+   remove all files in the directory and the directory itself).  This
+   drops users into an unfamiliar situation if the command was run in
+   a subdirectory that becomes subject to removal due to the command.
+   The commands have been taught to keep an empty directory if it is
+   the directory they were started in to avoid surprising users.
+
+ * "git am" learns "--empty=(stop|drop|keep)" option to tweak what is
+   done to a piece of e-mail without a patch in it.
+
+ * The default merge message prepared by "git merge" records the name
+   of the current branch; the name can be overridden with a new option
+   to allow users to pretend a merge is made on a different branch.
 
 Performance, Internal Implementation, Development Support etc.
 
@@ -122,6 +144,33 @@ Performance, Internal Implementation, Development Support etc.
  * diff and blame commands have been taught to work better with sparse
    index.
 
+ * The chainlint test script linter in the test suite has been updated.
+
+ * The DEVELOPER=yes build uses -std=gnu99 now.
+
+ * "git format-patch" uses a single rev_info instance and then exits.
+   Mark the structure with UNLEAK() macro to squelch leak sanitizer.
+
+ * New interface into the tmp-objdir API to help in-core use of the
+   quarantine feature.
+
+ * Broken &&-chains in the test scripts have been corrected.
+
+ * The RCS keyword substitution in "git p4" used to be done assuming
+   that the contents are UTF-8 text, which can trigger decoding
+   errors.  We now treat the contents as a bytestring for robustness
+   and correctness.
+
+ * The conditions to choose different definitions of the FLEX_ARRAY
+   macro for vendor compilers has been simplified to make it easier to
+   maintain.
+
+ * Correctness and performance update to "diff --color-moved" feature.
+
+ * "git upload-pack" (the other side of "git fetch") used a 8kB buffer
+   but most of its payload came on 64kB "packets".  The buffer size
+   has been enlarged so that such a packet fits.
+
 
 Fixes since v2.34
 -----------------
@@ -241,6 +290,26 @@ Fixes since v2.34
    to read and honor the settings given by the "--decorate-refs"
    option.
 
+ * "git fetch --set-upstream" did not check if there is a current
+   branch, leading to a segfault when it is run on a detached HEAD,
+   which has been corrected.
+   (merge 17baeaf82d ab/fetch-set-upstream-while-detached later to maint).
+
+ * Among some code paths that ask an yes/no question, only one place
+   gave a prompt that looked different from the others, which has been
+   updated to match what the others create.
+   (merge 0fc8ed154c km/help-prompt-fix later to maint).
+
+ * "git log --invert-grep --author=<name>" used to exclude commits
+   written by the given author, but now "--invert-grep" only affects
+   the matches made by the "--grep=<pattern>" option.
+   (merge 794c000267 rs/log-invert-grep-with-headers later to maint).
+
+ * "git grep --perl-regexp" failed to match UTF-8 characters with
+   wildcard when the pattern consists only of ASCII letters, which has
+   been corrected.
+   (merge 32e3e8bc55 rs/pcre2-utf later to maint).
+
  * Other code cleanup, docfix, build fix, etc.
    (merge 74db416c9c cw/protocol-v2-doc-fix later to maint).
    (merge f9b2b6684d ja/doc-cleanup later to maint).
@@ -259,3 +328,7 @@ Fixes since v2.34
    (merge 2c68f577fc ew/cbtree-remove-unused-and-broken-cb-unlink later to maint).
    (merge eafd6e7e55 ab/die-with-bug later to maint).
    (merge 91028f7659 jc/grep-patterntype-default-doc later to maint).
+   (merge 47ca93d071 ds/repack-fixlets later to maint).
+   (merge e6a9bc0c60 rs/t4202-invert-grep-test-fix later to maint).
+   (merge deb5407a42 gh/gpg-doc-markup-fix later to maint).
+   (merge 999bba3e0b rs/daemon-plug-leak later to maint).
index c9be554c73225f362ac300281bb3b1ddbc2dc88d..0cb189a077ca54ed83a6dfefad9be327f7176d40 100644 (file)
@@ -34,7 +34,7 @@ gpg.minTrustLevel::
 * `fully`
 * `ultimate`
 
-gpg.ssh.defaultKeyCommand:
+gpg.ssh.defaultKeyCommand::
        This command that will be run when user.signingkey is not set and a ssh
        signature is requested. On successful exit a valid ssh public key is
        expected in the first line of its output. To automatically use the first
@@ -44,7 +44,7 @@ gpg.ssh.allowedSignersFile::
        A file containing ssh public keys which you are willing to trust.
        The file consists of one or more lines of principals followed by an ssh
        public key.
-       e.g.: user1@example.com,user2@example.com ssh-rsa AAAAX1...
+       e.g.: `user1@example.com,user2@example.com ssh-rsa AAAAX1...`
        See ssh-keygen(1) "ALLOWED SIGNERS" for details.
        The principal is only used to identify the key and is available when
        verifying a signature.
index 0a4a984dfdecda8ef5d252e2a2883f6497f2cb1b..09107fb106703d14c9e695685e93f59e15362fc3 100644 (file)
@@ -16,8 +16,9 @@ SYNOPSIS
         [--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
         [--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
         [--quoted-cr=<action>]
+        [--empty=(stop|drop|keep)]
         [(<mbox> | <Maildir>)...]
-'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)])
+'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)] | --allow-empty)
 
 DESCRIPTION
 -----------
@@ -63,6 +64,14 @@ OPTIONS
 --quoted-cr=<action>::
        This flag will be passed down to 'git mailinfo' (see linkgit:git-mailinfo[1]).
 
+--empty=(stop|drop|keep)::
+       By default, or when the option is set to 'stop', the command
+       errors out on an input e-mail message lacking a patch
+       and stops into the middle of the current am session. When this
+       option is set to 'drop', skip such an e-mail message instead.
+       When this option is set to 'keep', create an empty commit,
+       recording the contents of the e-mail message as its log.
+
 -m::
 --message-id::
        Pass the `-m` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]),
@@ -191,6 +200,11 @@ default.   You can use `--no-utf8` to override this.
        the e-mail message; if `diff`, show the diff portion only.
        Defaults to `raw`.
 
+--allow-empty::
+       After a patch failure on an input e-mail message lacking a patch,
+       create an empty commit with the contents of the e-mail message
+       as its log message.
+
 DISCUSSION
 ----------
 
index aa1ae56a25e0428cabcfa2539900ef2a09abcb7c..b6d77f420682618be63cb27a34e803cfcac8f802 100644 (file)
@@ -16,7 +16,7 @@ SYNOPSIS
          [--ignore-space-change | --ignore-whitespace]
          [--whitespace=(nowarn|warn|fix|error|error-all)]
          [--exclude=<path>] [--include=<path>] [--directory=<root>]
-         [--verbose] [--unsafe-paths] [<patch>...]
+         [--verbose | --quiet] [--unsafe-paths] [--allow-empty] [<patch>...]
 
 DESCRIPTION
 -----------
@@ -228,6 +228,11 @@ behavior:
        current patch being applied will be printed. This option will cause
        additional information to be reported.
 
+-q::
+--quiet::
+       Suppress stderr output. Messages about patch status and progress
+       will not be printed.
+
 --recount::
        Do not trust the line counts in the hunk headers, but infer them
        by inspecting the patch (e.g. after editing the patch without
@@ -251,6 +256,10 @@ When `git apply` is used as a "better GNU patch", the user can pass
 the `--unsafe-paths` option to override this safety check.  This option
 has no effect when `--index` or `--cached` is in use.
 
+--allow-empty::
+       Don't return error for patches containing no diff. This includes
+       empty patches and patches with commit text only.
+
 CONFIGURATION
 -------------
 
index 9685ea0691534dead2d393959e9055ee7b23a06a..984d194934fb84253e7f6b763256e09e2ddd8e91 100644 (file)
@@ -167,10 +167,10 @@ objects from the source repository into a pack in the cloned repository.
        configuration variables are created.
 
 --sparse::
-       Initialize the sparse-checkout file so the working
-       directory starts with only the files in the root
-       of the repository. The sparse-checkout file can be
-       modified to grow the working directory as needed.
+       Employ a sparse-checkout, with only files in the toplevel
+       directory initially being present.  The
+       linkgit:git-sparse-checkout[1] command can be used to grow the
+       working directory as needed.
 
 --filter=<filter-spec>::
        Use the partial clone feature and request that the server sends
index 6793d8fc05218f61ebc399b9ac910f27832bc58b..6f28812f38defec0047f9c47ca554231a6adfd8e 100644 (file)
@@ -9,7 +9,7 @@ git-fmt-merge-msg - Produce a merge commit message
 SYNOPSIS
 --------
 [verse]
-'git fmt-merge-msg' [-m <message>] [--log[=<n>] | --no-log]
+'git fmt-merge-msg' [-m <message>] [--into-name <branch>] [--log[=<n>] | --no-log]
 'git fmt-merge-msg' [-m <message>] [--log[=<n>] | --no-log] -F <file>
 
 DESCRIPTION
@@ -44,6 +44,10 @@ OPTIONS
        Use <message> instead of the branch names for the first line
        of the log message.  For use with `--log`.
 
+--into-name <branch>::
+       Prepare the merge message as if merging to the branch `<branch>`,
+       instead of the name of the real branch to which the merge is made.
+
 -F <file>::
 --file <file>::
        Take the list of merged objects from <file> instead of
index 113eabc107ca94f801eca64591421065a2bc54b4..be797d7a28f62f38e2dc38c82141e71b97ea4aae 100644 (file)
@@ -18,7 +18,7 @@ SYNOPSIS
                   [-n | --numbered | -N | --no-numbered]
                   [--start-number <n>] [--numbered-files]
                   [--in-reply-to=<message id>] [--suffix=.<sfx>]
-                  [--ignore-if-in-upstream]
+                  [--ignore-if-in-upstream] [--always]
                   [--cover-from-description=<mode>]
                   [--rfc] [--subject-prefix=<subject prefix>]
                   [(--reroll-count|-v) <n>]
@@ -192,6 +192,10 @@ will want to ensure that threading is disabled for `git send-email`.
        patches being generated, and any patch that matches is
        ignored.
 
+--always::
+       Include patches for commits that do not introduce any change,
+       which are omitted by default.
+
 --cover-from-description=<mode>::
        Controls which parts of the cover letter will be automatically
        populated using the branch's description.
index 2e3d695fa213819610982f7d02441a492b0c2c68..48cc7c0b6f4b639688f64bdfc1d7562ead1da034 100644 (file)
@@ -187,6 +187,11 @@ Both the <eolinfo> in the index ("i/<eolinfo>")
 and in the working tree ("w/<eolinfo>") are shown for regular files,
 followed by the  ("attr/<eolattr>").
 
+--sparse::
+       If the index is sparse, show the sparse directories without expanding
+       to the contained files. Sparse directories will be shown with a
+       trailing slash, such as "x/" for a sparse directory "x".
+
 \--::
        Do not interpret any more arguments as options.
 
index e8cecf5a51daaea811541af35fe5955636d9a0a0..3125473cc1d19140cf54f5286106b86823a9b91f 100644 (file)
@@ -12,7 +12,8 @@ SYNOPSIS
 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
        [--no-verify] [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
        [--[no-]allow-unrelated-histories]
-       [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>...]
+       [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>]
+       [--into-name <branch>] [<commit>...]
 'git merge' (--continue | --abort | --quit)
 
 DESCRIPTION
@@ -76,6 +77,11 @@ The 'git fmt-merge-msg' command can be
 used to give a good default for automated 'git merge'
 invocations. The automated message can include the branch description.
 
+--into-name <branch>::
+       Prepare the default merge message as if merging to the branch
+       `<branch>`, instead of the name of the real branch to which
+       the merge is made.
+
 -F <file>::
 --file=<file>::
        Read the commit message to be used for the merge commit (in
index 7183fb498f4ccec69e6bd75dcef44f54974a159b..ee30edc178a4d418610612215935452b6daca567 100644 (file)
@@ -76,8 +76,9 @@ to the new separate pack will be written.
        linkgit:git-pack-objects[1].
 
 -q::
-       Pass the `-q` option to 'git pack-objects'. See
-       linkgit:git-pack-objects[1].
+--quiet::
+       Show no progress over the standard error stream and pass the `-q`
+       option to 'git pack-objects'. See linkgit:git-pack-objects[1].
 
 -n::
        Do not update the server information with
index 9a78dd721e8a5f6ec54e14c36854296b7038d229..b81dbe06543c169f44ffedf2e773ade6de23ecae 100644 (file)
@@ -30,28 +30,36 @@ COMMANDS
 'list'::
        Describe the patterns in the sparse-checkout file.
 
-'init'::
-       Enable the `core.sparseCheckout` setting. If the
-       sparse-checkout file does not exist, then populate it with
-       patterns that match every file in the root directory and
-       no other directories, then will remove all directories tracked
-       by Git. Add patterns to the sparse-checkout file to
-       repopulate the working directory.
+'set'::
+       Enable the necessary config settings
+       (extensions.worktreeConfig, core.sparseCheckout,
+       core.sparseCheckoutCone) if they are not already enabled, and
+       write a set of patterns to the sparse-checkout file from the
+       list of arguments following the 'set' subcommand. Update the
+       working directory to match the new patterns.
 +
-To avoid interfering with other worktrees, it first enables the
-`extensions.worktreeConfig` setting and makes sure to set the
-`core.sparseCheckout` setting in the worktree-specific config file.
+When the `--stdin` option is provided, the patterns are read from
+standard in as a newline-delimited list instead of from the arguments.
 +
-When `--cone` is provided, the `core.sparseCheckoutCone` setting is
-also set, allowing for better performance with a limited set of
-patterns (see 'CONE PATTERN SET' below).
+When `--cone` is passed or `core.sparseCheckoutCone` is enabled, the
+input list is considered a list of directories instead of
+sparse-checkout patterns.  This allows for better performance with a
+limited set of patterns (see 'CONE PATTERN SET' below).  Note that the
+set command will write patterns to the sparse-checkout file to include
+all files contained in those directories (recursively) as well as
+files that are siblings of ancestor directories. The input format
+matches the output of `git ls-tree --name-only`.  This includes
+interpreting pathnames that begin with a double quote (") as C-style
+quoted strings.  This may become the default in the future; --no-cone
+can be passed to request non-cone mode.
 +
-Use the `--[no-]sparse-index` option to toggle the use of the sparse
-index format. This reduces the size of the index to be more closely
-aligned with your sparse-checkout definition. This can have significant
-performance advantages for commands such as `git status` or `git add`.
-This feature is still experimental. Some commands might be slower with
-a sparse index until they are properly integrated with the feature.
+Use the `--[no-]sparse-index` option to use a sparse index (the
+default is to not use it).  A sparse index reduces the size of the
+index to be more closely aligned with your sparse-checkout
+definition. This can have significant performance advantages for
+commands such as `git status` or `git add`.  This feature is still
+experimental. Some commands might be slower with a sparse index until
+they are properly integrated with the feature.
 +
 **WARNING:** Using a sparse index requires modifying the index in a way
 that is not completely understood by external tools. If you have trouble
@@ -60,23 +68,6 @@ to rewrite your index to not be sparse. Older versions of Git will not
 understand the sparse directory entries index extension and may fail to
 interact with your repository until it is disabled.
 
-'set'::
-       Write a set of patterns to the sparse-checkout file, as given as
-       a list of arguments following the 'set' subcommand. Update the
-       working directory to match the new patterns. Enable the
-       core.sparseCheckout config setting if it is not already enabled.
-+
-When the `--stdin` option is provided, the patterns are read from
-standard in as a newline-delimited list instead of from the arguments.
-+
-When `core.sparseCheckoutCone` is enabled, the input list is considered a
-list of directories instead of sparse-checkout patterns. The command writes
-patterns to the sparse-checkout file to include all files contained in those
-directories (recursively) as well as files that are siblings of ancestor
-directories. The input format matches the output of `git ls-tree --name-only`.
-This includes interpreting pathnames that begin with a double quote (") as
-C-style quoted strings.
-
 'add'::
        Update the sparse-checkout file to include additional patterns.
        By default, these patterns are read from the command-line arguments,
@@ -93,12 +84,35 @@ C-style quoted strings.
        cases, it can make sense to run `git sparse-checkout reapply` later
        after cleaning up affected paths (e.g. resolving conflicts, undoing
        or committing changes, etc.).
++
+The `reapply` command can also take `--[no-]cone` and `--[no-]sparse-index`
+flags, with the same meaning as the flags from the `set` command, in order
+to change which sparsity mode you are using without needing to also respecify
+all sparsity paths.
 
 'disable'::
        Disable the `core.sparseCheckout` config setting, and restore the
-       working directory to include all files. Leaves the sparse-checkout
-       file intact so a later 'git sparse-checkout init' command may
-       return the working directory to the same state.
+       working directory to include all files.
+
+'init'::
+       Deprecated command that behaves like `set` with no specified paths.
+       May be removed in the future.
++
+Historically, `set` did not handle all the necessary config settings,
+which meant that both `init` and `set` had to be called.  Invoking
+both meant the `init` step would first remove nearly all tracked files
+(and in cone mode, ignored files too), then the `set` step would add
+many of the tracked files (but not ignored files) back.  In addition
+to the lost files, the performance and UI of this combination was
+poor.
++
+Also, historically, `init` would not actually initialize the
+sparse-checkout file if it already existed.  This meant it was
+possible to return to a sparse-checkout without remembering which
+paths to pass to a subsequent 'set' or 'add' command.  However,
+`--cone` and `--sparse-index` options would not be remembered across
+the disable command, so the easy restore of calling a plain `init`
+decreased in utility.
 
 SPARSE CHECKOUT
 ---------------
@@ -107,7 +121,7 @@ SPARSE CHECKOUT
 It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
 Git whether a file in the working directory is worth looking at. If
 the skip-worktree bit is set, then the file is ignored in the working
-directory. Git will not populate the contents of those files, which
+directory. Git will avoid populating the contents of those files, which
 makes a sparse checkout helpful when working in a repository with many
 files, but only a few are important to the current user.
 
@@ -117,10 +131,8 @@ directory, it updates the skip-worktree bits in the index based
 on this file. The files matching the patterns in the file will
 appear in the working directory, and the rest will not.
 
-To enable the sparse-checkout feature, run `git sparse-checkout init` to
-initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
-config setting. Then, run `git sparse-checkout set` to modify the patterns in
-the sparse-checkout file.
+To enable the sparse-checkout feature, run `git sparse-checkout set` to
+set the patterns you want to use.
 
 To repopulate the working directory with all files, use the
 `git sparse-checkout disable` command.
index 75ed168adbc7033d6ff18ebbec3faf2476b21b71..5580859afdb45b44459798fa490f9b53e426079b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1881,7 +1881,7 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
 endif
 
 ifndef NO_MSGFMT_EXTENDED_OPTIONS
-       MSGFMT += --check --statistics
+       MSGFMT += --check
 endif
 
 ifdef HAVE_CLOCK_GETTIME
@@ -2112,11 +2112,6 @@ ifdef DEFAULT_HELP_FORMAT
 BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"'
 endif
 
-PAGER_ENV_SQ = $(subst ','\'',$(PAGER_ENV))
-PAGER_ENV_CQ = "$(subst ",\",$(subst \,\\,$(PAGER_ENV)))"
-PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
-BASIC_CFLAGS += -DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
-
 ALL_CFLAGS += $(BASIC_CFLAGS)
 ALL_LDFLAGS += $(BASIC_LDFLAGS)
 
@@ -2223,14 +2218,20 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
                $(filter %.o,$^) $(LIBS)
 
 help.sp help.s help.o: command-list.h
-hook.sp hook.s hook.o: hook-list.h
+builtin/bugreport.sp builtin/bugreport.s builtin/bugreport.o: hook-list.h
 
-builtin/help.sp builtin/help.s builtin/help.o: config-list.h hook-list.h GIT-PREFIX
+builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX
 builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
        '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
        '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
        '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
 
+PAGER_ENV_SQ = $(subst ','\'',$(PAGER_ENV))
+PAGER_ENV_CQ = "$(subst ",\",$(subst \,\\,$(PAGER_ENV)))"
+PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
+pager.sp pager.s pager.o: EXTRA_CPPFLAGS = \
+       -DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
+
 version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
 version.sp version.s version.o: EXTRA_CPPFLAGS = \
        '-DGIT_VERSION="$(GIT_VERSION)"' \
diff --git a/apply.c b/apply.c
index 43a0aebf4eec85fa6b0a69f655c0224aa14f29e5..fed195250b64eea60e34849940c43016c2c3b5fa 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -4752,8 +4752,10 @@ static int apply_patch(struct apply_state *state,
        }
 
        if (!list && !skipped_patch) {
-               error(_("unrecognized input"));
-               res = -128;
+               if (!state->allow_empty) {
+                       error(_("No valid patches in input (allow with \"--allow-empty\")"));
+                       res = -128;
+               }
                goto end;
        }
 
@@ -5071,7 +5073,7 @@ int apply_parse_options(int argc, const char **argv,
                        N_("leave the rejected hunks in corresponding *.rej files")),
                OPT_BOOL(0, "allow-overlap", &state->allow_overlap,
                        N_("allow overlapping hunks")),
-               OPT__VERBOSE(&state->apply_verbosity, N_("be verbose")),
+               OPT__VERBOSITY(&state->apply_verbosity),
                OPT_BIT(0, "inaccurate-eof", options,
                        N_("tolerate incorrectly detected missing new-line at the end of file"),
                        APPLY_OPT_INACCURATE_EOF),
@@ -5081,6 +5083,8 @@ int apply_parse_options(int argc, const char **argv,
                OPT_CALLBACK(0, "directory", state, N_("root"),
                        N_("prepend <root> to all filenames"),
                        apply_option_parse_directory),
+               OPT_BOOL(0, "allow-empty", &state->allow_empty,
+                       N_("don't return error for empty patches")),
                OPT_END()
        };
 
diff --git a/apply.h b/apply.h
index da3d95fa50989bdd18289eec3a79b955c0d59443..16202da16026f8ef127e406418229d1f47802b53 100644 (file)
--- a/apply.h
+++ b/apply.h
@@ -66,6 +66,7 @@ struct apply_state {
        int threeway;
        int unidiff_zero;
        int unsafe_paths;
+       int allow_empty;
 
        /* Other non boolean parameters */
        struct repository *repo;
index 8677ea2348ab5b8017fc82cd1f8b79e4a7d20122..f2e7e533881083afbf0b52a5ed9f89d6a8bbda2c 100644 (file)
@@ -87,6 +87,12 @@ enum show_patch_type {
        SHOW_PATCH_DIFF = 1,
 };
 
+enum empty_action {
+       STOP_ON_EMPTY_COMMIT = 0,  /* output errors and stop in the middle of an am session */
+       DROP_EMPTY_COMMIT,         /* skip with a notice message, unless "--quiet" has been passed */
+       KEEP_EMPTY_COMMIT,         /* keep recording as empty commits */
+};
+
 struct am_state {
        /* state directory path */
        char *dir;
@@ -118,6 +124,7 @@ struct am_state {
        int message_id;
        int scissors; /* enum scissors_type */
        int quoted_cr; /* enum quoted_cr_action */
+       int empty_type; /* enum empty_action */
        struct strvec git_apply_opts;
        const char *resolvemsg;
        int committer_date_is_author_date;
@@ -178,6 +185,25 @@ static int am_option_parse_quoted_cr(const struct option *opt,
        return 0;
 }
 
+static int am_option_parse_empty(const struct option *opt,
+                                    const char *arg, int unset)
+{
+       int *opt_value = opt->value;
+
+       BUG_ON_OPT_NEG(unset);
+
+       if (!strcmp(arg, "stop"))
+               *opt_value = STOP_ON_EMPTY_COMMIT;
+       else if (!strcmp(arg, "drop"))
+               *opt_value = DROP_EMPTY_COMMIT;
+       else if (!strcmp(arg, "keep"))
+               *opt_value = KEEP_EMPTY_COMMIT;
+       else
+               return error(_("Invalid value for --empty: %s"), arg);
+
+       return 0;
+}
+
 /**
  * Returns path relative to the am_state directory.
  */
@@ -1126,6 +1152,12 @@ static void NORETURN die_user_resolve(const struct am_state *state)
 
                printf_ln(_("When you have resolved this problem, run \"%s --continue\"."), cmdline);
                printf_ln(_("If you prefer to skip this patch, run \"%s --skip\" instead."), cmdline);
+
+               if (advice_enabled(ADVICE_AM_WORK_DIR) &&
+                   is_empty_or_missing_file(am_path(state, "patch")) &&
+                   !repo_index_has_changes(the_repository, NULL, NULL))
+                       printf_ln(_("To record the empty patch as an empty commit, run \"%s --allow-empty\"."), cmdline);
+
                printf_ln(_("To restore the original branch and stop patching, run \"%s --abort\"."), cmdline);
        }
 
@@ -1248,11 +1280,6 @@ static int parse_mail(struct am_state *state, const char *mail)
                goto finish;
        }
 
-       if (is_empty_or_missing_file(am_path(state, "patch"))) {
-               printf_ln(_("Patch is empty."));
-               die_user_resolve(state);
-       }
-
        strbuf_addstr(&msg, "\n\n");
        strbuf_addbuf(&msg, &mi.log_message);
        strbuf_stripspace(&msg, 0);
@@ -1763,6 +1790,7 @@ static void am_run(struct am_state *state, int resume)
        while (state->cur <= state->last) {
                const char *mail = am_path(state, msgnum(state));
                int apply_status;
+               int to_keep;
 
                reset_ident_date();
 
@@ -1792,8 +1820,29 @@ static void am_run(struct am_state *state, int resume)
                if (state->interactive && do_interactive(state))
                        goto next;
 
+               to_keep = 0;
+               if (is_empty_or_missing_file(am_path(state, "patch"))) {
+                       switch (state->empty_type) {
+                       case DROP_EMPTY_COMMIT:
+                               say(state, stdout, _("Skipping: %.*s"), linelen(state->msg), state->msg);
+                               goto next;
+                               break;
+                       case KEEP_EMPTY_COMMIT:
+                               to_keep = 1;
+                               say(state, stdout, _("Creating an empty commit: %.*s"),
+                                       linelen(state->msg), state->msg);
+                               break;
+                       case STOP_ON_EMPTY_COMMIT:
+                               printf_ln(_("Patch is empty."));
+                               die_user_resolve(state);
+                               break;
+                       }
+               }
+
                if (run_applypatch_msg_hook(state))
                        exit(1);
+               if (to_keep)
+                       goto commit;
 
                say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
 
@@ -1827,6 +1876,7 @@ static void am_run(struct am_state *state, int resume)
                        die_user_resolve(state);
                }
 
+commit:
                do_commit(state);
 
 next:
@@ -1856,19 +1906,24 @@ next:
 /**
  * Resume the current am session after patch application failure. The user did
  * all the hard work, and we do not have to do any patch application. Just
- * trust and commit what the user has in the index and working tree.
+ * trust and commit what the user has in the index and working tree. If `allow_empty`
+ * is true, commit as an empty commit when index has not changed and lacking a patch.
  */
-static void am_resolve(struct am_state *state)
+static void am_resolve(struct am_state *state, int allow_empty)
 {
        validate_resume_state(state);
 
        say(state, stdout, _("Applying: %.*s"), linelen(state->msg), state->msg);
 
        if (!repo_index_has_changes(the_repository, NULL, NULL)) {
-               printf_ln(_("No changes - did you forget to use 'git add'?\n"
-                       "If there is nothing left to stage, chances are that something else\n"
-                       "already introduced the same changes; you might want to skip this patch."));
-               die_user_resolve(state);
+               if (allow_empty && is_empty_or_missing_file(am_path(state, "patch"))) {
+                       printf_ln(_("No changes - recorded it as an empty commit."));
+               } else {
+                       printf_ln(_("No changes - did you forget to use 'git add'?\n"
+                                   "If there is nothing left to stage, chances are that something else\n"
+                                   "already introduced the same changes; you might want to skip this patch."));
+                       die_user_resolve(state);
+               }
        }
 
        if (unmerged_cache()) {
@@ -2195,7 +2250,8 @@ enum resume_type {
        RESUME_SKIP,
        RESUME_ABORT,
        RESUME_QUIT,
-       RESUME_SHOW_PATCH
+       RESUME_SHOW_PATCH,
+       RESUME_ALLOW_EMPTY,
 };
 
 struct resume_mode {
@@ -2348,6 +2404,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
                  N_("show the patch being applied"),
                  PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
                  parse_opt_show_current_patch, RESUME_SHOW_PATCH },
+               OPT_CMDMODE(0, "allow-empty", &resume.mode,
+                       N_("record the empty patch as an empty commit"),
+                       RESUME_ALLOW_EMPTY),
                OPT_BOOL(0, "committer-date-is-author-date",
                        &state.committer_date_is_author_date,
                        N_("lie about committer date")),
@@ -2357,6 +2416,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
                { OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"),
                  N_("GPG-sign commits"),
                  PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
+               OPT_CALLBACK_F(STOP_ON_EMPTY_COMMIT, "empty", &state.empty_type, "{stop,drop,keep}",
+                 N_("how to handle empty patches"),
+                 PARSE_OPT_NONEG, am_option_parse_empty),
                OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
                        N_("(internal use for git-rebase)")),
                OPT_END()
@@ -2453,7 +2515,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
                am_run(&state, 1);
                break;
        case RESUME_RESOLVED:
-               am_resolve(&state);
+       case RESUME_ALLOW_EMPTY:
+               am_resolve(&state, resume.mode == RESUME_ALLOW_EMPTY ? 1 : 0);
                break;
        case RESUME_SKIP:
                am_skip(&state);
index 98a2860409bb4820af393ea9e50e58124fd7873e..3ff02bbbffeb7ed041b8a9af7f0b6f6d26c88492 100644 (file)
@@ -36,6 +36,8 @@ static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
 static const char *msg_would_skip_git_dir = N_("Would skip repository %s\n");
 static const char *msg_warn_remove_failed = N_("failed to remove %s");
 static const char *msg_warn_lstat_failed = N_("could not lstat %s\n");
+static const char *msg_skip_cwd = N_("Refusing to remove current working directory\n");
+static const char *msg_would_skip_cwd = N_("Would refuse to remove current working directory\n");
 
 enum color_clean {
        CLEAN_COLOR_RESET = 0,
@@ -153,6 +155,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
 {
        DIR *dir;
        struct strbuf quoted = STRBUF_INIT;
+       struct strbuf realpath = STRBUF_INIT;
+       struct strbuf real_ocwd = STRBUF_INIT;
        struct dirent *e;
        int res = 0, ret = 0, gone = 1, original_len = path->len, len;
        struct string_list dels = STRING_LIST_INIT_DUP;
@@ -231,16 +235,36 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
        strbuf_setlen(path, original_len);
 
        if (*dir_gone) {
-               res = dry_run ? 0 : rmdir(path->buf);
-               if (!res)
-                       *dir_gone = 1;
-               else {
-                       int saved_errno = errno;
-                       quote_path(path->buf, prefix, &quoted, 0);
-                       errno = saved_errno;
-                       warning_errno(_(msg_warn_remove_failed), quoted.buf);
+               /*
+                * Normalize path components in path->buf, e.g. change '\' to
+                * '/' on Windows.
+                */
+               strbuf_realpath(&realpath, path->buf, 1);
+
+               /*
+                * path and realpath are absolute; for comparison, we would
+                * like to transform startup_info->original_cwd to an absolute
+                * path too.
+                */
+                if (startup_info->original_cwd)
+                        strbuf_realpath(&real_ocwd,
+                                        startup_info->original_cwd, 1);
+
+               if (!strbuf_cmp(&realpath, &real_ocwd)) {
+                       printf("%s", dry_run ? _(msg_would_skip_cwd) : _(msg_skip_cwd));
                        *dir_gone = 0;
-                       ret = 1;
+               } else {
+                       res = dry_run ? 0 : rmdir(path->buf);
+                       if (!res)
+                               *dir_gone = 1;
+                       else {
+                               int saved_errno = errno;
+                               quote_path(path->buf, prefix, &quoted, 0);
+                               errno = saved_errno;
+                               warning_errno(_(msg_warn_remove_failed), quoted.buf);
+                               *dir_gone = 0;
+                               ret = 1;
+                       }
                }
        }
 
@@ -250,6 +274,8 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
                        printf(dry_run ?  _(msg_would_remove) : _(msg_remove), dels.items[i].string);
        }
 out:
+       strbuf_release(&realpath);
+       strbuf_release(&real_ocwd);
        strbuf_release(&quoted);
        string_list_clear(&dels, 0);
        return ret;
index fb377b27657c4048a04c85ddb82e15a950db5a7d..5bed37f8b51e4b0babc2adef52efc0cdb3ffda43 100644 (file)
@@ -633,7 +633,7 @@ static int git_sparse_checkout_init(const char *repo)
 {
        struct strvec argv = STRVEC_INIT;
        int result = 0;
-       strvec_pushl(&argv, "-C", repo, "sparse-checkout", "init", NULL);
+       strvec_pushl(&argv, "-C", repo, "sparse-checkout", "set", NULL);
 
        /*
         * We must apply the setting in the current process
index 8e2caf7281970cfb1bd3cf3bad07b488e61b6f07..cb1d6473f12630c855fb01922e95ef1d1a27af65 100644 (file)
@@ -107,18 +107,6 @@ static int parse_opt_reencode_mode(const struct option *opt,
 
 static struct decoration idnums;
 static uint32_t last_idnum;
-
-static int has_unshown_parent(struct commit *commit)
-{
-       struct commit_list *parent;
-
-       for (parent = commit->parents; parent; parent = parent->next)
-               if (!(parent->item->object.flags & SHOWN) &&
-                   !(parent->item->object.flags & UNINTERESTING))
-                       return 1;
-       return 0;
-}
-
 struct anonymized_entry {
        struct hashmap_entry hash;
        const char *anon;
@@ -752,20 +740,6 @@ static char *anonymize_tag(void *data)
        return strbuf_detach(&out, NULL);
 }
 
-static void handle_tail(struct object_array *commits, struct rev_info *revs,
-                       struct string_list *paths_of_changed_objects)
-{
-       struct commit *commit;
-       while (commits->nr) {
-               commit = (struct commit *)object_array_pop(commits);
-               if (has_unshown_parent(commit)) {
-                       /* Queue again, to be handled later */
-                       add_object_array(&commit->object, NULL, commits);
-                       return;
-               }
-               handle_commit(commit, revs, paths_of_changed_objects);
-       }
-}
 
 static void handle_tag(const char *name, struct tag *tag)
 {
@@ -1185,7 +1159,6 @@ static int parse_opt_anonymize_map(const struct option *opt,
 int cmd_fast_export(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
-       struct object_array commits = OBJECT_ARRAY_INIT;
        struct commit *commit;
        char *export_filename = NULL,
             *import_filename = NULL,
@@ -1283,18 +1256,13 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 
        if (prepare_revision_walk(&revs))
                die("revision walk setup failed");
+
+       revs.reverse = 1;
        revs.diffopt.format_callback = show_filemodify;
        revs.diffopt.format_callback_data = &paths_of_changed_objects;
        revs.diffopt.flags.recursive = 1;
-       while ((commit = get_revision(&revs))) {
-               if (has_unshown_parent(commit)) {
-                       add_object_array(&commit->object, NULL, &commits);
-               }
-               else {
-                       handle_commit(commit, &revs, &paths_of_changed_objects);
-                       handle_tail(&commits, &revs, &paths_of_changed_objects);
-               }
-       }
+       while ((commit = get_revision(&revs)))
+               handle_commit(commit, &revs, &paths_of_changed_objects);
 
        handle_tags_and_duplicates(&extra_refs);
        handle_tags_and_duplicates(&tag_refs);
index e45185cf9cf5ec71fa0a294a5f250c2d79342119..e33fda4174233fc47403a4c5fb53241bc7345205 100644 (file)
@@ -1643,6 +1643,16 @@ static int do_fetch(struct transport *transport,
                        }
                }
                if (source_ref) {
+                       if (!branch) {
+                               const char *shortname = source_ref->name;
+                               skip_prefix(shortname, "refs/heads/", &shortname);
+
+                               warning(_("could not set upstream of HEAD to '%s' from '%s' when "
+                                         "it does not point to any branch."),
+                                       shortname, transport->remote->name);
+                               goto skip;
+                       }
+
                        if (!strcmp(source_ref->name, "HEAD") ||
                            starts_with(source_ref->name, "refs/heads/"))
                                install_branch_config(0,
@@ -1999,6 +2009,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        }
 
        git_config(git_fetch_config, NULL);
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
 
        argc = parse_options(argc, argv, prefix,
                             builtin_fetch_options, builtin_fetch_usage, 0);
index 48a8699de728a950053b182fae23e73b14fba6a6..8d8fd393f8925c93155091db4f0959b7f03c31bb 100644 (file)
@@ -12,6 +12,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 {
        const char *inpath = NULL;
        const char *message = NULL;
+       char *into_name = NULL;
        int shortlog_len = -1;
        struct option options[] = {
                { OPTION_INTEGER, 0, "log", &shortlog_len, N_("n"),
@@ -23,6 +24,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
                  DEFAULT_MERGE_LOG_LEN },
                OPT_STRING('m', "message", &message, N_("text"),
                        N_("use <text> as start of message")),
+               OPT_STRING(0, "into-name", &into_name, N_("name"),
+                          N_("use <name> instead of the real target branch")),
                OPT_FILENAME('F', "file", &inpath, N_("file to read from")),
                OPT_END()
        };
@@ -56,6 +59,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
        opts.add_title = !message;
        opts.credit_people = 1;
        opts.shortlog_len = shortlog_len;
+       opts.into_name = into_name;
 
        ret = fmt_merge_msg(&input, &output, &opts);
        if (ret)
index 93ace0dde7d0db29a62602a2115c7a4b63327473..942c07ece6e4415791cda996cceb194937069e23 100644 (file)
@@ -2256,6 +2256,7 @@ done:
        strbuf_release(&rdiff1);
        strbuf_release(&rdiff2);
        strbuf_release(&rdiff_title);
+       UNLEAK(rev);
        return 0;
 }
 
index 031fef1bcaa9d08bdad41b56be6e81c18eae485d..c151eb1fb771316f97c06e6deb87039ca3aa6a9d 100644 (file)
@@ -37,6 +37,7 @@ static int debug_mode;
 static int show_eol;
 static int recurse_submodules;
 static int skipping_duplicates;
+static int show_sparse_dirs;
 
 static const char *prefix;
 static int max_prefix_len;
@@ -315,8 +316,10 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
 
        if (!(show_cached || show_stage || show_deleted || show_modified))
                return;
-       /* TODO: audit for interaction with sparse-index. */
-       ensure_full_index(repo->index);
+
+       if (!show_sparse_dirs)
+               ensure_full_index(repo->index);
+
        for (i = 0; i < repo->index->cache_nr; i++) {
                const struct cache_entry *ce = repo->index->cache[i];
                struct stat st;
@@ -670,6 +673,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
                OPT_BOOL(0, "deduplicate", &skipping_duplicates,
                         N_("suppress duplicate entries")),
+               OPT_BOOL(0, "sparse", &show_sparse_dirs,
+                        N_("show sparse directories in the presence of a sparse index")),
                OPT_END()
        };
        int ret = 0;
@@ -677,6 +682,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(ls_files_usage, builtin_ls_files_options);
 
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
+
        prefix = cmd_prefix;
        if (prefix)
                prefix_len = strlen(prefix);
index 5f0476b0b761b60fdddffbc15217bd4e345570e4..991de01bb4a1bd6a3e78dd9e82221ff14209b7b0 100644 (file)
@@ -87,6 +87,7 @@ static int signoff;
 static const char *sign_commit;
 static int autostash;
 static int no_verify;
+static char *into_name;
 
 static struct strategy all_strategy[] = {
        { "recursive",  NO_TRIVIAL },
@@ -286,6 +287,8 @@ static struct option builtin_merge_options[] = {
        { OPTION_LOWLEVEL_CALLBACK, 'F', "file", &merge_msg, N_("path"),
                N_("read message from file"), PARSE_OPT_NONEG,
                NULL, 0, option_read_message },
+       OPT_STRING(0, "into-name", &into_name, N_("name"),
+                  N_("use <name> instead of the real target")),
        OPT__VERBOSITY(&verbosity),
        OPT_BOOL(0, "abort", &abort_current_merge,
                N_("abort the current in-progress merge")),
@@ -1121,6 +1124,7 @@ static void prepare_merge_message(struct strbuf *merge_names, struct strbuf *mer
        opts.add_title = !have_message;
        opts.shortlog_len = shortlog_len;
        opts.credit_people = (0 < option_edit);
+       opts.into_name = into_name;
 
        fmt_merge_msg(merge_names, merge_msg, &opts);
        if (merge_msg->len)
index 485c9a3c56ff96aa59d9d9b4bfec1ea894ac32dd..c2bcdc07db46a76559ecbccda756642f7cd5b6b4 100644 (file)
@@ -26,10 +26,22 @@ static int prune_tmp_file(const char *fullpath)
                return error("Could not stat '%s'", fullpath);
        if (st.st_mtime > expire)
                return 0;
-       if (show_only || verbose)
-               printf("Removing stale temporary file %s\n", fullpath);
-       if (!show_only)
-               unlink_or_warn(fullpath);
+       if (S_ISDIR(st.st_mode)) {
+               if (show_only || verbose)
+                       printf("Removing stale temporary directory %s\n", fullpath);
+               if (!show_only) {
+                       struct strbuf remove_dir_buf = STRBUF_INIT;
+
+                       strbuf_addstr(&remove_dir_buf, fullpath);
+                       remove_dir_recursively(&remove_dir_buf, 0);
+                       strbuf_release(&remove_dir_buf);
+               }
+       } else {
+               if (show_only || verbose)
+                       printf("Removing stale temporary file %s\n", fullpath);
+               if (!show_only)
+                       unlink_or_warn(fullpath);
+       }
        return 0;
 }
 
index c8457619d865c57c2a3a228d64acad3a253c181f..100cbf9fb85b59fee6a8f9f90ced02c9abdaac6e 100644 (file)
@@ -994,6 +994,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                set_reflog_message(argc, argv);
 
        git_config(git_pull_config, NULL);
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
 
        argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
 
index 4f92e6f059dcb3f6668ca9973dfee9f149ffbb27..9f4a0b816cf9b6acd077a10a728a83e4048b9b5e 100644 (file)
@@ -2206,7 +2206,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
                strvec_push(&child.args, alt_shallow_file);
        }
 
-       tmp_objdir = tmp_objdir_create();
+       tmp_objdir = tmp_objdir_create("incoming");
        if (!tmp_objdir) {
                if (err_fd > 0)
                        close(err_fd);
index 9b0be6a6ab318ecdc6700f1b86da7dfbf89a468e..c393a5db774738f65b2b89d10bfb4ca27223658a 100644 (file)
@@ -612,7 +612,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        struct tempfile *refs_snapshot = NULL;
        int i, ext, ret;
        FILE *out;
-       int show_progress = isatty(2);
+       int show_progress;
 
        /* variables to be filled by option parsing */
        int pack_everything = 0;
@@ -693,7 +693,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                write_bitmaps = 0;
        }
        if (pack_kept_objects < 0)
-               pack_kept_objects = write_bitmaps > 0;
+               pack_kept_objects = write_bitmaps > 0 && !write_midx;
 
        if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) && !write_midx)
                die(_(incremental_bitmap_conflict_error));
@@ -725,6 +725,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
        prepare_pack_objects(&cmd, &po_args);
 
+       show_progress = !po_args.quiet && isatty(2);
+
        strvec_push(&cmd.args, "--keep-true-parents");
        if (!pack_kept_objects)
                strvec_push(&cmd.args, "--honor-pack-keep");
@@ -926,7 +928,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                        }
                        strbuf_release(&buf);
                }
-               if (!po_args.quiet && show_progress)
+               if (show_progress)
                        opts |= PRUNE_PACKED_VERBOSE;
                prune_packed_objects(opts);
 
index 3d0967cdc11308b966e6225d6b95dd7ae90ab364..b4132e5d8eebe5d486c9b76690f426c16ab53f58 100644 (file)
@@ -399,12 +399,13 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        if (!index_only) {
                int removed = 0, gitmodules_modified = 0;
                struct strbuf buf = STRBUF_INIT;
+               int flag = force ? REMOVE_DIR_PURGE_ORIGINAL_CWD : 0;
                for (i = 0; i < list.nr; i++) {
                        const char *path = list.entry[i].name;
                        if (list.entry[i].is_submodule) {
                                strbuf_reset(&buf);
                                strbuf_addstr(&buf, path);
-                               if (remove_dir_recursively(&buf, 0))
+                               if (remove_dir_recursively(&buf, flag))
                                        die(_("could not remove '%s'"), path);
 
                                removed = 1;
index d0f5c4702be69d0c9fade08ffbf5183c5f3dbe7e..679c10703684044aa02555227b5cdcdf92591d9b 100644 (file)
@@ -56,6 +56,9 @@ static int sparse_checkout_list(int argc, const char **argv)
        char *sparse_filename;
        int res;
 
+       if (!core_apply_sparse_checkout)
+               die(_("this worktree is not sparse"));
+
        argc = parse_options(argc, argv, NULL,
                             builtin_sparse_checkout_list_options,
                             builtin_sparse_checkout_list_usage, 0);
@@ -380,6 +383,41 @@ static int set_config(enum sparse_checkout_mode mode)
        return 0;
 }
 
+static int update_modes(int *cone_mode, int *sparse_index)
+{
+       int mode, record_mode;
+
+       /* Determine if we need to record the mode; ensure sparse checkout on */
+       record_mode = (*cone_mode != -1) || !core_apply_sparse_checkout;
+
+       /* If not specified, use previous definition of cone mode */
+       if (*cone_mode == -1 && core_apply_sparse_checkout)
+               *cone_mode = core_sparse_checkout_cone;
+
+       /* Set cone/non-cone mode appropriately */
+       core_apply_sparse_checkout = 1;
+       if (*cone_mode == 1) {
+               mode = MODE_CONE_PATTERNS;
+               core_sparse_checkout_cone = 1;
+       } else {
+               mode = MODE_ALL_PATTERNS;
+       }
+       if (record_mode && set_config(mode))
+               return 1;
+
+       /* Set sparse-index/non-sparse-index mode if specified */
+       if (*sparse_index >= 0) {
+               if (set_sparse_index_config(the_repository, *sparse_index) < 0)
+                       die(_("failed to modify sparse-index config"));
+
+               /* force an index rewrite */
+               repo_read_index(the_repository);
+               the_repository->index->updated_workdir = 1;
+       }
+
+       return 0;
+}
+
 static char const * const builtin_sparse_checkout_init_usage[] = {
        N_("git sparse-checkout init [--cone] [--[no-]sparse-index]"),
        NULL
@@ -396,7 +434,6 @@ static int sparse_checkout_init(int argc, const char **argv)
        char *sparse_filename;
        int res;
        struct object_id oid;
-       int mode;
        struct strbuf pattern = STRBUF_INIT;
 
        static struct option builtin_sparse_checkout_init_options[] = {
@@ -409,19 +446,14 @@ static int sparse_checkout_init(int argc, const char **argv)
 
        repo_read_index(the_repository);
 
+       init_opts.cone_mode = -1;
        init_opts.sparse_index = -1;
 
        argc = parse_options(argc, argv, NULL,
                             builtin_sparse_checkout_init_options,
                             builtin_sparse_checkout_init_usage, 0);
 
-       if (init_opts.cone_mode) {
-               mode = MODE_CONE_PATTERNS;
-               core_sparse_checkout_cone = 1;
-       } else
-               mode = MODE_ALL_PATTERNS;
-
-       if (set_config(mode))
+       if (update_modes(&init_opts.cone_mode, &init_opts.sparse_index))
                return 1;
 
        memset(&pl, 0, sizeof(pl));
@@ -429,17 +461,6 @@ static int sparse_checkout_init(int argc, const char **argv)
        sparse_filename = get_sparse_checkout_filename();
        res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
 
-       if (init_opts.sparse_index >= 0) {
-               if (set_sparse_index_config(the_repository, init_opts.sparse_index) < 0)
-                       die(_("failed to modify sparse-index config"));
-
-               /* force an index rewrite */
-               repo_read_index(the_repository);
-               the_repository->index->updated_workdir = 1;
-       }
-
-       core_apply_sparse_checkout = 1;
-
        /* If we already have a sparse-checkout file, use it. */
        if (res >= 0) {
                free(sparse_filename);
@@ -483,7 +504,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
                char *oldpattern = e->pattern;
                size_t newlen;
 
-               if (slash == e->pattern)
+               if (!slash || slash == e->pattern)
                        break;
 
                newlen = slash - e->pattern;
@@ -515,17 +536,9 @@ static void strbuf_to_cone_pattern(struct strbuf *line, struct pattern_list *pl)
        insert_recursive_pattern(pl, line);
 }
 
-static char const * const builtin_sparse_checkout_set_usage[] = {
-       N_("git sparse-checkout (set|add) (--stdin | <patterns>)"),
-       NULL
-};
-
-static struct sparse_checkout_set_opts {
-       int use_stdin;
-} set_opts;
-
 static void add_patterns_from_input(struct pattern_list *pl,
-                                   int argc, const char **argv)
+                                   int argc, const char **argv,
+                                   int use_stdin)
 {
        int i;
        if (core_sparse_checkout_cone) {
@@ -535,7 +548,7 @@ static void add_patterns_from_input(struct pattern_list *pl,
                hashmap_init(&pl->parent_hashmap, pl_hashmap_cmp, NULL, 0);
                pl->use_cone_patterns = 1;
 
-               if (set_opts.use_stdin) {
+               if (use_stdin) {
                        struct strbuf unquoted = STRBUF_INIT;
                        while (!strbuf_getline(&line, stdin)) {
                                if (line.buf[0] == '"') {
@@ -559,7 +572,7 @@ static void add_patterns_from_input(struct pattern_list *pl,
                        }
                }
        } else {
-               if (set_opts.use_stdin) {
+               if (use_stdin) {
                        struct strbuf line = STRBUF_INIT;
 
                        while (!strbuf_getline(&line, stdin)) {
@@ -580,7 +593,8 @@ enum modify_type {
 };
 
 static void add_patterns_cone_mode(int argc, const char **argv,
-                                  struct pattern_list *pl)
+                                  struct pattern_list *pl,
+                                  int use_stdin)
 {
        struct strbuf buffer = STRBUF_INIT;
        struct pattern_entry *pe;
@@ -588,7 +602,7 @@ static void add_patterns_cone_mode(int argc, const char **argv,
        struct pattern_list existing;
        char *sparse_filename = get_sparse_checkout_filename();
 
-       add_patterns_from_input(pl, argc, argv);
+       add_patterns_from_input(pl, argc, argv, use_stdin);
 
        memset(&existing, 0, sizeof(existing));
        existing.use_cone_patterns = core_sparse_checkout_cone;
@@ -598,6 +612,9 @@ static void add_patterns_cone_mode(int argc, const char **argv,
                die(_("unable to load existing sparse-checkout patterns"));
        free(sparse_filename);
 
+       if (!existing.use_cone_patterns)
+               die(_("existing sparse-checkout patterns do not use cone mode"));
+
        hashmap_for_each_entry(&existing.recursive_hashmap, &iter, pe, ent) {
                if (!hashmap_contains_parent(&pl->recursive_hashmap,
                                        pe->pattern, &buffer) ||
@@ -614,17 +631,19 @@ static void add_patterns_cone_mode(int argc, const char **argv,
 }
 
 static void add_patterns_literal(int argc, const char **argv,
-                                struct pattern_list *pl)
+                                struct pattern_list *pl,
+                                int use_stdin)
 {
        char *sparse_filename = get_sparse_checkout_filename();
        if (add_patterns_from_file_to_list(sparse_filename, "", 0,
                                           pl, NULL, 0))
                die(_("unable to load existing sparse-checkout patterns"));
        free(sparse_filename);
-       add_patterns_from_input(pl, argc, argv);
+       add_patterns_from_input(pl, argc, argv, use_stdin);
 }
 
-static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
+static int modify_pattern_list(int argc, const char **argv, int use_stdin,
+                              enum modify_type m)
 {
        int result;
        int changed_config = 0;
@@ -633,13 +652,13 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
        switch (m) {
        case ADD:
                if (core_sparse_checkout_cone)
-                       add_patterns_cone_mode(argc, argv, pl);
+                       add_patterns_cone_mode(argc, argv, pl, use_stdin);
                else
-                       add_patterns_literal(argc, argv, pl);
+                       add_patterns_literal(argc, argv, pl, use_stdin);
                break;
 
        case REPLACE:
-               add_patterns_from_input(pl, argc, argv);
+               add_patterns_from_input(pl, argc, argv, use_stdin);
                break;
        }
 
@@ -659,41 +678,124 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
        return result;
 }
 
-static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
-                              enum modify_type m)
+static char const * const builtin_sparse_checkout_add_usage[] = {
+       N_("git sparse-checkout add (--stdin | <patterns>)"),
+       NULL
+};
+
+static struct sparse_checkout_add_opts {
+       int use_stdin;
+} add_opts;
+
+static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
 {
-       static struct option builtin_sparse_checkout_set_options[] = {
-               OPT_BOOL(0, "stdin", &set_opts.use_stdin,
+       static struct option builtin_sparse_checkout_add_options[] = {
+               OPT_BOOL(0, "stdin", &add_opts.use_stdin,
                         N_("read patterns from standard in")),
                OPT_END(),
        };
 
+       if (!core_apply_sparse_checkout)
+               die(_("no sparse-checkout to add to"));
+
        repo_read_index(the_repository);
 
+       argc = parse_options(argc, argv, prefix,
+                            builtin_sparse_checkout_add_options,
+                            builtin_sparse_checkout_add_usage,
+                            PARSE_OPT_KEEP_UNKNOWN);
+
+       return modify_pattern_list(argc, argv, add_opts.use_stdin, ADD);
+}
+
+static char const * const builtin_sparse_checkout_set_usage[] = {
+       N_("git sparse-checkout set [--[no-]cone] [--[no-]sparse-index] (--stdin | <patterns>)"),
+       NULL
+};
+
+static struct sparse_checkout_set_opts {
+       int cone_mode;
+       int sparse_index;
+       int use_stdin;
+} set_opts;
+
+static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
+{
+       int default_patterns_nr = 2;
+       const char *default_patterns[] = {"/*", "!/*/", NULL};
+
+       static struct option builtin_sparse_checkout_set_options[] = {
+               OPT_BOOL(0, "cone", &set_opts.cone_mode,
+                        N_("initialize the sparse-checkout in cone mode")),
+               OPT_BOOL(0, "sparse-index", &set_opts.sparse_index,
+                        N_("toggle the use of a sparse index")),
+               OPT_BOOL_F(0, "stdin", &set_opts.use_stdin,
+                          N_("read patterns from standard in"),
+                          PARSE_OPT_NONEG),
+               OPT_END(),
+       };
+
+       repo_read_index(the_repository);
+
+       set_opts.cone_mode = -1;
+       set_opts.sparse_index = -1;
+
        argc = parse_options(argc, argv, prefix,
                             builtin_sparse_checkout_set_options,
                             builtin_sparse_checkout_set_usage,
                             PARSE_OPT_KEEP_UNKNOWN);
 
-       return modify_pattern_list(argc, argv, m);
+       if (update_modes(&set_opts.cone_mode, &set_opts.sparse_index))
+               return 1;
+
+       /*
+        * Cone mode automatically specifies the toplevel directory.  For
+        * non-cone mode, if nothing is specified, manually select just the
+        * top-level directory (much as 'init' would do).
+        */
+       if (!core_sparse_checkout_cone && argc == 0) {
+               argv = default_patterns;
+               argc = default_patterns_nr;
+       }
+
+       return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE);
 }
 
 static char const * const builtin_sparse_checkout_reapply_usage[] = {
-       N_("git sparse-checkout reapply"),
+       N_("git sparse-checkout reapply [--[no-]cone] [--[no-]sparse-index]"),
        NULL
 };
 
+static struct sparse_checkout_reapply_opts {
+       int cone_mode;
+       int sparse_index;
+} reapply_opts;
+
 static int sparse_checkout_reapply(int argc, const char **argv)
 {
        static struct option builtin_sparse_checkout_reapply_options[] = {
+               OPT_BOOL(0, "cone", &reapply_opts.cone_mode,
+                        N_("initialize the sparse-checkout in cone mode")),
+               OPT_BOOL(0, "sparse-index", &reapply_opts.sparse_index,
+                        N_("toggle the use of a sparse index")),
                OPT_END(),
        };
 
+       if (!core_apply_sparse_checkout)
+               die(_("must be in a sparse-checkout to reapply sparsity patterns"));
+
        argc = parse_options(argc, argv, NULL,
                             builtin_sparse_checkout_reapply_options,
                             builtin_sparse_checkout_reapply_usage, 0);
 
        repo_read_index(the_repository);
+
+       reapply_opts.cone_mode = -1;
+       reapply_opts.sparse_index = -1;
+
+       if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index))
+               return 1;
+
        return update_working_directory(NULL);
 }
 
@@ -710,6 +812,17 @@ static int sparse_checkout_disable(int argc, const char **argv)
        struct pattern_list pl;
        struct strbuf match_all = STRBUF_INIT;
 
+       /*
+        * We do not exit early if !core_apply_sparse_checkout; due to the
+        * ability for users to manually muck things up between
+        *   direct editing of .git/info/sparse-checkout
+        *   running read-tree -m u HEAD or update-index --skip-worktree
+        *   direct toggling of config options
+        * users might end up with an index with SKIP_WORKTREE bit set on
+        * some files and not know how to undo it.  So, here we just
+        * forcibly return to a dense checkout regardless of initial state.
+        */
+
        argc = parse_options(argc, argv, NULL,
                             builtin_sparse_checkout_disable_options,
                             builtin_sparse_checkout_disable_usage, 0);
@@ -758,9 +871,9 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
                if (!strcmp(argv[0], "init"))
                        return sparse_checkout_init(argc, argv);
                if (!strcmp(argv[0], "set"))
-                       return sparse_checkout_set(argc, argv, prefix, REPLACE);
+                       return sparse_checkout_set(argc, argv, prefix);
                if (!strcmp(argv[0], "add"))
-                       return sparse_checkout_set(argc, argv, prefix, ADD);
+                       return sparse_checkout_add(argc, argv, prefix);
                if (!strcmp(argv[0], "reapply"))
                        return sparse_checkout_reapply(argc, argv);
                if (!strcmp(argv[0], "disable"))
index 18c812bbe032cc24e57bd3083822bb4753dfa1ca..6da736d7189bee21a5f3681a5f4ac2554400297a 100644 (file)
@@ -1538,8 +1538,10 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
                        struct child_process cp = CHILD_PROCESS_INIT;
 
                        cp.git_cmd = 1;
+                       if (startup_info->original_cwd)
+                               cp.dir = startup_info->original_cwd;
                        strvec_pushl(&cp.args, "clean", "--force",
-                                    "--quiet", "-d", NULL);
+                                    "--quiet", "-d", ":/", NULL);
                        if (include_untracked == INCLUDE_ALL_FILES)
                                strvec_push(&cp.args, "-x");
                        if (run_command(&cp)) {
@@ -1681,6 +1683,7 @@ static int push_stash(int argc, const char **argv, const char *prefix,
        if (argc) {
                force_assume = !strcmp(argv[0], "-p");
                argc = parse_options(argc, argv, prefix, options,
+                                    push_assumed ? git_stash_usage :
                                     git_stash_push_usage,
                                     PARSE_OPT_KEEP_DASHDASH);
        }
diff --git a/cache.h b/cache.h
index cfba463aa97cb40ffebb4742c087f24daf791460..5d7463e6fb7e6ca631cd44fbca91920a56203eaf 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1846,8 +1846,10 @@ void overlay_tree_on_index(struct index_state *istate,
 struct startup_info {
        int have_repository;
        const char *prefix;
+       const char *original_cwd;
 };
 extern struct startup_info *startup_info;
+extern const char *tmp_original_cwd;
 
 /* merge.c */
 struct commit_list;
index 71e21dd20a3b141bed0d37512cdc9196321dc315..29fb7452f8a0b78cf7784ee4a1af7b26ebb53379 100644 (file)
@@ -26,6 +26,7 @@ static void restore_sigpipe_to_default(void)
 int main(int argc, const char **argv)
 {
        int result;
+       struct strbuf tmp = STRBUF_INIT;
 
        trace2_initialize_clock();
 
@@ -49,9 +50,15 @@ int main(int argc, const char **argv)
        trace2_cmd_start(argv);
        trace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);
 
-       result = cmd_main(argc, argv);
+       if (!strbuf_getcwd(&tmp))
+               tmp_original_cwd = strbuf_detach(&tmp, NULL);
 
-       trace2_cmd_exit(result);
+       result = cmd_main(argc, argv);
 
-       return result;
+       /*
+        * We define exit() to call trace2_cmd_exit_fl() in
+        * git-compat-util.h. Whether we reach this or exit()
+        * elsewhere we'll always run our trace2 exit handler.
+        */
+       exit(result);
 }
index 7673fed11425409c9a7fd584fb4387e79678d498..d4afac6b51fa9100e9f751ec0006cae5a259adc4 100644 (file)
@@ -19,6 +19,11 @@ endif
 endif
 endif
 endif
+
+ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang7,$(COMPILER_FEATURES))),)
+DEVELOPER_CFLAGS += -std=gnu99
+endif
+
 DEVELOPER_CFLAGS += -Wdeclaration-after-statement
 DEVELOPER_CFLAGS += -Wformat-security
 DEVELOPER_CFLAGS += -Wold-style-definition
index 016454749f8dfa8539c7af1ca7fe4338414ab661..d3e73126595df72b5d422b6afe708f16f15e9894 100755 (executable)
@@ -12,7 +12,7 @@ test_expect_success 'creating page w/ >500 revisions' '
        for i in $(test_seq 501)
        do
                echo "creating revision $i" &&
-               wiki_editpage foo "revision $i<br/>" true
+               wiki_editpage foo "revision $i<br/>" true || return 1
        done
 '
 
index 4153b6532195142c19f83c09ab2991d0abc821ad..1c1f76f04aaed3f15fec9d750762f46ee86c4cab 100755 (executable)
@@ -1445,7 +1445,7 @@ test_expect_success 'subtree descendant check' '
        ) &&
        test_create_commit "$test_count" folder_subtree/0 &&
        test_create_commit "$test_count" folder_subtree/b &&
-       cherry=$(cd "$test_count"; git rev-parse HEAD) &&
+       cherry=$(cd "$test_count" && git rev-parse HEAD) &&
        (
                cd "$test_count" &&
                git checkout branch
index 4a000ee4afa40387351936ea2ed583bda38668f9..94a5b8a36453f67d6d7de945c0d2427acd2f8188 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -232,13 +232,13 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
 
                rlen = strlcpy(interp_path, expanded_path.buf,
                               sizeof(interp_path));
+               strbuf_release(&expanded_path);
                if (rlen >= sizeof(interp_path)) {
                        logerror("interpolated path too large: %s",
                                 interp_path);
                        return NULL;
                }
 
-               strbuf_release(&expanded_path);
                loginfo("Interpolated dir '%s'", interp_path);
 
                dir = interp_path;
diff --git a/diff.c b/diff.c
index 410768574280f1179c78724ae13387f351cbf4cd..0b4f9b52c58eb156f2b076dbb0e1163ec6db6df3 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -18,6 +18,7 @@
 #include "submodule-config.h"
 #include "submodule.h"
 #include "hashmap.h"
+#include "mem-pool.h"
 #include "ll-merge.h"
 #include "string-list.h"
 #include "strvec.h"
@@ -773,6 +774,7 @@ struct emitted_diff_symbol {
        int flags;
        int indent_off;   /* Offset to first non-whitespace character */
        int indent_width; /* The visual width of the indentation */
+       unsigned id;
        enum diff_symbol s;
 };
 #define EMITTED_DIFF_SYMBOL_INIT { 0 }
@@ -798,9 +800,9 @@ static void append_emitted_diff_symbol(struct diff_options *o,
 }
 
 struct moved_entry {
-       struct hashmap_entry ent;
        const struct emitted_diff_symbol *es;
        struct moved_entry *next_line;
+       struct moved_entry *next_match;
 };
 
 struct moved_block {
@@ -808,11 +810,6 @@ struct moved_block {
        int wsd; /* The whitespace delta of this block */
 };
 
-static void moved_block_clear(struct moved_block *b)
-{
-       memset(b, 0, sizeof(*b));
-}
-
 #define INDENT_BLANKLINE INT_MIN
 
 static void fill_es_indent_data(struct emitted_diff_symbol *es)
@@ -856,79 +853,41 @@ static void fill_es_indent_data(struct emitted_diff_symbol *es)
 }
 
 static int compute_ws_delta(const struct emitted_diff_symbol *a,
-                           const struct emitted_diff_symbol *b,
-                           int *out)
-{
-       int a_len = a->len,
-           b_len = b->len,
-           a_off = a->indent_off,
-           a_width = a->indent_width,
-           b_off = b->indent_off,
+                           const struct emitted_diff_symbol *b)
+{
+       int a_width = a->indent_width,
            b_width = b->indent_width;
-       int delta;
 
-       if (a_width == INDENT_BLANKLINE && b_width == INDENT_BLANKLINE) {
-               *out = INDENT_BLANKLINE;
-               return 1;
-       }
-
-       if (a->s == DIFF_SYMBOL_PLUS)
-               delta = a_width - b_width;
-       else
-               delta = b_width - a_width;
-
-       if (a_len - a_off != b_len - b_off ||
-           memcmp(a->line + a_off, b->line + b_off, a_len - a_off))
-               return 0;
+       if (a_width == INDENT_BLANKLINE && b_width == INDENT_BLANKLINE)
+               return INDENT_BLANKLINE;
 
-       *out = delta;
-
-       return 1;
+       return a_width - b_width;
 }
 
-static int cmp_in_block_with_wsd(const struct diff_options *o,
-                                const struct moved_entry *cur,
-                                const struct moved_entry *match,
-                                struct moved_block *pmb,
-                                int n)
-{
-       struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
-       int al = cur->es->len, bl = match->es->len, cl = l->len;
-       const char *a = cur->es->line,
-                  *b = match->es->line,
-                  *c = l->line;
-       int a_off = cur->es->indent_off,
-           a_width = cur->es->indent_width,
-           c_off = l->indent_off,
-           c_width = l->indent_width;
+static int cmp_in_block_with_wsd(const struct moved_entry *cur,
+                                const struct emitted_diff_symbol *l,
+                                struct moved_block *pmb)
+{
+       int a_width = cur->es->indent_width, b_width = l->indent_width;
        int delta;
 
-       /*
-        * We need to check if 'cur' is equal to 'match'.  As those
-        * are from the same (+/-) side, we do not need to adjust for
-        * indent changes. However these were found using fuzzy
-        * matching so we do have to check if they are equal. Here we
-        * just check the lengths. We delay calling memcmp() to check
-        * the contents until later as if the length comparison for a
-        * and c fails we can avoid the call all together.
-        */
-       if (al != bl)
+       /* The text of each line must match */
+       if (cur->es->id != l->id)
                return 1;
 
-       /* If 'l' and 'cur' are both blank then they match. */
-       if (a_width == INDENT_BLANKLINE && c_width == INDENT_BLANKLINE)
+       /*
+        * If 'l' and 'cur' are both blank then we don't need to check the
+        * indent. We only need to check cur as we know the strings match.
+        * */
+       if (a_width == INDENT_BLANKLINE)
                return 0;
 
        /*
         * The indent changes of the block are known and stored in pmb->wsd;
         * however we need to check if the indent changes of the current line
-        * match those of the current block and that the text of 'l' and 'cur'
-        * after the indentation match.
+        * match those of the current block.
         */
-       if (cur->es->s == DIFF_SYMBOL_PLUS)
-               delta = a_width - c_width;
-       else
-               delta = c_width - a_width;
+       delta = b_width - a_width;
 
        /*
         * If the previous lines of this block were all blank then set its
@@ -937,166 +896,165 @@ static int cmp_in_block_with_wsd(const struct diff_options *o,
        if (pmb->wsd == INDENT_BLANKLINE)
                pmb->wsd = delta;
 
-       return !(delta == pmb->wsd && al - a_off == cl - c_off &&
-                !memcmp(a, b, al) && !
-                memcmp(a + a_off, c + c_off, al - a_off));
+       return delta != pmb->wsd;
 }
 
-static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
-                          const struct hashmap_entry *eptr,
-                          const struct hashmap_entry *entry_or_key,
-                          const void *keydata)
+struct interned_diff_symbol {
+       struct hashmap_entry ent;
+       struct emitted_diff_symbol *es;
+};
+
+static int interned_diff_symbol_cmp(const void *hashmap_cmp_fn_data,
+                                   const struct hashmap_entry *eptr,
+                                   const struct hashmap_entry *entry_or_key,
+                                   const void *keydata)
 {
        const struct diff_options *diffopt = hashmap_cmp_fn_data;
-       const struct moved_entry *a, *b;
+       const struct emitted_diff_symbol *a, *b;
        unsigned flags = diffopt->color_moved_ws_handling
                         & XDF_WHITESPACE_FLAGS;
 
-       a = container_of(eptr, const struct moved_entry, ent);
-       b = container_of(entry_or_key, const struct moved_entry, ent);
-
-       if (diffopt->color_moved_ws_handling &
-           COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
-               /*
-                * As there is not specific white space config given,
-                * we'd need to check for a new block, so ignore all
-                * white space. The setup of the white space
-                * configuration for the next block is done else where
-                */
-               flags |= XDF_IGNORE_WHITESPACE;
+       a = container_of(eptr, const struct interned_diff_symbol, ent)->es;
+       b = container_of(entry_or_key, const struct interned_diff_symbol, ent)->es;
 
-       return !xdiff_compare_lines(a->es->line, a->es->len,
-                                   b->es->line, b->es->len,
-                                   flags);
+       return !xdiff_compare_lines(a->line + a->indent_off,
+                                   a->len - a->indent_off,
+                                   b->line + b->indent_off,
+                                   b->len - b->indent_off, flags);
 }
 
-static struct moved_entry *prepare_entry(struct diff_options *o,
-                                        int line_no)
+static void prepare_entry(struct diff_options *o, struct emitted_diff_symbol *l,
+                         struct interned_diff_symbol *s)
 {
-       struct moved_entry *ret = xmalloc(sizeof(*ret));
-       struct emitted_diff_symbol *l = &o->emitted_symbols->buf[line_no];
        unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
-       unsigned int hash = xdiff_hash_string(l->line, l->len, flags);
-
-       hashmap_entry_init(&ret->ent, hash);
-       ret->es = l;
-       ret->next_line = NULL;
+       unsigned int hash = xdiff_hash_string(l->line + l->indent_off,
+                                             l->len - l->indent_off, flags);
 
-       return ret;
+       hashmap_entry_init(&s->ent, hash);
+       s->es = l;
 }
 
-static void add_lines_to_move_detection(struct diff_options *o,
-                                       struct hashmap *add_lines,
-                                       struct hashmap *del_lines)
+struct moved_entry_list {
+       struct moved_entry *add, *del;
+};
+
+static struct moved_entry_list *add_lines_to_move_detection(struct diff_options *o,
+                                                           struct mem_pool *entry_mem_pool)
 {
        struct moved_entry *prev_line = NULL;
-
+       struct mem_pool interned_pool;
+       struct hashmap interned_map;
+       struct moved_entry_list *entry_list = NULL;
+       size_t entry_list_alloc = 0;
+       unsigned id = 0;
        int n;
+
+       hashmap_init(&interned_map, interned_diff_symbol_cmp, o, 8096);
+       mem_pool_init(&interned_pool, 1024 * 1024);
+
        for (n = 0; n < o->emitted_symbols->nr; n++) {
-               struct hashmap *hm;
-               struct moved_entry *key;
+               struct interned_diff_symbol key;
+               struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
+               struct interned_diff_symbol *s;
+               struct moved_entry *entry;
 
-               switch (o->emitted_symbols->buf[n].s) {
-               case DIFF_SYMBOL_PLUS:
-                       hm = add_lines;
-                       break;
-               case DIFF_SYMBOL_MINUS:
-                       hm = del_lines;
-                       break;
-               default:
+               if (l->s != DIFF_SYMBOL_PLUS && l->s != DIFF_SYMBOL_MINUS) {
                        prev_line = NULL;
                        continue;
                }
 
                if (o->color_moved_ws_handling &
                    COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
-                       fill_es_indent_data(&o->emitted_symbols->buf[n]);
-               key = prepare_entry(o, n);
-               if (prev_line && prev_line->es->s == o->emitted_symbols->buf[n].s)
-                       prev_line->next_line = key;
+                       fill_es_indent_data(l);
 
-               hashmap_add(hm, &key->ent);
-               prev_line = key;
+               prepare_entry(o, l, &key);
+               s = hashmap_get_entry(&interned_map, &key, ent, &key.ent);
+               if (s) {
+                       l->id = s->es->id;
+               } else {
+                       l->id = id;
+                       ALLOC_GROW_BY(entry_list, id, 1, entry_list_alloc);
+                       hashmap_add(&interned_map,
+                                   memcpy(mem_pool_alloc(&interned_pool,
+                                                         sizeof(key)),
+                                          &key, sizeof(key)));
+               }
+               entry = mem_pool_alloc(entry_mem_pool, sizeof(*entry));
+               entry->es = l;
+               entry->next_line = NULL;
+               if (prev_line && prev_line->es->s == l->s)
+                       prev_line->next_line = entry;
+               prev_line = entry;
+               if (l->s == DIFF_SYMBOL_PLUS) {
+                       entry->next_match = entry_list[l->id].add;
+                       entry_list[l->id].add = entry;
+               } else {
+                       entry->next_match = entry_list[l->id].del;
+                       entry_list[l->id].del = entry;
+               }
        }
+
+       hashmap_clear(&interned_map);
+       mem_pool_discard(&interned_pool, 0);
+
+       return entry_list;
 }
 
 static void pmb_advance_or_null(struct diff_options *o,
-                               struct moved_entry *match,
-                               struct hashmap *hm,
+                               struct emitted_diff_symbol *l,
                                struct moved_block *pmb,
-                               int pmb_nr)
+                               int *pmb_nr)
 {
-       int i;
-       for (i = 0; i < pmb_nr; i++) {
+       int i, j;
+
+       for (i = 0, j = 0; i < *pmb_nr; i++) {
+               int match;
                struct moved_entry *prev = pmb[i].match;
                struct moved_entry *cur = (prev && prev->next_line) ?
                                prev->next_line : NULL;
-               if (cur && !hm->cmpfn(o, &cur->ent, &match->ent, NULL)) {
-                       pmb[i].match = cur;
-               } else {
-                       pmb[i].match = NULL;
-               }
-       }
-}
 
-static void pmb_advance_or_null_multi_match(struct diff_options *o,
-                                           struct moved_entry *match,
-                                           struct hashmap *hm,
-                                           struct moved_block *pmb,
-                                           int pmb_nr, int n)
-{
-       int i;
-       char *got_match = xcalloc(1, pmb_nr);
-
-       hashmap_for_each_entry_from(hm, match, ent) {
-               for (i = 0; i < pmb_nr; i++) {
-                       struct moved_entry *prev = pmb[i].match;
-                       struct moved_entry *cur = (prev && prev->next_line) ?
-                                       prev->next_line : NULL;
-                       if (!cur)
-                               continue;
-                       if (!cmp_in_block_with_wsd(o, cur, match, &pmb[i], n))
-                               got_match[i] |= 1;
-               }
-       }
+               if (o->color_moved_ws_handling &
+                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
+                       match = cur &&
+                               !cmp_in_block_with_wsd(cur, l, &pmb[i]);
+               else
+                       match = cur && cur->es->id == l->id;
 
-       for (i = 0; i < pmb_nr; i++) {
-               if (got_match[i]) {
-                       /* Advance to the next line */
-                       pmb[i].match = pmb[i].match->next_line;
-               } else {
-                       moved_block_clear(&pmb[i]);
+               if (match) {
+                       pmb[j] = pmb[i];
+                       pmb[j++].match = cur;
                }
        }
-
-       free(got_match);
+       *pmb_nr = j;
 }
 
-static int shrink_potential_moved_blocks(struct moved_block *pmb,
-                                        int pmb_nr)
-{
-       int lp, rp;
-
-       /* Shrink the set of potential block to the remaining running */
-       for (lp = 0, rp = pmb_nr - 1; lp <= rp;) {
-               while (lp < pmb_nr && pmb[lp].match)
-                       lp++;
-               /* lp points at the first NULL now */
+static void fill_potential_moved_blocks(struct diff_options *o,
+                                       struct moved_entry *match,
+                                       struct emitted_diff_symbol *l,
+                                       struct moved_block **pmb_p,
+                                       int *pmb_alloc_p, int *pmb_nr_p)
 
-               while (rp > -1 && !pmb[rp].match)
-                       rp--;
-               /* rp points at the last non-NULL */
+{
+       struct moved_block *pmb = *pmb_p;
+       int pmb_alloc = *pmb_alloc_p, pmb_nr = *pmb_nr_p;
 
-               if (lp < pmb_nr && rp > -1 && lp < rp) {
-                       pmb[lp] = pmb[rp];
-                       memset(&pmb[rp], 0, sizeof(pmb[rp]));
-                       rp--;
-                       lp++;
-               }
+       /*
+        * The current line is the start of a new block.
+        * Setup the set of potential blocks.
+        */
+       for (; match; match = match->next_match) {
+               ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
+               if (o->color_moved_ws_handling &
+                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
+                       pmb[pmb_nr].wsd = compute_ws_delta(l, match->es);
+               else
+                       pmb[pmb_nr].wsd = 0;
+               pmb[pmb_nr++].match = match;
        }
 
-       /* Remember the number of running sets */
-       return rp + 1;
+       *pmb_p = pmb;
+       *pmb_alloc_p = pmb_alloc;
+       *pmb_nr_p = pmb_nr;
 }
 
 /*
@@ -1115,6 +1073,8 @@ static int shrink_potential_moved_blocks(struct moved_block *pmb,
  * NEEDSWORK: This uses the same heuristic as blame_entry_score() in blame.c.
  * Think of a way to unify them.
  */
+#define DIFF_SYMBOL_MOVED_LINE_ZEBRA_MASK \
+  (DIFF_SYMBOL_MOVED_LINE | DIFF_SYMBOL_MOVED_LINE_ALT)
 static int adjust_last_block(struct diff_options *o, int n, int block_length)
 {
        int i, alnum_count = 0;
@@ -1131,95 +1091,85 @@ static int adjust_last_block(struct diff_options *o, int n, int block_length)
                }
        }
        for (i = 1; i < block_length + 1; i++)
-               o->emitted_symbols->buf[n - i].flags &= ~DIFF_SYMBOL_MOVED_LINE;
+               o->emitted_symbols->buf[n - i].flags &= ~DIFF_SYMBOL_MOVED_LINE_ZEBRA_MASK;
        return 0;
 }
 
 /* Find blocks of moved code, delegate actual coloring decision to helper */
 static void mark_color_as_moved(struct diff_options *o,
-                               struct hashmap *add_lines,
-                               struct hashmap *del_lines)
+                               struct moved_entry_list *entry_list)
 {
        struct moved_block *pmb = NULL; /* potentially moved blocks */
        int pmb_nr = 0, pmb_alloc = 0;
        int n, flipped_block = 0, block_length = 0;
+       enum diff_symbol moved_symbol = DIFF_SYMBOL_BINARY_DIFF_HEADER;
 
 
        for (n = 0; n < o->emitted_symbols->nr; n++) {
-               struct hashmap *hm = NULL;
-               struct moved_entry *key;
                struct moved_entry *match = NULL;
                struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
-               enum diff_symbol last_symbol = 0;
 
                switch (l->s) {
                case DIFF_SYMBOL_PLUS:
-                       hm = del_lines;
-                       key = prepare_entry(o, n);
-                       match = hashmap_get_entry(hm, key, ent, NULL);
-                       free(key);
+                       match = entry_list[l->id].del;
                        break;
                case DIFF_SYMBOL_MINUS:
-                       hm = add_lines;
-                       key = prepare_entry(o, n);
-                       match = hashmap_get_entry(hm, key, ent, NULL);
-                       free(key);
+                       match = entry_list[l->id].add;
                        break;
                default:
                        flipped_block = 0;
                }
 
-               if (!match) {
-                       int i;
-
-                       adjust_last_block(o, n, block_length);
-                       for(i = 0; i < pmb_nr; i++)
-                               moved_block_clear(&pmb[i]);
+               if (pmb_nr && (!match || l->s != moved_symbol)) {
+                       if (!adjust_last_block(o, n, block_length) &&
+                           block_length > 1) {
+                               /*
+                                * Rewind in case there is another match
+                                * starting at the second line of the block
+                                */
+                               match = NULL;
+                               n -= block_length;
+                       }
                        pmb_nr = 0;
                        block_length = 0;
                        flipped_block = 0;
-                       last_symbol = l->s;
+               }
+               if (!match) {
+                       moved_symbol = DIFF_SYMBOL_BINARY_DIFF_HEADER;
                        continue;
                }
 
                if (o->color_moved == COLOR_MOVED_PLAIN) {
-                       last_symbol = l->s;
                        l->flags |= DIFF_SYMBOL_MOVED_LINE;
                        continue;
                }
 
-               if (o->color_moved_ws_handling &
-                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
-                       pmb_advance_or_null_multi_match(o, match, hm, pmb, pmb_nr, n);
-               else
-                       pmb_advance_or_null(o, match, hm, pmb, pmb_nr);
-
-               pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
+               pmb_advance_or_null(o, l, pmb, &pmb_nr);
 
                if (pmb_nr == 0) {
-                       /*
-                        * The current line is the start of a new block.
-                        * Setup the set of potential blocks.
-                        */
-                       hashmap_for_each_entry_from(hm, match, ent) {
-                               ALLOC_GROW(pmb, pmb_nr + 1, pmb_alloc);
-                               if (o->color_moved_ws_handling &
-                                   COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) {
-                                       if (compute_ws_delta(l, match->es,
-                                                            &pmb[pmb_nr].wsd))
-                                               pmb[pmb_nr++].match = match;
-                               } else {
-                                       pmb[pmb_nr].wsd = 0;
-                                       pmb[pmb_nr++].match = match;
-                               }
-                       }
+                       int contiguous = adjust_last_block(o, n, block_length);
+
+                       if (!contiguous && block_length > 1)
+                               /*
+                                * Rewind in case there is another match
+                                * starting at the second line of the block
+                                */
+                               n -= block_length;
+                       else
+                               fill_potential_moved_blocks(o, match, l,
+                                                           &pmb, &pmb_alloc,
+                                                           &pmb_nr);
 
-                       if (adjust_last_block(o, n, block_length) &&
-                           pmb_nr && last_symbol != l->s)
+                       if (contiguous && pmb_nr && moved_symbol == l->s)
                                flipped_block = (flipped_block + 1) % 2;
                        else
                                flipped_block = 0;
 
+                       if (pmb_nr)
+                               moved_symbol = l->s;
+                       else
+                               moved_symbol = DIFF_SYMBOL_BINARY_DIFF_HEADER;
+
                        block_length = 0;
                }
 
@@ -1229,17 +1179,12 @@ static void mark_color_as_moved(struct diff_options *o,
                        if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
                                l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
                }
-               last_symbol = l->s;
        }
        adjust_last_block(o, n, block_length);
 
-       for(n = 0; n < pmb_nr; n++)
-               moved_block_clear(&pmb[n]);
        free(pmb);
 }
 
-#define DIFF_SYMBOL_MOVED_LINE_ZEBRA_MASK \
-  (DIFF_SYMBOL_MOVED_LINE | DIFF_SYMBOL_MOVED_LINE_ALT)
 static void dim_moved_lines(struct diff_options *o)
 {
        int n;
@@ -1573,7 +1518,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
 static void emit_diff_symbol(struct diff_options *o, enum diff_symbol s,
                             const char *line, int len, unsigned flags)
 {
-       struct emitted_diff_symbol e = {line, len, flags, 0, 0, s};
+       struct emitted_diff_symbol e = {
+               .line = line, .len = len, .flags = flags, .s = s
+       };
 
        if (o->emitted_symbols)
                append_emitted_diff_symbol(o, &e);
@@ -6345,24 +6292,18 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
 
        if (o->emitted_symbols) {
                if (o->color_moved) {
-                       struct hashmap add_lines, del_lines;
-
-                       if (o->color_moved_ws_handling &
-                           COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
-                               o->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE;
-
-                       hashmap_init(&del_lines, moved_entry_cmp, o, 0);
-                       hashmap_init(&add_lines, moved_entry_cmp, o, 0);
+                       struct mem_pool entry_pool;
+                       struct moved_entry_list *entry_list;
 
-                       add_lines_to_move_detection(o, &add_lines, &del_lines);
-                       mark_color_as_moved(o, &add_lines, &del_lines);
+                       mem_pool_init(&entry_pool, 1024 * 1024);
+                       entry_list = add_lines_to_move_detection(o,
+                                                                &entry_pool);
+                       mark_color_as_moved(o, entry_list);
                        if (o->color_moved == COLOR_MOVED_ZEBRA_DIM)
                                dim_moved_lines(o);
 
-                       hashmap_clear_and_free(&add_lines, struct moved_entry,
-                                               ent);
-                       hashmap_clear_and_free(&del_lines, struct moved_entry,
-                                               ent);
+                       mem_pool_discard(&entry_pool, 0);
+                       free(entry_list);
                }
 
                for (i = 0; i < esm.nr; i++)
diff --git a/dir.c b/dir.c
index 5aa6fbad0b76ad3ad026a8775761f9c7ea1776e8..d91295f2bcdcf86f0b1c41a32ac6a17d5d3cf65e 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -727,7 +727,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
        }
 
        if (given->patternlen < 2 ||
-           *given->pattern == '*' ||
+           *given->pattern != '/' ||
            strstr(given->pattern, "**")) {
                /* Not a cone pattern. */
                warning(_("unrecognized pattern: '%s'"), given->pattern);
@@ -819,9 +819,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
                /* we already included this at the parent level */
                warning(_("your sparse-checkout file may have issues: pattern '%s' is repeated"),
                        given->pattern);
-               hashmap_remove(&pl->parent_hashmap, &translated->ent, &data);
-               free(data);
-               free(translated);
+               goto clear_hashmaps;
        }
 
        return;
@@ -3160,6 +3158,7 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
        int ret = 0, original_len = path->len, len, kept_down = 0;
        int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY);
        int keep_toplevel = (flag & REMOVE_DIR_KEEP_TOPLEVEL);
+       int purge_original_cwd = (flag & REMOVE_DIR_PURGE_ORIGINAL_CWD);
        struct object_id submodule_head;
 
        if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
@@ -3215,9 +3214,14 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
        closedir(dir);
 
        strbuf_setlen(path, original_len);
-       if (!ret && !keep_toplevel && !kept_down)
-               ret = (!rmdir(path->buf) || errno == ENOENT) ? 0 : -1;
-       else if (kept_up)
+       if (!ret && !keep_toplevel && !kept_down) {
+               if (!purge_original_cwd &&
+                   startup_info->original_cwd &&
+                   !strcmp(startup_info->original_cwd, path->buf))
+                       ret = -1; /* Do not remove current working directory */
+               else
+                       ret = (!rmdir(path->buf) || errno == ENOENT) ? 0 : -1;
+       } else if (kept_up)
                /*
                 * report the uplevel that it is not an error that we
                 * did not rmdir() our directory.
@@ -3283,6 +3287,9 @@ int remove_path(const char *name)
                slash = dirs + (slash - name);
                do {
                        *slash = '\0';
+                       if (startup_info->original_cwd &&
+                           !strcmp(startup_info->original_cwd, dirs))
+                               break;
                } while (rmdir(dirs) == 0 && (slash = strrchr(dirs, '/')));
                free(dirs);
        }
diff --git a/dir.h b/dir.h
index 83f46c0fb4c4415c79d3a9fcdddbcbf372b35415..8e02dfb505d163eca3c33d17e495be8f166b83e5 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -495,6 +495,9 @@ int get_sparse_checkout_patterns(struct pattern_list *pl);
 /* Remove the contents of path, but leave path itself. */
 #define REMOVE_DIR_KEEP_TOPLEVEL 04
 
+/* Remove the_original_cwd too */
+#define REMOVE_DIR_PURGE_ORIGINAL_CWD 0x08
+
 /*
  * Remove path and its contents, recursively. flags is a combination
  * of the above REMOVE_DIR_* constants. Return 0 on success.
@@ -504,7 +507,11 @@ int get_sparse_checkout_patterns(struct pattern_list *pl);
  */
 int remove_dir_recursively(struct strbuf *path, int flag);
 
-/* tries to remove the path with empty directories along it, ignores ENOENT */
+/*
+ * Tries to remove the path, along with leading empty directories so long as
+ * those empty directories are not startup_info->original_cwd.  Ignores
+ * ENOENT.
+ */
 int remove_path(const char *path);
 
 int fspathcmp(const char *a, const char *b);
index 0d06a3102495977bd0fb5f50b5ff207905fde4ae..fd0501e77a5b8d96dad8b5fe3714b74f13786be7 100644 (file)
@@ -17,6 +17,7 @@
 #include "commit.h"
 #include "strvec.h"
 #include "object-store.h"
+#include "tmp-objdir.h"
 #include "chdir-notify.h"
 #include "shallow.h"
 
@@ -169,6 +170,10 @@ void setup_git_env(const char *git_dir)
        args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT);
        args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT);
        args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT);
+       if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
+               args.disable_ref_updates = 1;
+       }
+
        repo_set_gitdir(the_repository, git_dir, &args);
        strvec_clear(&to_free);
 
@@ -332,10 +337,14 @@ static void update_relative_gitdir(const char *name,
                                   void *data)
 {
        char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir());
+       struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb();
+
        trace_printf_key(&trace_setup_key,
                         "setup: move $GIT_DIR to '%s'",
                         path);
        set_git_dir_1(path);
+       if (tmp_objdir)
+               tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd);
        free(path);
 }
 
index e4f7810be208495e8883f3ca4abad3f21f320003..e5c0aff2bf684f2726a2628a80cedddfc1048e91 100644 (file)
@@ -650,12 +650,15 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
 
        memset(&merge_parents, 0, sizeof(merge_parents));
 
-       /* get current branch */
+       /* learn the commit that we merge into and the current branch name */
        current_branch = current_branch_to_free =
                resolve_refdup("HEAD", RESOLVE_REF_READING, &head_oid, NULL);
        if (!current_branch)
                die("No current branch");
-       if (starts_with(current_branch, "refs/heads/"))
+
+       if (opts->into_name)
+               current_branch = opts->into_name;
+       else if (starts_with(current_branch, "refs/heads/"))
                current_branch += 11;
 
        find_merge_parents(&merge_parents, in, &head_oid);
index f2ab0e0085ada6509c02427503b1ea04b18951e0..99054042dc5e574b2ef1c00394331955239e0324 100644 (file)
@@ -9,6 +9,7 @@ struct fmt_merge_msg_opts {
        unsigned add_title:1,
                credit_people:1;
        int shortlog_len;
+       const char *into_name;
 };
 
 extern int merge_log_config;
index 5fa54a7afe4bf9ef05d4fa400e677f4f5c94ea4a..b7caf23666092c44df88f47f27f99f6a8a9ddd03 100644 (file)
 /*
  * See if our compiler is known to support flexible array members.
  */
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && (!defined(__SUNPRO_C) || (__SUNPRO_C > 0x580))
-# define FLEX_ARRAY /* empty */
+
+/*
+ * Check vendor specific quirks first, before checking the
+ * __STDC_VERSION__, as vendor compilers can lie and we need to be
+ * able to work them around.  Note that by not defining FLEX_ARRAY
+ * here, we can fall back to use the "safer but a bit wasteful" one
+ * later.
+ */
+#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
 #elif defined(__GNUC__)
 # if (__GNUC__ >= 3)
 #  define FLEX_ARRAY /* empty */
 # else
 #  define FLEX_ARRAY 0 /* older GNU extension */
 # endif
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+# define FLEX_ARRAY /* empty */
 #endif
 
 /*
index 2b4500226aa7a48d2b2644d3b1f351342cda20f4..cb37545455e9d8b782c078582a7e5a8b902af845 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -56,6 +56,21 @@ defaultBlockSize = 1<<20
 
 p4_access_checked = False
 
+re_ko_keywords = re.compile(br'\$(Id|Header)(:[^$\n]+)?\$')
+re_k_keywords = re.compile(br'\$(Id|Header|Author|Date|DateTime|Change|File|Revision)(:[^$\n]+)?\$')
+
+def format_size_human_readable(num):
+    """ Returns a number of units (typically bytes) formatted as a human-readable
+        string.
+    """
+    if num < 1024:
+        return '{:d} B'.format(num)
+    for unit in ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
+        num /= 1024.0
+        if num < 1024.0:
+            return "{:3.1f} {}B".format(num, unit)
+    return "{:.1f} YiB".format(num)
+
 def p4_build_cmd(cmd):
     """Build a suitable p4 command line.
 
@@ -337,17 +352,19 @@ def p4_read_pipe(c, ignore_error=False, raw=False):
     real_cmd = p4_build_cmd(c)
     return read_pipe(real_cmd, ignore_error, raw=raw)
 
-def read_pipe_lines(c):
+def read_pipe_lines(c, raw=False):
     if verbose:
         sys.stderr.write('Reading pipe: %s\n' % str(c))
 
     expand = not isinstance(c, list)
     p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
     pipe = p.stdout
-    val = [decode_text_stream(line) for line in pipe.readlines()]
+    lines = pipe.readlines()
+    if not raw:
+        lines = [decode_text_stream(line) for line in lines]
     if pipe.close() or p.wait():
         die('Command failed: %s' % str(c))
-    return val
+    return lines
 
 def p4_read_pipe_lines(c):
     """Specifically invoke p4 on the command supplied. """
@@ -577,20 +594,12 @@ def p4_type(f):
 #
 def p4_keywords_regexp_for_type(base, type_mods):
     if base in ("text", "unicode", "binary"):
-        kwords = None
         if "ko" in type_mods:
-            kwords = 'Id|Header'
+            return re_ko_keywords
         elif "k" in type_mods:
-            kwords = 'Id|Header|Author|Date|DateTime|Change|File|Revision'
+            return re_k_keywords
         else:
             return None
-        pattern = r"""
-            \$              # Starts with a dollar, followed by...
-            (%s)            # one of the keywords, followed by...
-            (:[^$\n]+)?     # possibly an old expansion, followed by...
-            \$              # another dollar
-            """ % kwords
-        return pattern
     else:
         return None
 
@@ -1532,80 +1541,6 @@ class P4UserMap:
         except IOError:
             self.getUserMapFromPerforceServer()
 
-class P4Debug(Command):
-    def __init__(self):
-        Command.__init__(self)
-        self.options = []
-        self.description = "A tool to debug the output of p4 -G."
-        self.needsGit = False
-
-    def run(self, args):
-        j = 0
-        for output in p4CmdList(args):
-            print('Element: %d' % j)
-            j += 1
-            print(output)
-        return True
-
-class P4RollBack(Command):
-    def __init__(self):
-        Command.__init__(self)
-        self.options = [
-            optparse.make_option("--local", dest="rollbackLocalBranches", action="store_true")
-        ]
-        self.description = "A tool to debug the multi-branch import. Don't use :)"
-        self.rollbackLocalBranches = False
-
-    def run(self, args):
-        if len(args) != 1:
-            return False
-        maxChange = int(args[0])
-
-        if "p4ExitCode" in p4Cmd("changes -m 1"):
-            die("Problems executing p4");
-
-        if self.rollbackLocalBranches:
-            refPrefix = "refs/heads/"
-            lines = read_pipe_lines("git rev-parse --symbolic --branches")
-        else:
-            refPrefix = "refs/remotes/"
-            lines = read_pipe_lines("git rev-parse --symbolic --remotes")
-
-        for line in lines:
-            if self.rollbackLocalBranches or (line.startswith("p4/") and line != "p4/HEAD\n"):
-                line = line.strip()
-                ref = refPrefix + line
-                log = extractLogMessageFromGitCommit(ref)
-                settings = extractSettingsGitLog(log)
-
-                depotPaths = settings['depot-paths']
-                change = settings['change']
-
-                changed = False
-
-                if len(p4Cmd("changes -m 1 "  + ' '.join (['%s...@%s' % (p, maxChange)
-                                                           for p in depotPaths]))) == 0:
-                    print("Branch %s did not exist at change %s, deleting." % (ref, maxChange))
-                    system("git update-ref -d %s `git rev-parse %s`" % (ref, ref))
-                    continue
-
-                while change and int(change) > maxChange:
-                    changed = True
-                    if self.verbose:
-                        print("%s is at %s ; rewinding towards %s" % (ref, change, maxChange))
-                    system("git update-ref %s \"%s^\"" % (ref, ref))
-                    log = extractLogMessageFromGitCommit(ref)
-                    settings =  extractSettingsGitLog(log)
-
-
-                    depotPaths = settings['depot-paths']
-                    change = settings['change']
-
-                if changed:
-                    print("%s rewound to %s" % (ref, change))
-
-        return True
-
 class P4Submit(Command, P4UserMap):
 
     conflict_behavior_choices = ("ask", "skip", "quit")
@@ -1753,18 +1688,13 @@ class P4Submit(Command, P4UserMap):
 
         return result
 
-    def patchRCSKeywords(self, file, pattern):
-        # Attempt to zap the RCS keywords in a p4 controlled file matching the given pattern
+    def patchRCSKeywords(self, file, regexp):
+        # Attempt to zap the RCS keywords in a p4 controlled file matching the given regex
         (handle, outFileName) = tempfile.mkstemp(dir='.')
         try:
-            outFile = os.fdopen(handle, "w+")
-            inFile = open(file, "r")
-            regexp = re.compile(pattern, re.VERBOSE)
-            for line in inFile.readlines():
-                line = regexp.sub(r'$\1$', line)
-                outFile.write(line)
-            inFile.close()
-            outFile.close()
+            with os.fdopen(handle, "wb") as outFile, open(file, "rb") as inFile:
+                for line in inFile.readlines():
+                    outFile.write(regexp.sub(br'$\1$', line))
             # Forcibly overwrite the original file
             os.unlink(file)
             shutil.move(outFileName, file)
@@ -2091,25 +2021,24 @@ class P4Submit(Command, P4UserMap):
             # the patch to see if that's possible.
             if gitConfigBool("git-p4.attemptRCSCleanup"):
                 file = None
-                pattern = None
                 kwfiles = {}
                 for file in editedFiles | filesToDelete:
                     # did this file's delta contain RCS keywords?
-                    pattern = p4_keywords_regexp_for_file(file)
-
-                    if pattern:
+                    regexp = p4_keywords_regexp_for_file(file)
+                    if regexp:
                         # this file is a possibility...look for RCS keywords.
-                        regexp = re.compile(pattern, re.VERBOSE)
-                        for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]):
+                        for line in read_pipe_lines(
+                            ["git", "diff", "%s^..%s" % (id, id), file],
+                            raw=True):
                             if regexp.search(line):
                                 if verbose:
-                                    print("got keyword match on %s in %s in %s" % (pattern, line, file))
-                                kwfiles[file] = pattern
+                                    print("got keyword match on %s in %s in %s" % (regex.pattern, line, file))
+                                kwfiles[file] = regexp
                                 break
 
-                for file in kwfiles:
+                for file, regexp in kwfiles.items():
                     if verbose:
-                        print("zapping %s with %s" % (line,pattern))
+                        print("zapping %s with %s" % (line, regexp.pattern))
                     # File is being deleted, so not open in p4.  Must
                     # disable the read-only bit on windows.
                     if self.isWindows and file not in editedFiles:
@@ -2966,7 +2895,8 @@ class P4Sync(Command, P4UserMap):
                 size = int(self.stream_file['fileSize'])
             else:
                 size = 0 # deleted files don't get a fileSize apparently
-            sys.stdout.write('\r%s --> %s (%i MB)\n' % (file_path, relPath, size/1024/1024))
+            sys.stdout.write('\r%s --> %s (%s)\n' % (
+                file_path, relPath, format_size_human_readable(size)))
             sys.stdout.flush()
 
         (type_base, type_mods) = split_p4_type(file["type"])
@@ -3029,12 +2959,9 @@ class P4Sync(Command, P4UserMap):
 
         # Note that we do not try to de-mangle keywords on utf16 files,
         # even though in theory somebody may want that.
-        pattern = p4_keywords_regexp_for_type(type_base, type_mods)
-        if pattern:
-            regexp = re.compile(pattern, re.VERBOSE)
-            text = ''.join(decode_text_stream(c) for c in contents)
-            text = regexp.sub(r'$\1$', text)
-            contents = [ encode_text_stream(text) ]
+        regexp = p4_keywords_regexp_for_type(type_base, type_mods)
+        if regexp:
+            contents = [regexp.sub(br'$\1$', c) for c in contents]
 
         if self.largeFileSystem:
             (git_mode, contents) = self.largeFileSystem.processContent(git_mode, relPath, contents)
@@ -3064,9 +2991,8 @@ class P4Sync(Command, P4UserMap):
         if not err and 'fileSize' in self.stream_file:
             required_bytes = int((4 * int(self.stream_file["fileSize"])) - calcDiskFree())
             if required_bytes > 0:
-                err = 'Not enough space left on %s! Free at least %i MB.' % (
-                    os.getcwd(), required_bytes/1024/1024
-                )
+                err = 'Not enough space left on %s! Free at least %s.' % (
+                    os.getcwd(), format_size_human_readable(required_bytes))
 
         if err:
             f = None
@@ -3110,7 +3036,9 @@ class P4Sync(Command, P4UserMap):
             size = int(self.stream_file["fileSize"])
             if size > 0:
                 progress = 100*self.stream_file['streamContentSize']/size
-                sys.stdout.write('\r%s %d%% (%i MB)' % (self.stream_file['depotFile'], progress, int(size/1024/1024)))
+                sys.stdout.write('\r%s %d%% (%s)' % (
+                    self.stream_file['depotFile'], progress,
+                    format_size_human_readable(size)))
                 sys.stdout.flush()
 
         self.stream_have_file_info = True
@@ -3623,7 +3551,8 @@ class P4Sync(Command, P4UserMap):
             self.updateOptionDict(description)
 
             if not self.silent:
-                sys.stdout.write("\rImporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
+                sys.stdout.write("\rImporting revision %s (%d%%)" % (
+                    change, (cnt * 100) // len(changes)))
                 sys.stdout.flush()
             cnt = cnt + 1
 
@@ -4363,13 +4292,11 @@ def printUsage(commands):
     print("")
 
 commands = {
-    "debug" : P4Debug,
     "submit" : P4Submit,
     "commit" : P4Submit,
     "sync" : P4Sync,
     "rebase" : P4Rebase,
     "clone" : P4Clone,
-    "rollback" : P4RollBack,
     "branches" : P4Branches,
     "unshelve" : P4Unshelve,
 }
diff --git a/grep.c b/grep.c
index fe847a0111a209279656c5a14318d2fa196df2ed..47c75ab7fb6ab362e988e7a1231e912d95efda7b 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -362,6 +362,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
        int jitret;
        int patinforet;
        size_t jitsizearg;
+       int literal = !opt->ignore_case && (p->fixed || p->is_fixed);
 
        /*
         * Call pcre2_general_context_create() before calling any
@@ -382,8 +383,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
                }
                options |= PCRE2_CASELESS;
        }
-       if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern) &&
-           !(!opt->ignore_case && (p->fixed || p->is_fixed)))
+       if (!opt->ignore_locale && is_utf8_locale() && !literal)
                options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
 
 #ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER
@@ -699,6 +699,14 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
        return compile_pattern_or(list);
 }
 
+static struct grep_expr *grep_not_expr(struct grep_expr *expr)
+{
+       struct grep_expr *z = xcalloc(1, sizeof(*z));
+       z->node = GREP_NODE_NOT;
+       z->u.unary = expr;
+       return z;
+}
+
 static struct grep_expr *grep_true_expr(void)
 {
        struct grep_expr *z = xcalloc(1, sizeof(*z));
@@ -797,7 +805,7 @@ void compile_grep_patterns(struct grep_opt *opt)
                }
        }
 
-       if (opt->all_match || header_expr)
+       if (opt->all_match || opt->no_body_match || header_expr)
                opt->extended = 1;
        else if (!opt->extended)
                return;
@@ -808,6 +816,9 @@ void compile_grep_patterns(struct grep_opt *opt)
        if (p)
                die("incomplete pattern expression: %s", p->pattern);
 
+       if (opt->no_body_match && opt->pattern_expression)
+               opt->pattern_expression = grep_not_expr(opt->pattern_expression);
+
        if (!header_expr)
                return;
 
@@ -1057,6 +1068,8 @@ static int match_expr_eval(struct grep_opt *opt, struct grep_expr *x,
                        if (h && (*col < 0 || tmp.rm_so < *col))
                                *col = tmp.rm_so;
                }
+               if (x->u.atom->token == GREP_PATTERN_BODY)
+                       opt->body_hit |= h;
                break;
        case GREP_NODE_NOT:
                /*
@@ -1825,16 +1838,19 @@ int grep_source(struct grep_opt *opt, struct grep_source *gs)
         * we do not have to do the two-pass grep when we do not check
         * buffer-wide "all-match".
         */
-       if (!opt->all_match)
+       if (!opt->all_match && !opt->no_body_match)
                return grep_source_1(opt, gs, 0);
 
        /* Otherwise the toplevel "or" terms hit a bit differently.
         * We first clear hit markers from them.
         */
        clr_hit_marker(opt->pattern_expression);
+       opt->body_hit = 0;
        grep_source_1(opt, gs, 1);
 
-       if (!chk_hit_marker(opt->pattern_expression))
+       if (opt->all_match && !chk_hit_marker(opt->pattern_expression))
+               return 0;
+       if (opt->no_body_match && opt->body_hit)
                return 0;
 
        return grep_source_1(opt, gs, 0);
diff --git a/grep.h b/grep.h
index 3e8815c347b561b72b092aa3ccf781fbcc1b82a1..6a1f0ab01729b8a11eb873a93829f7ee57d07dd4 100644 (file)
--- a/grep.h
+++ b/grep.h
@@ -148,6 +148,8 @@ struct grep_opt {
        int word_regexp;
        int fixed;
        int all_match;
+       int no_body_match;
+       int body_hit;
 #define GREP_BINARY_DEFAULT    0
 #define GREP_BINARY_NOMATCH    1
 #define GREP_BINARY_TEXT       2
diff --git a/help.c b/help.c
index 973e47cdc30ce05603fb935b6574482b3556b31a..71444906ddfb24c6604a2da547cb94675553bcb0 100644 (file)
--- a/help.c
+++ b/help.c
@@ -643,7 +643,7 @@ const char *help_unknown_cmd(const char *cmd)
                else if (autocorrect == AUTOCORRECT_PROMPT) {
                        char *answer;
                        struct strbuf msg = STRBUF_INIT;
-                       strbuf_addf(&msg, _("Run '%s' instead? (y/N)"), assumed);
+                       strbuf_addf(&msg, _("Run '%s' instead [y/N]? "), assumed);
                        answer = git_prompt(msg.buf, PROMPT_ECHO);
                        strbuf_release(&msg);
                        if (!(starts_with(answer, "y") ||
index eb1426f98c2529b81b9812805aa5a95cd1355055..8be57f48de738a7f61de8b18e10a41e2007ac045 100644 (file)
@@ -680,6 +680,49 @@ void add_to_alternates_memory(const char *reference)
                             '\n', NULL, 0);
 }
 
+struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)
+{
+       struct object_directory *new_odb;
+
+       /*
+        * Make sure alternates are initialized, or else our entry may be
+        * overwritten when they are.
+        */
+       prepare_alt_odb(the_repository);
+
+       /*
+        * Make a new primary odb and link the old primary ODB in as an
+        * alternate
+        */
+       new_odb = xcalloc(1, sizeof(*new_odb));
+       new_odb->path = xstrdup(dir);
+
+       /*
+        * Disable ref updates while a temporary odb is active, since
+        * the objects in the database may roll back.
+        */
+       new_odb->disable_ref_updates = 1;
+       new_odb->will_destroy = will_destroy;
+       new_odb->next = the_repository->objects->odb;
+       the_repository->objects->odb = new_odb;
+       return new_odb->next;
+}
+
+void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)
+{
+       struct object_directory *cur_odb = the_repository->objects->odb;
+
+       if (strcmp(old_path, cur_odb->path))
+               BUG("expected %s as primary object store; found %s",
+                   old_path, cur_odb->path);
+
+       if (cur_odb->next != restore_odb)
+               BUG("we expect the old primary object store to be the first alternate");
+
+       the_repository->objects->odb = restore_odb;
+       free_object_directory(cur_odb);
+}
+
 /*
  * Compute the exact path an alternate is at and returns it. In case of
  * error NULL is returned and the human readable error is added to `err`
@@ -1806,8 +1849,11 @@ int hash_object_file(const struct git_hash_algo *algo, const void *buf,
 /* Finalize a file on disk, and close it. */
 static void close_loose_object(int fd)
 {
-       if (fsync_object_files)
-               fsync_or_die(fd, "loose object file");
+       if (!the_repository->objects->odb->will_destroy) {
+               if (fsync_object_files)
+                       fsync_or_die(fd, "loose object file");
+       }
+
        if (close(fd) != 0)
                die_errno(_("error when closing loose object file"));
 }
index 952efb6a4be25bbf6947b789246eedc0a09bdcd5..6f89482df030cb28c91a7d2620903473e661370f 100644 (file)
@@ -27,6 +27,18 @@ struct object_directory {
        uint32_t loose_objects_subdir_seen[8]; /* 256 bits */
        struct oidtree *loose_objects_cache;
 
+       /*
+        * This is a temporary object store created by the tmp_objdir
+        * facility. Disable ref updates since the objects in the store
+        * might be discarded on rollback.
+        */
+       int disable_ref_updates;
+
+       /*
+        * This object store is ephemeral, so there is no need to fsync.
+        */
+       int will_destroy;
+
        /*
         * Path to the alternative object store. If this is a relative path,
         * it is relative to the current working directory.
@@ -58,6 +70,17 @@ void add_to_alternates_file(const char *dir);
  */
 void add_to_alternates_memory(const char *dir);
 
+/*
+ * Replace the current writable object directory with the specified temporary
+ * object directory; returns the former primary object directory.
+ */
+struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);
+
+/*
+ * Restore a previous ODB replaced by set_temporary_main_odb.
+ */
+void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);
+
 /*
  * Populate and return the loose object cache array corresponding to the
  * given object ID.
@@ -68,6 +91,9 @@ struct oidtree *odb_loose_cache(struct object_directory *odb,
 /* Empty the loose object cache for the specified object directory. */
 void odb_clear_loose_cache(struct object_directory *odb);
 
+/* Clear and free the specified object directory */
+void free_object_directory(struct object_directory *odb);
+
 struct packed_git {
        struct hashmap_entry packmap_ent;
        struct packed_git *next;
index 4be82c1e7bc903ec7f22db2bd521e3b8094dc89e..c37501fc1202d17bf1002d39b06afed864c11be3 100644 (file)
--- a/object.c
+++ b/object.c
@@ -513,7 +513,7 @@ struct raw_object_store *raw_object_store_new(void)
        return o;
 }
 
-static void free_object_directory(struct object_directory *odb)
+void free_object_directory(struct object_directory *odb)
 {
        free(odb->path);
        odb_clear_loose_cache(odb);
index dcd8436c25706cdb998117d117cf2864361cc85b..19fabb4acf47dbb4fe0b23d25ce6a11bf3149ab7 100644 (file)
@@ -221,6 +221,10 @@ General advice:
 - Adjust the strings so that they're easy to translate. Most of the
   advice in `info '(gettext)Preparing Strings'` applies here.
 
+- Strings referencing numbers of items may need to be split into singular and
+  plural forms; see the Q\_() wrapper in the C sub-section below for an
+  example.
+
 - If something is unclear or ambiguous you can use a "TRANSLATORS"
   comment to tell the translators what to make of it. These will be
   extracted by xgettext(1) and put in the "po/\*.po" files, e.g. from
diff --git a/refs.c b/refs.c
index 4c317955813a67222be95c16b337cb55f1a07326..bd2546ae230dd614a4021537b2ad21956843f982 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2007,10 +2007,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
        return refs;
 }
 
-void base_ref_store_init(struct ref_store *refs,
-                        const struct ref_storage_be *be)
+void base_ref_store_init(struct ref_store *refs, struct repository *repo,
+                        const char *path, const struct ref_storage_be *be)
 {
        refs->be = be;
+       refs->repo = repo;
+       refs->gitdir = xstrdup(path);
 }
 
 /* backend functions */
@@ -2145,7 +2147,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
                break;
        }
 
-       if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
+       if (refs->repo->objects->odb->disable_ref_updates) {
                strbuf_addstr(err,
                              _("ref updates forbidden inside quarantine environment"));
                return -1;
index 791423c6a7dc1e6f849068d689fd289b0063a89c..2b0771ca53b7854c46ab231b22ecf8be919ca19a 100644 (file)
@@ -26,7 +26,8 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor
        be_copy->name = store->be->name;
        trace_printf_key(&trace_refs, "ref_store for %s\n", gitdir);
        res->refs = store;
-       base_ref_store_init((struct ref_store *)res, be_copy);
+       base_ref_store_init((struct ref_store *)res, store->repo, gitdir,
+                           be_copy);
        return (struct ref_store *)res;
 }
 
@@ -47,7 +48,8 @@ static int debug_transaction_prepare(struct ref_store *refs,
        transaction->ref_store = drefs->refs;
        res = drefs->refs->be->transaction_prepare(drefs->refs, transaction,
                                                   err);
-       trace_printf_key(&trace_refs, "transaction_prepare: %d\n", res);
+       trace_printf_key(&trace_refs, "transaction_prepare: %d \"%s\"\n", res,
+                        err->buf);
        return res;
 }
 
index 6178ad8c77c31396f63aff6e47cda46ea62b3e8a..b529fdf237eaeabd61ac350c1a42c5e24ec85108 100644 (file)
@@ -86,16 +86,12 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
        struct ref_store *ref_store = (struct ref_store *)refs;
        struct strbuf sb = STRBUF_INIT;
 
-       ref_store->repo = repo;
-       ref_store->gitdir = xstrdup(gitdir);
-       base_ref_store_init(ref_store, &refs_be_files);
+       base_ref_store_init(ref_store, repo, gitdir, &refs_be_files);
        refs->store_flags = flags;
-
        get_common_dir_noenv(&sb, gitdir);
        refs->gitcommondir = strbuf_detach(&sb, NULL);
-       strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
-       refs->packed_ref_store = packed_ref_store_create(repo, sb.buf, flags);
-       strbuf_release(&sb);
+       refs->packed_ref_store =
+               packed_ref_store_create(repo, refs->gitcommondir, flags);
 
        chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
        chdir_notify_reparent("files-backend $GIT_COMMONDIR",
index 67152c664e2e4bb0ee92d3f2ebc19cdd9840c895..d91a2018f6011d6c8e79a97e5742baa3c32a9f4a 100644 (file)
@@ -194,20 +194,19 @@ static int release_snapshot(struct snapshot *snapshot)
 }
 
 struct ref_store *packed_ref_store_create(struct repository *repo,
-                                         const char *path,
+                                         const char *gitdir,
                                          unsigned int store_flags)
 {
        struct packed_ref_store *refs = xcalloc(1, sizeof(*refs));
        struct ref_store *ref_store = (struct ref_store *)refs;
+       struct strbuf sb = STRBUF_INIT;
 
-       base_ref_store_init(ref_store, &refs_be_packed);
-       ref_store->repo = repo;
-       ref_store->gitdir = xstrdup(path);
+       base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed);
        refs->store_flags = store_flags;
 
-       refs->path = xstrdup(path);
+       strbuf_addf(&sb, "%s/packed-refs", gitdir);
+       refs->path = strbuf_detach(&sb, NULL);
        chdir_notify_reparent("packed-refs", &refs->path);
-
        return ref_store;
 }
 
index f61a73ec25b4cb55d96bac23ada11a53e2781f95..9dd8a344c34dd7ae078f8226abf044219d5f3a3c 100644 (file)
@@ -14,7 +14,7 @@ struct ref_transaction;
  */
 
 struct ref_store *packed_ref_store_create(struct repository *repo,
-                                         const char *path,
+                                         const char *gitdir,
                                          unsigned int store_flags);
 
 /*
index 46a839539e33451f7debc980a1a23744a7094d05..7ff6fba4f0d3ef138525edf6fd5b9511e2cfe07d 100644 (file)
@@ -710,8 +710,8 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid,
  * Fill in the generic part of refs and add it to our collection of
  * reference stores.
  */
-void base_ref_store_init(struct ref_store *refs,
-                        const struct ref_storage_be *be);
+void base_ref_store_init(struct ref_store *refs, struct repository *repo,
+                        const char *path, const struct ref_storage_be *be);
 
 /*
  * Support GIT_TRACE_REFS by optionally wrapping the given ref_store instance.
index c7ea706c205fee1f84301668c620906ec5c06650..34610c5a33e013169de14189274fd4ed42512a96 100644 (file)
@@ -82,6 +82,8 @@ void repo_set_gitdir(struct repository *repo,
        expand_base_dir(&repo->objects->odb->path, o->object_dir,
                        repo->commondir, "objects");
 
+       repo->objects->odb->disable_ref_updates = o->disable_ref_updates;
+
        free(repo->objects->alternate_db);
        repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
        expand_base_dir(&repo->graft_file, o->graft_file,
index 98f95834706eb9b3ab93bf6d9eb34edacaed4ce9..2b5cf97f31e88934d9b23d96a97cffc60a9606fd 100644 (file)
@@ -162,6 +162,7 @@ struct set_gitdir_args {
        const char *graft_file;
        const char *index_file;
        const char *alternate_db;
+       int disable_ref_updates;
 };
 
 void repo_set_gitdir(struct repository *repo, const char *root,
index 5390a479b30fb91222e2c326b6930182feb0620e..250f61e8cfe1eef3faac497c1187ba4cef26352d 100644 (file)
@@ -2498,7 +2498,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        } else if (!strcmp(arg, "--all-match")) {
                revs->grep_filter.all_match = 1;
        } else if (!strcmp(arg, "--invert-grep")) {
-               revs->invert_grep = 1;
+               revs->grep_filter.no_body_match = 1;
        } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
                if (strcmp(optarg, "none"))
                        git_log_output_encoding = xstrdup(optarg);
@@ -3783,7 +3783,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
                                     (char *)message, strlen(message));
        strbuf_release(&buf);
        unuse_commit_buffer(commit, message);
-       return opt->invert_grep ? !retval : retval;
+       return retval;
 }
 
 static inline int want_ancestry(const struct rev_info *revs)
index 5578bb4720ae37c2824a220a487dce0451bc7a85..3f66147bfd390abdd98de4f366014bdce88179c2 100644 (file)
@@ -246,8 +246,6 @@ struct rev_info {
 
        /* Filter by commit log message */
        struct grep_opt grep_filter;
-       /* Negate the match of grep_filter */
-       int invert_grep;
 
        /* Display history graph */
        struct git_graph *graph;
index e314af4d60a1dcb13f6ea215c80b219742275c3d..6abd72160ccd46791d5a262021804e07ab9ea37f 100644 (file)
@@ -4223,6 +4223,8 @@ static int run_git_checkout(struct repository *r, struct replay_opts *opts,
 
        cmd.git_cmd = 1;
 
+       if (startup_info->original_cwd)
+               cmd.dir = startup_info->original_cwd;
        strvec_push(&cmd.args, "checkout");
        strvec_push(&cmd.args, commit);
        strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
diff --git a/setup.c b/setup.c
index 347d7181ae907c027f01cbc8ec42a2b64de06ebc..af3b8c09abe398edd0f45828b81ecec72b3900b6 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -12,6 +12,7 @@ static int work_tree_config_is_bogus;
 
 static struct startup_info the_startup_info;
 struct startup_info *startup_info = &the_startup_info;
+const char *tmp_original_cwd;
 
 /*
  * The input parameter must contain an absolute path, and it must already be
@@ -432,6 +433,69 @@ void setup_work_tree(void)
        initialized = 1;
 }
 
+static void setup_original_cwd(void)
+{
+       struct strbuf tmp = STRBUF_INIT;
+       const char *worktree = NULL;
+       int offset = -1;
+
+       if (!tmp_original_cwd)
+               return;
+
+       /*
+        * startup_info->original_cwd points to the current working
+        * directory we inherited from our parent process, which is a
+        * directory we want to avoid removing.
+        *
+        * For convience, we would like to have the path relative to the
+        * worktree instead of an absolute path.
+        *
+        * Yes, startup_info->original_cwd is usually the same as 'prefix',
+        * but differs in two ways:
+        *   - prefix has a trailing '/'
+        *   - if the user passes '-C' to git, that modifies the prefix but
+        *     not startup_info->original_cwd.
+        */
+
+       /* Normalize the directory */
+       strbuf_realpath(&tmp, tmp_original_cwd, 1);
+       free((char*)tmp_original_cwd);
+       tmp_original_cwd = NULL;
+       startup_info->original_cwd = strbuf_detach(&tmp, NULL);
+
+       /*
+        * Get our worktree; we only protect the current working directory
+        * if it's in the worktree.
+        */
+       worktree = get_git_work_tree();
+       if (!worktree)
+               goto no_prevention_needed;
+
+       offset = dir_inside_of(startup_info->original_cwd, worktree);
+       if (offset >= 0) {
+               /*
+                * If startup_info->original_cwd == worktree, that is already
+                * protected and we don't need original_cwd as a secondary
+                * protection measure.
+                */
+               if (!*(startup_info->original_cwd + offset))
+                       goto no_prevention_needed;
+
+               /*
+                * original_cwd was inside worktree; precompose it just as
+                * we do prefix so that built up paths will match
+                */
+               startup_info->original_cwd = \
+                       precompose_string_if_needed(startup_info->original_cwd
+                                                   + offset);
+               return;
+       }
+
+no_prevention_needed:
+       free((char*)startup_info->original_cwd);
+       startup_info->original_cwd = NULL;
+}
+
 static int read_worktree_config(const char *var, const char *value, void *vdata)
 {
        struct repository_format *data = vdata;
@@ -1330,6 +1394,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
                setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
        }
 
+       setup_original_cwd();
 
        strbuf_release(&dir);
        strbuf_release(&gitdir);
index 5232d02020c725abdf0b486843c703403dcfc012..c667baa949b685c6c78c41eb8d272410c7574fe4 100644 (file)
@@ -279,7 +279,9 @@ static void do_remove_scheduled_dirs(int new_len)
 {
        while (removal.len > new_len) {
                removal.buf[removal.len] = '\0';
-               if (rmdir(removal.buf))
+               if ((startup_info->original_cwd &&
+                    !strcmp(removal.buf, startup_info->original_cwd)) ||
+                   rmdir(removal.buf))
                        break;
                do {
                        removal.len--;
@@ -293,6 +295,10 @@ void schedule_dir_for_removal(const char *name, int len)
 {
        int match_len, last_slash, i, previous_slash;
 
+       if (startup_info->original_cwd &&
+           !strcmp(name, startup_info->original_cwd))
+               return; /* Do not remove the current working directory */
+
        match_len = last_slash = i =
                longest_path_match(name, len, removal.buf, removal.len,
                                   &previous_slash);
index 882d26eee30b115f4c656e0ab5048f4e2e96319b..46cd5fc5273dc0bcb907ab49ce8c97c4783053be 100644 (file)
@@ -71,12 +71,10 @@ clean-chainlint:
 
 check-chainlint:
        @mkdir -p '$(CHAINLINTTMP_SQ)' && \
-       err=0 && \
-       for i in $(CHAINLINTTESTS); do \
-               $(CHAINLINT) <chainlint/$$i.test | \
-               sed -e '/^# LINT: /d' >'$(CHAINLINTTMP_SQ)'/$$i.actual && \
-               diff -u chainlint/$$i.expect '$(CHAINLINTTMP_SQ)'/$$i.actual || err=1; \
-       done && exit $$err
+       sed -e '/^# LINT: /d' $(patsubst %,chainlint/%.test,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/tests && \
+       sed -e '/^[     ]*$$/d' $(patsubst %,chainlint/%.expect,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/expect && \
+       $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/tests | grep -v '^[   ]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \
+       diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
 
 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
        test-lint-filenames
index d3b299e75cb1831d2c1044d8df979bc81f22e177..09e86f9ba0804f70d6561b5bda03d69535f11dcf 100644 (file)
@@ -161,7 +161,7 @@ test_expect_success 'blame huge graft' '
                        GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
                        git commit -a -m "$i$j" &&
                        commit=$(git rev-parse --verify HEAD) &&
-                       graft="$graft$commit "
+                       graft="$graft$commit " || return 1
                done
        done &&
        printf "%s " $graft >.git/info/grafts &&
index 8a25c5b855e7ea9d28d208a3302ecb68965f34b6..dc4ce37cb5188a63cf3a831a16d21363cfffd3f2 100644 (file)
@@ -24,9 +24,9 @@
 # in order to avoid misinterpreting the ")" in constructs such as "x=$(...)"
 # and "case $x in *)" as ending the subshell.
 #
-# Lines missing a final "&&" are flagged with "?!AMP?!", and lines which chain
-# commands with ";" internally rather than "&&" are flagged "?!SEMI?!". A line
-# may be flagged for both violations.
+# Lines missing a final "&&" are flagged with "?!AMP?!", as are lines which
+# chain commands with ";" internally rather than "&&". A line may be flagged
+# for both violations.
 #
 # Detection of a missing &&-link in a multi-line subshell is complicated by the
 # fact that the last statement before the closing ")" must not end with "&&".
@@ -47,8 +47,8 @@
 # "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold"
 # area) since the final statement of a subshell must not end with "&&". The
 # final line of a subshell may still break the &&-chain by using ";" internally
-# to chain commands together rather than "&&", so "?!SEMI?!" is never removed
-# from a line (even though "?!AMP?!" might be).
+# to chain commands together rather than "&&", but an internal "?!AMP?!" is
+# never removed from a line even though a line-ending "?!AMP?!" might be.
 #
 # Care is taken to recognize the last _statement_ of a multi-line subshell, not
 # necessarily the last textual _line_ within the subshell, since &&-chaining
 # receives similar treatment.
 #
 # Swallowing here-docs with arbitrary tags requires a bit of finesse. When a
-# line such as "cat <<EOF >out" is seen, the here-doc tag is moved to the front
-# of the line enclosed in angle brackets as a sentinel, giving "<EOF>cat >out".
+# line such as "cat <<EOF" is seen, the here-doc tag is copied to the front of
+# the line enclosed in angle brackets as a sentinel, giving "<EOF>cat <<EOF".
 # As each subsequent line is read, it is appended to the target line and a
 # (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if
 # the content inside "<...>" matches the entirety of the newly-read line. For
 # instance, if the next line read is "some data", when concatenated with the
-# target line, it becomes "<EOF>cat >out\nsome data", and a match is attempted
+# target line, it becomes "<EOF>cat <<EOF\nsome data", and a match is attempted
 # to see if "EOF" matches "some data". Since it doesn't, the next line is
 # attempted. When a line consisting of only "EOF" (and possible whitespace) is
-# encountered, it is appended to the target line giving "<EOF>cat >out\nEOF",
+# encountered, it is appended to the target line giving "<EOF>cat <<EOF\nEOF",
 # in which case the "EOF" inside "<...>" does match the text following the
 # newline, thus the closing here-doc tag has been found. The closing tag line
 # and the "<...>" prefix on the target line are then discarded, leaving just
-# the target line "cat >out".
-#
-# To facilitate regression testing (and manual debugging), a ">" annotation is
-# applied to the line containing ")" which closes a subshell, ">>" to a line
-# closing a nested subshell, and ">>>" to a line closing both at once. This
-# makes it easy to detect whether the heuristics correctly identify
-# end-of-subshell.
+# the target line "cat <<EOF".
 #------------------------------------------------------------------------------
 
 # incomplete line -- slurp up next line
@@ -94,9 +88,9 @@
 
 # here-doc -- swallow it to avoid false hits within its body (but keep the
 # command to which it was attached)
-/<<[   ]*[-\\'"]*[A-Za-z0-9_]/ {
-       s/^\(.*\)<<[    ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
-       s/[     ]*<<//
+/<<-*[         ]*[\\'"]*[A-Za-z0-9_]/ {
+       /"[^"]*<<[^"]*"/bnotdoc
+       s/^\(.*<<-*[    ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1\2/
        :hered
        N
        /^<\([^>]*\)>.*\n[      ]*\1[   ]*$/!{
        s/^<[^>]*>//
        s/\n.*$//
 }
+:notdoc
 
 # one-liner "(...) &&"
 /^[    ]*!*[   ]*(..*)[        ]*&&[   ]*$/boneline
@@ -126,7 +121,7 @@ b
 # "&&" (but not ";" in a string)
 :oneline
 /;/{
-       /"[^"]*;[^"]*"/!s/^/?!SEMI?!/
+       /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/
 }
 b
 
@@ -136,11 +131,15 @@ b
        h
        bnextln
 }
-# "(..." line -- split off and stash "(", then process "..." as its own line
+# "(..." line -- "(" opening subshell cuddled with command; temporarily replace
+# "(" with sentinel "^" and process the line as if "(" had been seen solo on
+# the preceding line; this temporary replacement prevents several rules from
+# accidentally thinking "(" introduces a nested subshell; "^" is changed back
+# to "(" at output time
 x
-s/.*/(/
+s/.*//
 x
-s/(//
+s/(/^/
 bslurp
 
 :nextln
@@ -157,8 +156,10 @@ s/.*\n//
        /"[^'"]*'[^'"]*"/!bsqstr
 }
 :folded
-# here-doc -- swallow it
-/<<[   ]*[-\\'"]*[A-Za-z0-9_]/bheredoc
+# here-doc -- swallow it (but not "<<" in a string)
+/<<-*[         ]*[\\'"]*[A-Za-z0-9_]/{
+       /"[^"]*<<[^"]*"/!bheredoc
+}
 # comment or empty line -- discard since final non-comment, non-empty line
 # before closing ")", "done", "elsif", "else", or "fi" will need to be
 # re-visited to drop "suspect" marking since final line of those constructs
@@ -171,12 +172,12 @@ s/.*\n//
        /"[^"]*#[^"]*"/!s/[     ]#.*$//
 }
 # one-liner "case ... esac"
-/^[    ]*case[         ]*..*esac/bchkchn
+/^[    ^]*case[        ]*..*esac/bchkchn
 # multi-line "case ... esac"
-/^[    ]*case[         ]..*[   ]in/bcase
+/^[    ^]*case[        ]..*[   ]in/bcase
 # multi-line "for ... done" or "while ... done"
-/^[    ]*for[  ]..*[   ]in/bcont
-/^[    ]*while[        ]/bcont
+/^[    ^]*for[         ]..*[   ]in/bcont
+/^[    ^]*while[       ]/bcont
 /^[    ]*do[   ]/bcont
 /^[    ]*do[   ]*$/bcont
 /;[    ]*do/bcont
@@ -187,7 +188,7 @@ s/.*\n//
 /||[   ]*exit[         ]/bcont
 /||[   ]*exit[         ]*$/bcont
 # multi-line "if...elsif...else...fi"
-/^[    ]*if[   ]/bcont
+/^[    ^]*if[  ]/bcont
 /^[    ]*then[         ]/bcont
 /^[    ]*then[         ]*$/bcont
 /;[    ]*then/bcont
@@ -200,15 +201,15 @@ s/.*\n//
 /^[    ]*fi[   ]*[<>|]/bdone
 /^[    ]*fi[   ]*)/bdone
 # nested one-liner "(...) &&"
-/^[    ]*(.*)[         ]*&&[   ]*$/bchkchn
+/^[    ^]*(.*)[        ]*&&[   ]*$/bchkchn
 # nested one-liner "(...)"
-/^[    ]*(.*)[         ]*$/bchkchn
+/^[    ^]*(.*)[        ]*$/bchkchn
 # nested one-liner "(...) >x" (or "2>x" or "<x" or "|x")
-/^[    ]*(.*)[         ]*[0-9]*[<>|]/bchkchn
+/^[    ^]*(.*)[        ]*[0-9]*[<>|]/bchkchn
 # nested multi-line "(...\n...)"
-/^[    ]*(/bnest
+/^[    ^]*(/bnest
 # multi-line "{...\n...}"
-/^[    ]*{/bblock
+/^[    ^]*{/bblock
 # closing ")" on own line -- exit subshell
 /^[    ]*)/bclssolo
 # "$((...))" -- arithmetic expansion; not closing ")"
@@ -230,16 +231,18 @@ s/.*\n//
 # string and not ";;" in one-liner "case...esac")
 /;/{
        /;;/!{
-               /"[^"]*;[^"]*"/!s/^/?!SEMI?!/
+               /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/
        }
 }
 # line ends with pipe "...|" -- valid; not missing "&&"
 /|[    ]*$/bcont
 # missing end-of-line "&&" -- mark suspect
-/&&[   ]*$/!s/^/?!AMP?!/
+/&&[   ]*$/!s/$/ ?!AMP?!/
 :cont
 # retrieve and print previous line
 x
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 n
 bslurp
 
@@ -280,8 +283,7 @@ bfolded
 # found here-doc -- swallow it to avoid false hits within its body (but keep
 # the command to which it was attached)
 :heredoc
-s/^\(.*\)<<[   ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
-s/[    ]*<<//
+s/^\(.*\)<<\(-*[       ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\3>\1?!HERE?!\2\3/
 :hdocsub
 N
 /^<\([^>]*\)>.*\n[     ]*\1[   ]*$/!{
@@ -295,7 +297,15 @@ bfolded
 # found "case ... in" -- pass through untouched
 :case
 x
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 n
+:cascom
+/^[    ]*#/{
+       N
+       s/.*\n//
+       bcascom
+}
 /^[    ]*esac/bslurp
 bcase
 
@@ -303,7 +313,7 @@ bcase
 # that line legitimately lacks "&&"
 :else
 x
-s/?!AMP?!//
+s/\( ?!AMP?!\)* ?!AMP?!$//
 x
 bcont
 
@@ -311,7 +321,7 @@ bcont
 # "suspect" from final contained line since that line legitimately lacks "&&"
 :done
 x
-s/?!AMP?!//
+s/\( ?!AMP?!\)* ?!AMP?!$//
 x
 # is 'done' or 'fi' cuddled with ")" to close subshell?
 /done.*)/bclose
@@ -322,11 +332,18 @@ bchkchn
 :nest
 x
 :nstslrp
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 n
+:nstcom
+# comment -- not closing ")" if in comment
+/^[    ]*#/{
+       N
+       s/.*\n//
+       bnstcom
+}
 # closing ")" on own line -- stop nested slurp
 /^[    ]*)/bnstcl
-# comment -- not closing ")" if in comment
-/^[    ]*#/bnstcnt
 # "$((...))" -- arithmetic expansion; not closing ")"
 /\$(([^)][^)]*))[^)]*$/bnstcnt
 # "$(...)" -- command substitution; not closing ")"
@@ -337,7 +354,6 @@ n
 x
 bnstslrp
 :nstcl
-s/^/>>/
 # is it "))" which closes nested and parent subshells?
 /)[    ]*)/bslurp
 bchkchn
@@ -345,7 +361,15 @@ bchkchn
 # found multi-line "{...\n...}" block -- pass through untouched
 :block
 x
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 n
+:blkcom
+/^[    ]*#/{
+       N
+       s/.*\n//
+       bblkcom
+}
 # closing "}" -- stop block slurp
 /}/bchkchn
 bblock
@@ -354,16 +378,22 @@ bblock
 # since that line legitimately lacks "&&" and exit subshell loop
 :clssolo
 x
-s/?!AMP?!//
+s/\( ?!AMP?!\)* ?!AMP?!$//
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 p
 x
-s/^/>/
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 b
 
 # found closing "...)" -- exit subshell loop
 :close
 x
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 p
 x
-s/^/>/
+s/^\([         ]*\)^/\1(/
+s/?!HERE?!/<</g
 b
index 09457d31966193da7a324f0cbc417ce05354f15a..46ee1046af73582ea5adf5e91b0be62025684bb6 100644 (file)
@@ -2,8 +2,8 @@
        foo &&
        bar=$((42 + 1)) &&
        baz
->) &&
+) &&
 (
-?!AMP?!        bar=$((42 + 1))
+       bar=$((42 + 1)) ?!AMP?!
        baz
->)
+)
index c4a830d1c1d6df9ae72c1d5c7777ceb056383388..4c34eaee45e2f706e80560edfa271f4a5e245a9e 100644 (file)
@@ -2,9 +2,9 @@
        foo &&
        bar=(gumbo stumbo wumbo) &&
        baz
->) &&
+) &&
 (
        foo &&
        bar=${#bar[@]} &&
        baz
->)
+)
index 3be939ed388c3668f030f78034a8c0204ee55dd2..f76fde1ffba91d7becf17c0990c39ac25a7083f0 100644 (file)
@@ -1,4 +1,4 @@
 (
        nothing &&
        something
->)
+)
index f6dd14302b2bed89e65634d9d57b0a97dbf7ead5..0fdf15b3e14c6aaac3bbbc8f2c4f04035845cd4c 100644 (file)
@@ -3,7 +3,7 @@
        nothing &&
 
        something
-# LINT: swallow blank lines since final _statement_ before subshell end is
+# LINT: ignore blank lines since final _statement_ before subshell end is
 # LINT: significant to "&&"-check, not final _line_ (which might be blank)
 
 
diff --git a/t/chainlint/block-comment.expect b/t/chainlint/block-comment.expect
new file mode 100644 (file)
index 0000000..d10b2ee
--- /dev/null
@@ -0,0 +1,6 @@
+(
+       {
+               echo a &&
+               echo b
+       }
+)
diff --git a/t/chainlint/block-comment.test b/t/chainlint/block-comment.test
new file mode 100644 (file)
index 0000000..df2beea
--- /dev/null
@@ -0,0 +1,8 @@
+(
+       {
+               # show a
+               echo a &&
+               # show b
+               echo b
+       }
+)
index fed7e89ae8ffaec249c2a3a86a915979a34681f0..da60257ebc4e1d2e019e2b8fee8da3742849ddd7 100644 (file)
@@ -7,6 +7,6 @@
        bar &&
        {
                echo c
-?!AMP?!        }
+       } ?!AMP?!
        baz
->)
+)
index d859151af1d9ac89709a3c972b75dbdc8cd53321..0a82fd579f6751a8ed7a88505d2c7988eaf3ae5c 100644 (file)
@@ -1,6 +1,5 @@
 (
-# LINT: missing "&&" in block not currently detected (for consistency with
-# LINT: --chain-lint at top level and to provide escape hatch if needed)
+# LINT: missing "&&" after first "echo"
        foo &&
        {
                echo a
index 55b0f42a534d65caefa2089c16eff01fd00462c8..cfb58fb6b937be645f79167eae7fa27ec27d9618 100644 (file)
@@ -1,6 +1,6 @@
 (
        foo &&
-?!AMP?!        bar
+       bar ?!AMP?!
        baz &&
        wop
->)
+)
index 3cc67b65d0c9ddf6739c9060c7cf3ff45fa277b8..2a44aa73b71a9794c4b51d7c13dc71ab25239596 100644 (file)
@@ -1,6 +1,6 @@
 (
        foo &&
-# LINT: missing "&&" from 'bar'
+# LINT: missing "&&" from "bar"
        bar
        baz &&
 # LINT: final statement before closing ")" legitimately lacks "&&"
diff --git a/t/chainlint/case-comment.expect b/t/chainlint/case-comment.expect
new file mode 100644 (file)
index 0000000..1e4b054
--- /dev/null
@@ -0,0 +1,8 @@
+(
+       case "$x" in
+       x) foo ;;
+       *)
+               bar
+               ;;
+       esac
+)
diff --git a/t/chainlint/case-comment.test b/t/chainlint/case-comment.test
new file mode 100644 (file)
index 0000000..641c157
--- /dev/null
@@ -0,0 +1,11 @@
+(
+       case "$x" in
+       # found foo
+       x) foo ;;
+       # found other
+       *)
+               # treat it as bar
+               bar
+               ;;
+       esac
+)
index 41f121fbbf9c9664640fc81c3e9e4315dadd42c3..31f280d8ceb3152a057c26cabe926f9defb8bdac 100644 (file)
@@ -4,16 +4,16 @@
        *) bar ;;
        esac &&
        foobar
->) &&
+) &&
 (
        case "$x" in
        x) foo ;;
        *) bar ;;
-?!AMP?!        esac
+       esac ?!AMP?!
        foobar
->) &&
+) &&
 (
        case "$x" in 1) true;; esac &&
-?!AMP?!        case "$y" in 2) false;; esac
+       case "$y" in 2) false;; esac ?!AMP?!
        foobar
->)
+)
index 5ef6ff7db5eafbc0abb835901e321ed13265a025..4cb086bf87b04c709601ca610aad6db39bbd8bb4 100644 (file)
@@ -1,5 +1,5 @@
 (
-# LINT: "...)" arms in 'case' not misinterpreted as subshell-closing ")"
+# LINT: "...)" arms in "case" not misinterpreted as subshell-closing ")"
        case "$x" in
        x) foo ;;
        *) bar ;;
@@ -7,7 +7,7 @@
        foobar
 ) &&
 (
-# LINT: missing "&&" on 'esac'
+# LINT: missing "&&" on "esac"
        case "$x" in
        x) foo ;;
        *) bar ;;
@@ -15,7 +15,7 @@
        foobar
 ) &&
 (
-# LINT: "...)" arm in one-liner 'case' not misinterpreted as closing ")"
+# LINT: "...)" arm in one-liner "case" not misinterpreted as closing ")"
        case "$x" in 1) true;; esac &&
 # LINT: same but missing "&&"
        case "$y" in 2) false;; esac
index 2a910f9d66604cd2f4a95377a9071a247e1e6d6e..72d482f76dd20f0d2ca7bbffd177417a257992e2 100644 (file)
@@ -1,4 +1,3 @@
-(
-cd foo &&
+(cd foo &&
        (bar &&
->>>            baz))
+               baz))
index 184688718a9c030097cab0bea570c829189ef34b..0f87db9ae6891f8536c6eec73b71e5f049ca9667 100644 (file)
@@ -1,25 +1,25 @@
 (
        foo
->) &&
+) &&
 (
        bar
->) >out &&
+) >out &&
 (
        baz
->) 2>err &&
+) 2>err &&
 (
        boo
->) <input &&
+) <input &&
 (
        bip
->) | wuzzle &&
+) | wuzzle &&
 (
        bop
->) | fazz      fozz &&
+) | fazz       fozz &&
 (
        bup
->) |
+) |
 fuzzle &&
 (
        yop
->)
+)
index ad4118e537e42e1156146c11ce80f288381b1af3..c72e4df9e709d1e26f393d6e2d906626d94aa3a3 100644 (file)
@@ -2,8 +2,8 @@
        foo &&
        bar=$(gobble) &&
        baz
->) &&
+) &&
 (
-?!AMP?!        bar=$(gobble blocks)
+       bar=$(gobble blocks) ?!AMP?!
        baz
->)
+)
index 3be939ed388c3668f030f78034a8c0204ee55dd2..f76fde1ffba91d7becf17c0990c39ac25a7083f0 100644 (file)
@@ -1,4 +1,4 @@
 (
        nothing &&
        something
->)
+)
index 9674b88cf252f7409241c847d6219547ff2b07cc..2fca1834095817a0aba1bce38a5a837dea0debae 100644 (file)
@@ -1,10 +1,9 @@
-(
-for i in a b c; do
+(for i in a b c; do
    if test "$(echo $(waffle bat))" = "eleventeen" &&
      test "$x" = "$y"; then
      :
    else
      echo >file
    fi
-> done) &&
+ done) &&
 test ! -f file
index 571bbd85cdfc41031de1026bb3c24ae3a9a604f7..5efeda58b2a7196d74999a514268ef0099f661d6 100644 (file)
@@ -1,4 +1,4 @@
-# LINT: 'for' loop cuddled with "(" and ")" and nested 'if' with complex
+# LINT: "for" loop cuddled with "(" and ")" and nested "if" with complex
 # LINT: multi-line condition; indented with spaces, not tabs
 (for i in a b c; do
    if test "$(echo $(waffle bat))" = "eleventeen" &&
index ab2a026fbc2f68048d67174fad32134ded3d2ce7..1d8ed58c4948ea2b975de2742ccad603f48042dc 100644 (file)
@@ -1,7 +1,6 @@
-(
-if test -z ""; then
+(if test -z ""; then
     echo empty
  else
     echo bizzy
-> fi) &&
+ fi) &&
 echo foobar
index eed774a9d64390449699238b4ad0e16c58c15390..7c53f4efe3eba3c3da52e620a89e87c371e15db3 100644 (file)
@@ -1,4 +1,4 @@
-# LINT: 'if' cuddled with "(" and ")"; indented with spaces, not tabs
+# LINT: "if" cuddled with "(" and ")"; indented with spaces, not tabs
 (if test -z ""; then
     echo empty
  else
index 8c0260d7f1d9ce7e85a8b0d47ffe97f57f39b92e..9cf260708e6a5c07282f37a03560781db8504ec0 100644 (file)
@@ -1,5 +1,4 @@
-(
- while read x
+( while read x
   do foobar bop || exit 1
->  done <file ) &&
+  done <file ) &&
 outside subshell
index a841d781f04f01ff1c906027d0b139fb854d4fb9..3c2a62f7518937e86ff2723f62e17be9d28e8eda 100644 (file)
@@ -1,4 +1,4 @@
-# LINT: 'while' loop cuddled with "(" and ")", with embedded (allowed)
+# LINT: "while" loop cuddled with "(" and ")", with embedded (allowed)
 # LINT: "|| exit {n}" to exit loop early, and using redirection "<" to feed
 # LINT: loop; indented with spaces, not tabs
 ( while read x
index b506d4622197a837c66ca56dd22cf7d191664e68..c3e0be404742cb62808ffa43026573dbe5cb9cd1 100644 (file)
@@ -1,21 +1,17 @@
-(
-cd foo &&
+(cd foo &&
        bar
->) &&
+) &&
 
-(
-?!AMP?!cd foo
+(cd foo ?!AMP?!
        bar
->) &&
+) &&
 
 (
        cd foo &&
->      bar) &&
+       bar) &&
 
-(
-cd foo &&
->      bar) &&
+(cd foo &&
+       bar) &&
 
-(
-?!AMP?!cd foo
->      bar)
+(cd foo ?!AMP?!
+       bar)
index 0499fa4180596cc4f8c054a7e2a8a640bdb679ce..257b5b5eed3a23a6549f3a6f2b5ea77a776ad7e9 100644 (file)
@@ -1,5 +1,4 @@
-# LINT: first subshell statement cuddled with opening "("; for implementation
-# LINT: simplicity, "(..." is split into two lines, "(" and "..."
+# LINT: first subshell statement cuddled with opening "("
 (cd foo &&
        bar
 ) &&
index 84d8bdebc02660d3a4ad0aeb341a9f991547b46c..f76aa60466adaf394b2e368e5feb3b54e23b30f8 100644 (file)
@@ -5,7 +5,7 @@
                bar &&
                baz
        done
->) &&
+) &&
 (
        while true
        do
@@ -13,7 +13,7 @@
                bar &&
                baz
        done
->) &&
+) &&
 (
        i=0 &&
        while test $i -lt 10
@@ -21,4 +21,4 @@
                echo $i || exit
                i=$(($i + 1))
        done
->)
+)
index bf78454f74c83d27b059b504859213abdb9acc6c..da80339f781230c19bc7203603d6310454dba4a9 100644 (file)
@@ -2,4 +2,4 @@
        foo || exit 1
        bar &&
        baz
->)
+)
index c33cf56ee73ab7b75c4194d842443d019fa08440..6671b8cd842de110882342fc4ee359eb7e4d1375 100644 (file)
@@ -1,11 +1,11 @@
 (
        for i in a b c
        do
-?!AMP?!                echo $i
-               cat
-?!AMP?!        done
+               echo $i ?!AMP?!
+               cat <<-EOF
+       done ?!AMP?!
        for i in a b c; do
                echo $i &&
                cat $i
        done
->)
+)
index 7db76262bc2e0089ea97581417b7ca95b2c9c2b4..6cb34281582055b118b75f37a006e6c3ae5c962c 100644 (file)
@@ -1,17 +1,17 @@
 (
-# LINT: 'for', 'do', 'done' do not need "&&"
+# LINT: "for", "do", "done" do not need "&&"
        for i in a b c
        do
-# LINT: missing "&&" on 'echo'
+# LINT: missing "&&" on "echo"
                echo $i
 # LINT: last statement of while does not need "&&"
                cat <<-\EOF
                bar
                EOF
-# LINT: missing "&&" on 'done'
+# LINT: missing "&&" on "done"
        done
 
-# LINT: 'do' on same line as 'for'
+# LINT: "do" on same line as "for"
        for i in a b c; do
                echo $i &&
                cat $i
index f011e335e5f12c36460836635dd220153de8f9e1..2af9ced71cc331414ce22e5d4ef3fc1320b3c15d 100644 (file)
@@ -1,2 +1,2 @@
 (
->      cat)
+       cat <<-INPUT)
index e5fb752d2fc22ac421704925a51fc952ecf530e1..f8b3aa73c4f180be48afff988c0f7cece67e45d4 100644 (file)
@@ -1,5 +1,5 @@
 (
-       x=$(bobble &&
-?!AMP?!>>              wiffle)
+       x=$(bobble <<-END &&
+               wiffle) ?!AMP?!
        echo $x
->)
+)
index 32038a070c2ad881f7136028ceb1be41f57c9a43..2578191ca8a809c8bbc271c9f1b8b744d9d8444e 100644 (file)
@@ -1,4 +1,4 @@
 (
-?!AMP?!        cat && echo "multi-line string"
+       cat <<-TXT && echo "multi-line  string" ?!AMP?!
        bap
->)
+)
index 534b065e38baa213da2a224e147cd41c649e55e8..110059ba58420e5924de64edb0ec44346b43cb34 100644 (file)
@@ -1,9 +1,7 @@
-boodle wobba        gorgo snoot        wafta snurb &&
+boodle wobba        gorgo snoot        wafta snurb <<EOF &&
 
-cat >foo &&
+cat <<-Arbitrary_Tag_42 >foo &&
 
-cat >bar &&
+cat <<zump >boo &&
 
-cat >boo &&
-
-horticulture
+horticulture <<EOF
index ad4ce8afd9b55650a2ce3751fbef3d67d07d534d..3f5f92cad34761a1daffa00e819a08c1fc5a07a1 100644 (file)
@@ -14,13 +14,6 @@ boz
 woz
 Arbitrary_Tag_42
 
-# LINT: swallow 'quoted' here-doc
-cat <<'FUMP' >bar &&
-snoz
-boz
-woz
-FUMP
-
 # LINT: swallow "quoted" here-doc
 cat <<"zump" >boo &&
 snoz
index 03d3ceb22d8971ddad5c81c1c5a7714d7f988f8e..03b82a3e58c21e1300befb317f19c7f063fba3ec 100644 (file)
@@ -3,10 +3,10 @@
        do
                if false
                then
-?!AMP?!                        echo "err"
+                       echo "err" ?!AMP?!
                        exit 1
-?!AMP?!                fi
+               fi ?!AMP?!
                foo
-?!AMP?!        done
+       done ?!AMP?!
        bar
->)
+)
index daf22da16476aac9e7467bf73cae8470fe29e98f..f0cf19cfadac8c1ae9d09a668bafc99517c50cdf 100644 (file)
@@ -3,13 +3,13 @@
        do
                if false
                then
-# LINT: missing "&&" on 'echo'
+# LINT: missing "&&" on "echo"
                        echo "err"
                        exit 1
-# LINT: missing "&&" on 'fi'
+# LINT: missing "&&" on "fi"
                fi
                foo
-# LINT: missing "&&" on 'done'
+# LINT: missing "&&" on "done"
        done
        bar
 )
index 5953c7bfbc2e792af695f1f711ea06662a61dcb5..44d86c35976ce1957aa0b4fb90f6b7e31f230d3c 100644 (file)
@@ -1,19 +1,20 @@
 (
        if test -n ""
        then
-?!AMP?!                echo very
+               echo very ?!AMP?!
                echo empty
        elif test -z ""
+       then
                echo foo
        else
                echo foo &&
-               cat
-?!AMP?!        fi
+               cat <<-EOF
+       fi ?!AMP?!
        echo poodle
->) &&
+) &&
 (
        if test -n ""; then
                echo very &&
-?!AMP?!                echo empty
-       if
->)
+               echo empty
+       fi
+)
index 9bd8e9a4c68c2b3b5fd367c6b28763d9765d7d5d..2055336c2b9ed2e975b21d20310f2821bbef7b6f 100644 (file)
@@ -1,28 +1,29 @@
 (
-# LINT: 'if', 'then', 'elif', 'else', 'fi' do not need "&&"
+# LINT: "if", "then", "elif", "else", "fi" do not need "&&"
        if test -n ""
        then
-# LINT: missing "&&" on 'echo'
+# LINT: missing "&&" on "echo"
                echo very
-# LINT: last statement before 'elif' does not need "&&"
+# LINT: last statement before "elif" does not need "&&"
                echo empty
        elif test -z ""
-# LINT: last statement before 'else' does not need "&&"
+       then
+# LINT: last statement before "else" does not need "&&"
                echo foo
        else
                echo foo &&
-# LINT: last statement before 'fi' does not need "&&"
+# LINT: last statement before "fi" does not need "&&"
                cat <<-\EOF
                bar
                EOF
-# LINT: missing "&&" on 'fi'
+# LINT: missing "&&" on "fi"
        fi
        echo poodle
 ) &&
 (
-# LINT: 'then' on same line as 'if'
+# LINT: "then" on same line as "if"
        if test -n ""; then
                echo very &&
                echo empty
-       if
+       fi
 )
index 2f3ebabdc286f440dec9bc0df2596e2fa7ff17ee..ffac8f901857eef401cdcfa6d60734c92a96b416 100644 (file)
@@ -1,4 +1,4 @@
 line 1 line 2 line 3 line 4 &&
 (
        line 5  line 6  line 7  line 8
->)
+)
index fc9f250ac48e61c1555eea13bdea0c84f691dbb8..dd0dace077f0e093ccda9dc33b3296830e13c8d2 100644 (file)
@@ -1,9 +1,8 @@
 (
        foobar &&
-?!AMP?!        barfoo
+       barfoo ?!AMP?!
        flibble "not a # comment"
->) &&
+) &&
 
-(
-cd foo &&
->      flibble "not a # comment")
+(cd foo &&
+       flibble "not a # comment")
index 088e622c3141e1a298ba79c85aa274dfab90ee53..e1be42376c5ef480c791222dc0cc75d4d01fe1ce 100644 (file)
@@ -3,10 +3,10 @@
        then
                while true
                do
-?!AMP?!                        echo "pop"
+                       echo "pop" ?!AMP?!
                        echo "glup"
-?!AMP?!                done
+               done ?!AMP?!
                foo
-?!AMP?!        fi
+       fi ?!AMP?!
        bar
->)
+)
index 93e8ba8e4d9acdefcd9f6e716c6e109cf790ee45..dfcc3f98fb11ce442100f39c844382e2719997ae 100644 (file)
@@ -3,13 +3,13 @@
        then
                while true
                do
-# LINT: missing "&&" on 'echo'
+# LINT: missing "&&" on "echo"
                        echo "pop"
                        echo "glup"
-# LINT: missing "&&" on 'done'
+# LINT: missing "&&" on "done"
                done
                foo
-# LINT: missing "&&" on 'fi'
+# LINT: missing "&&" on "fi"
        fi
        bar
 )
index 59b6c8b850a16d087e5d322c8ee25dcbeb553fa5..300058341b6f303dce9d8e8105b6f16fa25f2ebf 100644 (file)
@@ -3,16 +3,16 @@
        x=$(
                echo bar |
                cat
->>     ) &&
+       ) &&
        echo ok
->) |
+) |
 sort &&
 (
        bar &&
        x=$(echo bar |
                cat
->>     ) &&
+       ) &&
        y=$(echo baz |
->>             fip) &&
+               fip) &&
        echo fail
->)
+)
index 170cb5999322ea7798bceafb2222274c4112adde..ab0dadf748e859968e654cf8d6a28a3a5882460b 100644 (file)
@@ -1,15 +1,9 @@
 (
        x="line 1               line 2          line 3" &&
-?!AMP?!        y='line 1               line2'
+       y="line 1               line2" ?!AMP?!
        foobar
->) &&
-(
-       echo "there's nothing to see here" &&
-       exit
->) &&
+) &&
 (
        echo "xyz" "abc         def             ghi" &&
-       echo 'xyz' 'abc         def             ghi' &&
-       echo 'xyz' "abc         def             ghi" &&
        barfoo
->)
+)
index 287ab897054874972076ec6913bf8c8144196296..4a0af2107da6dfb0035ead1ada8add0353cc2199 100644 (file)
@@ -3,25 +3,13 @@
                line 2
                line 3" &&
 # LINT: missing "&&" on assignment
-       y='line 1
-               line2'
+       y="line 1
+               line2"
        foobar
 ) &&
-(
-# LINT: apostrophe (in a contraction) within string not misinterpreted as
-# LINT: starting multi-line single-quoted string
-       echo "there's nothing to see here" &&
-       exit
-) &&
 (
        echo "xyz" "abc
                def
                ghi" &&
-       echo 'xyz' 'abc
-               def
-               ghi' &&
-       echo 'xyz' "abc
-               def
-               ghi" &&
        barfoo
 )
index cf18429d03977403e66f2fd37a8f94a6ddf9be3e..ad4c2d949ebf5de221876bd83795c6caee1a4aa2 100644 (file)
@@ -1,5 +1,5 @@
 ! (foo && bar) &&
 ! (foo && bar) >baz &&
 
-?!SEMI?!! (foo; bar) &&
-?!SEMI?!! (foo; bar) >baz
+! (foo; ?!AMP?! bar) &&
+! (foo; ?!AMP?! bar) >baz
index c2a59ffc335cb1c4ed7a30c7a59597de4f24ef91..2a86885ee6a330450a76591248b60b89e601816f 100644 (file)
@@ -1,19 +1,19 @@
 (
        (cd foo &&
                bar
->>     ) &&
+       ) &&
        (cd foo &&
                bar
-?!AMP?!>>      )
+       ) ?!AMP?!
        (
                cd foo &&
->>             bar) &&
+               bar) &&
        (
                cd foo &&
-?!AMP?!>>              bar)
+               bar) ?!AMP?!
        (cd foo &&
->>             bar) &&
+               bar) &&
        (cd foo &&
-?!AMP?!>>              bar)
+               bar) ?!AMP?!
        foobar
->)
+)
index 0c9ef1cfc6959e1b4093200769b2401467e927ad..e3bef63f7548cb0c187ae938280029dd470922bb 100644 (file)
@@ -1,7 +1,7 @@
-cat >foop &&
+cat <<ARBITRARY >foop &&
 
 (
-       cat &&
-?!AMP?!        cat
+       cat <<-INPUT_END &&
+       cat <<-EOT ?!AMP?!
        foobar
->)
+)
index 15b68d437379d79ed563205e6246779bc84b967a..be4b27a305bec54678ae4669a1666405ec06f966 100644 (file)
@@ -2,10 +2,8 @@
        foo &&
        (
                bar &&
-               # bottles wobble while fiddles gobble
-               # minor numbers of cows (or do they?)
                baz &&
                snaff
-?!AMP?!>>      )
+       ) ?!AMP?!
        fuzzy
->)
+)
index 0ff136ab3cf1706b52f839686b259df0211d3914..0215cdb1921b5bf27c302ffdf4c48e5bf5a4848a 100644 (file)
@@ -7,7 +7,7 @@
                # minor numbers of cows (or do they?)
                baz &&
                snaff
-# LINT: missing "&&" on ')'
+# LINT: missing "&&" on ")"
        )
        fuzzy
 )
index c8165ad19ec5da791ac15fe5800d374885057633..41a48adaa2b8ff62784f9fe022281e094063e96a 100644 (file)
@@ -3,10 +3,10 @@
        (
                echo a &&
                echo b
->>     ) >file &&
+       ) >file &&
        cd foo &&
        (
                echo a
                echo b
->>     ) >file
->)
+       ) >file
+)
index 998b05a47d300570faf8ff16b584517677a21567..440ee9992da3491a85fae254bdb7eb14176d4a29 100644 (file)
@@ -7,7 +7,6 @@
 
        cd foo &&
        (
-# LINT: nested multi-line subshell not presently checked for missing "&&"
                echo a
                echo b
        ) >file
diff --git a/t/chainlint/not-heredoc.expect b/t/chainlint/not-heredoc.expect
new file mode 100644 (file)
index 0000000..2e9bb13
--- /dev/null
@@ -0,0 +1,14 @@
+echo "<<<<<<< ours" &&
+echo ourside &&
+echo "=======" &&
+echo theirside &&
+echo ">>>>>>> theirs" &&
+
+(
+       echo "<<<<<<< ours" &&
+       echo ourside &&
+       echo "=======" &&
+       echo theirside &&
+       echo ">>>>>>> theirs" ?!AMP?!
+       poodle
+) >merged
diff --git a/t/chainlint/not-heredoc.test b/t/chainlint/not-heredoc.test
new file mode 100644 (file)
index 0000000..9aa5734
--- /dev/null
@@ -0,0 +1,16 @@
+# LINT: "<< ours" inside string is not here-doc
+echo "<<<<<<< ours" &&
+echo ourside &&
+echo "=======" &&
+echo theirside &&
+echo ">>>>>>> theirs" &&
+
+(
+# LINT: "<< ours" inside string is not here-doc
+       echo "<<<<<<< ours" &&
+       echo ourside &&
+       echo "=======" &&
+       echo theirside &&
+       echo ">>>>>>> theirs"
+       poodle
+) >merged
index 237f22734963d62c7dafb25883530c73f730b32b..57a7a444c15033cd817502ea4ce9c4b833567acb 100644 (file)
@@ -2,8 +2,8 @@
 (foo && bar) |
 (foo && bar) >baz &&
 
-?!SEMI?!(foo; bar) &&
-?!SEMI?!(foo; bar) |
-?!SEMI?!(foo; bar) >baz
+(foo; ?!AMP?! bar) &&
+(foo; ?!AMP?! bar) |
+(foo; ?!AMP?! bar) >baz &&
 
 (foo "bar; baz")
index ec9acb98253de1e3c3f94c9843142b45745088b1..be9858fa29efbe862bf07269a35abe7324568e22 100644 (file)
@@ -3,10 +3,10 @@
 (foo && bar) |
 (foo && bar) >baz &&
 
-# LINT: top-level one-liner subshell missing internal "&&"
+# LINT: top-level one-liner subshell missing internal "&&" and broken &&-chain
 (foo; bar) &&
 (foo; bar) |
-(foo; bar) >baz
+(foo; bar) >baz &&
 
 # LINT: ";" in string not misinterpreted as broken &&-chain
 (foo "bar; baz")
index 98b3d881fda9a8d488fe6bbd5ffe7cdf263fb60a..1290fd1ff27153f8b2daabb1e5fdec711b530ab2 100644 (file)
@@ -1,4 +1,4 @@
 (
        p4 print -1 //depot/fiddle#42 >file &&
        foobar
->)
+)
index 211b901dbc423086a6b6ebfa80a695f5f21b8929..2cfc0282970db02dd37eaf1c0c079e22a233cef1 100644 (file)
@@ -3,6 +3,6 @@
        bar |
        baz &&
        fish |
-?!AMP?!        cow
+       cow ?!AMP?!
        sunder
->)
+)
index e6af4de91672f9bb9736dc598ef49e3557672b3d..dd82534c6678624eb259c70d51f7a61fab603994 100644 (file)
@@ -4,7 +4,7 @@
        bar |
        baz &&
 
-# LINT: final line of pipe sequence ('cow') lacking "&&"
+# LINT: final line of pipe sequence ("cow") lacking "&&"
        fish |
        cow
 
index 1d79384606d2a2f3d3ceb72a9cfaa3ee7adbc95e..ed0b3707ae90139de0aec8e4ccd8d08301cff1dc 100644 (file)
@@ -1,20 +1,19 @@
 (
-?!AMP?!?!SEMI?!        cat foo ; echo bar
-?!SEMI?!       cat foo ; echo bar
->) &&
+       cat foo ; ?!AMP?! echo bar ?!AMP?!
+       cat foo ; ?!AMP?! echo bar
+) &&
 (
-?!SEMI?!       cat foo ; echo bar &&
-?!SEMI?!       cat foo ; echo bar
->) &&
+       cat foo ; ?!AMP?! echo bar &&
+       cat foo ; ?!AMP?! echo bar
+) &&
 (
        echo "foo; bar" &&
-?!SEMI?!       cat foo; echo bar
->) &&
+       cat foo; ?!AMP?! echo bar
+) &&
 (
-?!SEMI?!       foo;
->) &&
-(
-cd foo &&
+       foo;
+) &&
+(cd foo &&
        for i in a b c; do
-?!SEMI?!               echo;
->      done)
+               echo;
+       done)
index d82c8ebbc00680cf3fc3753d07791865630962ba..67e1192c50ab0c47a74152a4fd59a6d70797b717 100644 (file)
        cat foo; echo bar
 ) &&
 (
-# LINT: unnecessary terminating semicolon
+# LINT: semicolon unnecessary but legitimate
        foo;
 ) &&
 (cd foo &&
        for i in a b c; do
-# LINT: unnecessary terminating semicolon
+# LINT: semicolon unnecessary but legitimate
                echo;
        done)
index 74723e734043bd6300318b91a4874509c850460c..029d129299a0a5c68d45661071ba3ae144cd5377 100644 (file)
@@ -1,11 +1,10 @@
 (
-       echo wobba             gorgo snoot             wafta snurb &&
-?!AMP?!        cat >bip
-       echo >bop
->) &&
+       echo wobba             gorgo snoot             wafta snurb <<-EOF &&
+       cat <<EOF >bip ?!AMP?!
+       echo <<-EOF >bop
+) &&
 (
-       cat >bup &&
-       cat >bup2 &&
-       cat >bup3 &&
+       cat <<-ARBITRARY >bup &&
+       cat <<-ARBITRARY3 >bup3 &&
        meep
->)
+)
index f6b3ba4214a41de2ca9f9b91d2407e2f9dc4683c..d40eb65583f92f375dddbd3db76a893562724703 100644 (file)
@@ -8,10 +8,10 @@
        nevermore...
        EOF
 
-# LINT: missing "&&" on 'cat'
+# LINT: missing "&&" on "cat"
        cat <<EOF >bip
        fish fly high
-       EOF
+EOF
 
 # LINT: swallow here-doc (EOF is last line of subshell)
        echo <<-\EOF >bop
        glink
        FIZZ
        ARBITRARY
-       cat <<-'ARBITRARY2' >bup2 &&
-       glink
-       FIZZ
-       ARBITRARY2
        cat <<-"ARBITRARY3" >bup3 &&
        glink
        FIZZ
index 51162821d7e146caf59f8c769da22ec5ca07047a..b7015361bfe6a3555d02e97d2bdc0413b8f8c432 100644 (file)
@@ -2,13 +2,13 @@
        (foo && bar) &&
        (foo && bar) |
        (foo && bar) >baz &&
-?!SEMI?!       (foo; bar) &&
-?!SEMI?!       (foo; bar) |
-?!SEMI?!       (foo; bar) >baz &&
+       (foo; ?!AMP?! bar) &&
+       (foo; ?!AMP?! bar) |
+       (foo; ?!AMP?! bar) >baz &&
        (foo || exit 1) &&
        (foo || exit 1) |
        (foo || exit 1) >baz &&
-?!AMP?!        (foo && bar)
-?!AMP?!?!SEMI?!        (foo && bar; baz)
+       (foo && bar) ?!AMP?!
+       (foo && bar; ?!AMP?! baz) ?!AMP?!
        foobar
->)
+)
index c9913429e64b4d4c50318625832366dcf0007b64..1cccc7bf7e1a47d9a922dda821b9eac513c83104 100644 (file)
@@ -1,10 +1,10 @@
 (
        chks="sub1sub2sub3sub4" &&
-       chks_sub=$(cat | sed 's,^,sub dir/,'
->>) &&
+       chks_sub=$(cat <<TXT | sed "s,^,sub dir/,"
+) &&
        chkms="main-sub1main-sub2main-sub3main-sub4" &&
-       chkms_sub=$(cat | sed 's,^,sub dir/,'
->>) &&
+       chkms_sub=$(cat <<TXT | sed "s,^,sub dir/,"
+) &&
        subfiles=$(git ls-files) &&
        check_equal "$subfiles" "$chkms$chks"
->)
+)
index 277d8358dfd5f8d104665c420be234d40da9fb4e..02f3129232a0d114bf90211b9a6508385d0115bd 100644 (file)
@@ -3,7 +3,7 @@
 sub2
 sub3
 sub4" &&
-       chks_sub=$(cat <<TXT | sed 's,^,sub dir/,'
+       chks_sub=$(cat <<TXT | sed "s,^,sub dir/,"
 $chks
 TXT
 ) &&
@@ -11,7 +11,7 @@ TXT
 main-sub2
 main-sub3
 main-sub4" &&
-       chkms_sub=$(cat <<TXT | sed 's,^,sub dir/,'
+       chkms_sub=$(cat <<TXT | sed "s,^,sub dir/,"
 $chkms
 TXT
 ) &&
index 13cff2c0a511c6f81171f667a63632b78d387bad..0d3a9b3d128940a9515d9924964e9efeeaf48152 100644 (file)
@@ -1,11 +1,11 @@
 (
        while true
        do
-?!AMP?!                echo foo
-               cat
-?!AMP?!        done
+               echo foo ?!AMP?!
+               cat <<-EOF
+       done ?!AMP?!
        while true; do
                echo foo &&
                cat bar
        done
->)
+)
index f1df085bf03bf4b417b8231c35302328e27b4dbf..d09fb016e4405c5d9f7378b2ee5b9a634c4a9dc2 100644 (file)
@@ -1,17 +1,17 @@
 (
-# LINT: 'while, 'do', 'done' do not need "&&"
+# LINT: "while", "do", "done" do not need "&&"
        while true
        do
-# LINT: missing "&&" on 'echo'
+# LINT: missing "&&" on "echo"
                echo foo
 # LINT: last statement of while does not need "&&"
                cat <<-\EOF
                bar
                EOF
-# LINT: missing "&&" on 'done'
+# LINT: missing "&&" on "done"
        done
 
-# LINT: 'do' on same line as 'while'
+# LINT: "do" on same line as "while"
        while true; do
                echo foo &&
                cat bar
index 0d9f08931a15f10a546ea2a9840f733cfb9955e0..b736ef16421ba14e81f8e8c1654d936051efecbb 100644 (file)
@@ -1,83 +1,39 @@
 #include "test-tool.h"
 #include "cache.h"
 #include "config.h"
-#include "blob.h"
-#include "commit.h"
-#include "tree.h"
-#include "sparse-index.h"
-
-static void print_cache_entry(struct cache_entry *ce)
-{
-       const char *type;
-       printf("%06o ", ce->ce_mode & 0177777);
-
-       if (S_ISSPARSEDIR(ce->ce_mode))
-               type = tree_type;
-       else if (S_ISGITLINK(ce->ce_mode))
-               type = commit_type;
-       else
-               type = blob_type;
-
-       printf("%s %s\t%s\n",
-              type,
-              oid_to_hex(&ce->oid),
-              ce->name);
-}
-
-static void print_cache(struct index_state *istate)
-{
-       int i;
-       for (i = 0; i < istate->cache_nr; i++)
-               print_cache_entry(istate->cache[i]);
-}
 
 int cmd__read_cache(int argc, const char **argv)
 {
-       struct repository *r = the_repository;
        int i, cnt = 1;
        const char *name = NULL;
-       int table = 0, expand = 0;
 
        initialize_the_repository();
 
-       for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
-               if (skip_prefix(*argv, "--print-and-refresh=", &name))
-                       continue;
-               if (!strcmp(*argv, "--table"))
-                       table = 1;
-               else if (!strcmp(*argv, "--expand"))
-                       expand = 1;
+       if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
+               argc--;
+               argv++;
        }
 
-       if (argc == 1)
-               cnt = strtol(argv[0], NULL, 0);
+       if (argc == 2)
+               cnt = strtol(argv[1], NULL, 0);
        setup_git_directory();
        git_config(git_default_config, NULL);
 
-       prepare_repo_settings(r);
-       r->settings.command_requires_full_index = 0;
-
        for (i = 0; i < cnt; i++) {
-               repo_read_index(r);
-
-               if (expand)
-                       ensure_full_index(r->index);
-
+               read_cache();
                if (name) {
                        int pos;
 
-                       refresh_index(r->index, REFRESH_QUIET,
+                       refresh_index(&the_index, REFRESH_QUIET,
                                      NULL, NULL, NULL);
-                       pos = index_name_pos(r->index, name, strlen(name));
+                       pos = index_name_pos(&the_index, name, strlen(name));
                        if (pos < 0)
                                die("%s not in index", name);
                        printf("%s is%s up to date\n", name,
-                              ce_uptodate(r->index->cache[pos]) ? "" : " not");
+                              ce_uptodate(the_index.cache[pos]) ? "" : " not");
                        write_file(name, "%d\n", i);
                }
-               if (table)
-                       print_cache(r->index);
-               discard_index(r->index);
+               discard_cache();
        }
        return 0;
 }
index 24dd4bec08c4cd6afc2c33bddfd7c86710141428..3e4ddaee70557690e14c09ad5da34ddbab4a781a 100644 (file)
@@ -269,7 +269,7 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv)
        struct object_id old_oid;
 
        if (get_oid_hex(sha1_buf, &old_oid))
-               die("not sha-1");
+               die("cannot parse %s as %s", sha1_buf, the_hash_algo->name);
 
        return refs_delete_ref(refs, msg, refname, &old_oid, flags);
 }
@@ -284,9 +284,10 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
        struct object_id old_oid;
        struct object_id new_oid;
 
-       if (get_oid_hex(old_sha1_buf, &old_oid) ||
-           get_oid_hex(new_sha1_buf, &new_oid))
-               die("not sha-1");
+       if (get_oid_hex(old_sha1_buf, &old_oid))
+               die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name);
+       if (get_oid_hex(new_sha1_buf, &new_oid))
+               die("cannot parse %s as %s", new_sha1_buf, the_hash_algo->name);
 
        return refs_update_ref(refs, msg, refname,
                               &new_oid, &old_oid,
index f93633f895a1926aa6ea4ca712305cccb5826a2d..59b124bb5f147f3a8cf1876230306c4fc5bdd60f 100644 (file)
@@ -262,8 +262,9 @@ static int print_usage(void)
  *    [] the "cmd_name" event has been generated.
  *    [] this writes various "def_param" events for interesting config values.
  *
- * We further assume that if we return (rather than exit()), trace2_cmd_exit()
- * will be called by test-tool.c:cmd_main().
+ * We return from here and let test-tool.c::cmd_main() pass the exit
+ * code to common-main.c::main(), which will use it to call
+ * trace2_cmd_exit().
  */
 int cmd__trace2(int argc, const char **argv)
 {
index 3aa7a3ffd8b0103752987872c84e75ea2b299b9e..e5eb28df4ef6cc80fe24c728595d683ab3d00b85 100644 (file)
@@ -3,7 +3,7 @@
 test_expect_success 'determine default pager' '
        test_might_fail git config --unset core.pager &&
        less=$(
-               unset PAGER GIT_PAGER;
+               sane_unset PAGER GIT_PAGER &&
                git var GIT_PAGER
        ) &&
        test -n "$less"
index 0b0aa9858f5dbf16f5c98639e25a8891846fe300..ca58d6c9b59493a37d4bf301e2c2d099fd841e91 100755 (executable)
@@ -24,17 +24,17 @@ test_perf_default_repo
 test_expect_success "setup repo" '
        if git rev-parse --verify refs/heads/p0006-ballast^{commit}
        then
-               echo Assuming synthetic repo from many-files.sh
-               git branch br_base            master
-               git branch br_ballast         p0006-ballast
-               git config --local core.sparsecheckout 1
+               echo Assuming synthetic repo from many-files.sh &&
+               git branch br_base            master &&
+               git branch br_ballast         p0006-ballast &&
+               git config --local core.sparsecheckout 1 &&
                cat >.git/info/sparse-checkout <<-EOF
                /*
                !ballast/*
                EOF
        else
-               echo Assuming non-synthetic repo...
-               git branch br_base            $(git rev-list HEAD | tail -n 1)
+               echo Assuming non-synthetic repo... &&
+               git branch br_base            $(git rev-list HEAD | tail -n 1) &&
                git branch br_ballast         HEAD
        fi &&
        git checkout -q br_ballast &&
index 78cc23fe2f32eff777aab058b12d109ac81bc83c..900b385c4bbc2d0bf9a803f06b48fe1c25909e86 100755 (executable)
@@ -24,21 +24,21 @@ test_perf_default_repo
 test_expect_success "setup repo" '
        if git rev-parse --verify refs/heads/p0006-ballast^{commit}
        then
-               echo Assuming synthetic repo from many-files.sh
-               git branch br_base            master
-               git branch br_ballast         p0006-ballast^
-               git branch br_ballast_alias   p0006-ballast^
-               git branch br_ballast_plus_1  p0006-ballast
-               git config --local core.sparsecheckout 1
+               echo Assuming synthetic repo from many-files.sh &&
+               git branch br_base            master &&
+               git branch br_ballast         p0006-ballast^ &&
+               git branch br_ballast_alias   p0006-ballast^ &&
+               git branch br_ballast_plus_1  p0006-ballast &&
+               git config --local core.sparsecheckout 1 &&
                cat >.git/info/sparse-checkout <<-EOF
                /*
                !ballast/*
                EOF
        else
-               echo Assuming non-synthetic repo...
-               git branch br_base            $(git rev-list HEAD | tail -n 1)
-               git branch br_ballast         HEAD^ || error "no ancestor commit from current head"
-               git branch br_ballast_alias   HEAD^
+               echo Assuming non-synthetic repo... &&
+               git branch br_base            $(git rev-list HEAD | tail -n 1) &&
+               git branch br_ballast         HEAD^ || error "no ancestor commit from current head" &&
+               git branch br_ballast_alias   HEAD^ &&
                git branch br_ballast_plus_1  HEAD
        fi &&
        git checkout -q br_ballast &&
index 09595264f09fa4b1dc28b3e5d2a3d6482d998bcc..25d8ff7443e77cafbcda0a5b08ed2335d2e798f9 100755 (executable)
@@ -9,8 +9,8 @@ test_perf_default_repo
 test_expect_success "setup repo" '
        if git rev-parse --verify refs/heads/p0006-ballast^{commit}
        then
-               echo Assuming synthetic repo from many-files.sh
-               git config --local core.sparsecheckout 1
+               echo Assuming synthetic repo from many-files.sh &&
+               git config --local core.sparsecheckout 1 &&
                cat >.git/info/sparse-checkout <<-EOF
                /*
                !ballast/*
index dd18a9ce2b115fbf92a4787f5336cb4c9f549d18..439e9c8e3c6484fe3a6f34a4f5903b07397d0c1f 100755 (executable)
@@ -19,9 +19,9 @@ test_expect_success 'setup' '
                printf "a" >>refname &&
                for j in $(test_seq 1 $i)
                do
-                       printf "a*" >>refglob.$i
+                       printf "a*" >>refglob.$i || return 1
                done &&
-               echo b >>refglob.$i
+               echo b >>refglob.$i || return 1
        done &&
        test_commit test $(cat refname).t "" $(cat refname).t
 '
index dda8a7486634488d65ca30ca6da1e795c4eb3a3a..a75969cbb1571ba5da46438c94397ee2130b9be9 100755 (executable)
@@ -13,7 +13,7 @@ test_expect_success "setup" '
        do
                printf "start\ncreate refs/heads/%d PRE\ncommit\n" $i &&
                printf "start\nupdate refs/heads/%d POST PRE\ncommit\n" $i &&
-               printf "start\ndelete refs/heads/%d POST\ncommit\n" $i
+               printf "start\ndelete refs/heads/%d POST\ncommit\n" $i || return 1
        done >instructions
 '
 
@@ -22,7 +22,7 @@ test_perf "update-ref" '
        do
                git update-ref refs/heads/branch PRE &&
                git update-ref refs/heads/branch POST PRE &&
-               git update-ref -d refs/heads/branch
+               git update-ref -d refs/heads/branch || return 1
        done
 '
 
index c2b97d2487bbcabf3ee1becc7bb8b7c0fb0ac784..f767d834f2ea08fe1415a24b4c20de63decf43e2 100755 (executable)
@@ -15,7 +15,7 @@ test_expect_success "setup $n bad commits" '
                echo "committer C <c@example.com> 1234567890 +0000" &&
                echo "data <<EOF" &&
                echo "$i.Q." &&
-               echo "EOF"
+               echo "EOF" || return 1
        done | q_to_nul | git fast-import
 '
 
index 43d5a34e8cadc8c9284e6586f426de5fa9857a9f..e6b0277729b19631ad49740070b092ff08121972 100755 (executable)
@@ -22,7 +22,7 @@ test_expect_success 'setup rebasing on top of a lot of changes' '
                git add unrelated-file$i &&
                test_tick &&
                git commit -m commit$i-reverse unrelated-file$i ||
-               break
+               return 1
        done &&
        git checkout to-rebase &&
        test_commit our-patch interesting-file
diff --git a/t/perf/p4002-diff-color-moved.sh b/t/perf/p4002-diff-color-moved.sh
new file mode 100755 (executable)
index 0000000..ab2af93
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+test_description='Tests diff --color-moved performance'
+. ./perf-lib.sh
+
+test_perf_default_repo
+
+# The endpoints of the diff can be customized by setting TEST_REV_A
+# and TEST_REV_B in the environment when running this test.
+
+rev="${TEST_REV_A:-v2.28.0}"
+if ! rev_a="$(git rev-parse --quiet --verify "$rev")"
+then
+       skip_all="skipping because '$rev' was not found. \
+                 Use TEST_REV_A and TEST_REV_B to set the revs to use"
+       test_done
+fi
+rev="${TEST_REV_B:-v2.29.0}"
+if ! rev_b="$(git rev-parse --quiet --verify "$rev")"
+then
+       skip_all="skipping because '$rev' was not found. \
+                 Use TEST_REV_A and TEST_REV_B to set the revs to use"
+       test_done
+fi
+
+GIT_PAGER_IN_USE=1
+test_export GIT_PAGER_IN_USE rev_a rev_b
+
+test_perf 'diff --no-color-moved --no-color-moved-ws large change' '
+       git diff --no-color-moved --no-color-moved-ws $rev_a $rev_b
+'
+
+test_perf 'diff --color-moved --no-color-moved-ws large change' '
+       git diff --color-moved=zebra --no-color-moved-ws $rev_a $rev_b
+'
+
+test_perf 'diff --color-moved-ws=allow-indentation-change large change' '
+       git diff --color-moved=zebra --color-moved-ws=allow-indentation-change \
+               $rev_a $rev_b
+'
+
+test_perf 'log --no-color-moved --no-color-moved-ws' '
+       git log --no-color-moved --no-color-moved-ws --no-merges --patch \
+               -n1000 $rev_b
+'
+
+test_perf 'log --color-moved --no-color-moved-ws' '
+       git log --color-moved=zebra --no-color-moved-ws --no-merges --patch \
+               -n1000 $rev_b
+'
+
+test_perf 'log --color-moved-ws=allow-indentation-change' '
+       git log --color-moved=zebra --color-moved-ws=allow-indentation-change \
+               --no-merges --patch -n1000 $rev_b
+'
+
+test_done
index 228593d9ad6b3a5c9a0b45eb5814a3a8746d42bc..c16f6a3ff698c088db427ae9d7b0a8f16f59a8c6 100755 (executable)
@@ -21,8 +21,8 @@ test_expect_success 'set up thread-counting tests' '
        threads= &&
        while test $t -gt 0
        do
-               threads="$t $threads"
-               t=$((t / 2))
+               threads="$t $threads" &&
+               t=$((t / 2)) || return 1
        done
 '
 
index 35c0cbdf49fbc14d659f9abff7e8624a6ae14cec..af173a7b73e398c33b5629717cc890ea14a5fa33 100755 (executable)
@@ -126,11 +126,11 @@ done
 # Measure pack loading with 10,000 packs.
 test_expect_success 'generate lots of packs' '
        for i in $(test_seq 10000); do
-               echo "blob"
-               echo "data <<EOF"
-               echo "blob $i"
-               echo "EOF"
-               echo "checkpoint"
+               echo "blob" &&
+               echo "data <<EOF" &&
+               echo "blob $i" &&
+               echo "EOF" &&
+               echo "checkpoint" || return 1
        done |
        git -c fastimport.unpackLimit=0 fast-import
 '
index 5eb5044a103cabd1d3dba4980a00f0d66d4818a5..c8be58f3c763beb7b890925251300494365b3900 100755 (executable)
@@ -119,10 +119,10 @@ 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; done &&
-       for i in $(test_seq 1 100); do touch 100_files/$i; done &&
-       for i in $(test_seq 1 1000); do touch 1000_files/$i; done &&
-       for i in $(test_seq 1 10000); do touch 10000_files/$i; done &&
+       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 &&
        git add 1_file 10_files 100_files 1000_files 10000_files &&
        git commit -qm "Add files" &&
 
index 780a7402d5191f72f7b50a48da4adf665090349f..407252bac70fbfc7b3a30fe29833f5944b3de8a5 100644 (file)
@@ -161,7 +161,7 @@ test_run_perf_ () {
        test_cleanup=:
        test_export_="test_cleanup"
        export test_cleanup test_export_
-       "$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c '
+       "$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c '
 . '"$TEST_DIRECTORY"/test-lib-functions.sh'
 test_export () {
        test_export_="$test_export_ $*"
index a5ec6a0315ca09893e5c2b7403e91f2a0be0109c..eba75a2490ce7e0918e6a981d42ec8f5d9fd9b2d 100755 (executable)
@@ -48,7 +48,7 @@ test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
 '
 
 test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
-       OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
+       OUT=$( ((trap "" PIPE && large_git; echo $? 1>&3) | :) 3>&1 ) &&
        test_match_signal 13 "$OUT"
 '
 
index 42d2314804966fae851eb3973310d615d5e1e053..5575dade8eee8184b24d6685213b9a30dcee4364 100755 (executable)
@@ -200,7 +200,7 @@ test_expect_success 'setup' '
        do
                : >$dir/not-ignored &&
                : >$dir/ignored-and-untracked &&
-               : >$dir/ignored-but-in-index
+               : >$dir/ignored-but-in-index || return 1
        done &&
        git add -f ignored-but-in-index a/ignored-but-in-index &&
        cat <<-\EOF >a/.gitignore &&
index e094975b13bf270992d9cac8999bb0972a633198..1cb6aa6824321656264e427f299899acf0754357 100755 (executable)
@@ -220,7 +220,7 @@ test_expect_success 'grow / shrink' '
        for n in $(test_seq 51)
        do
                echo put key$n value$n >> in &&
-               echo NULL >> expect
+               echo NULL >> expect || return 1
        done &&
        echo size >> in &&
        echo 64 51 >> expect &&
@@ -231,7 +231,7 @@ test_expect_success 'grow / shrink' '
        for n in $(test_seq 12)
        do
                echo remove key$n >> in &&
-               echo value$n >> expect
+               echo value$n >> expect || return 1
        done &&
        echo size >> in &&
        echo 256 40 >> expect &&
index 4125ab8b88403d2924e46e6c1fe0658e1ec8dba9..35cc8c3b39896cb5caf6740d6847f5dec66e1dea 100755 (executable)
@@ -23,10 +23,10 @@ test_expect_success setup '
 
        git config core.autocrlf false &&
 
-       for w in Hello world how are you; do echo $w; done >one &&
+       test_write_lines Hello world how are you >one &&
        mkdir dir &&
-       for w in I am very very fine thank you; do echo $w; done >dir/two &&
-       for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
+       test_write_lines I am very very fine thank you >dir/two &&
+       test_write_lines Oh here is NULQin text here | q_to_nul >three &&
        git add . &&
 
        git commit -m initial &&
@@ -36,7 +36,7 @@ test_expect_success setup '
        two=$(git rev-parse HEAD:dir/two) &&
        three=$(git rev-parse HEAD:three) &&
 
-       for w in Some extra lines here; do echo $w; done >>one &&
+       test_write_lines Some extra lines here >>one &&
        git diff >patch.file &&
        patched=$(git hash-object --stdin <one) &&
        git read-tree --reset -u HEAD
@@ -47,7 +47,7 @@ test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
        git config core.autocrlf input &&
        git config core.safecrlf true &&
 
-       for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
+       test_write_lines I am all CRLF | append_cr >allcrlf &&
        test_must_fail git add allcrlf
 '
 
@@ -56,7 +56,7 @@ test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' '
        git config core.autocrlf input &&
        git config core.safecrlf true &&
 
-       for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
+       test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
        test_must_fail git add mixed
 '
 
@@ -65,7 +65,7 @@ test_expect_success 'safecrlf: autocrlf=true, all LF' '
        git config core.autocrlf true &&
        git config core.safecrlf true &&
 
-       for w in I am all LF; do echo $w; done >alllf &&
+       test_write_lines I am all LF >alllf &&
        test_must_fail git add alllf
 '
 
@@ -74,7 +74,7 @@ test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' '
        git config core.autocrlf true &&
        git config core.safecrlf true &&
 
-       for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
+       test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
        test_must_fail git add mixed
 '
 
@@ -83,10 +83,10 @@ test_expect_success 'safecrlf: print warning only once' '
        git config core.autocrlf input &&
        git config core.safecrlf warn &&
 
-       for w in I am all LF; do echo $w; done >doublewarn &&
+       test_write_lines I am all LF >doublewarn &&
        git add doublewarn &&
        git commit -m "nowarn" &&
-       for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
+       test_write_lines Oh here is CRLFQ in text | q_to_cr >doublewarn &&
        git add doublewarn 2>err &&
        grep "CRLF will be replaced by LF" err >err.warnings &&
        test_line_count = 1 err.warnings
@@ -104,7 +104,7 @@ test_expect_success 'safecrlf: no warning with safecrlf=false' '
        git config core.autocrlf input &&
        git config core.safecrlf false &&
 
-       for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
+       test_write_lines I am all CRLF | append_cr >allcrlf &&
        git add allcrlf 2>err &&
        test_must_be_empty err
 '
@@ -352,9 +352,9 @@ test_expect_success 'setting up for new autocrlf tests' '
        git config core.autocrlf false &&
        git config core.safecrlf false &&
        rm -rf .????* * &&
-       for w in I am all LF; do echo $w; done >alllf &&
-       for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
-       for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
+       test_write_lines I am all LF >alllf &&
+       test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
+       test_write_lines I am all CRLF | append_cr >allcrlf &&
        git add -A . &&
        git commit -m "alllf, allcrlf and mixed only" &&
        git tag -a -m "message" autocrlf-checkpoint
index 33dfc9cd562327b725a3338ac0e9b6787f58c9fe..bad37abad2c376182ca0241afcfcb54a3f4f700e 100755 (executable)
@@ -76,13 +76,13 @@ test_expect_success setup '
        git config filter.rot13.clean ./rot13.sh &&
 
        {
-           echo "*.t filter=rot13"
+           echo "*.t filter=rot13" &&
            echo "*.i ident"
        } >.gitattributes &&
 
        {
-           echo a b c d e f g h i j k l m
-           echo n o p q r s t u v w x y z
+           echo a b c d e f g h i j k l m &&
+           echo n o p q r s t u v w x y z &&
            echo '\''$Id$'\''
        } >test &&
        cat test >test.t &&
@@ -118,17 +118,17 @@ test_expect_success check '
 # If an expanded ident ever gets into the repository, we want to make sure that
 # it is collapsed before being expanded again on checkout
 test_expect_success expanded_in_repo '
-       {
-               echo "File with expanded keywords"
-               echo "\$Id\$"
-               echo "\$Id:\$"
-               echo "\$Id: 0000000000000000000000000000000000000000 \$"
-               echo "\$Id: NoSpaceAtEnd\$"
-               echo "\$Id:NoSpaceAtFront \$"
-               echo "\$Id:NoSpaceAtEitherEnd\$"
-               echo "\$Id: NoTerminatingSymbol"
-               echo "\$Id: Foreign Commit With Spaces \$"
-       } >expanded-keywords.0 &&
+       cat >expanded-keywords.0 <<-\EOF &&
+       File with expanded keywords
+       $Id$
+       $Id:$
+       $Id: 0000000000000000000000000000000000000000 $
+       $Id: NoSpaceAtEnd$
+       $Id:NoSpaceAtFront $
+       $Id:NoSpaceAtEitherEnd$
+       $Id: NoTerminatingSymbol
+       $Id: Foreign Commit With Spaces $
+       EOF
 
        {
                cat expanded-keywords.0 &&
@@ -139,17 +139,17 @@ test_expect_success expanded_in_repo '
        git commit -m "File with keywords expanded" &&
        id=$(git rev-parse --verify :expanded-keywords) &&
 
-       {
-               echo "File with expanded keywords"
-               echo "\$Id: $id \$"
-               echo "\$Id: $id \$"
-               echo "\$Id: $id \$"
-               echo "\$Id: $id \$"
-               echo "\$Id: $id \$"
-               echo "\$Id: $id \$"
-               echo "\$Id: NoTerminatingSymbol"
-               echo "\$Id: Foreign Commit With Spaces \$"
-       } >expected-output.0 &&
+       cat >expected-output.0 <<-EOF &&
+       File with expanded keywords
+       \$Id: $id \$
+       \$Id: $id \$
+       \$Id: $id \$
+       \$Id: $id \$
+       \$Id: $id \$
+       \$Id: $id \$
+       \$Id: NoTerminatingSymbol
+       \$Id: Foreign Commit With Spaces \$
+       EOF
        {
                cat expected-output.0 &&
                printf "\$Id: NoTerminatingSymbolAtEOF"
@@ -159,7 +159,7 @@ test_expect_success expanded_in_repo '
                printf "\$Id: NoTerminatingSymbolAtEOF"
        } >expected-output-crlf &&
        {
-               echo "expanded-keywords ident"
+               echo "expanded-keywords ident" &&
                echo "expanded-keywords-crlf ident text eol=crlf"
        } >>.gitattributes &&
 
@@ -285,7 +285,7 @@ test_expect_success 'required filter with absent smudge field' '
 test_expect_success 'filtering large input to small output should use little memory' '
        test_config filter.devnull.clean "cat >/dev/null" &&
        test_config filter.devnull.required true &&
-       for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
+       for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB &&
        echo "30MB filter=devnull" >.gitattributes &&
        GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
 '
@@ -303,7 +303,7 @@ test_expect_success 'filter that does not read is fine' '
 test_expect_success EXPENSIVE 'filter large file' '
        test_config filter.largefile.smudge cat &&
        test_config filter.largefile.clean cat &&
-       for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
+       for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB &&
        echo "2GB filter=largefile" >.gitattributes &&
        git add 2GB 2>err &&
        test_must_be_empty err &&
@@ -643,7 +643,7 @@ test_expect_success PERL 'required process filter should process multiple packet
                for FILE in "$TEST_ROOT"/*.file
                do
                        cp "$FILE" . &&
-                       rot13.sh <"$FILE" >"$FILE.rot13"
+                       rot13.sh <"$FILE" >"$FILE.rot13" || return 1
                done &&
 
                echo "*.file filter=protocol" >.gitattributes &&
@@ -682,7 +682,7 @@ test_expect_success PERL 'required process filter should process multiple packet
 
                for FILE in *.file
                do
-                       test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
+                       test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1
                done
        )
 '
index cdcafcdff724e2c13ee056fb59e915a5371ec13c..f426a185bb9b32e732c0404d65237f8278435f0e 100755 (executable)
@@ -15,8 +15,8 @@ test_expect_success setup '
 
        echo "one text" > .gitattributes &&
 
-       for w in Hello world how are you; do echo $w; done >one &&
-       for w in I am very very fine thank you; do echo $w; done >two &&
+       test_write_lines Hello world how are you >one &&
+       test_write_lines I am very very fine thank you >two &&
        git add . &&
 
        git commit -m initial &&
index 34d1061f321fb406a5e3d6058860da957307dfab..71a5d370cc7bc7d369b7e3099c064bc8cb114d7d 100755 (executable)
@@ -216,7 +216,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
        mkdir second &&
        ln -s ../first second/other &&
        mkdir third &&
-       dir="$(cd .git; pwd -P)" &&
+       dir="$(cd .git && pwd -P)" &&
        dir2=third/../second/other/.git &&
        test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
        file="$dir"/index &&
@@ -224,7 +224,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' '
        basename=blub &&
        test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
        ln -s ../first/file .git/syml &&
-       sym="$(cd first; pwd -P)"/file &&
+       sym="$(cd first && pwd -P)"/file &&
        test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
 '
 
index 74cc59bf8a7de8dfe1f4605c5cd1059d889bc4c6..889db508183f7c858c438aa5144629279660e864 100755 (executable)
@@ -28,7 +28,7 @@ test_expect_success 'oidtree insert and contains' '
        EOF
        {
                echoid insert 444 1 2 3 4 5 a b c d e &&
-               echoid contains 44 441 440 444 4440 4444
+               echoid contains 44 441 440 444 4440 4444 &&
                echo clear
        } | test-tool oidtree >actual &&
        test_cmp expect actual
@@ -37,11 +37,11 @@ test_expect_success 'oidtree insert and contains' '
 test_expect_success 'oidtree each' '
        echoid "" 123 321 321 >expect &&
        {
-               echoid insert f 9 8 123 321 a b c d e
-               echo each 12300
-               echo each 3211
-               echo each 3210
-               echo each 32100
+               echoid insert f 9 8 123 321 a b c d e &&
+               echo each 12300 &&
+               echo each 3211 &&
+               echo each 3210 &&
+               echo each 32100 &&
                echo clear
        } | test-tool oidtree >actual &&
        test_cmp expect actual
index 7e4ab1795fb99890d5adb8b67ebf2d82042de3e5..5945973552a6af6ac1971920b573086b081f6160 100755 (executable)
@@ -84,7 +84,7 @@ test_expect_success 'get bloom filter for commit with 10 changes' '
        mkdir smallDir &&
        for i in $(test_seq 0 9)
        do
-               echo $i >smallDir/$i
+               echo $i >smallDir/$i || return 1
        done &&
        git add smallDir &&
        git commit -m "commit with 10 changes" &&
@@ -102,7 +102,7 @@ test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' '
        mkdir bigDir &&
        for i in $(test_seq 0 511)
        do
-               echo $i >bigDir/$i
+               echo $i >bigDir/$i || return 1
        done &&
        git add bigDir &&
        git commit -m "commit with 513 changes" &&
index c76485b1b60fe3292fdc55d99fe5c576660dffb9..f17abd298c83467b3ead07ff87c08623ff640502 100755 (executable)
@@ -469,7 +469,7 @@ test_expect_success 'rev-list dies for missing objects on cmd line' '
                git -C repo rev-list --ignore-missing --objects \
                        --exclude-promisor-objects "$OBJ" &&
                git -C repo rev-list --ignore-missing --objects-edge-aggressive \
-                       --exclude-promisor-objects "$OBJ"
+                       --exclude-promisor-objects "$OBJ" || return 1
        done
 '
 
index 0d4c55f74ec6470f7241a0929a7727e567738d89..39382fa1958152ae0cb88edda55cd63c33a15b6e 100755 (executable)
@@ -211,14 +211,14 @@ done
 test_expect_success "--batch-check for a non-existent named object" '
     test "foobar42 missing
 foobar84 missing" = \
-    "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
+    "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
 '
 
 test_expect_success "--batch-check for a non-existent hash" '
     test "0000000000000000000000000000000000000042 missing
 0000000000000000000000000000000000000084 missing" = \
-    "$( ( echo 0000000000000000000000000000000000000042;
-        echo_without_newline 0000000000000000000000000000000000000084; ) |
+    "$( ( echo 0000000000000000000000000000000000000042 &&
+        echo_without_newline 0000000000000000000000000000000000000084 ) |
        git cat-file --batch-check)"
 '
 
@@ -226,8 +226,8 @@ test_expect_success "--batch for an existent and a non-existent hash" '
     test "$tag_sha1 tag $tag_size
 $tag_content
 0000000000000000000000000000000000000000 missing" = \
-    "$( ( echo $tag_sha1;
-        echo_without_newline 0000000000000000000000000000000000000000; ) |
+    "$( ( echo $tag_sha1 &&
+        echo_without_newline 0000000000000000000000000000000000000000 ) |
        git cat-file --batch)"
 '
 
@@ -283,7 +283,7 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" '
 
 test_expect_success 'setup blobs which are likely to delta' '
        test-tool genrandom foo 10240 >foo &&
-       { cat foo; echo plus; } >foo-plus &&
+       { cat foo && echo plus; } >foo-plus &&
        git add foo foo-plus &&
        git commit -m foo &&
        cat >blobs <<-\EOF
index 48bfad07abca6f3ee8430078372108451517aaed..3c0819452653878ae51779798ce90712dc30a901 100755 (executable)
@@ -6,10 +6,10 @@ TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '
-       for d in a a. a0
+       for d in a a- a0
        do
                mkdir "$d" && echo "$d/one" >"$d/one" &&
-               git add "$d"
+               git add "$d" || return 1
        done &&
        echo zero >one &&
        git update-index --add --info-only one &&
index c2df75e4953d897acee5cf590b9c358e5a0b77c2..9fdbb2af80e0a82429289d06b24d4dcfac3f263d 100755 (executable)
@@ -11,9 +11,9 @@ test_description='Try various core-level commands in subdirectory.
 
 test_expect_success setup '
        long="a b c d e f g h i j k l m n o p q r s t u v w x y z" &&
-       for c in $long; do echo $c; done >one &&
+       test_write_lines $long >one &&
        mkdir dir &&
-       for c in x y z $long a b c; do echo $c; done >dir/two &&
+       test_write_lines x y z $long a b c >dir/two &&
        cp one original.one &&
        cp dir/two original.two
 '
@@ -22,7 +22,7 @@ test_expect_success 'update-index and ls-files' '
        git update-index --add one &&
        case "$(git ls-files)" in
        one) echo pass one ;;
-       *) echo bad one; exit 1 ;;
+       *) echo bad one; return 1 ;;
        esac &&
        (
                cd dir &&
@@ -34,7 +34,7 @@ test_expect_success 'update-index and ls-files' '
        ) &&
        case "$(git ls-files)" in
        dir/two"$LF"one) echo pass both ;;
-       *) echo bad; exit 1 ;;
+       *) echo bad; return 1 ;;
        esac
 '
 
@@ -57,7 +57,7 @@ test_expect_success 'diff-files' '
        echo d >>dir/two &&
        case "$(git diff-files --name-only)" in
        dir/two"$LF"one) echo pass top ;;
-       *) echo bad top; exit 1 ;;
+       *) echo bad top; return 1 ;;
        esac &&
        # diff should not omit leading paths
        (
index 6bc1d76fb108f38f1fdb9a68904c5251866149fb..4f3aa17c994240173fdb4de70da62611700e11fd 100755 (executable)
@@ -51,42 +51,32 @@ EOF
 test_expect_success 'add a large file or two' '
        git add large1 huge large2 &&
        # make sure we got a single packfile and no loose objects
-       bad= count=0 idx= &&
+       count=0 idx= &&
        for p in .git/objects/pack/pack-*.pack
        do
-               count=$(( $count + 1 ))
-               if test_path_is_file "$p" &&
-                  idx=${p%.pack}.idx && test_path_is_file "$idx"
-               then
-                       continue
-               fi
-               bad=t
+               count=$(( $count + 1 )) &&
+               test_path_is_file "$p" &&
+               idx=${p%.pack}.idx &&
+               test_path_is_file "$idx" || return 1
        done &&
-       test -z "$bad" &&
        test $count = 1 &&
        cnt=$(git show-index <"$idx" | wc -l) &&
        test $cnt = 2 &&
        for l in .git/objects/$OIDPATH_REGEX
        do
-               test_path_is_file "$l" || continue
-               bad=t
+               test_path_is_missing "$l" || return 1
        done &&
-       test -z "$bad" &&
 
        # attempt to add another copy of the same
        git add large3 &&
        bad= count=0 &&
        for p in .git/objects/pack/pack-*.pack
        do
-               count=$(( $count + 1 ))
-               if test_path_is_file "$p" &&
-                  idx=${p%.pack}.idx && test_path_is_file "$idx"
-               then
-                       continue
-               fi
-               bad=t
+               count=$(( $count + 1 )) &&
+               test_path_is_file "$p" &&
+               idx=${p%.pack}.idx &&
+               test_path_is_file "$idx" || return 1
        done &&
-       test -z "$bad" &&
        test $count = 1
 '
 
@@ -115,7 +105,7 @@ test_expect_success 'packsize limit' '
                count=0 &&
                for pi in .git/objects/pack/pack-*.idx
                do
-                       test_path_is_file "$pi" && count=$(( $count + 1 ))
+                       test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1
                done &&
                test $count = 2 &&
 
@@ -128,7 +118,7 @@ test_expect_success 'packsize limit' '
 
                for pi in .git/objects/pack/pack-*.idx
                do
-                       git show-index <"$pi"
+                       git show-index <"$pi" || return 1
                done |
                sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" |
                sort >actual &&
index 272ba1b566b3eaf43798f9ecfb1a77c26db3f59b..42776984fe77912c8bc6a8450935c08134858946 100755 (executable)
@@ -41,7 +41,15 @@ test_expect_success 'setup' '
        )
 '
 
-test_expect_success 'git sparse-checkout list (empty)' '
+test_expect_success 'git sparse-checkout list (not sparse)' '
+       test_must_fail git -C repo sparse-checkout list >list 2>err &&
+       test_must_be_empty list &&
+       test_i18ngrep "this worktree is not sparse" err
+'
+
+test_expect_success 'git sparse-checkout list (not sparse)' '
+       git -C repo sparse-checkout set &&
+       rm repo/.git/info/sparse-checkout &&
        git -C repo sparse-checkout list >list 2>err &&
        test_must_be_empty list &&
        test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err
@@ -103,6 +111,18 @@ test_expect_success 'clone --sparse' '
        check_files clone a
 '
 
+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 add dir &&
+               git config core.sparseCheckoutCone true &&
+               test_must_fail git sparse-checkout add dir 2>err &&
+               grep "existing sparse-checkout patterns do not use cone mode" err
+       )
+'
+
 test_expect_success 'interaction with clone --no-checkout (unborn index)' '
        git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout &&
        git -C clone_no_checkout sparse-checkout init --cone &&
@@ -165,12 +185,14 @@ test_expect_success 'set sparse-checkout using --stdin' '
 '
 
 test_expect_success 'add to sparse-checkout' '
-       cat repo/.git/info/sparse-checkout >expect &&
+       cat repo/.git/info/sparse-checkout >old &&
+       test_when_finished cp old repo/.git/info/sparse-checkout &&
        cat >add <<-\EOF &&
        pattern1
        /folder1/
        pattern2
        EOF
+       cat old >expect &&
        cat add >>expect &&
        git -C repo sparse-checkout add --stdin <add &&
        git -C repo sparse-checkout list >actual &&
@@ -212,12 +234,27 @@ test_expect_success 'sparse-index enabled and disabled' '
 
                git -C repo sparse-checkout init --cone --sparse-index &&
                test_cmp_config -C repo true index.sparse &&
-               test-tool -C repo read-cache --table >cache &&
-               grep " tree " cache &&
-
+               git -C repo ls-files --sparse >sparse &&
                git -C repo sparse-checkout disable &&
-               test-tool -C repo read-cache --table >cache &&
-               ! grep " tree " cache &&
+               git -C repo ls-files --sparse >full &&
+
+               cat >expect <<-\EOF &&
+               @@ -1,4 +1,7 @@
+                a
+               -deep/
+               -folder1/
+               -folder2/
+               +deep/a
+               +deep/deeper1/a
+               +deep/deeper1/deepest/a
+               +deep/deeper2/a
+               +folder1/a
+               +folder2/a
+               EOF
+
+               diff -u sparse full | tail -n +3 >actual &&
+               test_cmp expect actual &&
+
                git -C repo config --list >config &&
                ! grep index.sparse config
        )
@@ -586,7 +623,7 @@ test_expect_success 'pattern-checks: contained glob characters' '
                !/*/
                something$c-else/
                EOF
-               check_read_tree_errors repo "a" "disabling cone pattern matching"
+               check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1
        done
 '
 
@@ -708,4 +745,25 @@ test_expect_success 'cone mode clears ignored subdirectories' '
        test_cmp expect out
 '
 
+test_expect_success 'malformed cone-mode patterns' '
+       git -C repo sparse-checkout init --cone &&
+       mkdir -p repo/foo/bar &&
+       touch repo/foo/bar/x repo/foo/y &&
+       cat >repo/.git/info/sparse-checkout <<-\EOF &&
+       /*
+       !/*/
+       /foo/
+       !/foo/*/
+       /foo/\*/
+       EOF
+
+       # Listing the patterns will notice the duplicate pattern and
+       # emit a warning. It will list the patterns directly instead
+       # of using the cone-mode translation to a set of directories.
+       git -C repo sparse-checkout list >actual 2>err &&
+       test_cmp repo/.git/info/sparse-checkout actual &&
+       grep "warning: your sparse-checkout file may have issues: pattern .* is repeated" err &&
+       grep "warning: disabling cone pattern matching" err
+'
+
 test_done
index 49f70a656927d0a6893a78ac079a8ac76c53c429..4ba16177528c920e816bdd1cf8db117ca5f6519e 100755 (executable)
@@ -206,45 +206,42 @@ test_sparse_unstaged () {
 test_expect_success 'sparse-index contents' '
        init_repos &&
 
-       test-tool -C sparse-index read-cache --table >cache &&
+       git -C sparse-index ls-files --sparse --stage >cache &&
        for dir in folder1 folder2 x
        do
                TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
-               grep "040000 tree $TREE $dir/" cache \
+               grep "040000 $TREE 0    $dir/" cache \
                        || return 1
        done &&
 
        git -C sparse-index sparse-checkout set folder1 &&
 
-       test-tool -C sparse-index read-cache --table >cache &&
+       git -C sparse-index ls-files --sparse --stage >cache &&
        for dir in deep folder2 x
        do
                TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
-               grep "040000 tree $TREE $dir/" cache \
+               grep "040000 $TREE 0    $dir/" cache \
                        || return 1
        done &&
 
        git -C sparse-index sparse-checkout set deep/deeper1 &&
 
-       test-tool -C sparse-index read-cache --table >cache &&
+       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 $TREE $dir/" cache \
+               grep "040000 $TREE 0    $dir/" cache \
                        || return 1
        done &&
 
-       # Disabling the sparse-index removes tree entries with full ones
+       # Disabling the sparse-index replaces tree entries with full ones
        git -C sparse-index sparse-checkout init --no-sparse-index &&
-
-       test-tool -C sparse-index read-cache --table >cache &&
-       ! grep "040000 tree" cache &&
-       test_sparse_match test-tool read-cache --table
+       test_sparse_match git ls-files --stage --sparse
 '
 
 test_expect_success 'expanded in-memory index matches full index' '
        init_repos &&
-       test_sparse_match test-tool read-cache --expand --table
+       test_sparse_match git ls-files --stage
 '
 
 test_expect_success 'status with options' '
@@ -801,9 +798,9 @@ test_expect_success 'submodule handling' '
 
        # having a submodule prevents "modules" from collapse
        test_sparse_match git sparse-checkout set deep/deeper1 &&
-       test-tool -C sparse-index read-cache --table >cache &&
-       grep "100644 blob .*    modules/a" cache &&
-       grep "160000 commit $(git -C initial-repo rev-parse HEAD)       modules/sub" cache
+       git -C sparse-index ls-files --sparse --stage >cache &&
+       grep "100644 .* modules/a" cache &&
+       grep "160000 $(git -C initial-repo rev-parse HEAD) 0    modules/sub" cache
 '
 
 # When working with a sparse index, some commands will need to expand the
@@ -816,6 +813,12 @@ test_expect_success 'sparse-index is expanded and converted back' '
        GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
                git -C sparse-index reset -- folder1/a &&
        test_region index convert_to_sparse trace2.txt &&
+       test_region index ensure_full_index trace2.txt &&
+
+       # ls-files expands on read, but does not write.
+       rm trace2.txt &&
+       GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
+               git -C sparse-index ls-files &&
        test_region index ensure_full_index trace2.txt
 '
 
@@ -871,6 +874,7 @@ test_expect_success 'sparse-index is not expanded' '
        init_repos &&
 
        ensure_not_expanded status &&
+       ensure_not_expanded ls-files --sparse &&
        ensure_not_expanded commit --allow-empty -m empty &&
        echo >>sparse-index/a &&
        ensure_not_expanded commit -a -m a &&
@@ -1009,6 +1013,100 @@ test_expect_success 'sparse index is not expanded: blame' '
        done
 '
 
+test_expect_success 'sparse index is not expanded: fetch/pull' '
+       init_repos &&
+
+       git -C sparse-index remote add full "file://$(pwd)/full-checkout" &&
+       ensure_not_expanded fetch full &&
+       git -C full-checkout commit --allow-empty -m "for pull merge" &&
+       git -C sparse-index commit --allow-empty -m "for pull merge" &&
+       ensure_not_expanded pull full base
+'
+
+test_expect_success 'ls-files' '
+       init_repos &&
+
+       # Use a smaller sparse-checkout for reduced output
+       test_sparse_match git sparse-checkout set &&
+
+       # Behavior agrees by default. Sparse index is expanded.
+       test_all_match git ls-files &&
+
+       # With --sparse, the sparse index data changes behavior.
+       git -C sparse-index ls-files --sparse >actual &&
+
+       cat >expect <<-\EOF &&
+       a
+       deep/
+       e
+       folder1-
+       folder1.x
+       folder1/
+       folder10
+       folder2/
+       g
+       x/
+       z
+       EOF
+
+       test_cmp expect actual &&
+
+       # With --sparse and no sparse index, nothing changes.
+       git -C sparse-checkout ls-files >dense &&
+       git -C sparse-checkout ls-files --sparse >sparse &&
+       test_cmp dense sparse &&
+
+       # Set up a strange condition of having a file edit
+       # outside of the sparse-checkout cone. This is just
+       # to verify that sparse-checkout and sparse-index
+       # behave the same in this case.
+       write_script edit-content <<-\EOF &&
+       mkdir folder1 &&
+       echo content >>folder1/a
+       EOF
+       run_on_sparse ../edit-content &&
+
+       # ls-files does not currently notice modified files whose
+       # cache entries are marked SKIP_WORKTREE. This may change
+       # in the future, but here we test that sparse index does
+       # not accidentally create a change of behavior.
+       test_sparse_match git ls-files --modified &&
+       test_must_be_empty sparse-checkout-out &&
+       test_must_be_empty sparse-index-out &&
+
+       git -C sparse-index ls-files --sparse --modified >sparse-index-out &&
+       test_must_be_empty sparse-index-out &&
+
+       # Add folder1 to the sparse-checkout cone and
+       # check that ls-files shows the expanded files.
+       test_sparse_match git sparse-checkout add folder1 &&
+       test_sparse_match git ls-files --modified &&
+
+       test_all_match git ls-files &&
+       git -C sparse-index ls-files --sparse >actual &&
+
+       cat >expect <<-\EOF &&
+       a
+       deep/
+       e
+       folder1-
+       folder1.x
+       folder1/0/0/0
+       folder1/0/1
+       folder1/a
+       folder10
+       folder2/
+       g
+       x/
+       z
+       EOF
+
+       test_cmp expect actual &&
+
+       # Double-check index expansion is avoided
+       ensure_not_expanded ls-files --sparse
+'
+
 # 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' '
@@ -1024,13 +1122,13 @@ test_expect_success 'reset mixed and checkout orphan' '
        # the sparse checkouts skip "adding" the other side of
        # the conflict.
        test_sparse_match git reset --mixed HEAD~1 &&
-       test_sparse_match test-tool read-cache --table --expand &&
+       test_sparse_match git ls-files --stage &&
        test_sparse_match git status --porcelain=v2 &&
 
        # At this point, sparse-checkouts behave differently
        # from the full-checkout.
        test_sparse_match git checkout --orphan new-branch &&
-       test_sparse_match test-tool read-cache --table --expand &&
+       test_sparse_match git ls-files --stage &&
        test_sparse_match git status --porcelain=v2
 '
 
index f8031afaaf9199a48c1bd359c3c120be2abf65c4..78359f1f4a2d736f44b84075013e647a7fab3660 100755 (executable)
@@ -718,8 +718,8 @@ test_expect_success bool '
        rm -f result &&
        for i in 1 2 3 4
        do
-           git config --bool --get bool.true$i >>result
-           git config --bool --get bool.false$i >>result
+           git config --bool --get bool.true$i >>result &&
+           git config --bool --get bool.false$i >>result || return 1
        done &&
        test_cmp expect result'
 
@@ -902,7 +902,7 @@ test_expect_success 'get --expiry-date' '
        EOF
        : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" &&
        {
-               echo "$rel_out $(git config --expiry-date date.valid1)"
+               echo "$rel_out $(git config --expiry-date date.valid1)" &&
                git config --expiry-date date.valid2 &&
                git config --expiry-date date.valid3 &&
                git config --expiry-date date.valid4 &&
index 640659c9d7a80ccfaf684eaebabcf173fefa5479..cf58cf025cd2af621f6d58cdaf02d3be0480190c 100755 (executable)
@@ -1368,7 +1368,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches
 (
        for i in $(test_seq 33)
        do
-               echo "create refs/heads/$i HEAD"
+               echo "create refs/heads/$i HEAD" || exit 1
        done >large_input &&
        run_with_limited_open_files git update-ref --stdin <large_input &&
        git rev-parse --verify -q refs/heads/33
@@ -1379,7 +1379,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches
 (
        for i in $(test_seq 33)
        do
-               echo "delete refs/heads/$i HEAD"
+               echo "delete refs/heads/$i HEAD" || exit 1
        done >large_input &&
        run_with_limited_open_files git update-ref --stdin <large_input &&
        test_must_fail git rev-parse --verify -q refs/heads/33
index 4d261e80c6ff3117b06f3b383c45074aed3effdf..9252a581abf8a702fffb01bc7c388666207d5251 100755 (executable)
@@ -79,7 +79,7 @@ test_expect_success 'show-ref --verify -q' '
 test_expect_success 'show-ref -d' '
        {
                echo $(git rev-parse refs/tags/A) refs/tags/A &&
-               echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}"
+               echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" &&
                echo $(git rev-parse refs/tags/C) refs/tags/C
        } >expect &&
        git show-ref -d A C >actual &&
@@ -124,14 +124,14 @@ test_expect_success 'show-ref -d' '
 test_expect_success 'show-ref --heads, --tags, --head, pattern' '
        for branch in B main side
        do
-               echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
+               echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
        done >expect.heads &&
        git show-ref --heads >actual &&
        test_cmp expect.heads actual &&
 
        for tag in A B C
        do
-               echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
+               echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
        done >expect.tags &&
        git show-ref --tags >actual &&
        test_cmp expect.tags actual &&
@@ -149,7 +149,7 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
 
        {
                echo $(git rev-parse HEAD) HEAD &&
-               echo $(git rev-parse refs/heads/B) refs/heads/B
+               echo $(git rev-parse refs/heads/B) refs/heads/B &&
                echo $(git rev-parse refs/tags/B) refs/tags/B
        } >expect &&
        git show-ref --head B >actual &&
@@ -157,8 +157,8 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
 
        {
                echo $(git rev-parse HEAD) HEAD &&
-               echo $(git rev-parse refs/heads/B) refs/heads/B
-               echo $(git rev-parse refs/tags/B) refs/tags/B
+               echo $(git rev-parse refs/heads/B) refs/heads/B &&
+               echo $(git rev-parse refs/tags/B) refs/tags/B &&
                echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
        } >expect &&
        git show-ref --head -d B >actual &&
index d42f067ff8ca0feefcb7cc28a6fc549bd31827bd..d7ddf7612d48363ccbac0a4a80d8399bae7b453f 100755 (executable)
@@ -349,12 +349,12 @@ test_expect_success SHA1 'parsing reverse reflogs at BUFSIZ boundaries' '
                printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" &&
                if test $i = 75; then
                        for j in $(test_seq 1 89); do
-                               printf X
+                               printf X || return 1
                        done
                else
                        printf X
                fi &&
-               printf "\n"
+               printf "\n" || return 1
        done >.git/logs/refs/heads/reflogskip &&
        git rev-parse reflogskip@{73} >actual &&
        echo ${zf}03 >expect &&
index 7891a6becf3a0b4092b2a3fd91ed6679e24cdd08..b0119bf8bc8417439bee91bb7c1add21bc460c2e 100755 (executable)
@@ -34,10 +34,7 @@ fi
 test_expect_success 'blob and tree' '
        test_tick &&
        (
-               for i in 0 1 2 3 4 5 6 7 8 9
-               do
-                       echo $i
-               done &&
+               test_write_lines 0 1 2 3 4 5 6 7 8 9 &&
                echo &&
                echo b1rwzyc3
        ) >a0blgqsjc &&
@@ -204,10 +201,7 @@ test_expect_success 'more history' '
        git checkout v1.0.0^0 &&
        git mv a0blgqsjc f5518nwu &&
 
-       for i in h62xsjeu j08bekfvt kg7xflhm
-       do
-               echo $i
-       done >>f5518nwu &&
+       test_write_lines h62xsjeu j08bekfvt kg7xflhm >>f5518nwu &&
        git add f5518nwu &&
 
        test_tick &&
@@ -387,7 +381,7 @@ test_expect_success 'ambiguous commits are printed by type first, then hash orde
        do
                grep $type objects >$type.objects &&
                sort $type.objects >$type.objects.sorted &&
-               test_cmp $type.objects.sorted $type.objects
+               test_cmp $type.objects.sorted $type.objects || return 1
        done
 '
 
index decd2527ed6427fe760d082cedc8a37d0df4f312..b4ab166369ec06c69add33eb240d69531459276c 100755 (executable)
@@ -48,10 +48,10 @@ test_expect_success 'enable split index' '
        # NEEDSWORK: Stop hard-coding checksums.
        if test "$indexversion" = "4"
        then
-               own=$(test_oid own_v4)
+               own=$(test_oid own_v4) &&
                base=$(test_oid base_v4)
        else
-               own=$(test_oid own_v3)
+               own=$(test_oid own_v3) &&
                base=$(test_oid base_v3)
        fi &&
 
index 9bb503a97578c1d43a01409a93e2dd4f7c207a43..b16d69ca4ae0e8b61ce00a085273d8ad6f40f104 100755 (executable)
@@ -57,7 +57,7 @@ test_expect_success 'checkout all stage 0 to temporary files' '
                test $(grep $f actual | cut "-d " -f2) = $f &&
                p=$(grep $f actual | cut "-d    " -f1) &&
                test -f $p &&
-               test $(cat $p) = tree1$f
+               test $(cat $p) = tree1$f || return 1
        done
 '
 
@@ -85,7 +85,7 @@ test_expect_success 'checkout all stage 2 to temporary files' '
                test $(grep $f actual | cut "-d " -f2) = $f &&
                p=$(grep $f actual | cut "-d    " -f1) &&
                test -f $p &&
-               test $(cat $p) = tree2$f
+               test $(cat $p) = tree2$f || return 1
        done
 '
 
index 0e7d47ab318338a211bf444f890176086b9fed5d..42601d5a310de33185c40f928b566a45c9985f1c 100755 (executable)
@@ -49,14 +49,14 @@ test_expect_success '"checkout -" detaches again' '
 test_expect_success 'more switches' '
        for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
        do
-               git checkout -b branch$i
+               git checkout -b branch$i || return 1
        done
 '
 
 more_switches () {
        for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
        do
-               git checkout branch$i
+               git checkout branch$i || return 1
        done
 }
 
index d7a3485582dca10de9f1842d0a2aca51b69c9942..c49cdfb6e582f41ea4010df7f4556f7aad5f1cc4 100755 (executable)
@@ -26,7 +26,7 @@ test_expect_success \
 'the index entry must still be a symbolic link' '
 case "$(git ls-files --stage --cached symlink)" in
 120000" "*symlink) echo pass;;
-*) echo fail; git ls-files --stage --cached symlink; (exit 1);;
+*) echo fail; git ls-files --stage --cached symlink; false;;
 esac'
 
 test_done
index b304714fdb1aca63e85ab89651e51ad84264ec3a..e9451cd567cd61ffb678ee33d3c01e646b4cbe3a 100755 (executable)
@@ -24,7 +24,7 @@ test_expect_success basics '
        test_cmp expect actual &&
 
        git update-index --add one two three &&
-       for i in one three two; do echo $i; done >expect &&
+       test_write_lines one three two >expect &&
        git ls-files >actual &&
        test_cmp expect actual &&
 
index a8297c294347125ebf14503a8d9a64d61bbf4ec4..acd3650d3c08cc2ef8227c95d6c89dfd0f063b2f 100755 (executable)
@@ -151,13 +151,13 @@ test_expect_success 'add -u resolves unmerged paths' '
        {
                for path in path1 path2
                do
-                       echo "100644 $one 1     $path"
-                       echo "100644 $two 2     $path"
-                       echo "100644 $three 3   $path"
-               done
-               echo "100644 $one 1     path3"
-               echo "100644 $one 1     path4"
-               echo "100644 $one 3     path5"
+                       echo "100644 $one 1     $path" &&
+                       echo "100644 $two 2     $path" &&
+                       echo "100644 $three 3   $path" || return 1
+               done &&
+               echo "100644 $one 1     path3" &&
+               echo "100644 $one 1     path4" &&
+               echo "100644 $one 3     path5" &&
                echo "100644 $one 3     path6"
        } |
        git update-index --index-info &&
@@ -174,8 +174,8 @@ test_expect_success 'add -u resolves unmerged paths' '
        git add -u &&
        git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
        {
-               echo "100644 $three 0   path1"
-               echo "100644 $two 0     path3"
+               echo "100644 $three 0   path1" &&
+               echo "100644 $two 0     path3" &&
                echo "100644 $two 0     path5"
        } >expect &&
        test_cmp expect actual
index c6876b120f81b60b75e7314eae461078492a585e..dba62d69c6c5c18172bdbc62c5138643cf284b00 100755 (executable)
@@ -98,17 +98,17 @@ test_expect_success modify '
                "
        } >expect &&
        {
-               cat expect
-               echo ":100644 160000 $_empty $ZERO_OID T        yonk"
+               cat expect &&
+               echo ":100644 160000 $_empty $ZERO_OID T        yonk" &&
                echo ":100644 000000 $_empty $ZERO_OID D        zifmia"
        } >expect-files &&
        {
-               cat expect
+               cat expect &&
                echo ":000000 160000 $ZERO_OID $ZERO_OID A      yonk"
        } >expect-index &&
        {
-               echo "100644 $_empty 0  nitfol"
-               echo "160000 $yomin 0   yomin"
+               echo "100644 $_empty 0  nitfol" &&
+               echo "160000 $yomin 0   yomin" &&
                echo "160000 $yonk 0    yonk"
        } >expect-final
 '
index cf0175ad6e414e3a126a205d56a9d910ec173641..db7ca55998666138f3580fe430dfe53ece43be13 100755 (executable)
@@ -116,7 +116,7 @@ test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
                mkdir 2 &&
                for f in 1 2/1 2/2 3
                do
-                       echo "$f" >"$f"
+                       echo "$f" >"$f" || return 1
                done &&
                git add 1 2/2 3 &&
                git add -N 2/1 &&
diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh
new file mode 100755 (executable)
index 0000000..f6d8d7d
--- /dev/null
@@ -0,0 +1,277 @@
+#!/bin/sh
+
+test_description='Test handling of the current working directory becoming empty'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+       test_commit init &&
+
+       git branch fd_conflict &&
+
+       mkdir -p foo/bar &&
+       test_commit foo/bar/baz &&
+
+       git revert HEAD &&
+       git tag reverted &&
+
+       git checkout fd_conflict &&
+       mkdir dirORfile &&
+       test_commit dirORfile/foo &&
+
+       git rm -r dirORfile &&
+       echo not-a-directory >dirORfile &&
+       git add dirORfile &&
+       git commit -m dirORfile &&
+
+       git switch -c df_conflict HEAD~1 &&
+       test_commit random_file &&
+
+       git switch -c undo_fd_conflict fd_conflict &&
+       git revert HEAD
+'
+
+test_incidental_dir_removal () {
+       test_when_finished "git reset --hard" &&
+
+       git checkout foo/bar/baz^{commit} &&
+       test_path_is_dir foo/bar &&
+
+       (
+               cd foo &&
+               "$@" &&
+
+               # Make sure foo still exists, and commands needing it work
+               test-tool getcwd &&
+               git status --porcelain
+       ) &&
+       test_path_is_missing foo/bar/baz &&
+       test_path_is_missing foo/bar &&
+
+       test_path_is_dir foo
+}
+
+test_required_dir_removal () {
+       git checkout df_conflict^{commit} &&
+       test_when_finished "git clean -fdx" &&
+
+       (
+               cd dirORfile &&
+
+               # Ensure command refuses to run
+               test_must_fail "$@" 2>../error &&
+               grep "Refusing to remove.*current working directory" ../error &&
+
+               # ...and that the index and working tree are left clean
+               git diff --exit-code HEAD &&
+
+               # Ensure that getcwd and git status do not error out (which
+               # they might if the current working directory had been removed)
+               test-tool getcwd &&
+               git status --porcelain
+       ) &&
+
+       test_path_is_dir dirORfile
+}
+
+test_expect_success 'checkout does not clean cwd incidentally' '
+       test_incidental_dir_removal git checkout init
+'
+
+test_expect_success 'checkout fails if cwd needs to be removed' '
+       test_required_dir_removal git checkout fd_conflict
+'
+
+test_expect_success 'reset --hard does not clean cwd incidentally' '
+       test_incidental_dir_removal git reset --hard init
+'
+
+test_expect_success 'reset --hard fails if cwd needs to be removed' '
+       test_required_dir_removal git reset --hard fd_conflict
+'
+
+test_expect_success 'merge does not clean cwd incidentally' '
+       test_incidental_dir_removal git merge reverted
+'
+
+# This file uses some simple merges where
+#   Base: 'dirORfile/' exists
+#   Side1: random other file changed
+#   Side2: 'dirORfile/' removed, 'dirORfile' added
+# this should resolve cleanly, but merge-recursive throws merge conflicts
+# because it's dumb.  Add a special test for checking merge-recursive (and
+# merge-ort), then after this just hard require ort for all remaining tests.
+#
+test_expect_success 'merge fails if cwd needs to be removed; recursive friendly' '
+       git checkout foo/bar/baz &&
+       test_when_finished "git clean -fdx" &&
+
+       mkdir dirORfile &&
+       (
+               cd dirORfile &&
+
+               test_must_fail git merge fd_conflict 2>../error
+       ) &&
+
+       test_path_is_dir dirORfile &&
+       grep "Refusing to remove the current working directory" error
+'
+
+GIT_TEST_MERGE_ALGORITHM=ort
+
+test_expect_success 'merge fails if cwd needs to be removed' '
+       test_required_dir_removal git merge fd_conflict
+'
+
+test_expect_success 'cherry-pick does not clean cwd incidentally' '
+       test_incidental_dir_removal git cherry-pick reverted
+'
+
+test_expect_success 'cherry-pick fails if cwd needs to be removed' '
+       test_required_dir_removal git cherry-pick fd_conflict
+'
+
+test_expect_success 'rebase does not clean cwd incidentally' '
+       test_incidental_dir_removal git rebase reverted
+'
+
+test_expect_success 'rebase fails if cwd needs to be removed' '
+       test_required_dir_removal git rebase fd_conflict
+'
+
+test_expect_success 'revert does not clean cwd incidentally' '
+       test_incidental_dir_removal git revert HEAD
+'
+
+test_expect_success 'revert fails if cwd needs to be removed' '
+       test_required_dir_removal git revert undo_fd_conflict
+'
+
+test_expect_success 'rm does not clean cwd incidentally' '
+       test_incidental_dir_removal git rm bar/baz.t
+'
+
+test_expect_success 'apply does not remove cwd incidentally' '
+       git diff HEAD HEAD~1 >patch &&
+       test_incidental_dir_removal git apply ../patch
+'
+
+test_incidental_untracked_dir_removal () {
+       test_when_finished "git reset --hard" &&
+
+       git checkout foo/bar/baz^{commit} &&
+       mkdir -p untracked &&
+       mkdir empty
+       >untracked/random &&
+
+       (
+               cd untracked &&
+               "$@" &&
+
+               # Make sure untracked still exists, and commands needing it work
+               test-tool getcwd &&
+               git status --porcelain
+       ) &&
+       test_path_is_missing empty &&
+       test_path_is_missing untracked/random &&
+
+       test_path_is_dir untracked
+}
+
+test_expect_success 'clean does not remove cwd incidentally' '
+       test_incidental_untracked_dir_removal \
+               git -C .. clean -fd -e warnings . >warnings &&
+       grep "Refusing to remove current working directory" warnings
+'
+
+test_expect_success 'stash does not remove cwd incidentally' '
+       test_incidental_untracked_dir_removal \
+               git stash --include-untracked
+'
+
+test_expect_success '`rm -rf dir` only removes a subset of dir' '
+       test_when_finished "rm -rf a/" &&
+
+       mkdir -p a/b/c &&
+       >a/b/c/untracked &&
+       >a/b/c/tracked &&
+       git add a/b/c/tracked &&
+
+       (
+               cd a/b &&
+               git rm -rf ../b
+       ) &&
+
+       test_path_is_dir a/b &&
+       test_path_is_missing a/b/c/tracked &&
+       test_path_is_file a/b/c/untracked
+'
+
+test_expect_success '`rm -rf dir` even with only tracked files will remove something else' '
+       test_when_finished "rm -rf a/" &&
+
+       mkdir -p a/b/c &&
+       >a/b/c/tracked &&
+       git add a/b/c/tracked &&
+
+       (
+               cd a/b &&
+               git rm -rf ../b
+       ) &&
+
+       test_path_is_missing a/b/c/tracked &&
+       test_path_is_missing a/b/c &&
+       test_path_is_dir a/b
+'
+
+test_expect_success 'git version continues working from a deleted dir' '
+       mkdir tmp &&
+       (
+               cd tmp &&
+               rm -rf ../tmp &&
+               git version
+       )
+'
+
+test_submodule_removal () {
+       path_status=$1 &&
+       shift &&
+
+       test_status=
+       test "$path_status" = dir && test_status=test_must_fail
+
+       test_when_finished "git reset --hard HEAD~1" &&
+       test_when_finished "rm -rf .git/modules/my_submodule" &&
+
+       git checkout foo/bar/baz &&
+
+       git init my_submodule &&
+       touch my_submodule/file &&
+       git -C my_submodule add file &&
+       git -C my_submodule commit -m "initial commit" &&
+       git submodule add ./my_submodule &&
+       git commit -m "Add the submodule" &&
+
+       (
+               cd my_submodule &&
+               $test_status "$@"
+       ) &&
+
+       test_path_is_${path_status} my_submodule
+}
+
+test_expect_success 'rm -r with -C leaves submodule if cwd inside' '
+       test_submodule_removal dir git -C .. rm -r my_submodule/
+'
+
+test_expect_success 'rm -r leaves submodule if cwd inside' '
+       test_submodule_removal dir \
+               git --git-dir=../.git --work-tree=.. rm -r ../my_submodule/
+'
+
+test_expect_success 'rm -rf removes submodule even if cwd inside' '
+       test_submodule_removal missing \
+               git --git-dir=../.git --work-tree=.. rm -rf ../my_submodule/
+'
+
+test_done
index 6ba8b589cd00d3ad401f4018dc0eed7be1b54e05..fbfa210a50b2906e57853095a2830f3bc6e18136 100755 (executable)
@@ -39,10 +39,7 @@ test_expect_success 'ls-files with mixed levels' '
 test_expect_success 'ls-files -c' '
        (
                cd top/sub &&
-               for f in ../y*
-               do
-                       echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
-               done >expect.err &&
+               printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../y* >expect.err &&
                echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
                ls ../x* >expect.out &&
                test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err &&
@@ -54,10 +51,7 @@ test_expect_success 'ls-files -c' '
 test_expect_success 'ls-files -o' '
        (
                cd top/sub &&
-               for f in ../x*
-               do
-                       echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
-               done >expect.err &&
+               printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../x* >expect.err &&
                echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
                ls ../y* >expect.out &&
                test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&
index 72d5b014d82c6c3fbdbf693a791e8599138594c0..f9539968e4c16a53e2d0add8b448c7338925828f 100755 (executable)
@@ -193,7 +193,7 @@ match() {
                file=$(cat .git/expected_test_file) &&
                if should_create_test_file "$file"
                then
-                       dirs=${file%/*}
+                       dirs=${file%/*} &&
                        if test "$file" != "$dirs"
                        then
                                mkdir -p -- "$dirs" &&
index d4d64401e4b08f0bebd62ba5191310a6b173b80b..7a1be73ce8771b851dfc2c7a95d80dece4c2b5cb 100755 (executable)
@@ -12,7 +12,7 @@ test_expect_success 'setup' '
        for i in $(test_seq 1 10)
        do
                git checkout -b branch$i initial &&
-               test_commit --no-tag branch$i
+               test_commit --no-tag branch$i || return 1
        done &&
        git for-each-ref \
                --sort=version:refname \
@@ -52,7 +52,7 @@ test_expect_success 'show-branch with more than 8 branches' '
 test_expect_success 'show-branch with showbranch.default' '
        for branch in $(cat branches.sorted)
        do
-               test_config showbranch.default $branch --add
+               test_config showbranch.default $branch --add || return 1
        done &&
        git show-branch >actual &&
        test_cmp expect actual
@@ -127,7 +127,7 @@ test_expect_success 'show branch --merge-base with one argument' '
        do
                git rev-parse $branch >expect &&
                git show-branch --merge-base $branch >actual &&
-               test_cmp expect actual
+               test_cmp expect actual || return 1
        done
 '
 
@@ -136,7 +136,7 @@ test_expect_success 'show branch --merge-base with two arguments' '
        do
                git rev-parse initial >expect &&
                git show-branch --merge-base initial $branch >actual &&
-               test_cmp expect actual
+               test_cmp expect actual || return 1
        done
 '
 
index f5fd80d4d3f492776931e1da4a5761bdc162e663..7e0a8960af886fb83d555766919e34fcd532bf7c 100755 (executable)
@@ -31,7 +31,7 @@ verify_notes () {
        while [ $i -gt 0 ]; do
                echo "    commit #$i" &&
                echo "    note for commit #$i" &&
-               i=$(($i-1));
+               i=$(($i-1)) || return 1
        done > expect &&
        test_cmp expect output
 }
@@ -43,7 +43,7 @@ test_expect_success "setup: create $number_of_commits commits" '
                while [ $nr -lt $number_of_commits ]; do
                        nr=$(($nr+1)) &&
                        test_tick &&
-                       cat <<INPUT_END
+                       cat <<INPUT_END || return 1
 commit refs/heads/main
 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 data <<COMMIT
@@ -179,7 +179,7 @@ verify_concatenated_notes () {
                echo "    first note for commit #$i" &&
                echo "    " &&
                echo "    second note for commit #$i" &&
-               i=$(($i-1));
+               i=$(($i-1)) || return 1
        done > expect &&
        test_cmp expect output
 }
index 960d0587e189a57049d64688c995bff580ac42ef..1f5964865ae173e05fab2070c179ff305886bf82 100755 (executable)
@@ -58,7 +58,7 @@ test_expect_success 'many notes created correctly with git-notes' '
        do
                echo "    commit #$i" &&
                echo "    note #$i" &&
-               i=$(($i - 1));
+               i=$(($i - 1)) || return 1
        done > expect &&
        test_cmp expect output
 '
@@ -107,7 +107,7 @@ test_expect_success 'most notes deleted correctly with git-notes' '
        do
                echo "    commit #$i" &&
                echo "    note #$i" &&
-               i=$(($i - 1));
+               i=$(($i - 1)) || return 1
        done > expect &&
        test_cmp expect output
 '
index cfde68f1939baeba49dc1b0d34d2c666042f9177..7e46f4ca850616b695cc6ffa061ca39ac404fb7d 100755 (executable)
@@ -68,7 +68,7 @@ test_expect_success 'merge and rebase should match' '
        if test -s difference
        then
                cat difference
-               (exit 1)
+               false
        else
                echo happy
        fi
@@ -102,7 +102,7 @@ test_expect_success 'merge and rebase should match' '
        if test -s difference
        then
                cat difference
-               (exit 1)
+               false
        else
                echo happy
        fi
@@ -117,7 +117,7 @@ test_expect_success 'picking rebase' '
                echo happy
        else
                git show-branch
-               (exit 1)
+               false
        fi &&
        f=$(git diff-tree --name-only HEAD^ HEAD) &&
        g=$(git diff-tree --name-only HEAD^^ HEAD^) &&
@@ -127,7 +127,7 @@ test_expect_success 'picking rebase' '
        *)
                echo "$f"
                echo "$g"
-               (exit 1)
+               false
        esac
 '
 
index 0baa68e9b4f89fa03f569eee4c779c4e1297e916..a38f2da7691e870f8dfa90936c0107d7d080e0d1 100755 (executable)
@@ -824,7 +824,7 @@ test_expect_success 'always cherry-pick with --no-ff' '
        do
                test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
                git diff HEAD~$p original-no-ff-branch~$p > out &&
-               test_must_be_empty out
+               test_must_be_empty out || return 1
        done &&
        test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
        git diff HEAD~3 original-no-ff-branch~3 > out &&
@@ -1339,7 +1339,7 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
                test_seq 5 | sed "s/$double/&&/" >seq &&
                git add seq &&
                test_tick &&
-               git commit -m seq-$double
+               git commit -m seq-$double || return 1
        done &&
        git tag seq-onto &&
        git reset --hard HEAD~2 &&
index 946e92f8dac84edcad260d4f7354b996e54b61ec..96f2cf22fafd4795e54928b14b5c2b4b2333e8f3 100755 (executable)
@@ -115,9 +115,7 @@ test_expect_success 'at beginning of file' '
        git config core.whitespace "blank-at-eol" &&
        cp beginning file &&
        git commit -m beginning file &&
-       for i in 1 2 3 4 5; do
-               echo $i
-       done >> file &&
+       test_write_lines 1 2 3 4 5 >>file &&
        git commit -m more file &&
        git rebase --whitespace=fix HEAD^^ &&
        test_cmp expect-beginning file
index 4b5b607673329d30ef71c26f673c36ae0058cc67..8617efaaf1e66f6f5d8246a817085ebd2d43c477 100755 (executable)
@@ -19,7 +19,7 @@ test_expect_success setup '
 
        for l in a b c d e f g h i j k l m n o
        do
-               echo $l$l$l$l$l$l$l$l$l
+               echo $l$l$l$l$l$l$l$l$l || return 1
        done >oops &&
 
        test_tick &&
index e8375d1c970e3313302a2580d742f1e88732070c..2d53ce754c5fb75ceeaa43dc1ba2f748fd58f43e 100755 (executable)
@@ -29,7 +29,7 @@ test_expect_success setup '
                git add file1 &&
                test_tick &&
                git commit -m "$val" &&
-               git tag $val
+               git tag $val || return 1
        done
 '
 
index bb9ef35dac082e396d5cbcbdc83bc5394fb95a7c..e74a318ac33ac00d10e6517b10b838ac8e0c899a 100755 (executable)
@@ -265,7 +265,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft (induce S
 
 test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' '
        choke_git_rm_setup &&
-       OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
+       OUT=$( ((trap "" PIPE && git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
        test_match_signal 13 "$OUT" &&
        test_path_is_missing .git/index.lock
 '
@@ -274,10 +274,7 @@ test_expect_success 'Resolving by removal is not a warning-worthy event' '
        git reset -q --hard &&
        test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
        blob=$(echo blob | git hash-object -w --stdin) &&
-       for stage in 1 2 3
-       do
-               echo "100644 $blob $stage       blob"
-       done | git update-index --index-info &&
+       printf "100644 $blob %d\tblob\n" 1 2 3 | git update-index --index-info &&
        git rm blob >msg 2>&1 &&
        test_i18ngrep ! "needs merge" msg &&
        test_must_fail git ls-files -s --error-unmatch blob
index 283a66955d6dbb8415697a8a911effa6f291f8e9..b1f90ba3250fa39863f6fe58e85b27613e303df4 100755 (executable)
@@ -141,9 +141,9 @@ test_expect_success 'check correct prefix detection' '
 test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries' '
        for s in 1 2 3
        do
-               echo $s > stage$s
-               echo "100755 $(git hash-object -w stage$s) $s   file"
-               echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s       symlink"
+               echo $s > stage$s &&
+               echo "100755 $(git hash-object -w stage$s) $s   file" &&
+               echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s       symlink" || return 1
        done | git update-index --index-info &&
        git config core.filemode 0 &&
        git config core.symlinks 0 &&
@@ -177,7 +177,7 @@ test_expect_success 'git add --refresh' '
        git read-tree HEAD &&
        case "$(git diff-index HEAD -- foo)" in
        :100644" "*"M   foo") echo pass;;
-       *) echo fail; (exit 1);;
+       *) echo fail; false;;
        esac &&
        git add --refresh -- foo &&
        test -z "$(git diff-index HEAD -- foo)"
index f3143c92908d013e4394a76578b1a3fbd5328ab4..81f3384eeed4bba508f2e87aeb72a1a6f9a37394 100755 (executable)
@@ -181,13 +181,13 @@ test_expect_success 'git add fails outside of sparse-checkout definition' '
        # Avoid munging CRLFs to avoid an error message
        git -c core.autocrlf=input add --sparse sparse_entry 2>stderr &&
        test_must_be_empty stderr &&
-       test-tool read-cache --table >actual &&
-       grep "^100644 blob.*sparse_entry\$" actual &&
+       git ls-files --stage >actual &&
+       grep "^100644 .*sparse_entry\$" actual &&
 
        git add --sparse --chmod=+x sparse_entry 2>stderr &&
        test_must_be_empty stderr &&
-       test-tool read-cache --table >actual &&
-       grep "^100755 blob.*sparse_entry\$" actual &&
+       git ls-files --stage >actual &&
+       grep "^100755 .*sparse_entry\$" actual &&
 
        git reset &&
 
index 2c66cfbc3b7fbadaa3f8c7a34a38cba2a6eac37f..b17c52d8807a767cdac0bb35b645d9b076d2a9b2 100755 (executable)
@@ -10,6 +10,25 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
+test_expect_success 'usage on cmd and subcommand invalid option' '
+       test_expect_code 129 git stash --invalid-option 2>usage &&
+       grep "or: git stash" usage &&
+
+       test_expect_code 129 git stash push --invalid-option 2>usage &&
+       ! grep "or: git stash" usage
+'
+
+test_expect_success 'usage on main command -h emits a summary of subcommands' '
+       test_expect_code 129 git stash -h >usage &&
+       grep -F "usage: git stash list" usage &&
+       grep -F "or: git stash show" usage
+'
+
+test_expect_failure 'usage for subcommands should emit subcommand usage' '
+       test_expect_code 129 git stash push -h >usage &&
+       grep -F "usage: git stash [push" usage
+'
+
 diff_cmp () {
        for i in "$1" "$2"
        do
index a8ad5462d96d3e1acda9172f4f77806d7a3e8093..0276edbe3d389b70cace45906626276cce3db44b 100755 (executable)
@@ -70,7 +70,7 @@ test_crlf_subject_body_and_contents() {
                        for ref in ${LIB_CRLF_BRANCHES}
                        do
                                cat .crlf-${file}-\"\${ref}\".txt >>expect &&
-                               printf \"\n\" >>expect
+                               printf \"\n\" >>expect || return 1
                        done &&
                        git $command_and_args --format=\"%${atom}\" >actual &&
                        test_cmp expect actual
@@ -90,7 +90,7 @@ test_expect_success 'branch: --verbose works with messages using CRLF' '
        do
                printf "  " >>expect &&
                cat .crlf-subject-${branch}.txt >>expect &&
-               printf "\n" >>expect
+               printf "\n" >>expect || return 1
        done &&
        git branch -v >tmp &&
        # Remove first two columns, and the line for the currently checked out branch
index 68f2ebca58a3213fa438a792510efab84d71871a..3dc90470446dbb81e9c9421dbc7c21d3648d91f4 100755 (executable)
@@ -174,7 +174,7 @@ test_expect_success 'setup for many rename source candidates' '
        do
                for j in 0 1 2 3 4 5 6 7 8 9;
                do
-                       echo "$i$j" >"path$i$j"
+                       echo "$i$j" >"path$i$j" || return 1
                done
        done &&
        git add "path??" &&
index 00eeafb2ace57226bcec1cae6deb24f111d80ef2..c509143c8141e0c4c2f2696080922f339afd432c 100755 (executable)
@@ -123,7 +123,7 @@ test_expect_success 'diff --stat with binary files and big change count' '
        i=0 &&
        while test $i -lt 10000; do
                echo $i &&
-               i=$(($i + 1))
+               i=$(($i + 1)) || return 1
        done >textfile &&
        git add textfile &&
        git diff --cached --stat binfile textfile >output &&
index 28683d059d3bdcc79b7d0ac0a1add9c164e957c5..750aee17ea9650530a5e716020b4ae05ad6c0ef9 100755 (executable)
@@ -19,8 +19,8 @@ test_expect_success setup '
 
        mkdir dir &&
        mkdir dir2 &&
-       for i in 1 2 3; do echo $i; done >file0 &&
-       for i in A B; do echo $i; done >dir/sub &&
+       test_write_lines 1 2 3 >file0 &&
+       test_write_lines A B >dir/sub &&
        cat file0 >file2 &&
        git add file0 file2 dir/sub &&
        git commit -m Initial &&
@@ -32,8 +32,8 @@ test_expect_success setup '
        GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
 
-       for i in 4 5 6; do echo $i; done >>file0 &&
-       for i in C D; do echo $i; done >>dir/sub &&
+       test_write_lines 4 5 6 >>file0 &&
+       test_write_lines C D >>dir/sub &&
        rm -f file2 &&
        git update-index --remove file0 file2 dir/sub &&
        git commit -m "Second${LF}${LF}This is the second commit." &&
@@ -42,9 +42,9 @@ test_expect_success setup '
        GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
 
-       for i in A B C; do echo $i; done >file1 &&
+       test_write_lines A B C >file1 &&
        git add file1 &&
-       for i in E F; do echo $i; done >>dir/sub &&
+       test_write_lines E F >>dir/sub &&
        git update-index dir/sub &&
        git commit -m Third &&
 
@@ -53,8 +53,8 @@ test_expect_success setup '
        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
 
        git checkout side &&
-       for i in A B C; do echo $i; done >>file0 &&
-       for i in 1 2; do echo $i; done >>dir/sub &&
+       test_write_lines A B C >>file0 &&
+       test_write_lines 1 2 >>dir/sub &&
        cat dir/sub >file3 &&
        git add file3 &&
        git update-index file0 dir/sub &&
@@ -71,8 +71,8 @@ test_expect_success setup '
        GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
 
-       for i in A B C; do echo $i; done >>file0 &&
-       for i in 1 2; do echo $i; done >>dir/sub &&
+       test_write_lines A B C >>file0 &&
+       test_write_lines 1 2 >>dir/sub &&
        git update-index file0 dir/sub &&
 
        mkdir dir3 &&
@@ -86,7 +86,7 @@ test_expect_success setup '
        GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
        export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
        git checkout -b rearrange initial &&
-       for i in B A; do echo $i; done >dir/sub &&
+       test_write_lines B A >dir/sub &&
        git add dir/sub &&
        git commit -m "Rearranged lines in dir/sub" &&
        git checkout master &&
index 712d4b5ddf0b1ba028c5d16b1fbb7067d83301fe..7dc5a5c736e3f2db0c4bc29c20321b6a386661df 100755 (executable)
@@ -12,25 +12,25 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_expect_success setup '
-       for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 10 >file &&
        cat file >elif &&
        git add file elif &&
        test_tick &&
        git commit -m Initial &&
        git checkout -b side &&
 
-       for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
+       test_write_lines 1 2 5 6 A B C 7 8 9 10 >file &&
        test_chmod +x elif &&
        test_tick &&
        git commit -m "Side changes #1" &&
 
-       for i in D E F; do echo "$i"; done >>file &&
+       test_write_lines D E F >>file &&
        git update-index file &&
        test_tick &&
        git commit -m "Side changes #2" &&
        git tag C2 &&
 
-       for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
+       test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file &&
        git update-index file &&
        test_tick &&
        git commit -m "Side changes #3 with \\n backslash-n in it." &&
@@ -43,18 +43,18 @@ test_expect_success setup '
 
        git checkout side &&
        git checkout -b patchid &&
-       for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file2 &&
-       for i in 1 2 3 A 4 B C 7 8 9 10 D E F 5 6; do echo "$i"; done >file3 &&
-       for i in 8 9 10; do echo "$i"; done >file &&
+       test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file2 &&
+       test_write_lines 1 2 3 A 4 B C 7 8 9 10 D E F 5 6 >file3 &&
+       test_write_lines 8 9 10 >file &&
        git add file file2 file3 &&
        test_tick &&
        git commit -m "patchid 1" &&
-       for i in 4 A B 7 8 9 10; do echo "$i"; done >file2 &&
-       for i in 8 9 10 5 6; do echo "$i"; done >file3 &&
+       test_write_lines 4 A B 7 8 9 10 >file2 &&
+       test_write_lines 8 9 10 5 6 >file3 &&
        git add file2 file3 &&
        test_tick &&
        git commit -m "patchid 2" &&
-       for i in 10 5 6; do echo "$i"; done >file &&
+       test_write_lines 10 5 6 >file &&
        git add file &&
        test_tick &&
        git commit -m "patchid 3" &&
@@ -325,7 +325,7 @@ test_expect_success 'filename length limit' '
                max=$(
                        for patch in 000[1-9]-*.patch
                        do
-                               echo "$patch" | wc -c
+                               echo "$patch" | wc -c || exit 1
                        done |
                        sort -nr |
                        head -n 1
@@ -343,7 +343,7 @@ test_expect_success 'filename length limit from config' '
                max=$(
                        for patch in 000[1-9]-*.patch
                        do
-                               echo "$patch" | wc -c
+                               echo "$patch" | wc -c || exit 1
                        done |
                        sort -nr |
                        head -n 1
@@ -361,7 +361,7 @@ test_expect_success 'filename limit applies only to basename' '
                max=$(
                        for patch in patches/000[1-9]-*.patch
                        do
-                               echo "${patch#patches/}" | wc -c
+                               echo "${patch#patches/}" | wc -c || exit 1
                        done |
                        sort -nr |
                        head -n 1
@@ -653,7 +653,7 @@ test_expect_success 'excessive subject' '
        git checkout side &&
        before=$(git hash-object file) &&
        before=$(git rev-parse --short $before) &&
-       for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
+       test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >>file &&
        after=$(git hash-object file) &&
        after=$(git rev-parse --short $after) &&
        git update-index file &&
@@ -1086,7 +1086,7 @@ test_expect_success TTY 'format-patch --stdout paginates' '
 test_expect_success 'format-patch handles multi-line subjects' '
        rm -rf patches/ &&
        echo content >>file &&
-       for i in one two three; do echo $i; done >msg &&
+       test_write_lines one two three >msg &&
        git add file &&
        git commit -F msg &&
        git format-patch -o patches -1 &&
@@ -1098,7 +1098,7 @@ test_expect_success 'format-patch handles multi-line subjects' '
 test_expect_success 'format-patch handles multi-line encoded subjects' '
        rm -rf patches/ &&
        echo content >>file &&
-       for i in en tvÃ¥ tre; do echo $i; done >msg &&
+       test_write_lines en tvÃ¥ tre >msg &&
        git add file &&
        git commit -F msg &&
        git format-patch -o patches -1 &&
index 2c13b62d3c654807b85307748c1ec52b6f4155ff..9babf13bc9b977737167569adb4586da336a5470 100755 (executable)
@@ -843,7 +843,7 @@ test_expect_success 'whitespace changes with modification reported (diffstat)' '
 
 test_expect_success 'whitespace-only changes reported across renames (diffstat)' '
        git reset --hard &&
-       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
+       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x &&
        git add x &&
        git commit -m "base" &&
        sed -e "5s/^/ /" x >z &&
@@ -859,7 +859,7 @@ test_expect_success 'whitespace-only changes reported across renames (diffstat)'
 
 test_expect_success 'whitespace-only changes reported across renames' '
        git reset --hard HEAD~1 &&
-       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
+       for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x &&
        git add x &&
        hash_x=$(git hash-object x) &&
        before=$(git rev-parse --short "$hash_x") &&
@@ -1442,6 +1442,143 @@ test_expect_success 'detect permutations inside moved code -- dimmed-zebra' '
        test_cmp expected actual
 '
 
+test_expect_success 'zebra alternate color is only used when necessary' '
+       cat >old.txt <<-\EOF &&
+       line 1A should be marked as oldMoved newMovedAlternate
+       line 1B should be marked as oldMoved newMovedAlternate
+       unchanged
+       line 2A should be marked as oldMoved newMovedAlternate
+       line 2B should be marked as oldMoved newMovedAlternate
+       line 3A should be marked as oldMovedAlternate newMoved
+       line 3B should be marked as oldMovedAlternate newMoved
+       unchanged
+       line 4A should be marked as oldMoved newMovedAlternate
+       line 4B should be marked as oldMoved newMovedAlternate
+       line 5A should be marked as oldMovedAlternate newMoved
+       line 5B should be marked as oldMovedAlternate newMoved
+       line 6A should be marked as oldMoved newMoved
+       line 6B should be marked as oldMoved newMoved
+       EOF
+       cat >new.txt <<-\EOF &&
+         line 1A should be marked as oldMoved newMovedAlternate
+         line 1B should be marked as oldMoved newMovedAlternate
+       unchanged
+         line 3A should be marked as oldMovedAlternate newMoved
+         line 3B should be marked as oldMovedAlternate newMoved
+         line 2A should be marked as oldMoved newMovedAlternate
+         line 2B should be marked as oldMoved newMovedAlternate
+       unchanged
+         line 6A should be marked as oldMoved newMoved
+         line 6B should be marked as oldMoved newMoved
+           line 4A should be marked as oldMoved newMovedAlternate
+           line 4B should be marked as oldMoved newMovedAlternate
+         line 5A should be marked as oldMovedAlternate newMoved
+         line 5B should be marked as oldMovedAlternate newMoved
+       EOF
+       test_expect_code 1 git diff --no-index --color --color-moved=zebra \
+                --color-moved-ws=allow-indentation-change \
+                old.txt new.txt >output &&
+       grep -v index output | test_decode_color >actual &&
+       cat >expected <<-\EOF &&
+       <BOLD>diff --git a/old.txt b/new.txt<RESET>
+       <BOLD>--- a/old.txt<RESET>
+       <BOLD>+++ b/new.txt<RESET>
+       <CYAN>@@ -1,14 +1,14 @@<RESET>
+       <BOLD;MAGENTA>-line 1A should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;MAGENTA>-line 1B should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 1A should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 1B should be marked as oldMoved newMovedAlternate<RESET>
+        unchanged<RESET>
+       <BOLD;MAGENTA>-line 2A should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;MAGENTA>-line 2B should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;BLUE>-line 3A should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;BLUE>-line 3B should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 3A should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 3B should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;YELLOW>+<RESET><BOLD;YELLOW>  line 2A should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;YELLOW>+<RESET><BOLD;YELLOW>  line 2B should be marked as oldMoved newMovedAlternate<RESET>
+        unchanged<RESET>
+       <BOLD;MAGENTA>-line 4A should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;MAGENTA>-line 4B should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;BLUE>-line 5A should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;BLUE>-line 5B should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;MAGENTA>-line 6A should be marked as oldMoved newMoved<RESET>
+       <BOLD;MAGENTA>-line 6B should be marked as oldMoved newMoved<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 6A should be marked as oldMoved newMoved<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 6B should be marked as oldMoved newMoved<RESET>
+       <BOLD;YELLOW>+<RESET><BOLD;YELLOW>    line 4A should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;YELLOW>+<RESET><BOLD;YELLOW>    line 4B should be marked as oldMoved newMovedAlternate<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 5A should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>  line 5B should be marked as oldMovedAlternate newMoved<RESET>
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'short lines of opposite sign do not get marked as moved' '
+       cat >old.txt <<-\EOF &&
+       this line should be marked as moved
+       unchanged
+       unchanged
+       unchanged
+       unchanged
+       too short
+       this line should be marked as oldMoved newMoved
+       this line should be marked as oldMovedAlternate newMoved
+       unchanged 1
+       unchanged 2
+       unchanged 3
+       unchanged 4
+       this line should be marked as oldMoved newMoved/newMovedAlternate
+       EOF
+       cat >new.txt <<-\EOF &&
+       too short
+       unchanged
+       unchanged
+       this line should be marked as moved
+       too short
+       unchanged
+       unchanged
+       this line should be marked as oldMoved newMoved/newMovedAlternate
+       unchanged 1
+       unchanged 2
+       this line should be marked as oldMovedAlternate newMoved
+       this line should be marked as oldMoved newMoved/newMovedAlternate
+       unchanged 3
+       this line should be marked as oldMoved newMoved
+       unchanged 4
+       EOF
+       test_expect_code 1 git diff --no-index --color --color-moved=zebra \
+               old.txt new.txt >output && cat output &&
+       grep -v index output | test_decode_color >actual &&
+       cat >expect <<-\EOF &&
+       <BOLD>diff --git a/old.txt b/new.txt<RESET>
+       <BOLD>--- a/old.txt<RESET>
+       <BOLD>+++ b/new.txt<RESET>
+       <CYAN>@@ -1,13 +1,15 @@<RESET>
+       <BOLD;MAGENTA>-this line should be marked as moved<RESET>
+       <GREEN>+<RESET><GREEN>too short<RESET>
+        unchanged<RESET>
+        unchanged<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as moved<RESET>
+       <GREEN>+<RESET><GREEN>too short<RESET>
+        unchanged<RESET>
+        unchanged<RESET>
+       <RED>-too short<RESET>
+       <BOLD;MAGENTA>-this line should be marked as oldMoved newMoved<RESET>
+       <BOLD;BLUE>-this line should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMoved newMoved/newMovedAlternate<RESET>
+        unchanged 1<RESET>
+        unchanged 2<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMovedAlternate newMoved<RESET>
+       <BOLD;YELLOW>+<RESET><BOLD;YELLOW>this line should be marked as oldMoved newMoved/newMovedAlternate<RESET>
+        unchanged 3<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMoved newMoved<RESET>
+        unchanged 4<RESET>
+       <BOLD;MAGENTA>-this line should be marked as oldMoved newMoved/newMovedAlternate<RESET>
+       EOF
+       test_cmp expect actual
+'
+
 test_expect_success 'cmd option assumes configured colored-moved' '
        test_config color.diff.oldMoved "magenta" &&
        test_config color.diff.newMoved "cyan" &&
@@ -1833,6 +1970,52 @@ test_expect_success '--color-moved treats adjacent blocks as separate for MIN_AL
        test_cmp expected actual
 '
 
+test_expect_success '--color-moved rewinds for MIN_ALNUM_COUNT' '
+       git reset --hard &&
+       test_write_lines >file \
+               A B C one two three four five six seven D E F G H I J &&
+       git add file &&
+       test_write_lines >file \
+               one two A B C D E F G H I J two three four five six seven &&
+       git diff --color-moved=zebra -- file &&
+
+       git diff --color-moved=zebra --color -- file >actual.raw &&
+       grep -v "index" actual.raw | test_decode_color >actual &&
+       cat >expected <<-\EOF &&
+       <BOLD>diff --git a/file b/file<RESET>
+       <BOLD>--- a/file<RESET>
+       <BOLD>+++ b/file<RESET>
+       <CYAN>@@ -1,13 +1,8 @@<RESET>
+       <GREEN>+<RESET><GREEN>one<RESET>
+       <GREEN>+<RESET><GREEN>two<RESET>
+        A<RESET>
+        B<RESET>
+        C<RESET>
+       <RED>-one<RESET>
+       <BOLD;MAGENTA>-two<RESET>
+       <BOLD;MAGENTA>-three<RESET>
+       <BOLD;MAGENTA>-four<RESET>
+       <BOLD;MAGENTA>-five<RESET>
+       <BOLD;MAGENTA>-six<RESET>
+       <BOLD;MAGENTA>-seven<RESET>
+        D<RESET>
+        E<RESET>
+        F<RESET>
+       <CYAN>@@ -15,3 +10,9 @@<RESET> <RESET>G<RESET>
+        H<RESET>
+        I<RESET>
+        J<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>two<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>three<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>four<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>five<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>six<RESET>
+       <BOLD;CYAN>+<RESET><BOLD;CYAN>seven<RESET>
+       EOF
+
+       test_cmp expected actual
+'
+
 test_expect_success 'move detection with submodules' '
        test_create_repo bananas &&
        echo ripe >bananas/recipe &&
@@ -2023,10 +2206,10 @@ EMPTY=''
 test_expect_success 'compare mixed whitespace delta across moved blocks' '
 
        git reset --hard &&
-       tr Q_ "\t " <<-EOF >text.txt &&
-       ${EMPTY}
-       ____too short without
-       ${EMPTY}
+       tr "^|Q_" "\f\v\t " <<-EOF >text.txt &&
+       ^__
+       |____too short without
+       ^
        ___being grouped across blank line
        ${EMPTY}
        context
@@ -2045,7 +2228,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
        git add text.txt &&
        git commit -m "add text.txt" &&
 
-       tr Q_ "\t " <<-EOF >text.txt &&
+       tr "^|Q_" "\f\v\t " <<-EOF >text.txt &&
        context
        lines
        to
@@ -2056,7 +2239,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
        ${EMPTY}
        QQtoo short without
        ${EMPTY}
-       Q_______being grouped across blank line
+       ^Q_______being grouped across blank line
        ${EMPTY}
        Q_QThese two lines have had their
        indentation reduced by four spaces
@@ -2068,16 +2251,16 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
                -c core.whitespace=space-before-tab \
                diff --color --color-moved --ws-error-highlight=all \
                --color-moved-ws=allow-indentation-change >actual.raw &&
-       grep -v "index" actual.raw | test_decode_color >actual &&
+       grep -v "index" actual.raw | tr "\f\v" "^|" | test_decode_color >actual &&
 
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/text.txt b/text.txt<RESET>
        <BOLD>--- a/text.txt<RESET>
        <BOLD>+++ b/text.txt<RESET>
        <CYAN>@@ -1,16 +1,16 @@<RESET>
-       <BOLD;MAGENTA>-<RESET>
-       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>    too short without<RESET>
-       <BOLD;MAGENTA>-<RESET>
+       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>^<RESET><BRED>  <RESET>
+       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>|    too short without<RESET>
+       <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>^<RESET>
        <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>   being grouped across blank line<RESET>
        <BOLD;MAGENTA>-<RESET>
         <RESET>context<RESET>
@@ -2097,7 +2280,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
        <BOLD;YELLOW>+<RESET>
        <BOLD;YELLOW>+<RESET>           <BOLD;YELLOW>too short without<RESET>
        <BOLD;YELLOW>+<RESET>
-       <BOLD;YELLOW>+<RESET>   <BOLD;YELLOW>       being grouped across blank line<RESET>
+       <BOLD;YELLOW>+<RESET><BOLD;YELLOW>^            being grouped across blank line<RESET>
        <BOLD;YELLOW>+<RESET>
        <BOLD;CYAN>+<RESET>     <BRED> <RESET>  <BOLD;CYAN>These two lines have had their<RESET>
        <BOLD;CYAN>+<RESET><BOLD;CYAN>indentation reduced by four spaces<RESET>
index 740696c8f7f2c437ce9260ed30e4ba2b563a30ab..42a2b9a13b7a5bd6cf28cfbe9bbfb9a5a3e5f3e6 100755 (executable)
@@ -75,7 +75,7 @@ test_expect_success 'last regexp must not be negated' '
 test_expect_success 'setup hunk header tests' '
        for i in $diffpatterns
        do
-               echo "$i-* diff=$i"
+               echo "$i-* diff=$i" || return 1
        done > .gitattributes &&
 
        # add all test files to the index
index c68729ac098401c16c2d7d232dec35d56e545846..d2b3109c2d37445f2f3cf9b892df67f7519191ff 100755 (executable)
@@ -287,9 +287,9 @@ test_expect_success 'do not color trailing cr in context' '
 '
 
 test_expect_success 'color new trailing blank lines' '
-       { echo a; echo b; echo; echo; } >x &&
+       test_write_lines a b "" "" >x &&
        git add x &&
-       { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
+       test_write_lines a "" "" "" c "" "" "" "" >x &&
        git diff --color x >output &&
        cnt=$($grep_a "${blue_grep}" output | wc -l) &&
        test $cnt = 2
index 47d6f35dcc4d93bbbdd083d6cdd23e7a5c2dff36..7cb99092938d7dd64e8ab6f4e147fc5f70c0a310 100755 (executable)
@@ -55,7 +55,7 @@ test_expect_success 'cross renames to be detected for regular files' '
 
        git diff-tree five six -r --name-status -B -M | sort >actual &&
        {
-               echo "R100      foo     bar"
+               echo "R100      foo     bar" &&
                echo "R100      bar     foo"
        } | sort >expect &&
        test_cmp expect actual
@@ -66,7 +66,7 @@ test_expect_success 'cross renames to be detected for typechange' '
 
        git diff-tree one two -r --name-status -B -M | sort >actual &&
        {
-               echo "R100      foo     bar"
+               echo "R100      foo     bar" &&
                echo "R100      bar     foo"
        } | sort >expect &&
        test_cmp expect actual
@@ -78,7 +78,7 @@ test_expect_success 'moves and renames' '
        git diff-tree three four -r --name-status -B -M | sort >actual &&
        {
                # see -B -M (#6) in t4008
-               echo "C100      foo     bar"
+               echo "C100      foo     bar" &&
                echo "T100      foo"
        } | sort >expect &&
        test_cmp expect actual
index 540f93715e4efd2b9293c81a0dd9700e482a77ed..e2f0eca4af065071a3ea5096e259212557aa4491 100755 (executable)
@@ -149,7 +149,7 @@ test_expect_success 'diff -U0' '
 
        for n in $sample
        do
-               git diff -U0 file-?$n
+               git diff -U0 file-?$n || return 1
        done | zc >actual &&
        test_cmp expect actual
 
index 6356961de46c78f5168ab437b9aff50fc979afd0..5397cb7d42d748054eb5a244415c2f5062e3eca2 100755 (executable)
@@ -14,15 +14,9 @@ test_expect_success setup '
 
        (
                echo "A $NS" &&
-               for c in B C D E F G H I J K
-               do
-                       echo "  $c"
-               done &&
+               printf "  %s\n" B C D E F G H I J K &&
                echo "L  $NS" &&
-               for c in M N O P Q R S T U V
-               do
-                       echo "  $c"
-               done
+               printf "  %s\n" M N O P Q R S T U V
        ) >file &&
        git add file &&
 
index aeac203c424905be395d5ef6d43f2b606dc3bb1d..9a292bac70c248c9273bf29a94d5ce39f17551df 100755 (executable)
@@ -100,7 +100,7 @@ test_expect_success 'setup for --cc --raw' '
        for i in $(test_seq 1 40)
        do
                blob=$(echo file$i | git hash-object --stdin -w) &&
-               trees="$trees$(echo "100644 blob $blob  file" | git mktree)$LF"
+               trees="$trees$(echo "100644 blob $blob  file" | git mktree)$LF" || return 1
        done
 '
 
index fd3f3a7260b68b09ca7714f7a805cee81eb4869f..0ae0cd3a524da312d7f1cc7b1d4b0f6ed7b2b529 100755 (executable)
@@ -20,7 +20,7 @@ test_expect_success setup '
                        for t in o x
                        do
                                path="$b$o$t" &&
-                               case "$path" in ooo) continue ;; esac
+                               case "$path" in ooo) continue ;; esac &&
                                paths="$paths$path " &&
                                p="     $path" &&
                                case "$b" in x) echo "$m1$p" ;; esac &&
@@ -39,7 +39,7 @@ test_expect_success 'diff-files -0' '
        for path in $paths
        do
                >"$path" &&
-               echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path"
+               echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" || return 1
        done >diff-files-0.expect &&
        git diff-files -0 >diff-files-0.actual &&
        test_cmp diff-files-0.expect diff-files-0.actual
@@ -52,7 +52,7 @@ test_expect_success 'diff-files -1' '
                echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" &&
                case "$path" in
                x??) echo ":100644 100644 $blob1 $ZERO_OID M    $path"
-               esac
+               esac || return 1
        done >diff-files-1.expect &&
        git diff-files -1 >diff-files-1.actual &&
        test_cmp diff-files-1.expect diff-files-1.actual
@@ -65,7 +65,7 @@ test_expect_success 'diff-files -2' '
                echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" &&
                case "$path" in
                ?x?) echo ":100644 100644 $blob2 $ZERO_OID M    $path"
-               esac
+               esac || return 1
        done >diff-files-2.expect &&
        git diff-files -2 >diff-files-2.actual &&
        test_cmp diff-files-2.expect diff-files-2.actual &&
@@ -80,7 +80,7 @@ test_expect_success 'diff-files -3' '
                echo ":000000 100644 $ZERO_OID $ZERO_OID U      $path" &&
                case "$path" in
                ??x) echo ":100644 100644 $blob3 $ZERO_OID M    $path"
-               esac
+               esac || return 1
        done >diff-files-3.expect &&
        git diff-files -3 >diff-files-3.actual &&
        test_cmp diff-files-3.expect diff-files-3.actual
index f5b35e7860ea4910288bc8513449b1cc1ec96c79..0a4fc735d44ad525f0924b86e355d4a257650a62 100755 (executable)
@@ -53,7 +53,7 @@ test_expect_success 'exclude unmerged entries from total file count' '
        git rm -f d &&
        for stage in 1 2 3
        do
-               sed -e "s/ 0    a/ $stage       d/" x
+               sed -e "s/ 0    a/ $stage       d/" x || return 1
        done |
        git update-index --index-info &&
        echo d >d &&
index 9eba436211f147864e0ce6afbcfa3166eedc0255..b5c281edaa7037097f3c8fad28c1bb1994607a20 100755 (executable)
@@ -101,7 +101,7 @@ test_expect_success 'preparation for big change tests' '
        i=0 &&
        while test $i -lt 1000
        do
-               echo $i && i=$(($i + 1))
+               echo $i && i=$(($i + 1)) || return 1
        done >abcd &&
        git commit -m message abcd
 '
index 7e5b74f72ee975ef87c8d5e539bc287268e18493..04b8a1542a8ec3ad2ffc28964f21940d034c2ed6 100755 (executable)
@@ -18,13 +18,13 @@ test_expect_success 'trivial merge - combine-diff empty' '
        for i in $(test_seq 1 9)
        do
                echo $i >$i.txt &&
-               git add $i.txt
+               git add $i.txt || return 1
        done &&
        git commit -m "init" &&
        git checkout -b side &&
        for i in $(test_seq 2 9)
        do
-               echo $i/2 >>$i.txt
+               echo $i/2 >>$i.txt || return 1
        done &&
        git commit -a -m "side 2-9" &&
        git checkout main &&
@@ -40,14 +40,14 @@ test_expect_success 'only one truly conflicting path' '
        git checkout side &&
        for i in $(test_seq 2 9)
        do
-               echo $i/3 >>$i.txt
+               echo $i/3 >>$i.txt || return 1
        done &&
        echo "4side" >>4.txt &&
        git commit -a -m "side 2-9 +4" &&
        git checkout main &&
        for i in $(test_seq 1 9)
        do
-               echo $i/3 >>$i.txt
+               echo $i/3 >>$i.txt || return 1
        done &&
        echo "4main" >>4.txt &&
        git commit -a -m "main 1-9 +4" &&
@@ -69,13 +69,13 @@ test_expect_success 'merge introduces new file' '
        git checkout side &&
        for i in $(test_seq 5 9)
        do
-               echo $i/4 >>$i.txt
+               echo $i/4 >>$i.txt || return 1
        done &&
        git commit -a -m "side 5-9" &&
        git checkout main &&
        for i in $(test_seq 1 3)
        do
-               echo $i/4 >>$i.txt
+               echo $i/4 >>$i.txt || return 1
        done &&
        git commit -a -m "main 1-3 +4hello" &&
        git merge side &&
@@ -90,13 +90,13 @@ test_expect_success 'merge removed a file' '
        git checkout side &&
        for i in $(test_seq 5 9)
        do
-               echo $i/5 >>$i.txt
+               echo $i/5 >>$i.txt || return 1
        done &&
        git commit -a -m "side 5-9" &&
        git checkout main &&
        for i in $(test_seq 1 3)
        do
-               echo $i/4 >>$i.txt
+               echo $i/4 >>$i.txt || return 1
        done &&
        git commit -a -m "main 1-3" &&
        git merge side &&
index 76e2c01b0f5a083f605e8493aaa1068f73b30023..ed814a839e679d4b394cd88729da8921e0a19b14 100755 (executable)
@@ -17,15 +17,9 @@ dotest () {
 
 test_expect_success setup '
 
-       for i in 1 2 3 4 5 6 7 8 9 10 11 12
-       do
-               echo $i
-       done >file &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 >file &&
        git update-index --add file &&
-       for i in 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12
-       do
-               echo $i
-       done >file &&
+       test_write_lines 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12 >file &&
        cat file >expect &&
        git diff >O0.diff &&
 
index a57a318699e8989e29e07e4f7559a3656ab42523..5c150f3b0b23913ac9b515820431a5651a1b8726 100755 (executable)
@@ -20,7 +20,10 @@ test_expect_success 'git apply --numstat - < patch' '
 '
 
 test_expect_success 'git apply --numstat - < patch patch' '
-       for i in 1 2; do echo "1        1       text"; done >expect &&
+       cat >expect <<-\EOF &&
+       1       1       text
+       1       1       text
+       EOF
        git apply --numstat - < patch patch >actual &&
        test_cmp expect actual
 '
index f3b635475a446597ebb6cd15336c91b6d12a49dc..a9f4ddda6c3bd650634219968ecec92e5247cff7 100755 (executable)
@@ -13,14 +13,14 @@ TEST_PASSES_SANITIZE_LEAK=true
 
 test_expect_success setup '
 
-       for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
+       test_write_lines a b c d e f g h i j k l m n >file1 &&
        perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
 
        git add file1 file2 &&
        git commit -m initial &&
        git tag initial &&
 
-       for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
+       test_write_lines a b c g h i J K L m o n p q >file1 &&
        perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
 
        git commit -a -m second &&
index 0ee93fe845afec2aebb50819d3301c3c1972b34c..c86d05a96fe8d5c7a561028c8dad452f89eb6876 100755 (executable)
@@ -10,25 +10,16 @@ test_description='git apply with rejects
 . ./test-lib.sh
 
 test_expect_success setup '
-       for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
-       do
-               echo $i
-       done >file1 &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >file1 &&
        cat file1 >saved.file1 &&
        git update-index --add file1 &&
        git commit -m initial &&
 
-       for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21
-       do
-               echo $i
-       done >file1 &&
+       test_write_lines 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 >file1 &&
        git diff >patch.1 &&
        cat file1 >clean &&
 
-       for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21
-       do
-               echo $i
-       done >expected &&
+       test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 >expected &&
 
        mv file1 file2 &&
        git update-index --add --remove file1 file2 &&
@@ -38,10 +29,7 @@ test_expect_success setup '
        mv saved.file1 file1 &&
        git update-index --add --remove file1 file2 &&
 
-       for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21
-       do
-               echo $i
-       done >file1 &&
+       test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 >file1 &&
 
        cat file1 >saved.file1
 '
index 5fc6d3e4e7c01f37572e52dd7f55fce6d58fb622..69c9c48e72b4930b3ee21887c33122468f43be4a 100755 (executable)
@@ -12,11 +12,7 @@ TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success setup '
-       {
-               echo; echo;
-               echo A; echo B; echo C;
-               echo;
-       } >file1 &&
+       test_write_lines "" "" A B C "" >file1 &&
        cat file1 >file1.orig &&
        {
                cat file1 &&
index ef57cd3aebb67d88861b8e02a63baa7437076053..dfa053ff28e8cbeb9ae311732871811777a8a18c 100755 (executable)
@@ -47,8 +47,8 @@ test_expect_success 'apply should fail gracefully' '
                echo Oops, should not have succeeded
                false
        else
-               status=$?
-               echo "Status was $status"
+               status=$? &&
+               echo "Status was $status" &&
                if test -f .git/index.lock
                then
                        echo Oops, should not have crashed
index 0ca29821ece3fda711c5c8c82791bed7a829b538..485c7d2d124ade54d00f8752399be91f43eefbc8 100755 (executable)
@@ -230,10 +230,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' '
        test_might_fail git config --unset core.whitespace &&
        rm -f .gitattributes &&
 
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        git add one &&
-       { echo a; echo b; echo c; } >expect &&
-       { cat expect; echo; } >one &&
+       test_write_lines a b c >expect &&
+       { cat expect && echo; } >one &&
        git diff -- one >patch &&
 
        git checkout one &&
@@ -242,10 +242,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' '
 '
 
 test_expect_success 'blank at EOF with --whitespace=fix (2)' '
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        git add one &&
-       { echo a; echo c; } >expect &&
-       { cat expect; echo; echo; } >one &&
+       test_write_lines a b >expect &&
+       { cat expect && test_write_lines "" ""; } >one &&
        git diff -- one >patch &&
 
        git checkout one &&
@@ -254,10 +254,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (2)' '
 '
 
 test_expect_success 'blank at EOF with --whitespace=fix (3)' '
-       { echo a; echo b; echo; } >one &&
+       test_write_lines a b "" >one &&
        git add one &&
-       { echo a; echo c; echo; } >expect &&
-       { cat expect; echo; echo; } >one &&
+       test_write_lines a c "" >expect &&
+       { cat expect && test_write_lines "" ""; } >one &&
        git diff -- one >patch &&
 
        git checkout one &&
@@ -266,9 +266,9 @@ test_expect_success 'blank at EOF with --whitespace=fix (3)' '
 '
 
 test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' '
-       { echo a; echo b; echo; echo; echo; echo; echo; echo d; } >one &&
+       test_write_lines a b "" "" "" "" "" d >one &&
        git add one &&
-       { echo a; echo c; echo; echo; echo; echo; echo; echo; echo d; } >expect &&
+       test_write_lines a b "" "" "" "" "" "" d >expect &&
        cp expect one &&
        git diff -- one >patch &&
 
@@ -278,7 +278,7 @@ test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' '
 '
 
 test_expect_success 'blank at EOF with --whitespace=warn' '
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        git add one &&
        echo >>one &&
        cat one >expect &&
@@ -291,7 +291,7 @@ test_expect_success 'blank at EOF with --whitespace=warn' '
 '
 
 test_expect_success 'blank at EOF with --whitespace=error' '
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        git add one &&
        cat one >expect &&
        echo >>one &&
@@ -304,7 +304,7 @@ test_expect_success 'blank at EOF with --whitespace=error' '
 '
 
 test_expect_success 'blank but not empty at EOF' '
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        git add one &&
        echo "   " >>one &&
        cat one >expect &&
@@ -317,13 +317,13 @@ test_expect_success 'blank but not empty at EOF' '
 '
 
 test_expect_success 'applying beyond EOF requires one non-blank context line' '
-       { echo; echo; echo; echo; } >one &&
+       test_write_lines "" "" "" "" >one &&
        git add one &&
-       { echo b; } >>one &&
+       echo b >>one &&
        git diff -- one >patch &&
 
        git checkout one &&
-       { echo a; echo; } >one &&
+       test_write_lines a "" >one &&
        cp one expect &&
        test_must_fail git apply --whitespace=fix patch &&
        test_cmp expect one &&
@@ -333,7 +333,7 @@ test_expect_success 'applying beyond EOF requires one non-blank context line' '
 
 test_expect_success 'tons of blanks at EOF should not apply' '
        for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
-               echo; echo; echo; echo;
+               test_write_lines "" "" "" "" || return 1
        done >one &&
        git add one &&
        echo a >>one &&
@@ -362,9 +362,9 @@ test_expect_success 'missing blank line at end with --whitespace=fix' '
 '
 
 test_expect_success 'two missing blank lines at end with --whitespace=fix' '
-       { echo a; echo; echo b; echo c; } >one &&
+       test_write_lines a "" b c >one &&
        cp one no-blank-lines &&
-       { echo; echo; } >>one &&
+       test_write_lines "" "" >>one &&
        git add one &&
        echo d >>one &&
        cp one expect &&
@@ -381,9 +381,9 @@ test_expect_success 'two missing blank lines at end with --whitespace=fix' '
 '
 
 test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' '
-       { echo a; echo; } >one &&
+       test_write_lines a "" >one &&
        git add one &&
-       { echo b; echo a; echo; } >one &&
+       test_write_lines b a "" >one &&
        cp one expect &&
        git diff -- one >patch &&
        echo a >one &&
@@ -393,10 +393,10 @@ test_expect_success 'missing blank line at end, insert before end, --whitespace=
 '
 
 test_expect_success 'shrink file with tons of missing blanks at end of file' '
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        cp one no-blank-lines &&
        for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
-               echo; echo; echo; echo;
+               test_write_lines "" "" "" "" || return 1
        done >>one &&
        git add one &&
        echo a >one &&
@@ -412,9 +412,9 @@ test_expect_success 'shrink file with tons of missing blanks at end of file' '
 '
 
 test_expect_success 'missing blanks at EOF must only match blank lines' '
-       { echo a; echo b; } >one &&
+       test_write_lines a b >one &&
        git add one &&
-       { echo c; echo d; } >>one &&
+       test_write_lines c d >>one &&
        git diff -- one >patch &&
 
        echo a >one &&
@@ -434,9 +434,9 @@ test_expect_success 'missing blank line should match context line with spaces' '
        git add one &&
        echo d >>one &&
        git diff -- one >patch &&
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        cp one expect &&
-       { echo; echo d; } >>expect &&
+       test_write_lines "" d >>expect &&
        git add one &&
 
        git apply --whitespace=fix patch &&
@@ -455,7 +455,7 @@ test_expect_success 'same, but with the --ignore-space-option' '
        echo d >>one &&
        cp one expect &&
        git diff -- one >patch &&
-       { echo a; echo b; echo c; } >one &&
+       test_write_lines a b c >one &&
        git add one &&
 
        git checkout-index -f one &&
index 9671de799949f8f67f906cd3db907e3a53cf4eef..090987c89b24b4795bcb80c0461e5c90f3fe5b3b 100755 (executable)
@@ -10,10 +10,7 @@ test_expect_success setup '
        git add file &&
 
        # file-0 is full of whitespace breakages
-       for l in a bb c d eeee f ggg h
-       do
-               echo "$l "
-       done >file-0 &&
+       printf "%s \n" a bb c d eeee f ggg h >file-0 &&
 
        # patch-0 creates a whitespace broken file
        cat file-0 >file &&
index a361e79a815690469585428d70a5cda2836dfe4a..33860d3829085211d5a5aa4da9468fa52cae4d9b 100755 (executable)
@@ -11,10 +11,9 @@ test_expect_success setup '
        git add empty &&
        test_tick &&
        git commit -m initial &&
-       for i in a b c d e
-       do
-               echo $i
-       done >empty &&
+       git commit --allow-empty -m "empty commit" &&
+       git format-patch --always HEAD~ >empty.patch &&
+       test_write_lines a b c d e >empty &&
        cat empty >expect &&
        git diff |
        sed -e "/^diff --git/d" \
@@ -27,30 +26,42 @@ test_expect_success setup '
 '
 
 test_expect_success 'apply empty' '
-       git reset --hard &&
        rm -f missing &&
+       test_when_finished "git reset --hard" &&
        git apply patch0 &&
        test_cmp expect empty
 '
 
+test_expect_success 'apply empty patch fails' '
+       test_when_finished "git reset --hard" &&
+       test_must_fail git apply empty.patch &&
+       test_must_fail git apply - </dev/null
+'
+
+test_expect_success 'apply with --allow-empty succeeds' '
+       test_when_finished "git reset --hard" &&
+       git apply --allow-empty empty.patch &&
+       git apply --allow-empty - </dev/null
+'
+
 test_expect_success 'apply --index empty' '
-       git reset --hard &&
        rm -f missing &&
+       test_when_finished "git reset --hard" &&
        git apply --index patch0 &&
        test_cmp expect empty &&
        git diff --exit-code
 '
 
 test_expect_success 'apply create' '
-       git reset --hard &&
        rm -f missing &&
+       test_when_finished "git reset --hard" &&
        git apply patch1 &&
        test_cmp expect missing
 '
 
 test_expect_success 'apply --index create' '
-       git reset --hard &&
        rm -f missing &&
+       test_when_finished "git reset --hard" &&
        git apply --index patch1 &&
        test_cmp expect missing &&
        git diff --exit-code
index c27e9aec570401ab76c69aed17083b07558889de..aa5cfae2b681c0a73d9e09493c8cdcbb6a273f87 100755 (executable)
@@ -12,10 +12,7 @@ modify () {
 }
 
 test_expect_success setup '
-       for i in a b c d e f g h i j k l m
-       do
-               echo $i
-       done >same_fn &&
+       test_write_lines a b c d e f g h i j k l m >same_fn &&
        cp same_fn other_fn &&
        git add same_fn other_fn &&
        git commit -m initial
index b19faeb67a3cffcc241ef2487ab8f4d0c598af2a..8bbf8260fa6b982e82f3ecb1e41d81f08adb9f4b 100755 (executable)
@@ -29,8 +29,8 @@ test_expect_success setup '
        x=1 &&
        while test $x -lt $n
        do
-               printf "%63s%d\n" "" $x >>after
-               x=$(( $x + 1 ))
+               printf "%63s%d\n" "" $x >>after &&
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "\t%s\n" d e f >>after &&
        test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
@@ -40,8 +40,8 @@ test_expect_success setup '
        x=1 &&
        while test $x -lt $n
        do
-               printf "%63s%d\n" "" $x >>expect-2
-               x=$(( $x + 1 ))
+               printf "%63s%d\n" "" $x >>expect-2 &&
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "%64s\n" d e f >>expect-2 &&
 
@@ -52,8 +52,8 @@ test_expect_success setup '
        x=0 &&
        while test $x -lt $n
        do
-               printf "%63s%02d\n" "" $x >>after
-               x=$(( $x + 1 ))
+               printf "%63s%02d\n" "" $x >>after &&
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "\t%s\n" d e f >>after &&
        test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
@@ -63,8 +63,8 @@ test_expect_success setup '
        x=0 &&
        while test $x -lt $n
        do
-               printf "%63s%02d\n" "" $x >>expect-3
-               x=$(( $x + 1 ))
+               printf "%63s%02d\n" "" $x >>expect-3 &&
+               x=$(( $x + 1 )) || return 1
        done &&
        printf "%64s\n" d e f >>expect-3 &&
 
@@ -73,16 +73,16 @@ test_expect_success setup '
        x=0 &&
        while test $x -lt 50
        do
-               printf "\t%02d\n" $x >>before
-               x=$(( $x + 1 ))
+               printf "\t%02d\n" $x >>before &&
+               x=$(( $x + 1 )) || return 1
        done &&
        cat before >after &&
        printf "%64s\n" a b c >>after &&
        while test $x -lt 100
        do
-               printf "\t%02d\n" $x >>before
-               printf "\t%02d\n" $x >>after
-               x=$(( $x + 1 ))
+               printf "\t%02d\n" $x >>before &&
+               printf "\t%02d\n" $x >>after &&
+               x=$(( $x + 1 )) || return 1
        done &&
        test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
        sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
@@ -90,16 +90,16 @@ test_expect_success setup '
        x=0 &&
        while test $x -lt 50
        do
-               printf "%63s%02d\n" "" $x >>test-4
-               x=$(( $x + 1 ))
+               printf "%63s%02d\n" "" $x >>test-4 &&
+               x=$(( $x + 1 )) || return 1
        done &&
        cat test-4 >expect-4 &&
        printf "%64s\n" a b c >>expect-4 &&
        while test $x -lt 100
        do
-               printf "%63s%02d\n" "" $x >>test-4
-               printf "%63s%02d\n" "" $x >>expect-4
-               x=$(( $x + 1 ))
+               printf "%63s%02d\n" "" $x >>test-4 &&
+               printf "%63s%02d\n" "" $x >>expect-4 &&
+               x=$(( $x + 1 )) || return 1
        done &&
 
        git config core.whitespace tab-in-indent,tabwidth=63 &&
index 2aaaa0d7dedf68934e8d5b4c6610f1a859acbb29..6caff0ca397e442d9d053c0ed1a7808e74bcbfe4 100755 (executable)
@@ -116,7 +116,7 @@ test_expect_success setup '
                git format-patch --stdout first | sed -e "1d"
        } | append_cr >patch1-crlf.eml &&
        {
-               printf "%255s\\n" ""
+               printf "%255s\\n" "" &&
                echo "X-Fake-Field: Line One" &&
                echo "X-Fake-Field: Line Two" &&
                echo "X-Fake-Field: Line Three" &&
@@ -196,6 +196,12 @@ test_expect_success setup '
 
        git format-patch -M --stdout lorem^ >rename-add.patch &&
 
+       git checkout -b empty-commit &&
+       git commit -m "empty commit" --allow-empty &&
+
+       : >empty.patch &&
+       git format-patch --always --stdout empty-commit^ >empty-commit.patch &&
+
        # reset time
        sane_unset test_tick &&
        test_tick
@@ -1152,4 +1158,105 @@ test_expect_success 'apply binary blob in partial clone' '
        git -C client am ../patch
 '
 
+test_expect_success 'an empty input file is error regardless of --empty option' '
+       test_when_finished "git am --abort || :" &&
+       test_must_fail git am --empty=drop empty.patch 2>actual &&
+       echo "Patch format detection failed." >expected &&
+       test_cmp expected actual
+'
+
+test_expect_success 'invalid when passing the --empty option alone' '
+       test_when_finished "git am --abort || :" &&
+       git checkout empty-commit^ &&
+       test_must_fail git am --empty empty-commit.patch 2>err &&
+       echo "error: Invalid value for --empty: empty-commit.patch" >expected &&
+       test_cmp expected err
+'
+
+test_expect_success 'a message without a patch is an error (default)' '
+       test_when_finished "git am --abort || :" &&
+       test_must_fail git am empty-commit.patch >err &&
+       grep "Patch is empty" err
+'
+
+test_expect_success 'a message without a patch is an error where an explicit "--empty=stop" is given' '
+       test_when_finished "git am --abort || :" &&
+       test_must_fail git am --empty=stop empty-commit.patch >err &&
+       grep "Patch is empty." err
+'
+
+test_expect_success 'a message without a patch will be skipped when "--empty=drop" is given' '
+       git am --empty=drop empty-commit.patch >output &&
+       git rev-parse empty-commit^ >expected &&
+       git rev-parse HEAD >actual &&
+       test_cmp expected actual &&
+       grep "Skipping: empty commit" output
+'
+
+test_expect_success 'record as an empty commit when meeting e-mail message that lacks a patch' '
+       git am --empty=keep empty-commit.patch >output &&
+       test_path_is_missing .git/rebase-apply &&
+       git show empty-commit --format="%B" >expected &&
+       git show HEAD --format="%B" >actual &&
+       grep -f actual expected &&
+       grep "Creating an empty commit: empty commit" output
+'
+
+test_expect_success 'skip an empty patch in the middle of an am session' '
+       git checkout empty-commit^ &&
+       test_must_fail git am empty-commit.patch >err &&
+       grep "Patch is empty." err &&
+       grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
+       git am --skip &&
+       test_path_is_missing .git/rebase-apply &&
+       git rev-parse empty-commit^ >expected &&
+       git rev-parse HEAD >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'record an empty patch as an empty commit in the middle of an am session' '
+       git checkout empty-commit^ &&
+       test_must_fail git am empty-commit.patch >err &&
+       grep "Patch is empty." err &&
+       grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
+       git am --allow-empty >output &&
+       grep "No changes - recorded it as an empty commit." output &&
+       test_path_is_missing .git/rebase-apply &&
+       git show empty-commit --format="%B" >expected &&
+       git show HEAD --format="%B" >actual &&
+       grep -f actual expected
+'
+
+test_expect_success 'create an non-empty commit when the index IS changed though "--allow-empty" is given' '
+       git checkout empty-commit^ &&
+       test_must_fail git am empty-commit.patch >err &&
+       : >empty-file &&
+       git add empty-file &&
+       git am --allow-empty &&
+       git show empty-commit --format="%B" >expected &&
+       git show HEAD --format="%B" >actual &&
+       grep -f actual expected &&
+       git diff HEAD^..HEAD --name-only
+'
+
+test_expect_success 'cannot create empty commits when there is a clean index due to merge conflicts' '
+       test_when_finished "git am --abort || :" &&
+       git rev-parse HEAD >expected &&
+       test_must_fail git am seq.patch &&
+       test_must_fail git am --allow-empty >err &&
+       ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
+       git rev-parse HEAD >actual &&
+       test_cmp actual expected
+'
+
+test_expect_success 'cannot create empty commits when there is unmerged index due to merge conflicts' '
+       test_when_finished "git am --abort || :" &&
+       git rev-parse HEAD >expected &&
+       test_must_fail git am -3 seq.patch &&
+       test_must_fail git am --allow-empty >err &&
+       ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err &&
+       git rev-parse HEAD >actual &&
+       test_cmp actual expected
+'
+
 test_done
index 2374151662b88ceec17777e01b823612fd8edfd4..5ed7e228274ed6d283f138c4fe244f9b3d14e2f3 100755 (executable)
@@ -5,10 +5,7 @@ test_description='am --abort'
 . ./test-lib.sh
 
 test_expect_success setup '
-       for i in a b c d e f g
-       do
-               echo $i
-       done >file-1 &&
+       test_write_lines a b c d e f g >file-1 &&
        cp file-1 file-2 &&
        test_tick &&
        git add file-1 file-2 &&
@@ -43,10 +40,7 @@ do
 
                test_must_fail git am$with3 000[1245]-*.patch &&
                git log --pretty=tformat:%s >actual &&
-               for i in 3 2 initial
-               do
-                       echo $i
-               done >expect &&
+               test_write_lines 3 2 initial >expect &&
                test_cmp expect actual
        '
 
index 2ced7e9d817821fa5c030afe1372d00890cac708..504955986197224ecc41c15e52fea98a021b9f00 100755 (executable)
@@ -120,48 +120,48 @@ test_expect_success 'diff-filter=A' '
 
 test_expect_success 'diff-filter=M' '
 
-       actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
-       expect=$(echo second) &&
-       verbose test "$actual" = "$expect"
+       git log --pretty="format:%s" --diff-filter=M HEAD >actual &&
+       printf "second" >expect &&
+       test_cmp expect actual
 
 '
 
 test_expect_success 'diff-filter=D' '
 
-       actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
-       expect=$(echo sixth ; echo third) &&
-       verbose test "$actual" = "$expect"
+       git log --no-renames --pretty="format:%s" --diff-filter=D HEAD >actual &&
+       printf "sixth\nthird" >expect &&
+       test_cmp expect actual
 
 '
 
 test_expect_success 'diff-filter=R' '
 
-       actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
-       expect=$(echo third) &&
-       verbose test "$actual" = "$expect"
+       git log -M --pretty="format:%s" --diff-filter=R HEAD >actual &&
+       printf "third" >expect &&
+       test_cmp expect actual
 
 '
 
 test_expect_success 'diff-filter=C' '
 
-       actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
-       expect=$(echo fourth) &&
-       verbose test "$actual" = "$expect"
+       git log -C -C --pretty="format:%s" --diff-filter=C HEAD >actual &&
+       printf "fourth" >expect &&
+       test_cmp expect actual
 
 '
 
 test_expect_success 'git log --follow' '
 
-       actual=$(git log --follow --pretty="format:%s" ichi) &&
-       expect=$(echo third ; echo second ; echo initial) &&
-       verbose test "$actual" = "$expect"
+       git log --follow --pretty="format:%s" ichi >actual &&
+       printf "third\nsecond\ninitial" >expect &&
+       test_cmp expect actual
 '
 
 test_expect_success 'git config log.follow works like --follow' '
        test_config log.follow true &&
-       actual=$(git log --pretty="format:%s" ichi) &&
-       expect=$(echo third ; echo second ; echo initial) &&
-       verbose test "$actual" = "$expect"
+       git log --pretty="format:%s" ichi >actual &&
+       printf "third\nsecond\ninitial" >expect &&
+       test_cmp expect actual
 '
 
 test_expect_success 'git config log.follow does not die with multiple paths' '
@@ -176,9 +176,9 @@ test_expect_success 'git config log.follow does not die with no paths' '
 
 test_expect_success 'git config log.follow is overridden by --no-follow' '
        test_config log.follow true &&
-       actual=$(git log --no-follow --pretty="format:%s" ichi) &&
-       expect="third" &&
-       verbose test "$actual" = "$expect"
+       git log --no-follow --pretty="format:%s" ichi >actual &&
+       printf "third" >expect &&
+       test_cmp expect actual
 '
 
 # Note that these commits are intentionally listed out of order.
@@ -250,7 +250,7 @@ test_expect_success 'log --invert-grep --grep' '
        test_cmp expect actual &&
 
        # POSIX extended
-       git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
+       git -c grep.patternType=extended log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
        test_cmp expect actual &&
 
        # PCRE
@@ -2090,4 +2090,23 @@ test_expect_success 'log --end-of-options' '
        test_cmp expect actual
 '
 
+test_expect_success 'set up commits with different authors' '
+       git checkout --orphan authors &&
+       test_commit --author "Jim <jim@example.com>" jim_1 &&
+       test_commit --author "Val <val@example.com>" val_1 &&
+       test_commit --author "Val <val@example.com>" val_2 &&
+       test_commit --author "Jim <jim@example.com>" jim_2 &&
+       test_commit --author "Val <val@example.com>" val_3 &&
+       test_commit --author "Jim <jim@example.com>" jim_3
+'
+
+test_expect_success 'log --invert-grep --grep --author' '
+       cat >expect <<-\EOF &&
+       val_3
+       val_1
+       EOF
+       git log --format=%s --author=Val --grep 2 --invert-grep >actual &&
+       test_cmp expect actual
+'
+
 test_done
index e78d8097f39690ee094f601344d104a6e3a4ce09..80f4a65b285c55cfc7dce38fb115fb0190de97a2 100755 (executable)
@@ -5,7 +5,6 @@ test_description='git patch-id'
 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' '
@@ -28,7 +27,8 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'patch-id output is well-formed' '
-       git log -p -1 | git patch-id >output &&
+       git log -p -1 >log.output &&
+       git patch-id <log.output >output &&
        grep "^$OID_REGEX $(git rev-parse HEAD)$" output
 '
 
@@ -36,8 +36,8 @@ test_expect_success 'patch-id output is well-formed' '
 calc_patch_id () {
        patch_name="$1"
        shift
-       git patch-id "$@" |
-       sed "s/ .*//" >patch-id_"$patch_name" &&
+       git patch-id "$@" >patch-id.output &&
+       sed "s/ .*//" patch-id.output >patch-id_"$patch_name" &&
        test_line_count -gt 0 patch-id_"$patch_name"
 }
 
@@ -46,7 +46,8 @@ get_top_diff () {
 }
 
 get_patch_id () {
-       get_top_diff "$1" | calc_patch_id "$@"
+       get_top_diff "$1" >top-diff.output &&
+       calc_patch_id <top-diff.output "$@"
 }
 
 test_expect_success 'patch-id detects equality' '
@@ -64,16 +65,18 @@ test_expect_success 'patch-id detects inequality' '
 test_expect_success 'patch-id supports git-format-patch output' '
        get_patch_id main &&
        git checkout same &&
-       git format-patch -1 --stdout | calc_patch_id same &&
+       git format-patch -1 --stdout >format-patch.output &&
+       calc_patch_id same <format-patch.output &&
        test_cmp patch-id_main patch-id_same &&
-       set $(git format-patch -1 --stdout | git patch-id) &&
+       set $(git patch-id <format-patch.output) &&
        test "$2" = $(git rev-parse HEAD)
 '
 
 test_expect_success 'whitespace is irrelevant in footer' '
        get_patch_id main &&
        git checkout same &&
-       git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same &&
+       git format-patch -1 --stdout >format-patch.output &&
+       sed "s/ \$//" format-patch.output | calc_patch_id same &&
        test_cmp patch-id_main patch-id_same
 '
 
@@ -92,10 +95,11 @@ test_patch_id_file_order () {
        shift
        name="order-${1}-$relevant"
        shift
-       get_top_diff "main" | calc_patch_id "$name" "$@" &&
+       get_top_diff "main" >top-diff.output &&
+       calc_patch_id <top-diff.output "$name" "$@" &&
        git checkout same &&
-       git format-patch -1 --stdout -O foo-then-bar |
-               calc_patch_id "ordered-$name" "$@" &&
+       git format-patch -1 --stdout -O foo-then-bar >format-patch.output &&
+       calc_patch_id <format-patch.output "ordered-$name" "$@" &&
        cmp_patch_id $relevant "$name" "ordered-$name"
 
 }
@@ -143,7 +147,8 @@ test_expect_success '--stable overrides patchid.stable = false' '
 test_expect_success 'patch-id supports git-format-patch MIME output' '
        get_patch_id main &&
        git checkout same &&
-       git format-patch -1 --attach --stdout | calc_patch_id same &&
+       git format-patch -1 --attach --stdout >format-patch.output &&
+       calc_patch_id <format-patch.output same &&
        test_cmp patch-id_main patch-id_same
 '
 
index 35eef4c865e01da27f401e6319144e1d0c41d552..e448ef2928a8261e7c991ee6eb0e96bf299d84ee 100755 (executable)
@@ -976,7 +976,7 @@ test_expect_success '%(describe) vs git describe' '
                else
                        : >expect-contains-bad
                fi &&
-               echo "$hash $desc"
+               echo "$hash $desc" || return 1
        done >expect &&
        test_path_exists expect-contains-good &&
        test_path_exists expect-contains-bad &&
index 560127cc078ad09c7fd87e7d5dc0a4d65fcb22d3..ac9e4d0928593cd37b4a79e27f5fe99b6e4a3faf 100755 (executable)
@@ -137,7 +137,7 @@ test_expect_success 'range_set_union' '
        test_seq 1000 > c.c &&
        git add c.c &&
        git commit -m "modify many lines" &&
-       git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done)
+       git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c || return 1; done)
 '
 
 test_expect_success '-s shows only line-log commits' '
index 03b952c90d2fca011038e38075344530b5d64477..0244888a5a7a8939276b0425b9144a8e262a2c8f 100755 (executable)
@@ -20,10 +20,10 @@ test_expect_success 'fsck notices broken commit' '
 
 test_expect_success 'git log with broken author email' '
        {
-               echo commit $(cat broken_email.hash)
-               echo "Author: A U Thor <author@example.com>"
-               echo "Date:   Thu Apr 7 15:13:13 2005 -0700"
-               echo
+               echo commit $(cat broken_email.hash) &&
+               echo "Author: A U Thor <author@example.com>" &&
+               echo "Date:   Thu Apr 7 15:13:13 2005 -0700" &&
+               echo &&
                echo "    foo"
        } >expect.out &&
 
index 8018c12a6a40eac7cf2a33caa0ba1110117904f2..cc3cebf672242a622e86b388ada63c9e0c1a9c04 100755 (executable)
@@ -374,7 +374,7 @@ test_expect_success 'Bloom generation backfills empty commits' '
                cd empty &&
                for i in $(test_seq 1 6)
                do
-                       git commit --allow-empty -m "$i"
+                       git commit --allow-empty -m "$i" || return 1
                done &&
 
                # Generate Bloom filters for empty commits 1-6, two at a time.
@@ -387,7 +387,7 @@ test_expect_success 'Bloom generation backfills empty commits' '
                        test_filter_computed 2 trace.event &&
                        test_filter_not_computed 4 trace.event &&
                        test_filter_trunc_empty 2 trace.event &&
-                       test_filter_trunc_large 0 trace.event
+                       test_filter_trunc_large 0 trace.event || return 1
                done &&
 
                # Finally, make sure that once all commits have filters, that
index 2c88d1c159623d6ba8a201352f7df26b4d2f23f7..7f8d2ab0a72dac716198a424556d1e9323f2f8c3 100755 (executable)
@@ -77,7 +77,7 @@ check_tar() {
                                        path=$(get_pax_header $header path) &&
                                        if test -n "$path"
                                        then
-                                               mv "$data" "$path"
+                                               mv "$data" "$path" || exit 1
                                        fi
                                fi
                        done
@@ -133,7 +133,7 @@ test_expect_success 'populate workdir' '
                for depth in 1 2 3 4 5
                do
                        mkdir $p &&
-                       cd $p
+                       cd $p || exit 1
                done &&
                echo text >file_with_long_path
        ) &&
index 1e6d18b140e5193d1eb046adbbbbba8c20cb63b1..d726964307ca89373eeaf206bbb2dc2d4c1c3008 100755 (executable)
@@ -106,7 +106,7 @@ test_expect_success \
      printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
      printf "A not substituted O" >a/substfile2 &&
      (p=long_path_to_a_file && cd a &&
-      for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
+      for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done &&
       echo text >file_with_long_path)
 '
 
index 2d32d0ed122277089966b44f015b5f8ff6765e1c..ae508e21623fb4af7b55c1c8afe27556b24bb232 100755 (executable)
@@ -131,7 +131,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
        do
                for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
                do
-                       : >00/$a$b
+                       : >00/$a$b || return 1
                done
        done &&
        git add 00 &&
@@ -143,7 +143,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' '
        do
                for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
                do
-                       echo "040000 tree $subtree      $c$d"
+                       echo "040000 tree $subtree      $c$d" || return 1
                done
        done >tree &&
        tree=$(git mktree <tree) &&
@@ -171,7 +171,7 @@ test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \
        # create tree containing 65500 entries of that blob
        for i in $(test_seq 1 65500)
        do
-               echo "100644 blob $blob $i"
+               echo "100644 blob $blob $i" || return 1
        done >tree &&
        tree=$(git mktree <tree) &&
 
index 141b29f0319a606ceefce3a06cd26990a64c8f06..cebad1048cfca3a142bcaef361dfab69fe889ceb 100755 (executable)
@@ -122,7 +122,7 @@ test_expect_success 'mailinfo unescapes with --mboxrd' '
        do
                git mailinfo mboxrd/msg mboxrd/patch \
                  <mboxrd/$i >mboxrd/out &&
-               test_cmp "$DATA/${i}mboxrd" mboxrd/msg
+               test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1
        done &&
        sp=" " &&
        echo "From " >expect &&
index e13a884207589d3c804745acb9c1f91e731a6f1d..2fd845187e76bd2ca7269ae45441c1495eae5839 100755 (executable)
@@ -347,7 +347,7 @@ test_expect_success 'unpacking with --strict' '
                for i in 0 1 2 3 4 5 6 7 8 9
                do
                        o=$(echo $j$i | git hash-object -w --stdin) &&
-                       echo "100644 $o 0 $j$i"
+                       echo "100644 $o 0 $j$i" || return 1
                done
        done >LIST &&
        rm -f .git/index &&
@@ -361,11 +361,7 @@ test_expect_success 'unpacking with --strict' '
        ST=$(git write-tree) &&
        git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
        PACK5=$( git pack-objects test-5 <actual ) &&
-       PACK6=$( (
-                       echo "$LIST"
-                       echo "$LI"
-                       echo "$ST"
-                ) | git pack-objects test-6 ) &&
+       PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
        test_create_repo test-5 &&
        (
                cd test-5 &&
@@ -394,7 +390,7 @@ test_expect_success 'index-pack with --strict' '
                for i in 0 1 2 3 4 5 6 7 8 9
                do
                        o=$(echo $j$i | git hash-object -w --stdin) &&
-                       echo "100644 $o 0 $j$i"
+                       echo "100644 $o 0 $j$i" || return 1
                done
        done >LIST &&
        rm -f .git/index &&
@@ -408,11 +404,7 @@ test_expect_success 'index-pack with --strict' '
        ST=$(git write-tree) &&
        git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
        PACK5=$( git pack-objects test-5 <actual ) &&
-       PACK6=$( (
-                       echo "$LIST"
-                       echo "$LI"
-                       echo "$ST"
-                ) | git pack-objects test-6 ) &&
+       PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
        test_create_repo test-7 &&
        (
                cd test-7 &&
@@ -594,7 +586,7 @@ test_expect_success 'setup for --stdin-packs tests' '
                for id in A B C
                do
                        git pack-objects .git/objects/pack/pack-$id \
-                               --incremental --revs <<-EOF
+                               --incremental --revs <<-EOF || exit 1
                        refs/tags/$id
                        EOF
                done &&
index 7c9d687367088346191434b1ceac6dd3726dff1d..8ee67df38f6c1c272834adcc3deef239eab6dd30 100755 (executable)
@@ -14,7 +14,7 @@ test_expect_success 'setup' '
        i=1 &&
        while test $i -le 100
        do
-               iii=$(printf "%03i" $i)
+               iii=$(printf "%03i" $i) &&
                test-tool genrandom "bar" 200 > wide_delta_$iii &&
                test-tool genrandom "baz $iii" 50 >> wide_delta_$iii &&
                test-tool genrandom "foo"$i 100 > deep_delta_$iii &&
index f4931c0c2a4050ddbf3896bba643d8091ee47e2a..51973f4a512bf914ee0fb50d5472d050f241a2ed 100755 (executable)
@@ -12,7 +12,7 @@ test_description='git-pack-object with missing base
 #
 test_expect_success \
     'setup base' \
-    'for a in a b c d e f g h i; do echo $a >>text; done &&
+    'test_write_lines a b c d e f g h i >text &&
      echo side >side &&
      git update-index --add text side &&
      A=$(echo A | git commit-tree $(git write-tree)) &&
index d3482ab279c91d6a005cdc30a9d0c74d301d4df4..1e02c305c4fe5f910935463bbbb6724a3bde212d 100755 (executable)
@@ -12,7 +12,7 @@ test_expect_success setup '
                git add "file$i" &&
                test_tick &&
                git commit -m "$i" &&
-               git tag "tag$i"
+               git tag "tag$i" || return 1
        done &&
        obj=$(git rev-parse --verify tag3) &&
        fanout=$(expr "$obj" : "\(..\)") &&
index cbd33d5bde1f59a6ad4a002e6fd01c2da44cfefc..d05ab716f6aa1fd6f641f14e308e2e5b80e70af3 100755 (executable)
@@ -228,7 +228,7 @@ test_expect_success 'pack reuse respects --honor-pack-keep' '
        test_when_finished "rm -f .git/objects/pack/*.keep" &&
        for i in .git/objects/pack/*.pack
        do
-               >${i%.pack}.keep
+               >${i%.pack}.keep || return 1
        done &&
        reusable_pack --honor-pack-keep >empty.pack &&
        git index-pack empty.pack &&
index 759169d0742c999adb33f91bc1ae1283877cb3db..df524f7b6dde1fa63d268bb88730dc766a003f4d 100755 (executable)
@@ -57,8 +57,11 @@ test_expect_success 'create series of packs' '
                git commit -m $i &&
                cur=$(git rev-parse HEAD^{tree}) &&
                {
-                       test -n "$prev" && echo "-$prev"
-                       echo $cur
+                       if test -n "$prev"
+                       then
+                               echo "-$prev"
+                       fi &&
+                       echo $cur &&
                        echo "$(git rev-parse :file) file"
                } | git pack-objects --stdout >tmp &&
                git index-pack --stdin --fix-thin <tmp || return 1
index 13ed3eb13652dcf07727f2a64b2b1f999604459c..33b740ce628f834a339154bd05d1acb5a1bbe4b7 100755 (executable)
@@ -16,9 +16,9 @@ test_expect_success 'setup r1' '
        git init r1 &&
        for n in 1 2 3 4 5
        do
-               echo "This is file: $n" > r1/file.$n
-               git -C r1 add file.$n
-               git -C r1 commit -m "$n"
+               echo "This is file: $n" > r1/file.$n &&
+               git -C r1 add file.$n &&
+               git -C r1 commit -m "$n" || return 1
        done
 '
 
@@ -116,9 +116,9 @@ test_expect_success 'setup r2' '
        git init r2 &&
        for n in 1000 10000
        do
-               printf "%"$n"s" X > r2/large.$n
-               git -C r2 add large.$n
-               git -C r2 commit -m "$n"
+               printf "%"$n"s" X > r2/large.$n &&
+               git -C r2 add large.$n &&
+               git -C r2 commit -m "$n" || return 1
        done
 '
 
@@ -278,10 +278,10 @@ test_expect_success 'setup r3' '
        mkdir r3/dir1 &&
        for n in sparse1 sparse2
        do
-               echo "This is file: $n" > r3/$n
-               git -C r3 add $n
-               echo "This is file: dir1/$n" > r3/dir1/$n
-               git -C r3 add dir1/$n
+               echo "This is file: $n" > r3/$n &&
+               git -C r3 add $n &&
+               echo "This is file: dir1/$n" > r3/dir1/$n &&
+               git -C r3 add dir1/$n || return 1
        done &&
        git -C r3 commit -m "sparse" &&
        echo dir1/ >pattern1 &&
@@ -331,10 +331,10 @@ test_expect_success 'setup r4' '
        mkdir r4/dir1 &&
        for n in sparse1 sparse2
        do
-               echo "This is file: $n" > r4/$n
-               git -C r4 add $n
-               echo "This is file: dir1/$n" > r4/dir1/$n
-               git -C r4 add dir1/$n
+               echo "This is file: $n" > r4/$n &&
+               git -C r4 add $n &&
+               echo "This is file: dir1/$n" > r4/dir1/$n &&
+               git -C r4 add dir1/$n || return 1
        done &&
        echo dir1/ >r4/pattern &&
        git -C r4 add pattern &&
@@ -409,7 +409,7 @@ test_expect_success 'setup r1 - delete loose blobs' '
 
        for id in `cat expected | sed "s|..|&/|"`
        do
-               rm r1/.git/objects/$id
+               rm r1/.git/objects/$id || return 1
        done
 '
 
index f516fda7cc934dc7672f0e0765206461a01df51e..edb728f77c3583cecde2d87555a4547464db7b96 100755 (executable)
@@ -64,7 +64,7 @@ test_expect_success 'create commits and repack' '
        for i in $(test_seq 3)
        do
                test_commit $i &&
-               git branch commits/$i
+               git branch commits/$i || return 1
        done &&
        git repack
 '
@@ -147,13 +147,13 @@ test_expect_success 'Add more commits' '
        for i in $(test_seq 4 5)
        do
                test_commit $i &&
-               git branch commits/$i
+               git branch commits/$i || return 1
        done &&
        git reset --hard commits/2 &&
        for i in $(test_seq 6 7)
        do
                test_commit $i &&
-               git branch commits/$i
+               git branch commits/$i || return 1
        done &&
        git reset --hard commits/2 &&
        git merge commits/4 &&
index a612e445472cd25c8e1bcc544f78595d44c9dd07..afbe93f162e854b462774cd5242ddfe40a64bf6c 100755 (executable)
@@ -93,7 +93,7 @@ test_expect_success 'create objects' '
        test_commit initial &&
        for i in $(test_seq 1 5)
        do
-               generate_objects $i
+               generate_objects $i || return 1
        done &&
        commit_and_list_objects
 '
@@ -155,7 +155,7 @@ test_expect_success 'corrupt idx reports errors' '
 test_expect_success 'add more objects' '
        for i in $(test_seq 6 10)
        do
-               generate_objects $i
+               generate_objects $i || return 1
        done &&
        commit_and_list_objects
 '
@@ -203,7 +203,7 @@ test_expect_success 'add more packs' '
        do
                generate_objects $j &&
                commit_and_list_objects &&
-               git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
+               git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list || return 1
        done
 '
 
@@ -596,7 +596,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '
        mkdir objects64/pack &&
        for i in $(test_seq 1 11)
        do
-               generate_objects 11
+               generate_objects 11 || return 1
        done &&
        commit_and_list_objects &&
        pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
@@ -640,7 +640,7 @@ test_expect_success 'setup expire tests' '
                git update-index --add large_file.txt &&
                for i in $(test_seq 1 20)
                do
-                       test_commit $i
+                       test_commit $i || exit 1
                done &&
                git branch A HEAD &&
                git branch B HEAD~8 &&
index 61cb907a9035219aecde0d425bfe73a7c98083ae..d39958c066de5e3739b48a4a3a64cb46f21f6700 100755 (executable)
@@ -14,7 +14,7 @@ test_expect_success 'setup repo' '
                for j in $(test_seq 1 3)
                do
                        mkdir f$i/f$j &&
-                       echo $j >f$i/f$j/data.txt
+                       echo $j >f$i/f$j/data.txt || return 1
                done
        done &&
        git add . &&
@@ -23,7 +23,7 @@ test_expect_success 'setup repo' '
        do
                git checkout -b topic$i main &&
                echo change-$i >f$i/f$i/data.txt &&
-               git commit -a -m "Changed f$i/f$i/data.txt"
+               git commit -a -m "Changed f$i/f$i/data.txt" || return 1
        done &&
        cat >packinput.txt <<-EOF &&
        topic1
index da453f68d67974327248563c25694adbe19154af..d042d26f2b393d52049ba3c9972e2516b03ed239 100755 (executable)
@@ -46,7 +46,7 @@ test_expect_success 'index-pack with --[no-]rev-index' '
                test_path_exists $rev &&
 
                test_index_pack "$conf" --no-rev-index &&
-               test_path_is_missing $rev
+               test_path_is_missing $rev || return 1
        done
 '
 
index 8a5d3492c713b8ca5eceef13ed55f7bd49edcae9..f0dc4e696860a4435a1be1182457325290bb1eb4 100755 (executable)
@@ -95,7 +95,7 @@ test_expect_success 'setup' '
        while [ $cur -le 10 ]; do
                add A$cur $(eval echo \$A$prev) &&
                prev=$cur &&
-               cur=$(($cur+1))
+               cur=$(($cur+1)) || return 1
        done &&
        add B1 $A1 &&
        git update-ref refs/heads/A "$ATIP" &&
@@ -112,7 +112,7 @@ test_expect_success 'post 1st pull setup' '
        while [ $cur -le 65 ]; do
                add B$cur $(eval echo \$B$prev) &&
                prev=$cur &&
-               cur=$(($cur+1))
+               cur=$(($cur+1)) || return 1
        done
 '
 
@@ -464,11 +464,11 @@ test_expect_success 'fetch creating new shallow root' '
 test_expect_success 'setup tests for the --stdin parameter' '
        for head in C D E F
        do
-               add $head
+               add $head || return 1
        done &&
        for head in A B C D E F
        do
-               git tag $head $head
+               git tag $head $head || return 1
        done &&
        cat >input <<-\EOF &&
        refs/heads/C
index 8c05c7715bff85c643bf8f09540a13ebe9312fb0..b160f8b7fb7e1f9973361cf3ed86d769d5610206 100755 (executable)
@@ -130,7 +130,7 @@ test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' '
        for i in 0 1 2 3 4 5 6 7 8 9; do
                for j in 0 1 2 3 4 5 6 7 8 9; do
                        for k in 0 1 2 3 4 5 6 7 8 9; do
-                               echo "$branchprefix$i$j$k" >> .git/packed-refs
+                               echo "$branchprefix$i$j$k" >> .git/packed-refs || return 1
                        done
                done
        done &&
index 7ce1a28ef65e62f9f8ff0dd03ec6633ba627fc8e..9ab315424c4b71e1a431c511bddc02b9c0b4e49b 100755 (executable)
@@ -1329,7 +1329,6 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
        (
                cd test &&
                git tag -a -m "Some tag" some-tag main &&
-               exit_with=true &&
                for type in commit tag tree blob
                do
                        if test "$type" = "blob"
@@ -1345,9 +1344,8 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' '
                                push origin $oid:dst 2>err &&
                        test_i18ngrep "error: The destination you" err &&
                        test_i18ngrep ! "hint: Did you mean" err ||
-                       exit_with=false
-               done &&
-               $exit_with
+                       exit 1
+               done
        )
 '
 
index 8c33755c26792e571b55341279b2a1ca18c0f97c..20f7110ec108fda462f5e9a0a43221d2c66e7fe1 100755 (executable)
@@ -37,11 +37,11 @@ test_expect_success "clone and setup child repos" '
                git config branch.main.remote two &&
                git config branch.main.merge refs/heads/one &&
                mkdir -p .git/remotes &&
-               {
-                       echo "URL: ../two/.git/"
-                       echo "Pull: refs/heads/main:refs/heads/two"
-                       echo "Pull: refs/heads/one:refs/heads/one"
-               } >.git/remotes/two
+               cat >.git/remotes/two <<-\EOF
+               URL: ../two/.git/
+               Pull: refs/heads/main:refs/heads/two
+               Pull: refs/heads/one:refs/heads/one
+               EOF
        ) &&
        git clone . bundle &&
        git clone . seven
@@ -68,7 +68,7 @@ test_expect_success "fetch test for-merge" '
        main_in_two=$(cd ../two && git rev-parse main) &&
        one_in_two=$(cd ../two && git rev-parse one) &&
        {
-               echo "$one_in_two       "
+               echo "$one_in_two       " &&
                echo "$main_in_two      not-for-merge"
        } >expected &&
        cut -f -2 .git/FETCH_HEAD >actual &&
@@ -547,7 +547,7 @@ test_expect_success 'bundle should record HEAD correctly' '
        git bundle list-heads bundle5 >actual &&
        for h in HEAD refs/heads/main
        do
-               echo "$(git rev-parse --verify $h) $h"
+               echo "$(git rev-parse --verify $h) $h" || return 1
        done >expect &&
        test_cmp expect actual
 
index 50f14101c532d67480cd9796c797df3932d33d56..320d26796d24d8a2281d37220a7bdf73cafaa503 100755 (executable)
@@ -105,19 +105,19 @@ test_expect_success setup '
        remotes="$remotes config-glob" &&
 
        mkdir -p .git/remotes &&
-       {
-               echo "URL: ../.git/"
-               echo "Pull: refs/heads/main:remotes/rem/main"
-               echo "Pull: refs/heads/one:remotes/rem/one"
-               echo "Pull: two:remotes/rem/two"
-               echo "Pull: refs/heads/three:remotes/rem/three"
-       } >.git/remotes/remote-explicit &&
+       cat >.git/remotes/remote-explicit <<-\EOF &&
+       URL: ../.git/
+       Pull: refs/heads/main:remotes/rem/main
+       Pull: refs/heads/one:remotes/rem/one
+       Pull: two:remotes/rem/two
+       Pull: refs/heads/three:remotes/rem/three
+       EOF
        remotes="$remotes remote-explicit" &&
 
-       {
-               echo "URL: ../.git/"
-               echo "Pull: refs/heads/*:refs/remotes/rem/*"
-       } >.git/remotes/remote-glob &&
+       cat >.git/remotes/remote-glob <<-\EOF &&
+       URL: ../.git/
+       Pull: refs/heads/*:refs/remotes/rem/*
+       EOF
        remotes="$remotes remote-glob" &&
 
        mkdir -p .git/branches &&
@@ -133,7 +133,7 @@ test_expect_success setup '
                git config branch.br-$remote-merge.merge refs/heads/three &&
                git config branch.br-$remote-octopus.remote $remote &&
                git config branch.br-$remote-octopus.merge refs/heads/one &&
-               git config --add branch.br-$remote-octopus.merge two
+               git config --add branch.br-$remote-octopus.merge two || return 1
        done &&
        build_script sed_script
 '
@@ -191,17 +191,17 @@ do
                cp "$expect_r" expect_r &&
                convert_expected expect_r sed_script &&
                {
-                       echo "# $cmd"
-                       set x $cmd; shift
-                       git symbolic-ref HEAD refs/heads/$1 ; shift
-                       rm -f .git/FETCH_HEAD
+                       echo "# $cmd" &&
+                       set x $cmd && shift &&
+                       git symbolic-ref HEAD refs/heads/$1 && shift &&
+                       rm -f .git/FETCH_HEAD &&
                        git for-each-ref \
                                refs/heads refs/remotes/rem refs/tags |
                        while read val type refname
                        do
-                               git update-ref -d "$refname" "$val"
-                       done
-                       git fetch "$@" >/dev/null
+                               git update-ref -d "$refname" "$val" || return 1
+                       done &&
+                       git fetch "$@" >/dev/null &&
                        cat .git/FETCH_HEAD
                } >"$actual_f" &&
                git show-ref >"$actual_r" &&
index 837a49642a059324950fc29609dadea217e1aa11..2f04cf9a1c7700c599237cee93c3877a0f9f649e 100755 (executable)
@@ -1325,10 +1325,7 @@ test_expect_success 'fetch follows tags by default' '
                git pull ../testrepo main &&
                git tag -m "annotated" tag &&
                git for-each-ref >tmp1 &&
-               (
-                       cat tmp1
-                       sed -n "s|refs/heads/main$|refs/remotes/origin/main|p" tmp1
-               ) |
+               sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
                sort -k 3 >../expect
        ) &&
        git init dst &&
index 8b68bb38a442747bff7a8b416f5300a9e2135662..b0dbacf0b9b5ee8300368c1defe54cf87ce3ee05 100755 (executable)
@@ -18,6 +18,12 @@ then
        test_done
 fi
 
+if test_have_prereq !REFFILES
+then
+       skip_all='skipping test; dumb HTTP protocol not supported with reftable.'
+       test_done
+fi
+
 LIB_HTTPD_DAV=t
 . "$TEST_DIRECTORY"/lib-httpd.sh
 ROOT_PATH="$PWD"
index 6d9142afc3b24b39594ce869b48df9549fe603c4..259203926a95d0342a87cff42e00976e66631798 100755 (executable)
@@ -5,6 +5,13 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
+
+if test_have_prereq !REFFILES
+then
+       skip_all='skipping test; dumb HTTP protocol not supported with reftable.'
+       test_done
+fi
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
index 7b9fb4ff02c2145a6029dee781661dcab37c3bdc..165427d57e5cfb2c4ecd3826564bf7ea89fba629 100755 (executable)
@@ -48,7 +48,7 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
        git init client &&
        for i in $(test_seq 7)
        do
-               test_commit -C client c$i
+               test_commit -C client c$i || return 1
        done &&
 
        # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
@@ -68,7 +68,7 @@ test_expect_success 'when two skips collide, favor the larger one' '
        git init client &&
        for i in $(test_seq 11)
        do
-               test_commit -C client c$i
+               test_commit -C client c$i || return 1
        done &&
        git -C client checkout c5 &&
        test_commit -C client c5side &&
@@ -155,14 +155,14 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
        for i in $(test_seq 8)
        do
                git -C client checkout --orphan b$i &&
-               test_commit -C client b$i.c0
+               test_commit -C client b$i.c0 || return 1
        done &&
        for j in $(test_seq 19)
        do
                for i in $(test_seq 8)
                do
                        git -C client checkout b$i &&
-                       test_commit -C client b$i.c$j
+                       test_commit -C client b$i.c$j || return 1
                done
        done &&
 
@@ -201,7 +201,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
        # should still send the others (in this test, just check b2).
        for i in $(test_seq 0 8)
        do
-               have_not_sent b1.c$i
+               have_not_sent b1.c$i || return 1
        done &&
        have_sent b2.c1 b2.c0
 '
index 9c12c0f8c321def9e39d0887d463b5d227d3157d..48050162c27440dab8a0dbc5cd19a2781bee2d37 100755 (executable)
@@ -91,6 +91,17 @@ test_expect_success 'fetch --set-upstream with valid URL sets upstream to URL' '
        check_config_missing other2
 '
 
+test_expect_success 'fetch --set-upstream with a detached HEAD' '
+       git checkout HEAD^0 &&
+       test_when_finished "git checkout -" &&
+       cat >expect <<-\EOF &&
+       warning: could not set upstream of HEAD to '"'"'main'"'"' from '"'"'upstream'"'"' when it does not point to any branch.
+       EOF
+       git fetch --set-upstream upstream main 2>actual.raw &&
+       grep ^warning: actual.raw >actual &&
+       test_cmp expect actual
+'
+
 # tests for pull --set-upstream
 
 test_expect_success 'setup bare parent pull' '
@@ -178,4 +189,15 @@ test_expect_success 'pull --set-upstream with valid URL and branch sets branch'
        check_config_missing other2
 '
 
+test_expect_success 'pull --set-upstream with a detached HEAD' '
+       git checkout HEAD^0 &&
+       test_when_finished "git checkout -" &&
+       cat >expect <<-\EOF &&
+       warning: could not set upstream of HEAD to '"'"'main'"'"' from '"'"'upstream'"'"' when it does not point to any branch.
+       EOF
+       git pull --no-rebase --set-upstream upstream main 2>actual.raw &&
+       grep ^warning: actual.raw >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 05a58069b0cd41243f072c37b612c721ee88c2e1..b68ec22d3fdb0bab650b39642a61a11a6579fcb5 100755 (executable)
@@ -63,7 +63,7 @@ test_expect_success 'setup' '
        hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
        {
                printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
-                       "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw
+                       "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw &&
                printf 0000 &&
                echo "$hash_next" | git pack-objects --stdout
        } >push_body &&
index b87ca06a585ca9791ca766dea212704dacddd7ff..1131503b760c48cbb6f6b0d10a5027d76ec40db5 100755 (executable)
@@ -194,7 +194,7 @@ test_expect_success 'hostname cannot break out of directory' '
 
 test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
        {
-               printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw
+               printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw &&
                printf "0000"
        } >input &&
        fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
index ad8d5804f7b7df3995643db0f30a6b87c524ce36..660f876eec2122f3b00e2dd087a03e2ffcd685e2 100755 (executable)
@@ -114,11 +114,11 @@ test_expect_success 'push to URL' '
 
 test_expect_success 'set up many-ref tests' '
        {
-               nr=1000
+               nr=1000 &&
                while test $nr -lt 2000
                do
-                       nr=$(( $nr + 1 ))
-                       echo "create refs/heads/b/$nr $COMMIT3"
+                       nr=$(( $nr + 1 )) &&
+                       echo "create refs/heads/b/$nr $COMMIT3" || return 1
                done
        } | git update-ref --stdin
 '
index f8625f915821b5db03a5667b548ed055d26ccca3..4b3877216ee4649a0a31986962740e0f37b5ad85 100755 (executable)
@@ -17,7 +17,7 @@ test_expect_success 'clone -c sets config in cloned repo' '
 test_expect_success 'clone -c can set multi-keys' '
        rm -rf child &&
        git clone -c core.foo=bar -c core.foo=baz . child &&
-       { echo bar; echo baz; } >expect &&
+       test_write_lines bar baz >expect &&
        git --git-dir=child/.git config --get-all core.foo >actual &&
        test_cmp expect actual
 '
index cf3e82bdf5cc1c823709963402eb3396ba0ba01a..34469b6ac10fef6dac4fb161f5377a8f47a6dd98 100755 (executable)
@@ -16,10 +16,10 @@ test_expect_success 'setup normal src repo' '
        git init src &&
        for n in 1 2 3 4
        do
-               echo "This is file: $n" > src/file.$n.txt
-               git -C src add file.$n.txt
-               git -C src commit -m "file $n"
-               git -C src ls-files -s file.$n.txt >>temp
+               echo "This is file: $n" > src/file.$n.txt &&
+               git -C src add file.$n.txt &&
+               git -C src commit -m "file $n" &&
+               git -C src ls-files -s file.$n.txt >>temp || return 1
        done &&
        awk -f print_2.awk <temp | sort >expect_1.oids &&
        test_line_count = 4 expect_1.oids
@@ -72,9 +72,9 @@ test_expect_success 'push new commits to server' '
        git -C src remote add srv "file://$(pwd)/srv.bare" &&
        for x in a b c d e
        do
-               echo "Mod file.1.txt $x" >>src/file.1.txt
-               git -C src add file.1.txt
-               git -C src commit -m "mod $x"
+               echo "Mod file.1.txt $x" >>src/file.1.txt &&
+               git -C src add file.1.txt &&
+               git -C src commit -m "mod $x" || return 1
        done &&
        git -C src blame main -- file.1.txt >expect.blame &&
        git -C src push -u srv main
@@ -114,9 +114,9 @@ test_expect_success 'verify blame causes dynamic object fetch' '
 test_expect_success 'push new commits to server for file.2.txt' '
        for x in a b c d e f
        do
-               echo "Mod file.2.txt $x" >>src/file.2.txt
-               git -C src add file.2.txt
-               git -C src commit -m "mod $x"
+               echo "Mod file.2.txt $x" >>src/file.2.txt &&
+               git -C src add file.2.txt &&
+               git -C src commit -m "mod $x" || return 1
        done &&
        git -C src push -u srv main
 '
@@ -135,9 +135,9 @@ test_expect_success 'override inherited filter-spec using --no-filter' '
 test_expect_success 'push new commits to server for file.3.txt' '
        for x in a b c d e f
        do
-               echo "Mod file.3.txt $x" >>src/file.3.txt
-               git -C src add file.3.txt
-               git -C src commit -m "mod $x"
+               echo "Mod file.3.txt $x" >>src/file.3.txt &&
+               git -C src add file.3.txt &&
+               git -C src commit -m "mod $x" || return 1
        done &&
        git -C src push -u srv main
 '
@@ -385,7 +385,7 @@ setup_triangle () {
        for i in $(test_seq 1 100)
        do
                echo "make the tree big" >server/file$i &&
-               git -C server add file$i
+               git -C server add file$i || return 1
        done &&
        git -C server commit -m "initial" &&
        git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
@@ -669,7 +669,7 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor
        for i in $(test_seq 10)
        do
                echo "this is a line" >>"$SERVER/foo.txt" &&
-               echo "this is another line" >>"$SERVER/have.txt"
+               echo "this is another line" >>"$SERVER/have.txt" || return 1
        done &&
        git -C "$SERVER" add foo.txt have.txt &&
        git -C "$SERVER" commit -m bar &&
index 78f85b0714acbc9064199cec25f634370a58d36f..710f33e2aa0d1775c21c00a939d04cd129f5b3e5 100755 (executable)
@@ -747,7 +747,7 @@ test_expect_success 'clone big repository with http:// using protocol v2' '
                echo "data 0" &&
                echo "M 644 inline bla.txt" &&
                echo "data 4" &&
-               echo "bla"
+               echo "bla" || return 1
        done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import &&
 
        GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \
@@ -942,7 +942,7 @@ test_expect_success 'part of packfile response provided as URI' '
                        then
                                >h2found
                        fi
-               fi
+               fi || return 1
        done &&
        test -f hfound &&
        test -f h2found &&
index d763de0041ca8937402a94b596291c0d34a6786a..86542c650e241976943ca58c5496cf03965c630e 100755 (executable)
@@ -6,10 +6,10 @@ TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-    for n in 1 2 3 4 5 ; do \
-        echo $n > a ; \
-        git add a ; \
-        git commit -m "$n" ; \
+    for n in 1 2 3 4 5 ; do
+       echo $n > a &&
+       git add a &&
+       git commit -m "$n" || return 1
     done
 '
 
index 63fa7c83130ba371913ac07db1f95d3e57991d35..5a67bbc760fdc8c2b53dc7721a144e033bf8e934 100755 (executable)
@@ -124,7 +124,7 @@ test_expect_success 'dodecapus' '
                git checkout -b root$i five &&
                test_commit $i &&
                roots="$roots root$i" ||
-               return
+               return 1
        done &&
        git checkout main &&
        test_tick &&
@@ -142,8 +142,8 @@ test_expect_success 'ancestors with the same commit time' '
 
        test_tick_keep=$test_tick &&
        for i in 1 2 3 4 5 6 7 8; do
-               test_tick=$test_tick_keep
-               test_commit t$i
+               test_tick=$test_tick_keep &&
+               test_commit t$i || return 1
        done &&
        git rev-list t1^! --not t$i >result &&
        test_must_be_empty result
index 20adbece6588a70ab72ac44825e8f359bdcff014..af57a04b7ffa01644768ee507714ad5f5d5b79c6 100755 (executable)
@@ -51,7 +51,7 @@ test_expect_success setup '
 '
 
 test_expect_success 'rev-list D..M' '
-       for c in E F G H I J K L M; do echo $c; done >expect &&
+       test_write_lines E F G H I J K L M >expect &&
        git rev-list --format=%s D..M |
        sed -e "/^commit /d" |
        sort >actual &&
@@ -59,7 +59,7 @@ test_expect_success 'rev-list D..M' '
 '
 
 test_expect_success 'rev-list --ancestry-path D..M' '
-       for c in E F H I J L M; do echo $c; done >expect &&
+       test_write_lines E F H I J L M >expect &&
        git rev-list --ancestry-path --format=%s D..M |
        sed -e "/^commit /d" |
        sort >actual &&
@@ -81,7 +81,7 @@ test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
 '
 
 test_expect_success 'rev-list F...I' '
-       for c in F G H I; do echo $c; done >expect &&
+       test_write_lines F G H I >expect &&
        git rev-list --format=%s F...I |
        sed -e "/^commit /d" |
        sort >actual &&
@@ -89,7 +89,7 @@ test_expect_success 'rev-list F...I' '
 '
 
 test_expect_success 'rev-list --ancestry-path F...I' '
-       for c in F H I; do echo $c; done >expect &&
+       test_write_lines F H I >expect &&
        git rev-list --ancestry-path --format=%s F...I |
        sed -e "/^commit /d" |
        sort >actual &&
@@ -111,7 +111,7 @@ test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
 '
 
 test_expect_success 'rev-list --ancestry-path --simplify-merges G^..M -- G.t' '
-       for c in G L; do echo $c; done >expect &&
+       test_write_lines G L >expect &&
        git rev-list --ancestry-path --simplify-merges --format=%s G^..M -- G.t |
        sed -e "/^commit /d" |
        sort >actual &&
index ddf34f0115b08b401a8981099459d10e1b1c4a02..ed449abe5520e59ddb0ad27def5711007f620650 100755 (executable)
@@ -4,9 +4,7 @@ test_description='basic git merge-index / git-merge-one-file tests'
 . ./test-lib.sh
 
 test_expect_success 'setup diverging branches' '
-       for i in 1 2 3 4 5 6 7 8 9 10; do
-               echo $i
-       done >file &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 10 >file &&
        git add file &&
        git commit -m base &&
        git tag base &&
index 78b585178051615a3712b58d1f87192aa678fb7f..c571fa517978818703e29c72e36faf52643a8ee5 100755 (executable)
@@ -32,7 +32,7 @@ test_expect_success 'setup' '
                test_tick &&
                git commit --allow-empty -m "$i" &&
                commit=$(git rev-parse --verify HEAD) &&
-               printf "$commit " >>.git/info/grafts
+               printf "$commit " >>.git/info/grafts || return 1
        done
 '
 
index 4ade105db385c3458d4549d596923bb4197c605d..8d9d6604f052f6645e8760d3890f1ed29384fd49 100755 (executable)
@@ -16,9 +16,9 @@ test_expect_success 'setup r1' '
        git init r1 &&
        for n in 1 2 3 4 5
        do
-               echo "This is file: $n" > r1/file.$n
-               git -C r1 add file.$n
-               git -C r1 commit -m "$n"
+               echo "This is file: $n" > r1/file.$n &&
+               git -C r1 add file.$n &&
+               git -C r1 commit -m "$n" || return 1
        done
 '
 
@@ -73,9 +73,9 @@ test_expect_success 'setup r2' '
        git init r2 &&
        for n in 1000 10000
        do
-               printf "%"$n"s" X > r2/large.$n
-               git -C r2 add large.$n
-               git -C r2 commit -m "$n"
+               printf "%"$n"s" X > r2/large.$n &&
+               git -C r2 add large.$n &&
+               git -C r2 commit -m "$n" || return 1
        done
 '
 
@@ -245,10 +245,10 @@ test_expect_success 'setup r3' '
        mkdir r3/dir1 &&
        for n in sparse1 sparse2
        do
-               echo "This is file: $n" > r3/$n
-               git -C r3 add $n
-               echo "This is file: dir1/$n" > r3/dir1/$n
-               git -C r3 add dir1/$n
+               echo "This is file: $n" > r3/$n &&
+               git -C r3 add $n &&
+               echo "This is file: dir1/$n" > r3/dir1/$n &&
+               git -C r3 add dir1/$n || return 1
        done &&
        git -C r3 commit -m "sparse" &&
        echo dir1/ >pattern1 &&
@@ -672,7 +672,7 @@ test_expect_success 'rev-list W/ --missing=print' '
 
        for id in `cat expected | sed "s|..|&/|"`
        do
-               rm r1/.git/objects/$id
+               rm r1/.git/objects/$id || return 1
        done &&
 
        git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&
index bae2419150b8b52244dda726a4d2eaf10c1405ce..d8af2bb9d2b876c3277d1211468ce4717b83697e 100755 (executable)
@@ -262,7 +262,7 @@ test_expect_success 'name-rev --all' '
        >expect.unsorted &&
        for rev in $(git rev-list --all)
        do
-               git name-rev $rev >>expect.unsorted
+               git name-rev $rev >>expect.unsorted || return 1
        done &&
        sort <expect.unsorted >expect &&
        git name-rev --all >actual.unsorted &&
@@ -275,7 +275,7 @@ test_expect_success 'name-rev --stdin' '
        for rev in $(git rev-list --all)
        do
                name=$(git name-rev --name-only $rev) &&
-               echo "$rev ($name)" >>expect.unsorted
+               echo "$rev ($name)" >>expect.unsorted || return 1
        done &&
        sort <expect.unsorted >expect &&
        git rev-list --all | git name-rev --stdin >actual.unsorted &&
@@ -390,9 +390,12 @@ test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' '
 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
 data <<EOF
 commit #$i
-EOF"
-               test $i = 1 && echo "from refs/heads/main^0"
-               i=$(($i + 1))
+EOF" &&
+               if test $i = 1
+               then
+                       echo "from refs/heads/main^0"
+               fi &&
+               i=$(($i + 1)) || return 1
        done | git fast-import &&
        git checkout main &&
        git tag far-far-away HEAD^ &&
index 30328b87f07657c899801304bf6e0331f569f1bb..8ff1d76f794783346c1b3597c55924e8acb4811d 100755 (executable)
@@ -11,7 +11,7 @@ test_expect_success 'setup' '
                fi &&
                : >$p &&
                git add $p &&
-               git commit -m $p
+               git commit -m $p || return 1
        done &&
        git log --oneline --format=%s >actual &&
        cat <<EOF >expect &&
index 6e10a539ce69e81a36396b2b7b7210d20b03083a..7544245f9026d5a705dd8ab00e645db5a2e19c36 100755 (executable)
@@ -579,7 +579,7 @@ test_expect_success 'merge-msg lots of commits' '
                while test $i -gt 9
                do
                        echo "  $i" &&
-                       i=$(($i-1))
+                       i=$(($i-1)) || return 1
                done &&
                echo "  ..."
        } >expected &&
@@ -633,7 +633,35 @@ test_expect_success 'merge-msg with "merging" an annotated tag' '
        test_cmp expected .git/MERGE_MSG
 '
 
+test_expect_success 'merge --into-name=<name>' '
+       test_when_finished "git checkout main" &&
+       git checkout -B side main &&
+       git commit --allow-empty -m "One step ahead" &&
+
+       git checkout --detach main &&
+       git merge --no-ff side &&
+       git show -s --format="%s" >full.0 &&
+       head -n1 full.0 >actual &&
+       # expect that HEAD is shown as-is
+       grep -e "Merge branch .side. into HEAD$" actual &&
+
+       git reset --hard main &&
+       git merge --no-ff --into-name=main side &&
+       git show -s --format="%s" >full.1 &&
+       head -n1 full.1 >actual &&
+       # expect that we pretend to be merging to main, that is suppressed
+       grep -e "Merge branch .side.$" actual &&
+
+       git checkout -b throwaway main &&
+       git merge --no-ff --into-name=main side &&
+       git show -s --format="%s" >full.2 &&
+       head -n1 full.2 >actual &&
+       # expect that we pretend to be merging to main, that is suppressed
+       grep -e "Merge branch .side.$" actual
+'
+
 test_expect_success 'merge.suppressDest configuration' '
+       test_when_finished "git checkout main" &&
        git checkout -B side main &&
        git commit --allow-empty -m "One step ahead" &&
        git checkout main &&
@@ -650,7 +678,19 @@ test_expect_success 'merge.suppressDest configuration' '
        git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 &&
        head -n1 full.3 >actual &&
        grep -e "Merge branch .side." actual &&
-       ! grep -e " into main$" actual
+       ! grep -e " into main$" actual &&
+
+       git checkout --detach HEAD &&
+       git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 &&
+       head -n1 full.4 >actual &&
+       grep -e "Merge branch .side. into HEAD$" actual &&
+
+       git -c merge.suppressDest="main" fmt-merge-msg \
+               --into-name=main <.git/FETCH_HEAD >full.5 &&
+       head -n1 full.5 >actual &&
+       grep -e "Merge branch .side." actual &&
+       ! grep -e " into main$" actual &&
+       ! grep -e " into HEAD$" actual
 '
 
 test_done
index 6aa9fb17ea3f95a6cdd7429e38b670491f25f57d..dcaab7265f5c75a8be444db3e2d1766732192f8d 100755 (executable)
@@ -952,10 +952,7 @@ test_expect_success '%(raw) with --shell and --sort=raw must fail' '
 '
 
 test_expect_success '%(raw:size) with --shell' '
-       git for-each-ref --format="%(raw:size)" | while read line
-       do
-               echo "'\''$line'\''" >>expect
-       done &&
+       git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect &&
        git for-each-ref --format="%(raw:size)" --shell >actual &&
        test_cmp expect actual
 '
@@ -1338,7 +1335,7 @@ test_expect_success ':remotename and :remoteref' '
                        echo "${pair#*=}" >expect &&
                        git for-each-ref --format="${pair%=*}" \
                                refs/heads/main >actual &&
-                       test_cmp expect actual
+                       test_cmp expect actual || exit 1
                done &&
                git branch push-simple &&
                git config branch.push-simple.pushRemote from &&
index 849464583713c40859d2473d2a4075367b1e4c09..57e6af5eaa09e52e9f867c957e2117cb66c46e4b 100755 (executable)
@@ -62,10 +62,10 @@ test_expect_success setup '
 
 test_expect_success merge '
 
-       {
-               echo "binary -merge"
-               echo "union merge=union"
-       } >.gitattributes &&
+       cat >.gitattributes <<-\EOF &&
+       binary -merge
+       union merge=union
+       EOF
 
        if git merge main
        then
index e34676c204b41a76b3c90519386e275db42c3b55..8e6241f92e6a6c10b8686900bf1ed61c2c96d4d3 100755 (executable)
@@ -48,7 +48,7 @@ test_expect_success resolve '
                echo Oops, should not have succeeded
                false
        else
-               git ls-files -s >current
+               git ls-files -s >current &&
                test_cmp expect current
        fi
 '
@@ -63,7 +63,7 @@ test_expect_success recursive '
                echo Oops, should not have succeeded
                false
        else
-               git ls-files -s >current
+               git ls-files -s >current &&
                test_cmp expect current
        fi
 '
index ba7890ec521f510cf9d389331bf12d7cf11be4fb..e9ba6f1690d015d06e13c69db2c1190ef8436443 100755 (executable)
@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 test_expect_success setup '
 
        s="1 2 3 4 5 6 7 8" &&
-       for i in $s; do echo $i; done >hello &&
+       test_write_lines $s >hello &&
        git add hello &&
        git commit -m initial &&
        git checkout -b side &&
@@ -18,7 +18,7 @@ test_expect_success setup '
        git add hello &&
        git commit -m second &&
        git checkout main &&
-       for i in mundo $s; do echo $i; done >hello &&
+       test_write_lines mundo $s >hello &&
        git add hello &&
        git commit -m main
 
@@ -27,7 +27,7 @@ test_expect_success setup '
 test_expect_success 'subtree available and works like recursive' '
 
        git merge -s subtree side &&
-       for i in mundo $s world; do echo $i; done >expect &&
+       test_write_lines mundo $s world >expect &&
        test_cmp expect hello
 
 '
index f54c915d6a540719329277e7c9e77a8ed4536a93..6ae2489286c278f978c3a87f1015f16fe2bb005f 100755 (executable)
@@ -51,10 +51,10 @@ test_expect_success 'set up mode change in both branches' '
        : >file2 &&
        git add file2 &&
        git commit -m b2 &&
-       {
-               echo "100755 $H 2       file2"
-               echo "100644 $H 3       file2"
-       } >expect
+       cat >expect <<-EOF
+       100755 $H 2     file2
+       100644 $H 3     file2
+       EOF
 '
 
 do_both_modes () {
index c50d31572221eb934134f3ba5baa82577e03161d..ca018d11f547978bf66a41804c16bf24a0b614f8 100755 (executable)
@@ -37,18 +37,18 @@ test_rename() {
        test_might_fail git branch -D test$n &&
        git reset --hard initial &&
        for i in $(count $n); do
-               make_text $i initial initial >$i
+               make_text $i initial initial >$i || return 1
        done &&
        git add . &&
        git commit -m add=$n &&
        for i in $(count $n); do
-               make_text $i changed initial >$i
+               make_text $i changed initial >$i || return 1
        done &&
        git commit -a -m change=$n &&
        git checkout -b test$n HEAD^ &&
        for i in $(count $n); do
-               git rm $i
-               make_text $i initial changed >$i.moved
+               git rm $i &&
+               make_text $i initial changed >$i.moved || return 1
        done &&
        git add . &&
        git commit -m change+rename=$n &&
@@ -79,7 +79,7 @@ test_expect_success 'setup large simple rename' '
 
        git reset --hard initial &&
        for i in $(count 200); do
-               make_text foo bar baz >$i
+               make_text foo bar baz >$i || return 1
        done &&
        git add . &&
        git commit -m create-files &&
index 84f50823666671e54328670dbc7e370600fd1a51..690c8482b13a3763b223be19799ce22197cd383c 100755 (executable)
@@ -24,14 +24,8 @@ test_expect_success 'setup basic criss-cross + rename with no modifications' '
                cd basic-rename &&
 
                ten="0 1 2 3 4 5 6 7 8 9" &&
-               for i in $ten
-               do
-                       echo line $i in a sample file
-               done >one &&
-               for i in $ten
-               do
-                       echo line $i in another sample file
-               done >two &&
+               printf "line %d in a sample file\n" $ten >one &&
+               printf "line %d in another sample file\n" $ten >two &&
                git add one two &&
                test_tick && git commit -m initial &&
 
@@ -96,14 +90,8 @@ test_expect_success 'setup criss-cross + rename merges with basic modification'
                cd rename-modify &&
 
                ten="0 1 2 3 4 5 6 7 8 9" &&
-               for i in $ten
-               do
-                       echo line $i in a sample file
-               done >one &&
-               for i in $ten
-               do
-                       echo line $i in another sample file
-               done >two &&
+               printf "line %d in a sample file\n" $ten >one &&
+               printf "line %d in another sample file\n" $ten >two &&
                git add one two &&
                test_tick && git commit -m initial &&
 
@@ -1588,10 +1576,7 @@ test_expect_success 'setup nested conflicts' '
                cd nested_conflicts &&
 
                # Create some related files now
-               for i in $(test_seq 1 10)
-               do
-                       echo Random base content line $i
-               done >initial &&
+               printf "Random base content line %d\n" $(test_seq 1 10) >initial &&
 
                cp initial b_L1 &&
                cp initial b_R1 &&
@@ -1777,10 +1762,7 @@ test_expect_success 'setup virtual merge base with nested conflicts' '
                cd virtual_merge_base_has_nested_conflicts &&
 
                # Create some related files now
-               for i in $(test_seq 1 10)
-               do
-                       echo Random base content line $i
-               done >content &&
+               printf "Random base content line %d\n" $(test_seq 1 10) >content &&
 
                # Setup original commit
                git add content &&
index ec065d6a6581dc368fa9f03edfa9cfdcb0483eb2..62d1406119e8c2b08a1a93e3d8fb95167ad16e7d 100755 (executable)
@@ -7,10 +7,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-       for i in 1 2 3 4 5 6 7 8 9
-       do
-               echo "$i"
-       done >file &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 >file &&
        git add file &&
        cp file elif &&
        git commit -m initial &&
index a0efe7cb6dbe77215f0b2bd220f6974ad0c17ec0..07067bb347955b146b9654b353e9db2b8b2cd323 100755 (executable)
@@ -706,7 +706,7 @@ test_expect_success 'merge-recursive remembers the names of all base trees' '
        # more trees than static slots used by oid_to_hex()
        for commit in $c0 $c2 $c4 $c5 $c6 $c7
        do
-               git rev-parse "$commit^{tree}"
+               git rev-parse "$commit^{tree}" || return 1
        done >trees &&
 
        # ignore the return code; it only fails because the input is weird...
index 3d7a62ddab61729d37c183fe327a9d8997f96c1c..338a9c46a24b02caf471da4afb1cff14a75b6f2f 100755 (executable)
@@ -32,7 +32,7 @@ test_expect_success 'setup' '
        do
                test_commit "1-$i" &&
                git branch -f commit-1-$i &&
-               git tag -a -m "1-$i" tag-1-$i commit-1-$i
+               git tag -a -m "1-$i" tag-1-$i commit-1-$i || return 1
        done &&
        for j in $(test_seq 1 9)
        do
@@ -46,7 +46,7 @@ test_expect_success 'setup' '
                do
                        git merge commit-$j-$i -m "$x-$i" &&
                        git branch -f commit-$x-$i &&
-                       git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i
+                       git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i || return 1
                done
        done &&
        git commit-graph write --reachable &&
index 082be85dffc7b1765471e11d2c580c853cf0965b..9aa1660651b8a96397ce2a83cb3d107c8b7d43dc 100755 (executable)
@@ -94,10 +94,10 @@ test_expect_success 'creating a tag with --create-reflog should create reflog' '
        git log -1 \
                --format="format:tag: tagging %h (%s, %cd)%n" \
                --date=format:%Y-%m-%d >expected &&
-       test_when_finished "git tag -d tag_with_reflog" &&
-       git tag --create-reflog tag_with_reflog &&
-       git reflog exists refs/tags/tag_with_reflog &&
-       sed -e "s/^.*   //" .git/logs/refs/tags/tag_with_reflog >actual &&
+       test_when_finished "git tag -d tag_with_reflog1" &&
+       git tag --create-reflog tag_with_reflog1 &&
+       git reflog exists refs/tags/tag_with_reflog1 &&
+       test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e "s/^.* //" >actual &&
        test_cmp expected actual
 '
 
@@ -105,10 +105,10 @@ test_expect_success 'annotated tag with --create-reflog has correct message' '
        git log -1 \
                --format="format:tag: tagging %h (%s, %cd)%n" \
                --date=format:%Y-%m-%d >expected &&
-       test_when_finished "git tag -d tag_with_reflog" &&
-       git tag -m "annotated tag" --create-reflog tag_with_reflog &&
-       git reflog exists refs/tags/tag_with_reflog &&
-       sed -e "s/^.*   //" .git/logs/refs/tags/tag_with_reflog >actual &&
+       test_when_finished "git tag -d tag_with_reflog2" &&
+       git tag -m "annotated tag" --create-reflog tag_with_reflog2 &&
+       git reflog exists refs/tags/tag_with_reflog2 &&
+       test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog2 | sed -e "s/^.* //" >actual &&
        test_cmp expected actual
 '
 
@@ -118,10 +118,10 @@ test_expect_success '--create-reflog does not create reflog on failure' '
 '
 
 test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
-       test_when_finished "git tag -d tag_with_reflog" &&
+       test_when_finished "git tag -d tag_with_reflog3" &&
        test_config core.logAllRefUpdates always &&
-       git tag tag_with_reflog &&
-       git reflog exists refs/tags/tag_with_reflog
+       git tag tag_with_reflog3 &&
+       git reflog exists refs/tags/tag_with_reflog3
 '
 
 test_expect_success 'listing all tags if one exists should succeed' '
@@ -1976,9 +1976,12 @@ test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a de
 committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
 data <<EOF
 commit #$i
-EOF"
-               test $i = 1 && echo "from refs/heads/main^0"
-               i=$(($i + 1))
+EOF" &&
+               if test $i = 1
+               then
+                       echo "from refs/heads/main^0"
+               fi &&
+               i=$(($i + 1)) || return 1
        done | git fast-import &&
        git checkout main &&
        git tag far-far-away HEAD^ &&
index 0335a9a158ab507b2e37e4d7642a69ba4344c0ad..520f96d09fb71778704119929012a40aa7c0072a 100755 (executable)
@@ -137,7 +137,7 @@ test_expect_success 'setup deeper work tree' '
 
 test_expect_success 'add a directory outside the work tree' '(
        cd tester &&
-       d1="$(cd .. ; pwd)" &&
+       d1="$(cd .. && pwd)" &&
        test_must_fail git add "$d1"
 )'
 
index a82a07a04a8500cdac2cfb7ef39fb3f5981f437f..3d62e10b53fe16fd2eae0d0fa0363d8839f97b95 100755 (executable)
@@ -8,7 +8,7 @@ test_description='Tests for "git reset" with "--merge" and "--keep" options'
 . ./test-lib.sh
 
 test_expect_success setup '
-    for i in 1 2 3; do echo line $i; done >file1 &&
+    printf "line %d\n" 1 2 3 >file1 &&
     cat file1 >file2 &&
     git add file1 file2 &&
     test_tick &&
index 512ae2781fe2c9b02a5a37f5230ec14992114ae7..fb5417d5e7e044f5bfbbe1b4ef8f6b42857c4e73 100755 (executable)
@@ -667,10 +667,7 @@ test_expect_success 'amend can copy notes' '
 
 test_expect_success 'commit a file whose name is a dash' '
        git reset --hard &&
-       for i in 1 2 3 4 5
-       do
-               echo $i
-       done >./- &&
+       test_write_lines 1 2 3 4 5 >./- &&
        git add ./- &&
        test_tick &&
        git commit -m "add dash" >output </dev/null &&
index 2a07c70867966ccfa901d91667358a7d86f34e5e..e39c809ca42f04dbda578689e627b4aceb67d044 100755 (executable)
@@ -16,7 +16,7 @@ test_expect_success 'set up commits for rebasing' '
        test_commit rebase-b b bb &&
        for i in $(test_seq 1 13)
        do
-               test_commit rebase-$i c $i
+               test_commit rebase-$i c $i || return 1
        done &&
        git checkout main &&
 
index 7f2956d77ad033a57981a9569db3ef803ef93961..2f16d5787edfb16956312a3be70fb9da1ffadc46 100755 (executable)
@@ -659,6 +659,7 @@ On branch am_empty
 You are in the middle of an am session.
 The current patch is empty.
   (use "git am --skip" to skip this patch)
+  (use "git am --allow-empty" to record this patch as an empty commit)
   (use "git am --abort" to restore the original branch)
 
 nothing to commit (use -u to show untracked files)
index 04885d0a5e5c2697409395698af15b48002cabe2..97f10905d23fd3077aa9dd253fa079eb9c5be73d 100755 (executable)
@@ -156,7 +156,7 @@ test_expect_success 'with config option on the command line' '
                Acked-by: Johan
                Reviewed-by: Peff
        EOF
-       { echo; echo "Acked-by: Johan"; } |
+       { echo && echo "Acked-by: Johan"; } |
        git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
                --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
        test_cmp expected actual
index a5e2233cb1957797a864ab0255ed5679bba1d321..a6308acf006c9e4d35e47578465e348bb213356f 100755 (executable)
@@ -248,7 +248,7 @@ do
                git config core.preloadIndex $preload_val &&
                if test $preload_val = true
                then
-                       GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
+                       GIT_TEST_PRELOAD_INDEX=$preload_val && export GIT_TEST_PRELOAD_INDEX
                else
                        sane_unset GIT_TEST_PRELOAD_INDEX
                fi
index c773e30b3fa17bc129ca78afe3aef9194d77cb1d..f0f6fda150bc29695dc8b56cb3c204de251e6e1d 100755 (executable)
@@ -967,7 +967,7 @@ test_expect_success 'set up mod-256 conflict scenario' '
        # 256 near-identical stanzas...
        for i in $(test_seq 1 256); do
                for j in 1 2 3 4 5; do
-                       echo $i-$j
+                       echo $i-$j || return 1
                done
        done >file &&
        git add file &&
index a9c816b47f269ad0bf073f97f50e03a6ba3890d7..ff085b086cc38f36a180e22ab02bbea12a29cc0c 100755 (executable)
@@ -29,8 +29,8 @@ test_expect_success 'merge c1 with c2, c3, c4, ... c29' '
        refs="" &&
        while test $i -le 30
        do
-               refs="$refs c$i"
-               i=$(expr $i + 1)
+               refs="$refs c$i" &&
+               i=$(expr $i + 1) || return 1
        done &&
        git merge $refs &&
        test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
index 27cd94ad6f7770f93c84bad8a0a966e6d026ea78..4887ca705b330e8cbf6f25595cbcadfdfd67f9f2 100755 (executable)
@@ -95,7 +95,7 @@ test_expect_success 'setup' '
                echo $i > $i.c &&
                git add $i.c &&
                git commit -m $i &&
-               git tag $i
+               git tag $i || return 1
        done &&
        git reset --hard A &&
        for i in F G H I
@@ -103,7 +103,7 @@ test_expect_success 'setup' '
                echo $i > $i.c &&
                git add $i.c &&
                git commit -m $i &&
-               git tag $i
+               git tag $i || return 1
        done
 '
 
index 0260ad6f0e06ec3cbd4d6515a4f893e219b42b0a..e489869dd94daf98f900d14d75a3da97f5f7ab34 100755 (executable)
@@ -5,6 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 . "${TEST_DIRECTORY}/lib-bitmap.sh"
 . "${TEST_DIRECTORY}/lib-midx.sh"
+. "${TEST_DIRECTORY}/lib-terminal.sh"
 
 commit_and_pack () {
        test_commit "$@" 1>&2 &&
@@ -117,7 +118,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
                        rm alt_objects/pack/$base_name.keep
                else
                        touch alt_objects/pack/$base_name.keep
-               fi
+               fi || return 1
        done &&
        git repack -a -d &&
        test_no_missing_in_packs
@@ -372,4 +373,16 @@ test_expect_success '--write-midx with preferred bitmap tips' '
        )
 '
 
+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
+'
+
+test_expect_success TTY '--quiet disables progress' '
+       test_terminal env GIT_PROGRESS_DELAY=0 \
+               git -C midx repack -ad --quiet --write-midx 2>stderr &&
+       test_must_be_empty stderr
+'
+
 test_done
index 6b6423a07c3a6e0b497e3fbd109679b38dbe3856..424c31c3287d352e135faf1754e221cc17eb8247 100755 (executable)
@@ -31,28 +31,28 @@ int main(int argc, const char **argv)
 EOF
 
 test_expect_success setup '
-       {
-               echo foo mmap bar
-               echo foo_mmap bar
-               echo foo_mmap bar mmap
-               echo foo mmap bar_mmap
-               echo foo_mmap bar mmap baz
-       } >file &&
-       {
-               echo Hello world
-               echo HeLLo world
-               echo Hello_world
-               echo HeLLo_world
-       } >hello_world &&
-       {
-               echo "a+b*c"
-               echo "a+bc"
-               echo "abc"
-       } >ab &&
-       {
-               echo d &&
-               echo 0
-       } >d0 &&
+       cat >file <<-\EOF &&
+       foo mmap bar
+       foo_mmap bar
+       foo_mmap bar mmap
+       foo mmap bar_mmap
+       foo_mmap bar mmap baz
+       EOF
+       cat >hello_world <<-\EOF &&
+       Hello world
+       HeLLo world
+       Hello_world
+       HeLLo_world
+       EOF
+       cat >ab <<-\EOF &&
+       a+b*c
+       a+bc
+       abc
+       EOF
+       cat >d0 <<-\EOF &&
+       d
+       0
+       EOF
        echo vvv >v &&
        echo ww w >w &&
        echo x x xx x >x &&
@@ -63,13 +63,13 @@ test_expect_success setup '
        echo vvv >t/v &&
        mkdir t/a &&
        echo vvv >t/a/v &&
-       {
-               echo "line without leading space1"
-               echo " line with leading space1"
-               echo " line with leading space2"
-               echo " line with leading space3"
-               echo "line without leading space2"
-       } >space &&
+       qz_to_tab_space >space <<-\EOF &&
+       line without leading space1
+       Zline with leading space1
+       Zline with leading space2
+       Zline with leading space3
+       line without leading space2
+       EOF
        cat >hello.ps1 <<-\EOF &&
        # No-op.
        function dummy() {}
@@ -106,129 +106,129 @@ do
        esac
 
        test_expect_success "grep -w $L" '
-               {
-                       echo ${HC}file:1:foo mmap bar
-                       echo ${HC}file:3:foo_mmap bar mmap
-                       echo ${HC}file:4:foo mmap bar_mmap
-                       echo ${HC}file:5:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:1:foo mmap bar
+               ${HC}file:3:foo_mmap bar mmap
+               ${HC}file:4:foo mmap bar_mmap
+               ${HC}file:5:foo_mmap bar mmap baz
+               EOF
                git -c grep.linenumber=false grep -n -w -e mmap $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (with --column)" '
-               {
-                       echo ${HC}file:5:foo mmap bar
-                       echo ${HC}file:14:foo_mmap bar mmap
-                       echo ${HC}file:5:foo mmap bar_mmap
-                       echo ${HC}file:14:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:5:foo mmap bar
+               ${HC}file:14:foo_mmap bar mmap
+               ${HC}file:5:foo mmap bar_mmap
+               ${HC}file:14:foo_mmap bar mmap baz
+               EOF
                git grep --column -w -e mmap $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (with --column, extended OR)" '
-               {
-                       echo ${HC}file:14:foo_mmap bar mmap
-                       echo ${HC}file:19:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:14:foo_mmap bar mmap
+               ${HC}file:19:foo_mmap bar mmap baz
+               EOF
                git grep --column -w -e mmap$ --or -e baz $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (with --column, --invert-match)" '
-               {
-                       echo ${HC}file:1:foo mmap bar
-                       echo ${HC}file:1:foo_mmap bar
-                       echo ${HC}file:1:foo_mmap bar mmap
-                       echo ${HC}file:1:foo mmap bar_mmap
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:1:foo mmap bar
+               ${HC}file:1:foo_mmap bar
+               ${HC}file:1:foo_mmap bar mmap
+               ${HC}file:1:foo mmap bar_mmap
+               EOF
                git grep --column --invert-match -w -e baz $H -- file >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L (with --column, --invert-match, extended OR)" '
-               {
-                       echo ${HC}hello_world:6:HeLLo_world
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}hello_world:6:HeLLo_world
+               EOF
                git grep --column --invert-match -e ll --or --not -e _ $H -- hello_world \
                        >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L (with --column, --invert-match, extended AND)" '
-               {
-                       echo ${HC}hello_world:3:Hello world
-                       echo ${HC}hello_world:3:Hello_world
-                       echo ${HC}hello_world:6:HeLLo_world
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}hello_world:3:Hello world
+               ${HC}hello_world:3:Hello_world
+               ${HC}hello_world:6:HeLLo_world
+               EOF
                git grep --column --invert-match --not -e _ --and --not -e ll $H -- hello_world \
                        >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep $L (with --column, double-negation)" '
-               {
-                       echo ${HC}file:1:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:1:foo_mmap bar mmap baz
+               EOF
                git grep --column --not \( --not -e foo --or --not -e baz \) $H -- file \
                        >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (with --column, -C)" '
-               {
-                       echo ${HC}file:5:foo mmap bar
-                       echo ${HC}file-foo_mmap bar
-                       echo ${HC}file:14:foo_mmap bar mmap
-                       echo ${HC}file:5:foo mmap bar_mmap
-                       echo ${HC}file:14:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:5:foo mmap bar
+               ${HC}file-foo_mmap bar
+               ${HC}file:14:foo_mmap bar mmap
+               ${HC}file:5:foo mmap bar_mmap
+               ${HC}file:14:foo_mmap bar mmap baz
+               EOF
                git grep --column -w -C1 -e mmap $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (with --line-number, --column)" '
-               {
-                       echo ${HC}file:1:5:foo mmap bar
-                       echo ${HC}file:3:14:foo_mmap bar mmap
-                       echo ${HC}file:4:5:foo mmap bar_mmap
-                       echo ${HC}file:5:14:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:1:5:foo mmap bar
+               ${HC}file:3:14:foo_mmap bar mmap
+               ${HC}file:4:5:foo mmap bar_mmap
+               ${HC}file:5:14:foo_mmap bar mmap baz
+               EOF
                git grep -n --column -w -e mmap $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (with non-extended patterns, --column)" '
-               {
-                       echo ${HC}file:5:foo mmap bar
-                       echo ${HC}file:10:foo_mmap bar
-                       echo ${HC}file:10:foo_mmap bar mmap
-                       echo ${HC}file:5:foo mmap bar_mmap
-                       echo ${HC}file:10:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:5:foo mmap bar
+               ${HC}file:10:foo_mmap bar
+               ${HC}file:10:foo_mmap bar mmap
+               ${HC}file:5:foo mmap bar_mmap
+               ${HC}file:10:foo_mmap bar mmap baz
+               EOF
                git grep --column -w -e bar -e mmap $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L" '
-               {
-                       echo ${HC}file:1:foo mmap bar
-                       echo ${HC}file:3:foo_mmap bar mmap
-                       echo ${HC}file:4:foo mmap bar_mmap
-                       echo ${HC}file:5:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:1:foo mmap bar
+               ${HC}file:3:foo_mmap bar mmap
+               ${HC}file:4:foo mmap bar_mmap
+               ${HC}file:5:foo_mmap bar mmap baz
+               EOF
                git -c grep.linenumber=true grep -w -e mmap $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L" '
-               {
-                       echo ${HC}file:foo mmap bar
-                       echo ${HC}file:foo_mmap bar mmap
-                       echo ${HC}file:foo mmap bar_mmap
-                       echo ${HC}file:foo_mmap bar mmap baz
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:foo mmap bar
+               ${HC}file:foo_mmap bar mmap
+               ${HC}file:foo mmap bar_mmap
+               ${HC}file:foo_mmap bar mmap baz
+               EOF
                git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual &&
                test_cmp expected actual
        '
@@ -239,17 +239,17 @@ do
        '
 
        test_expect_success "grep -w $L (x)" '
-               {
-                       echo ${HC}x:1:x x xx x
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}x:1:x x xx x
+               EOF
                git grep -n -w -e "x xx* x" $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep -w $L (y-1)" '
-               {
-                       echo ${HC}y:1:y yy
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}y:1:y yy
+               EOF
                git grep -n -w -e "^y" $H >actual &&
                test_cmp expected actual
        '
@@ -277,16 +277,16 @@ do
        '
 
        test_expect_success "grep $L (with --column, --only-matching)" '
-               {
-                       echo ${HC}file:1:5:mmap
-                       echo ${HC}file:2:5:mmap
-                       echo ${HC}file:3:5:mmap
-                       echo ${HC}file:3:13:mmap
-                       echo ${HC}file:4:5:mmap
-                       echo ${HC}file:4:13:mmap
-                       echo ${HC}file:5:5:mmap
-                       echo ${HC}file:5:13:mmap
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}file:1:5:mmap
+               ${HC}file:2:5:mmap
+               ${HC}file:3:5:mmap
+               ${HC}file:3:13:mmap
+               ${HC}file:4:5:mmap
+               ${HC}file:4:13:mmap
+               ${HC}file:5:5:mmap
+               ${HC}file:5:13:mmap
+               EOF
                git grep --column -n -o -e mmap $H >actual &&
                test_cmp expected actual
        '
@@ -320,11 +320,11 @@ do
        '
 
        test_expect_success "grep --max-depth -1 $L" '
-               {
-                       echo ${HC}t/a/v:1:vvv
-                       echo ${HC}t/v:1:vvv
-                       echo ${HC}v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}t/a/v:1:vvv
+               ${HC}t/v:1:vvv
+               ${HC}v:1:vvv
+               EOF
                git grep --max-depth -1 -n -e vvv $H >actual &&
                test_cmp expected actual &&
                git grep --recursive -n -e vvv $H >actual &&
@@ -332,9 +332,9 @@ do
        '
 
        test_expect_success "grep --max-depth 0 $L" '
-               {
-                       echo ${HC}v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}v:1:vvv
+               EOF
                git grep --max-depth 0 -n -e vvv $H >actual &&
                test_cmp expected actual &&
                git grep --no-recursive -n -e vvv $H >actual &&
@@ -342,11 +342,11 @@ do
        '
 
        test_expect_success "grep --max-depth 0 -- '*' $L" '
-               {
-                       echo ${HC}t/a/v:1:vvv
-                       echo ${HC}t/v:1:vvv
-                       echo ${HC}v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}t/a/v:1:vvv
+               ${HC}t/v:1:vvv
+               ${HC}v:1:vvv
+               EOF
                git grep --max-depth 0 -n -e vvv $H -- "*" >actual &&
                test_cmp expected actual &&
                git grep --no-recursive -n -e vvv $H -- "*" >actual &&
@@ -354,18 +354,18 @@ do
        '
 
        test_expect_success "grep --max-depth 1 $L" '
-               {
-                       echo ${HC}t/v:1:vvv
-                       echo ${HC}v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}t/v:1:vvv
+               ${HC}v:1:vvv
+               EOF
                git grep --max-depth 1 -n -e vvv $H >actual &&
                test_cmp expected actual
        '
 
        test_expect_success "grep --max-depth 0 -- t $L" '
-               {
-                       echo ${HC}t/v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}t/v:1:vvv
+               EOF
                git grep --max-depth 0 -n -e vvv $H -- t >actual &&
                test_cmp expected actual &&
                git grep --no-recursive -n -e vvv $H -- t >actual &&
@@ -373,10 +373,10 @@ do
        '
 
        test_expect_success "grep --max-depth 0 -- . t $L" '
-               {
-                       echo ${HC}t/v:1:vvv
-                       echo ${HC}v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}t/v:1:vvv
+               ${HC}v:1:vvv
+               EOF
                git grep --max-depth 0 -n -e vvv $H -- . t >actual &&
                test_cmp expected actual &&
                git grep --no-recursive -n -e vvv $H -- . t >actual &&
@@ -384,10 +384,10 @@ do
        '
 
        test_expect_success "grep --max-depth 0 -- t . $L" '
-               {
-                       echo ${HC}t/v:1:vvv
-                       echo ${HC}v:1:vvv
-               } >expected &&
+               cat >expected <<-EOF &&
+               ${HC}t/v:1:vvv
+               ${HC}v:1:vvv
+               EOF
                git grep --max-depth 0 -n -e vvv $H -- t . >actual &&
                test_cmp expected actual &&
                git grep --no-recursive -n -e vvv $H -- t . >actual &&
@@ -1314,10 +1314,10 @@ test_expect_success PCRE 'grep -P pattern with grep.extendedRegexp=true' '
 '
 
 test_expect_success PCRE 'grep -P -v pattern' '
-       {
-               echo "ab:a+b*c"
-               echo "ab:a+bc"
-       } >expected &&
+       cat >expected <<-\EOF &&
+       ab:a+b*c
+       ab:a+bc
+       EOF
        git grep -P -v "abc" ab >actual &&
        test_cmp expected actual
 '
@@ -1331,10 +1331,10 @@ test_expect_success PCRE 'grep -P -i pattern' '
 '
 
 test_expect_success PCRE 'grep -P -w pattern' '
-       {
-               echo "hello_world:Hello world"
-               echo "hello_world:HeLLo world"
-       } >expected &&
+       cat >expected <<-\EOF &&
+       hello_world:Hello world
+       hello_world:HeLLo world
+       EOF
        git grep -P -w "He((?i)ll)o" hello_world >actual &&
        test_cmp expected actual
 '
@@ -1469,10 +1469,10 @@ test_expect_success 'grep -F pattern with grep.patternType=basic' '
 '
 
 test_expect_success 'grep -G pattern with grep.patternType=fixed' '
-       {
-               echo "ab:a+b*c"
-               echo "ab:a+bc"
-       } >expected &&
+       cat >expected <<-\EOF &&
+       ab:a+b*c
+       ab:a+bc
+       EOF
        git \
                -c grep.patterntype=fixed \
                grep -G "a+b" ab >actual &&
@@ -1480,11 +1480,11 @@ test_expect_success 'grep -G pattern with grep.patternType=fixed' '
 '
 
 test_expect_success 'grep -E pattern with grep.patternType=fixed' '
-       {
-               echo "ab:a+b*c"
-               echo "ab:a+bc"
-               echo "ab:abc"
-       } >expected &&
+       cat >expected <<-\EOF &&
+       ab:a+b*c
+       ab:a+bc
+       ab:abc
+       EOF
        git \
                -c grep.patterntype=fixed \
                grep -E "a+" ab >actual &&
index e5d1e4ea6862694b0392415807d37ef4d3efc71b..ca3f24f8079b7acf491f8e8b0cb20c14e43272d3 100755 (executable)
@@ -123,4 +123,10 @@ test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: gr
        test_cmp invalid-0xe5 actual
 '
 
+test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-literal ASCII from UTF-8' '
+       git grep --perl-regexp -h -o -e ll. file >actual &&
+       echo "lló" >expected &&
+       test_cmp expected actual
+'
+
 test_done
index 5bb302b1ba0f36eff7c3bd64a4a0dd690a135559..ee4fdd8f18d572f82392b6ed2e4b4da9837b63b5 100755 (executable)
@@ -97,7 +97,7 @@ test_expect_success 'set up abbrev tests' '
        test_commit abbrev &&
        sha1=$(git rev-parse --verify HEAD) &&
        check_abbrev () {
-               expect=$1; shift
+               expect=$1 && shift &&
                echo $sha1 | cut -c 1-$expect >expect &&
                git blame "$@" abbrev.t >actual &&
                perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
index da80f815ce9d38f109df07a8dcbe803f8a794309..d751d48b7dae6a3e007d5eb19f92cd41eb445065 100755 (executable)
@@ -13,14 +13,8 @@ test_expect_success setup '
        echo B B B B B >two &&
        echo C C C C C >tres &&
        echo ABC >mouse &&
-       for i in 1 2 3 4 5 6 7 8 9
-       do
-               echo $i
-       done >nine_lines &&
-       for i in 1 2 3 4 5 6 7 8 9 a
-       do
-               echo $i
-       done >ten_lines &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 >nine_lines &&
+       test_write_lines 1 2 3 4 5 6 7 8 9 a >ten_lines &&
        git add one two tres mouse nine_lines ten_lines &&
        test_tick &&
        GIT_AUTHOR_NAME=Initial git commit -m Initial &&
index e68e6115a66d3722413a1982aa86cc2a5d5932eb..0bd034130189db8561d824449de646f2bfcef61f 100755 (executable)
@@ -310,7 +310,7 @@ test_expect_success setup '
                        echo "$line" >>"$i" &&
                        git add "$i" &&
                        test_tick &&
-                       GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count"
+                       GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" || return 1
                done <"a$i"
        done &&
 
@@ -318,7 +318,7 @@ test_expect_success setup '
        do
                # Overwrite the files with the final content.
                cp b$i $i &&
-               git add $i
+               git add $i || return 1
        done &&
        test_tick &&
 
index 67eed2fefcec974f7f166b3221150392323211c5..c7d8e0bf00f6344d1216f117f57587cda3116fc2 100755 (executable)
@@ -117,7 +117,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' '
        mkdir -p import/trunk/subversion/bindings/swig/perl/t &&
        for i in a b c ; do \
          echo $i > import/trunk/subversion/bindings/swig/perl/$i.pm &&
-         echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t; \
+         echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t || return 1
        done &&
          echo "bad delete test" > \
           import/trunk/subversion/bindings/swig/perl/t/larger-parent &&
@@ -134,7 +134,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' '
                svn mv t native/t &&
                for i in a b c
                do
-                       svn mv $i.pm native/$i.pm
+                       svn mv $i.pm native/$i.pm || return 1
                done &&
                echo z >>native/t/c.t &&
                poke native/t/c.t &&
index ceaa5bad105e52eca3d193255766548e41d84f31..aa908bbc2f7dad953a3ee35c2fe32b027826f9fc 100755 (executable)
@@ -98,10 +98,10 @@ test_expect_success 'migrate --minimize on old inited layout' '
        rm -rf "$GIT_DIR"/svn &&
        for i in $(cat fetch.out)
        do
-               path=$(expr $i : "\([^:]*\):.*$")
-               ref=$(expr $i : "[^:]*:\(refs/remotes/.*\)$")
-               if test -z "$ref"; then continue; fi
-               if test -n "$path"; then path="/$path"; fi
+               path=${i%%:*} &&
+               ref=${i#*:} &&
+               if test "$ref" = "${ref#refs/remotes/}"; then continue; fi &&
+               if test -n "$path"; then path="/$path"; fi &&
                mkdir -p "$GIT_DIR"/svn/$ref/info/ &&
                echo "$svnrepo"$path >"$GIT_DIR"/svn/$ref/info/url ||
                return 1
index cb764bcadc72cd954d3727f6fbc4d1e0d1fe6c46..90325db909e43c09b13cdf0c731d5e4260566313 100755 (executable)
@@ -15,7 +15,7 @@ EOF
 test_expect_success 'setup svnrepo' '
        for i in aa bb cc dd
        do
-               svn_cmd mkdir -m $i --username $i "$svnrepo"/$i
+               svn_cmd mkdir -m $i --username $i "$svnrepo"/$i || return 1
        done
        '
 
@@ -59,8 +59,8 @@ test_expect_success 'authors-file against globs' '
        git svn clone --authors-file=svn-authors -s "$svnrepo"/aa aa-work &&
        for i in bb ee cc
        do
-               branch="aa/branches/$i"
-               svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch"
+               branch="aa/branches/$i" &&
+               svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" || return 1
        done
        '
 
index fff49c4100852b28899c6694a33acd3b96b188b8..4a77eb9f60da3ade87ed701ecb0dca7f7ad13d87 100755 (executable)
@@ -27,7 +27,7 @@ test_expect_success 'setup test repository' '
 test_expect_success 'clone an SVN repository with ignored www directory' '
        git svn clone --ignore-paths="^www" "$svnrepo" g &&
        echo test_qqq > expect &&
-       for i in g/*/*.txt; do cat $i >> expect2; done &&
+       for i in g/*/*.txt; do cat $i >> expect2 || return 1; done &&
        test_cmp expect expect2
 '
 
@@ -36,7 +36,7 @@ test_expect_success 'init+fetch an SVN repository with ignored www directory' '
        ( cd c && git svn fetch --ignore-paths="^www" ) &&
        rm expect2 &&
        echo test_qqq > expect &&
-       for i in c/*/*.txt; do cat $i >> expect2; done &&
+       for i in c/*/*.txt; do cat $i >> expect2 || return 1; done &&
        test_cmp expect expect2
 '
 
@@ -62,7 +62,7 @@ test_expect_success 'update git svn-cloned repo (config ignore)' '
                cd g &&
                git svn rebase &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -73,7 +73,7 @@ test_expect_success 'update git svn-cloned repo (option ignore)' '
                cd c &&
                git svn rebase --ignore-paths="^www" &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -94,7 +94,7 @@ test_expect_success 'update git svn-cloned repo (config ignore)' '
                cd g &&
                git svn rebase &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -105,7 +105,7 @@ test_expect_success 'update git svn-cloned repo (option ignore)' '
                cd c &&
                git svn rebase --ignore-paths="^www" &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -127,7 +127,7 @@ test_expect_success 'update git svn-cloned repo again (config ignore)' '
                cd g &&
                git svn rebase &&
                printf "test_qqq\nb\nygg\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -138,7 +138,7 @@ test_expect_success 'update git svn-cloned repo again (option ignore)' '
                cd c &&
                git svn rebase --ignore-paths="^www" &&
                printf "test_qqq\nb\nygg\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
index 027b416720ddf774ffd52e9bd3267b009bd70899..784ec7fc2d6e4d22feaad6dfc17120e24856b407 100755 (executable)
@@ -27,7 +27,7 @@ test_expect_success 'svn-authors setup' '
 test_expect_success 'setup svnrepo' '
        for i in aa bb cc-sub dd-sub ee-foo ff
        do
-               svn mkdir -m $i --username $i "$svnrepo"/$i
+               svn mkdir -m $i --username $i "$svnrepo"/$i || return 1
        done
 '
 
index 5f91c0d68b4582958e2ba5e20e888b9369e6a3f4..80cb55fee70e2affd719c0b6812e01f3125ce42e 100755 (executable)
@@ -8,7 +8,7 @@ test_description='git svn creates empty directories'
 test_expect_success 'initialize repo' '
        for i in a b c d d/e d/e/f "weird file name"
        do
-               svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
+               svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1
        done
 '
 
@@ -102,7 +102,7 @@ test_expect_success 'git svn mkdirs -r works' '
 test_expect_success 'initialize trunk' '
        for i in trunk trunk/a trunk/"weird file name"
        do
-               svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
+               svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1
        done
 '
 
index d292bf9f55cdbedefca4e3e0777dd1f701dea9be..257fc8f2f8d194bbf1a0bb151da1b80d85874e28 100755 (executable)
@@ -28,7 +28,7 @@ test_expect_success 'setup test repository' '
 test_expect_success 'clone an SVN repository with filter to include qqq directory' '
        git svn clone --include-paths="qqq" "$svnrepo" g &&
        echo test_qqq > expect &&
-       for i in g/*/*.txt; do cat $i >> expect2; done &&
+       for i in g/*/*.txt; do cat $i >> expect2 || return 1; done &&
        test_cmp expect expect2
 '
 
@@ -38,7 +38,7 @@ test_expect_success 'init+fetch an SVN repository with included qqq directory' '
        ( cd c && git svn fetch --include-paths="qqq" ) &&
        rm expect2 &&
        echo test_qqq > expect &&
-       for i in c/*/*.txt; do cat $i >> expect2; done &&
+       for i in c/*/*.txt; do cat $i >> expect2 || return 1; done &&
        test_cmp expect expect2
 '
 
@@ -64,7 +64,7 @@ test_expect_success 'update git svn-cloned repo (config include)' '
                cd g &&
                git svn rebase &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -75,7 +75,7 @@ test_expect_success 'update git svn-cloned repo (option include)' '
                cd c &&
                git svn rebase --include-paths="qqq" &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -96,7 +96,7 @@ test_expect_success 'update git svn-cloned repo (config include)' '
                cd g &&
                git svn rebase &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -107,7 +107,7 @@ test_expect_success 'update git svn-cloned repo (option include)' '
                cd c &&
                git svn rebase --include-paths="qqq" &&
                printf "test_qqq\nb\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -129,7 +129,7 @@ test_expect_success 'update git svn-cloned repo again (config include)' '
                cd g &&
                git svn rebase &&
                printf "test_qqq\nb\nygg\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
@@ -140,7 +140,7 @@ test_expect_success 'update git svn-cloned repo again (option include)' '
                cd c &&
                git svn rebase --include-paths="qqq" &&
                printf "test_qqq\nb\nygg\n" > expect &&
-               for i in */*.txt; do cat $i >> expect2; done &&
+               for i in */*.txt; do cat $i >> expect2 || exit 1; done &&
                test_cmp expect2 expect &&
                rm expect expect2
        )
index 89f285d082965c0b8f0d8cbee226f3c8e2a75cfd..a597c42f77de667047c94a02534f11f884995ed7 100755 (executable)
@@ -8,7 +8,7 @@ test_description='git svn creates empty directories, calls git gc, makes sure th
 test_expect_success 'initialize repo' '
        for i in a b c d d/e d/e/f "weird file name"
        do
-               svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i"
+               svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1
        done
 '
 
index d4359dba21c9cff29da7f96541e7c2293da759f3..bed01c99ea704244ace8c189dc428cd432eb6205 100755 (executable)
@@ -16,7 +16,7 @@ test_expect_success 'setup large marks file' '
        blob=$(git rev-parse HEAD:one.t) &&
        for i in $(test_seq 1024 16384)
        do
-               echo ":$i $blob"
+               echo ":$i $blob" || return 1
        done >>marks
 '
 
index 409b48e244224629a11ced5d9cbd99fd81f167ae..7b7a18dd2c1e07afe2a129b868bf878020882a1f 100755 (executable)
@@ -750,4 +750,36 @@ test_expect_success 'merge commit gets exported with --import-marks' '
        )
 '
 
+
+test_expect_success 'fast-export --first-parent outputs all revisions output by revision walk' '
+       git init first-parent &&
+       (
+               cd first-parent &&
+               test_commit A &&
+               git checkout -b topic1 &&
+               test_commit B &&
+               git checkout main &&
+               git merge --no-ff topic1 &&
+
+               git checkout -b topic2 &&
+               test_commit C &&
+               git checkout main &&
+               git merge --no-ff topic2 &&
+
+               test_commit D &&
+
+               git fast-export main -- --first-parent >first-parent-export &&
+               git fast-export main -- --first-parent --reverse >first-parent-reverse-export &&
+               test_cmp first-parent-export first-parent-reverse-export &&
+
+               git init import &&
+               git -C import fast-import <first-parent-export &&
+
+               git log --format="%ad %s" --first-parent main >expected &&
+               git -C import log --format="%ad %s" --all >actual &&
+               test_cmp expected actual &&
+               test_line_count = 4 actual
+       )
+'
+
 test_done
index 17f988edd268d60e4b4a7dd2074c5566b290554f..210ddf09e3094ebe5fa00599db22106813f4229e 100755 (executable)
@@ -338,7 +338,7 @@ test_expect_success 'cvs update (subdirectories)' \
   '(for dir in A A/B A/B/C A/D E; do
       mkdir $dir &&
       echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
-      git add $dir
+      git add $dir || exit 1
    done) &&
    git commit -q -m "deep sub directory structure" &&
    git push gitcvs.git >/dev/null &&
@@ -350,10 +350,9 @@ test_expect_success 'cvs update (subdirectories)' \
        test_cmp "$dir/$filename" "../$dir/$filename"; then
         :
       else
-        echo >failure
+       exit 1
       fi
-    done) &&
-   test ! -f failure'
+    done)'
 
 cd "$WORKDIR"
 test_expect_success 'cvs update (delete file)' \
@@ -382,7 +381,7 @@ test_expect_success 'cvs update (merge)' \
    for i in 1 2 3 4 5 6 7
    do
      echo Line $i >>merge &&
-     echo Line $i >>expected
+     echo Line $i >>expected || return 1
    done &&
    echo Line 8 >>expected &&
    git add merge &&
@@ -592,7 +591,7 @@ test_expect_success 'cvs annotate' '
     cd cvswork &&
     GIT_CONFIG="$git_config" cvs annotate merge >../out &&
     sed -e "s/ .*//" ../out >../actual &&
-    for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
+    printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
     test_cmp ../expect ../actual
 '
 
index 81bc8e8da1aa3feeec001b9f479998d76e899dd8..806005a793a3ed70492d08878d99fae499464ca9 100755 (executable)
@@ -171,7 +171,7 @@ test_expect_success 'clone using non-numeric revision ranges' '
                        cd "$git" &&
                        git ls-files >lines &&
                        test_line_count = 8 lines
-               )
+               ) || return 1
        done
 '
 
index e3836888ec8b322cf1032d9a1804fec915c10b11..5fe83315ecd57a81055bdcf2d055122ec53fd3b8 100755 (executable)
@@ -4,6 +4,8 @@ test_description='git p4 rcs keywords'
 
 . ./lib-git-p4.sh
 
+CP1252="\223\224"
+
 test_expect_success 'start p4d' '
        start_p4d
 '
@@ -32,6 +34,9 @@ test_expect_success 'init depot' '
                p4 submit -d "filek" &&
                p4 add -t text+ko fileko &&
                p4 submit -d "fileko" &&
+               printf "$CP1252" >fileko_cp1252 &&
+               p4 add -t text+ko fileko_cp1252 &&
+               p4 submit -d "fileko_cp1252" &&
                p4 add -t text file_text &&
                p4 submit -d "file_text"
        )
@@ -359,4 +364,14 @@ test_expect_failure 'Add keywords in git which do not match the default p4 value
        )
 '
 
+test_expect_success 'check cp1252 smart quote are preserved through RCS keyword processing' '
+       test_when_finished cleanup_git &&
+       git p4 clone --dest="$git" //depot &&
+       (
+               cd "$git" &&
+               printf "$CP1252" >expect &&
+               test_cmp_bin expect fileko_cp1252
+       )
+'
+
 test_done
index 0db7ab99184add2c500f821659b09cc833c6a225..de591d875c2bbc94fd1c9b093867d23f3ce1b00c 100755 (executable)
@@ -92,11 +92,11 @@ test_expect_success 'Add some more files' '
        for i in $(test_seq 0 10)
        do
                p4_add_file "included/x$i" &&
-               p4_add_file "excluded/x$i"
+               p4_add_file "excluded/x$i" || return 1
        done &&
        for i in $(test_seq 0 10)
        do
-               p4_add_file "excluded/y$i"
+               p4_add_file "excluded/y$i" || return 1
        done
 '
 
@@ -123,7 +123,7 @@ test_expect_success 'Create a repo with multiple depot paths' '
        do
                for i in $(test_seq 1 10)
                do
-                       p4_add_file "$p/file$p$i"
+                       p4_add_file "$p/file$p$i" || return 1
                done
        done
 '
index 0f28c4ad940504f05c262c2040672ab6d9524526..98c628063288bca40f08664abf329340f05a28fa 100755 (executable)
@@ -876,7 +876,7 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer
                refs/remotes/remote/branch-in-remote
        do
                git update-ref $remote_ref main &&
-               test_when_finished "git update-ref -d $remote_ref"
+               test_when_finished "git update-ref -d $remote_ref" || return 1
        done &&
        (
                cur= &&
@@ -1049,7 +1049,7 @@ test_expect_success '__git_refs - only matching refs - checkout DWIMery' '
                refs/remotes/remote/branch-in-remote
        do
                git update-ref $remote_ref main &&
-               test_when_finished "git update-ref -d $remote_ref"
+               test_when_finished "git update-ref -d $remote_ref" || return 1
        done &&
        (
                cur=mat &&
index 389153e591620a379ebe496026eaa05db8ac8dc2..c3d38aaccbd526be398416de3a942f6335aa9bb4 100644 (file)
@@ -1759,6 +1759,40 @@ test_subcommand () {
        fi
 }
 
+# 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.
 #
index b8d880e3626a9cdbc818cf69bda67fcd256194b1..3d38eeab66bfb048c20dd3490f92f2a6e15e040b 100644 (file)
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "tmp-objdir.h"
+#include "chdir-notify.h"
 #include "dir.h"
 #include "sigchain.h"
 #include "string-list.h"
@@ -11,6 +12,8 @@
 struct tmp_objdir {
        struct strbuf path;
        struct strvec env;
+       struct object_directory *prev_odb;
+       int will_destroy;
 };
 
 /*
@@ -38,6 +41,9 @@ static int tmp_objdir_destroy_1(struct tmp_objdir *t, int on_signal)
        if (t == the_tmp_objdir)
                the_tmp_objdir = NULL;
 
+       if (!on_signal && t->prev_odb)
+               restore_primary_odb(t->prev_odb, t->path.buf);
+
        /*
         * This may use malloc via strbuf_grow(), but we should
         * have pre-grown t->path sufficiently so that this
@@ -52,6 +58,7 @@ static int tmp_objdir_destroy_1(struct tmp_objdir *t, int on_signal)
         */
        if (!on_signal)
                tmp_objdir_free(t);
+
        return err;
 }
 
@@ -121,7 +128,7 @@ static int setup_tmp_objdir(const char *root)
        return ret;
 }
 
-struct tmp_objdir *tmp_objdir_create(void)
+struct tmp_objdir *tmp_objdir_create(const char *prefix)
 {
        static int installed_handlers;
        struct tmp_objdir *t;
@@ -129,11 +136,16 @@ struct tmp_objdir *tmp_objdir_create(void)
        if (the_tmp_objdir)
                BUG("only one tmp_objdir can be used at a time");
 
-       t = xmalloc(sizeof(*t));
+       t = xcalloc(1, sizeof(*t));
        strbuf_init(&t->path, 0);
        strvec_init(&t->env);
 
-       strbuf_addf(&t->path, "%s/incoming-XXXXXX", get_object_directory());
+       /*
+        * Use a string starting with tmp_ so that the builtin/prune.c code
+        * can recognize any stale objdirs left behind by a crash and delete
+        * them.
+        */
+       strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", get_object_directory(), prefix);
 
        /*
         * Grow the strbuf beyond any filename we expect to be placed in it.
@@ -269,6 +281,13 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
        if (!t)
                return 0;
 
+       if (t->prev_odb) {
+               if (the_repository->objects->odb->will_destroy)
+                       BUG("migrating an ODB that was marked for destruction");
+               restore_primary_odb(t->prev_odb, t->path.buf);
+               t->prev_odb = NULL;
+       }
+
        strbuf_addbuf(&src, &t->path);
        strbuf_addstr(&dst, get_object_directory());
 
@@ -292,3 +311,33 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *t)
 {
        add_to_alternates_memory(t->path.buf);
 }
+
+void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy)
+{
+       if (t->prev_odb)
+               BUG("the primary object database is already replaced");
+       t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy);
+       t->will_destroy = will_destroy;
+}
+
+struct tmp_objdir *tmp_objdir_unapply_primary_odb(void)
+{
+       if (!the_tmp_objdir || !the_tmp_objdir->prev_odb)
+               return NULL;
+
+       restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf);
+       the_tmp_objdir->prev_odb = NULL;
+       return the_tmp_objdir;
+}
+
+void tmp_objdir_reapply_primary_odb(struct tmp_objdir *t, const char *old_cwd,
+               const char *new_cwd)
+{
+       char *path;
+
+       path = reparent_relative_path(old_cwd, new_cwd, t->path.buf);
+       strbuf_reset(&t->path);
+       strbuf_addstr(&t->path, path);
+       free(path);
+       tmp_objdir_replace_primary_odb(t, t->will_destroy);
+}
index b1e45b4c75d2d8877dce507a7f2134aa93da8e17..cda5ec7677881c5a47bb5f2ebf3edc3a3140a73c 100644 (file)
@@ -10,7 +10,7 @@
  *
  * Example:
  *
- *     struct tmp_objdir *t = tmp_objdir_create();
+ *     struct tmp_objdir *t = tmp_objdir_create("incoming");
  *     if (!run_command_v_opt_cd_env(cmd, 0, NULL, tmp_objdir_env(t)) &&
  *         !tmp_objdir_migrate(t))
  *             printf("success!\n");
 struct tmp_objdir;
 
 /*
- * Create a new temporary object directory; returns NULL on failure.
+ * Create a new temporary object directory with the specified prefix;
+ * returns NULL on failure.
  */
-struct tmp_objdir *tmp_objdir_create(void);
+struct tmp_objdir *tmp_objdir_create(const char *prefix);
 
 /*
  * Return a list of environment strings, suitable for use with
@@ -51,4 +52,26 @@ int tmp_objdir_destroy(struct tmp_objdir *);
  */
 void tmp_objdir_add_as_alternate(const struct tmp_objdir *);
 
+/*
+ * Replaces the writable object store in the current process with the temporary
+ * object directory and makes the former main object store an alternate.
+ * If will_destroy is nonzero, the object directory may not be migrated.
+ */
+void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy);
+
+/*
+ * If the primary object database was replaced by a temporary object directory,
+ * restore it to its original value while keeping the directory contents around.
+ * Returns NULL if the primary object database was not replaced.
+ */
+struct tmp_objdir *tmp_objdir_unapply_primary_odb(void);
+
+/*
+ * Reapplies the former primary temporary object database, after potentially
+ * changing its relative path.
+ */
+void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd,
+               const char *new_cwd);
+
+
 #endif /* TMP_OBJDIR_H */
index 98e2f2e0e6f7470f77d92782b86aa8ad8be00943..360844bda3ab976c73e9443b318b58dfc400f475 100644 (file)
@@ -36,6 +36,9 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = {
        /* ERROR_NOT_UPTODATE_DIR */
        "Updating '%s' would lose untracked files in it",
 
+       /* ERROR_CWD_IN_THE_WAY */
+       "Refusing to remove '%s' since it is the current working directory.",
+
        /* ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN */
        "Untracked working tree file '%s' would be overwritten by merge.",
 
@@ -131,6 +134,9 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
        msgs[ERROR_NOT_UPTODATE_DIR] =
                _("Updating the following directories would lose untracked files in them:\n%s");
 
+       msgs[ERROR_CWD_IN_THE_WAY] =
+               _("Refusing to remove the current working directory:\n%s");
+
        if (!strcmp(cmd, "checkout"))
                msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
                      ? _("The following untracked working tree files would be removed by checkout:\n%%s"
@@ -2159,10 +2165,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
                cnt++;
        }
 
-       /*
-        * Then we need to make sure that we do not lose a locally
-        * present file that is not ignored.
-        */
+       /* Do not lose a locally present file that is not ignored. */
        pathbuf = xstrfmt("%.*s/", namelen, ce->name);
 
        memset(&d, 0, sizeof(d));
@@ -2173,6 +2176,12 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
        free(pathbuf);
        if (i)
                return add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
+
+       /* Do not lose startup_info->original_cwd */
+       if (startup_info->original_cwd &&
+           !strcmp(startup_info->original_cwd, ce->name))
+               return add_rejected_path(o, ERROR_CWD_IN_THE_WAY, ce->name);
+
        return cnt;
 }
 
@@ -2265,9 +2274,18 @@ static int verify_absent_1(const struct cache_entry *ce,
        int len;
        struct stat st;
 
-       if (o->index_only || !o->update ||
-           o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED)
+       if (o->index_only || !o->update)
+               return 0;
+
+       if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED) {
+               /* Avoid nuking startup_info->original_cwd... */
+               if (startup_info->original_cwd &&
+                   !strcmp(startup_info->original_cwd, ce->name))
+                       return add_rejected_path(o, ERROR_CWD_IN_THE_WAY,
+                                                ce->name);
+               /* ...but nuke anything else. */
                return 0;
+       }
 
        len = check_leading_path(ce->name, ce_namelen(ce), 0);
        if (!len)
index 71ffb7eeb0c0d1df8539cdff4d6383116d4ff1b4..efb9edfbb2717b4739247ecdd58a104e1d44cfd2 100644 (file)
@@ -19,6 +19,7 @@ enum unpack_trees_error_types {
        ERROR_WOULD_OVERWRITE = 0,
        ERROR_NOT_UPTODATE_FILE,
        ERROR_NOT_UPTODATE_DIR,
+       ERROR_CWD_IN_THE_WAY,
        ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN,
        ERROR_WOULD_LOSE_UNTRACKED_REMOVED,
        ERROR_BIND_OVERLAP,
index 9b5db32623fa3100a697a6ddf64cccc75865563f..8acc98741bbb83db90dc6b0901d5be817cacd0a3 100644 (file)
@@ -194,7 +194,13 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
 }
 
 struct output_state {
-       char buffer[8193];
+       /*
+        * We do writes no bigger than LARGE_PACKET_DATA_MAX - 1, because with
+        * sideband-64k the band designator takes up 1 byte of space. Because
+        * relay_pack_data keeps the last byte to itself, we make the buffer 1
+        * byte bigger than the intended maximum write size.
+        */
+       char buffer[(LARGE_PACKET_DATA_MAX - 1) + 1];
        int used;
        unsigned packfile_uris_started : 1;
        unsigned packfile_started : 1;
@@ -269,7 +275,7 @@ static void create_pack_file(struct upload_pack_data *pack_data,
                             const struct string_list *uri_protocols)
 {
        struct child_process pack_objects = CHILD_PROCESS_INIT;
-       struct output_state output_state = { { 0 } };
+       struct output_state *output_state = xcalloc(1, sizeof(struct output_state));
        char progress[128];
        char abort_msg[] = "aborting due to possible repository "
                "corruption on the remote side.";
@@ -404,7 +410,7 @@ static void create_pack_file(struct upload_pack_data *pack_data,
                }
                if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
                        int result = relay_pack_data(pack_objects.out,
-                                                    &output_state,
+                                                    output_state,
                                                     pack_data->use_sideband,
                                                     !!uri_protocols);
 
@@ -438,11 +444,12 @@ static void create_pack_file(struct upload_pack_data *pack_data,
        }
 
        /* flush the data */
-       if (output_state.used > 0) {
-               send_client_data(1, output_state.buffer, output_state.used,
+       if (output_state->used > 0) {
+               send_client_data(1, output_state->buffer, output_state->used,
                                 pack_data->use_sideband);
                fprintf(stderr, "flushed.\n");
        }
+       free(output_state);
        if (pack_data->use_sideband)
                packet_flush(1);
        return;
index 5d215f4e4f1ea862a169bab5c2cb2039ad0d50d3..335e723a71e2537095359d3d4ee6cb77daea1e16 100644 (file)
@@ -1218,17 +1218,23 @@ static void show_merge_in_progress(struct wt_status *s,
 static void show_am_in_progress(struct wt_status *s,
                                const char *color)
 {
+       int am_empty_patch;
+
        status_printf_ln(s, color,
                _("You are in the middle of an am session."));
        if (s->state.am_empty_patch)
                status_printf_ln(s, color,
                        _("The current patch is empty."));
        if (s->hints) {
-               if (!s->state.am_empty_patch)
+               am_empty_patch = s->state.am_empty_patch;
+               if (!am_empty_patch)
                        status_printf_ln(s, color,
                                _("  (fix conflicts and then run \"git am --continue\")"));
                status_printf_ln(s, color,
                        _("  (use \"git am --skip\" to skip this patch)"));
+               if (am_empty_patch)
+                       status_printf_ln(s, color,
+                               _("  (use \"git am --allow-empty\" to record this patch as an empty commit)"));
                status_printf_ln(s, color,
                        _("  (use \"git am --abort\" to restore the original branch)"));
        }