Merge tag 'l10n-2.9.0-rc0' of git://github.com/git-l10n/git-po

l10n-2.9.0-rc0

* tag 'l10n-2.9.0-rc0' of git://github.com/git-l10n/git-po:
  l10n: ko.po: Update Korean translation
  l10n: ru.po: update Russian translation
  l10n: de.po: translate 104 new messages
  l10n: zh_CN: review for git v2.9.0 l10n round 1
  l10n: zh_CN: for git v2.9.0 l10n round 1
  l10n: pt_PT: update Portuguese translation
  l10n: pt_PT: update according to git-gui glossary
  l10n: pt_PT: merge git.pot file
  l10n: Updated Bulgarian translation of git (2597t,0f,0u)
  l10n: sv.po: Update Swedish translation (2597t0f0u)
  l10n: fr.po v2.9.0rnd1
  l10n: Updated Vietnamese translation (2597t)
  l10n: git.pot: v2.9.0 round 1 (104 new, 37 removed)
  l10n: fr.po Fixed grammar mistake
diff --git a/Documentation/Makefile b/Documentation/Makefile
index f6e288b..35c1385 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -146,7 +146,7 @@
 	ASCIIDOC_EXTRA += -a git-asciidoc-no-roff
 	endif
 endif
-ifdef MAN_BOLD_LITERAL
+ifndef NO_MAN_BOLD_LITERAL
 XMLTO_EXTRA += -m manpage-bold-literal.xsl
 endif
 ifdef DOCBOOK_SUPPRESS_SP
diff --git a/Documentation/RelNotes/2.8.4.txt b/Documentation/RelNotes/2.8.4.txt
new file mode 100644
index 0000000..f4e2552
--- /dev/null
+++ b/Documentation/RelNotes/2.8.4.txt
@@ -0,0 +1,69 @@
+Git v2.8.4 Release Notes
+========================
+
+Fixes since v2.8.3
+------------------
+
+ * Documentation for "git merge --verify-signatures" has been updated
+   to clarify that the signature of only the commit at the tip is
+   verified.  Also the phrasing used for signature and key validity is
+   adjusted to align with that used by OpenPGP.
+
+ * On Windows, .git and optionally any files whose name starts with a
+   dot are now marked as hidden, with a core.hideDotFiles knob to
+   customize this behaviour.
+
+ * Portability enhancement for "rebase -i" to help platforms whose
+   shell does not like "for i in <empty>" (which is not POSIX-kosher).
+
+ * "git fsck" learned to catch NUL byte in a commit object as
+   potential error and warn.
+
+ * CI test was taught to build documentation pages.
+
+ * Many 'linkgit:<git documentation page>' references were broken,
+   which are all fixed with this.
+
+ * "git describe --contains" often made a hard-to-justify choice of
+   tag to give name to a given commit, because it tried to come up
+   with a name with smallest number of hops from a tag, causing an old
+   commit whose close descendant that is recently tagged were not
+   described with respect to an old tag but with a newer tag.  It did
+   not help that its computation of "hop" count was further tweaked to
+   penalize being on a side branch of a merge.  The logic has been
+   updated to favor using the tag with the oldest tagger date, which
+   is a lot easier to explain to the end users: "We describe a commit
+   in terms of the (chronologically) oldest tag that contains the
+   commit."
+
+ * Running tests with '-x' option to trace the individual command
+   executions is a useful way to debug test scripts, but some tests
+   that capture the standard error stream and check what the command
+   said can be broken with the trace output mixed in.  When running
+   our tests under "bash", however, we can redirect the trace output
+   to another file descriptor to keep the standard error of programs
+   being tested intact.
+
+ * "http.cookieFile" configuration variable clearly wants a pathname,
+   but we forgot to treat it as such by e.g. applying tilde expansion.
+
+ * When de-initialising all submodules, "git submodule deinit" gave a
+   faulty recommendation to use "git submodule deinit .", which would
+   result in a strange error message in a pathological corner case.
+   This has been corrected to suggest "submodule deinit --all" instead.
+
+ * Many commands normalize command line arguments from NFD to NFC
+   variant of UTF-8 on OSX, but commands in the "diff" family did
+   not, causing "git diff $path" to complain that no such path is
+   known to Git.  They have been taught to do the normalization.
+
+ * A couple of bugs around core.autocrlf have been fixed.
+
+ * "git difftool" learned to handle unmerged paths correctly in
+   dir-diff mode.
+
+ * The "are we talking with TTY, doing an interactive session?"
+   detection has been updated to work better for "Git for Windows".
+
+
+Also contains other minor documentation updates and code clean-ups.
diff --git a/Documentation/RelNotes/2.9.0.txt b/Documentation/RelNotes/2.9.0.txt
index a60e92e..b61d367 100644
--- a/Documentation/RelNotes/2.9.0.txt
+++ b/Documentation/RelNotes/2.9.0.txt
@@ -1,12 +1,12 @@
 Git 2.9 Release Notes
 =====================
 
-Backward compatibility note
----------------------------
+Backward compatibility notes
+----------------------------
 
 The end-user facing Porcelain level commands in the "git diff" and
-"git log" by default enables the rename detection; you can still use
-"diff.renames" configuration variable to disable this.
+"git log" family by default enable the rename detection; you can still
+use "diff.renames" configuration variable to disable this.
 
 Merging two branches that have no common ancestor with "git merge" is
 by default forbidden now to prevent creating such an unusual merge by
@@ -30,8 +30,8 @@
 
  * Comes with git-multimail 1.3.1 (in contrib/).
 
- * The end-user facing Porcelain level commands like "diff" and "log"
-   now enables the rename detection by default.
+ * The end-user facing commands like "git diff" and "git log"
+   now enable the rename detection by default.
 
  * The credential.helper configuration variable is cumulative and
    there is no good way to override it from the command line.  As
@@ -39,7 +39,7 @@
    as the signal to clear the values specified in various files.
 
  * A new "interactive.diffFilter" configuration can be used to
-   customize the diff shown in "git add -i" session.
+   customize the diff shown in "git add -i" sessions.
 
  * "git p4" now allows P4 author names to be mapped to Git author
    names.
@@ -64,7 +64,7 @@
    to be used in a rare event that merges histories of two projects
    that started their lives independently.
 
- * "git pull" has been taught to pass --allow-unrelated-histories
+ * "git pull" has been taught to pass the "--allow-unrelated-histories"
    option to underlying "git merge".
 
  * "git apply -v" learned to report paths in the patch that were
@@ -87,7 +87,7 @@
 
  * When "git log" shows the log message indented by 4-spaces, the
    remainder of a line after a HT does not align in the way the author
-   originally intended.  The command now expands tabs by default in
+   originally intended.  The command now expands tabs by default to help
    such a case, and allows the users to override it with a new option,
    "--no-expand-tabs".
 
@@ -97,13 +97,12 @@
  * "git rerere" can encounter two or more files with the same conflict
    signature that have to be resolved in different ways, but there was
    no way to record these separate resolutions.
-   (merge d9d501b068 jc/rerere-multi later to maint).
 
  * "git p4" learned to record P4 jobs in Git commit that imports from
    the history in Perforce.
 
  * "git describe --contains" often made a hard-to-justify choice of
-   tag to give name to a given commit, because it tried to come up
+   tag to name a given commit, because it tried to come up
    with a name with smallest number of hops from a tag, causing an old
    commit whose close descendant that is recently tagged were not
    described with respect to an old tag but with a newer tag.  It did
@@ -113,16 +112,17 @@
    is a lot easier to explain to the end users: "We describe a commit
    in terms of the (chronologically) oldest tag that contains the
    commit."
-   (merge 7550424 js/name-rev-use-oldest-ref later to maint).
 
- * "git clone" learned "--shallow-submodules" option.
+ * "git clone" learned the "--shallow-submodules" option.
 
  * HTTP transport clients learned to throw extra HTTP headers at the
    server, specified via http.extraHeader configuration variable.
 
- * Patch output from "git diff" and friends has been tweaked to be
-   more readable by using a blank line as a strong hint that the
-   contents before and after it belong to a logically separate unit.
+ * The "--compaction-heuristic" option to "git diff" family of
+   commands enables a heuristic to make the patch output more readable
+   by using a blank line as a strong hint that the contents before and
+   after it belong to logically separate units.  It is still
+   experimental.
 
  * A new configuration variable core.hooksPath allows customizing
    where the hook directory is.
@@ -147,9 +147,20 @@
    (public, well-known) commit the original series was built on in
    its output.
 
- * "git commit" learned to pay attention to "commit.verbose"
-   configuration variable and act as if "--verbose" option was
-   given from the command line.
+ * "git commit" learned to pay attention to the "commit.verbose"
+   configuration variable and act as if the "--verbose" option
+   was given from the command line.
+
+ * Updated documentation gives hints to GMail users with two-factor
+   auth enabled that they need app-specific-password when using
+   "git send-email".
+
+ * The manpage output of our documentation did not render well in
+   terminal; typeset literals in bold by default to make them stand
+   out more.
+
+ * The mark-up in the top-level README.md file has been updated to
+   typeset CLI command names differently from the body text.
 
 
 Performance, Internal Implementation, Development Support etc.
@@ -171,7 +182,8 @@
 
  * A major part of "git submodule update" has been ported to C to take
    advantage of the recently added framework to run download tasks in
-   parallel.
+   parallel.  Other updates to "git submodule" that move pieces of
+   logic to C continues.
 
  * Rename bunch of tests on "git clone" for better organization.
 
@@ -185,16 +197,15 @@
    do not attempt to look into refs/* when we know we do not have a
    Git repository.
 
- * Code restructuring around the "refs" area to prepare for pluggable
+ * Code restructuring around the "refs" API to prepare for pluggable
    refs backends.
 
- * Sources to many test helper binaries (and the generated helpers)
+ * Sources to many test helper binaries and the generated helpers
    have been moved to t/helper/ subdirectory to reduce clutter at the
    top level of the tree.
 
  * Unify internal logic between "git tag -v" and "git verify-tag"
    commands by making one directly call into the other.
-   (merge bef234b st/verify-tag later to maint).
 
  * "merge-recursive" strategy incorrectly checked if a path that is
    involved in its internal merge exists in the working tree.
@@ -206,9 +217,7 @@
  * As nobody maintains our in-tree git.spec.in and distros use their
    own spec file, we stopped pretending that we support "make rpm".
 
- * Move from unsigned char[20] to struct object_id continues.
-
- * Update of "git submodule" to move pieces of logic to C continues.
+ * Move from "unsigned char[20]" to "struct object_id" continues.
 
  * The code for warning_errno/die_errno has been refactored and a new
    error_errno() reporting helper is introduced.
@@ -221,24 +230,40 @@
    our tests under "bash", however, we can redirect the trace output
    to another file descriptor to keep the standard error of programs
    being tested intact.
-   (merge d88785e jk/test-send-sh-x-trace-elsewhere later to maint).
 
  * t0040 had too many unnecessary repetitions in its test data.  Teach
    test-parse-options program so that a caller can tell what it
    expects in its output, so that these repetitions can be cleaned up.
 
- * Add perf test for "rebase -i"
+ * Add perf test for "rebase -i".
 
  * Common mistakes when writing gitlink: in our documentation are
    found by "make check-docs".
 
  * t9xxx series has been updated primarily for readability, while
-   fixing small bugs in it.  A few scripted Porcelains have also been
-   updated to fix possible bugs around their use of "test -z" and
-   "test -n".
+   fixing small bugs in it.  A few scripted Porcelain commands have
+   also been updated to fix possible bugs around their use of
+   "test -z" and "test -n".
 
  * CI test was taught to run git-svn tests.
 
+ * "git cat-file --batch-all" has been sped up, by taking advantage
+   of the fact that it does not have to read a list of objects, in two
+   ways.
+
+ * test updates to make it more readable and maintainable.
+   (merge e6273f4 es/t1500-modernize later to maint).
+
+ * "make DEVELOPER=1" worked as expected; setting DEVELOPER=1 in
+   config.mak didn't.
+   (merge 51dd3e8 mm/makefile-developer-can-be-in-config-mak later to maint).
+
+ * The way how "submodule--helper list" signals unmatch error to its
+   callers has been updated.
+
+ * A bash-ism "local" has been removed from "git submodule" scripted
+   Porcelain.
+
 
 Also contains various documentation updates and code clean-ups.
 
@@ -326,11 +351,11 @@
  * Support for CRAM-MD5 authentication method in "git imap-send" did
    not work well.
 
- * Upcoming OpenSSL 1.1.0 will break compilation b updating a few APIs
-   we use in imap-send, which has been adjusted for the change.
+ * Upcoming OpenSSL 1.1.0 will break compilation by updating a few API
+   elements we use in imap-send, which has been adjusted for the change.
 
  * The socks5:// proxy support added back in 2.6.4 days was not aware
-   that socks5h:// proxies behave differently.
+   that socks5h:// proxies behave differently from socks5:// proxies.
 
  * "git config" had a codepath that tried to pass a NULL to
    printf("%s"), which nobody seems to have noticed.
@@ -351,12 +376,12 @@
  * When "git merge" notices that the merge can be resolved purely at
    the tree level (without having to merge blobs) and the resulting
    tree happens to already exist in the object store, it forgot to
-   update the index, which lead to an inconsistent state for later
-   operations.
+   update the index, which left an inconsistent state that would
+   break later operations.
 
  * "git submodule" reports the paths of submodules the command
-   recurses into, but this was incorrect when the command was not run
-   from the root level of the superproject.
+   recurses into, but these paths were incorrectly reported when
+   the command was not run from the root level of the superproject.
 
  * The "user.useConfigOnly" configuration variable makes it an error
    if users do not explicitly set user.name and user.email.  However,
@@ -388,7 +413,6 @@
  * "git rebase -m" could be asked to rebase an entire branch starting
    from the root, but failed by assuming that there always is a parent
    commit to the first commit on the branch.
-   (merge 79f4344 bw/rebase-merge-entire-branch later to maint).
 
  * Fix a broken "p4 lfs" test.
 
@@ -414,24 +438,19 @@
    the configuration variable.  This will stop requiring the users to
    sign commit objects used internally as an implementation detail of
    "git stash".
-   (merge 6694856 jc/commit-tree-ignore-commit-gpgsign later to maint).
 
  * "http.cookieFile" configuration variable clearly wants a pathname,
    but we forgot to treat it as such by e.g. applying tilde expansion.
-   (merge e5a39ad bn/http-cookiefile-config later to maint).
 
  * Consolidate description of tilde-expansion that is done to
    configuration variables that take pathname to a single place.
-   (merge dca83ab jc/config-pathname-type later to maint).
 
  * Correct faulty recommendation to use "git submodule deinit ." when
    de-initialising all submodules, which would result in a strange
    error message in a pathological corner case.
-   (merge f6a5279 sb/submodule-deinit-all later to maint).
 
  * Many 'linkgit:<git documentation page>' references were broken,
    which are all fixed with this.
-   (merge 1cca17d jc/linkgit-fix later to maint).
 
  * "git rerere" can get confused by conflict markers deliberately left
    by the inner merge step, because they are indistinguishable from
@@ -441,48 +460,53 @@
    (merge 0f9fd5c jc/ll-merge-internal later to maint).
 
  * CI test was taught to build documentation pages.
-   (merge b98712b ls/travis-build-doc later to maint).
 
  * "git fsck" learned to catch NUL byte in a commit object as
    potential error and warn.
-   (merge 6d2d780 jc/fsck-nul-in-commit later to maint).
 
  * Portability enhancement for "rebase -i" to help platforms whose
    shell does not like "for i in <empty>" (which is not POSIX-kosher).
-   (merge 8e98b35 jk/rebase-interative-eval-fix later to maint).
 
  * On Windows, .git and optionally any files whose name starts with a
    dot are now marked as hidden, with a core.hideDotFiles knob to
    customize this behaviour.
-   (merge ebf31e7 js/windows-dotgit later to maint).
 
  * Documentation for "git merge --verify-signatures" has been updated
    to clarify that the signature of only the commit at the tip is
    verified.  Also the phrasing used for signature and key validity is
    adjusted to align with that used by OpenPGP.
-   (merge 05a5869 kf/gpg-sig-verification-doc later to maint).
 
  * A couple of bugs around core.autocrlf have been fixed.
-   (merge caa47ad tb/core-eol-fix later to maint).
 
  * Many commands normalize command line arguments from NFD to NFC
    variant of UTF-8 on OSX, but commands in the "diff" family did
    not, causing "git diff $path" to complain that no such path is
    known to Git.  They have been taught to do the normalization.
-   (merge 90a78b8 ar/diff-args-osx-precompose later to maint).
 
  * "git difftool" learned to handle unmerged paths correctly in
    dir-diff mode.
-   (merge 366f9ce da/difftool later to maint).
+
+ * The "are we talking with TTY, doing an interactive session?"
+   detection has been updated to work better for "Git for Windows".
+
+ * We forgot to add "git log --decorate=auto" to documentation when we
+   added the feature back in v2.1.0 timeframe.
+   (merge 462cbb4 rj/log-decorate-auto later to maint).
+
+ * "git fast-import --export-marks" would overwrite the existing marks
+   file even when it makes a dump from its custom die routine.
+   Prevent it from doing so when we have an import-marks file but
+   haven't finished reading it.
+   (merge f4beed6 fc/fast-import-broken-marks-file later to maint).
+
+ * "git rebase -i", after it fails to auto-resolve the conflict, had
+   an unnecessary call to "git rerere" from its very early days, which
+   was spotted recently; the call has been removed.
+   (merge 7063693 js/rebase-i-dedup-call-to-rerere later to maint).
 
  * Other minor clean-ups and documentation updates
-   (merge 832c0e5 lp/typofixes later to maint).
-   (merge f5ee54a sb/z-is-gnutar-ism later to maint).
-   (merge 2e3926b va/i18n-misc-updates later to maint).
-   (merge f212dcc bn/config-doc-tt-varnames later to maint).
-   (merge f54bea4 nd/remote-plural-ours-plus-theirs later to maint).
-   (merge 2bb0518 ak/t4151-ls-files-could-be-empty later to maint).
-   (merge 4df4313 jc/test-seq later to maint).
-   (merge a75a308 tb/t5601-sed-fix later to maint).
-   (merge 6c1fbe1 va/i18n-remote-comment-to-align later to maint).
-   (merge dee2303 va/mailinfo-doc-typofix later to maint).
+   (merge cd82b7a pa/cherry-pick-doc-typo later to maint).
+   (merge 2bb73ae rs/patch-id-use-skip-prefix later to maint).
+   (merge aa20cbc rs/apply-name-terminate later to maint).
+   (merge fe17fc0 jc/t2300-setup later to maint).
+   (merge e256eec jk/shell-portability later to maint).
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 53f00db..2e1b2e4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1956,7 +1956,10 @@
 	command. If 'short' is specified, the ref name prefixes 'refs/heads/',
 	'refs/tags/' and 'refs/remotes/' will not be printed. If 'full' is
 	specified, the full ref name (including prefix) will be printed.
-	This is the same as the log commands '--decorate' option.
+	If 'auto' is specified, then if the output is going to a terminal,
+	the ref names are shown as if 'short' were given, otherwise no ref
+	names are shown. This is the same as the '--decorate' option
+	of the `git log`.
 
 log.follow::
 	If `true`, `git log` will act as if the `--follow` option was used when
diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt
index edba565..d78cfc5 100644
--- a/Documentation/diff-config.txt
+++ b/Documentation/diff-config.txt
@@ -170,6 +170,11 @@
 
 include::mergetools-diff.txt[]
 
+diff.compactionHeuristic::
+	Set this option to `true` to enable an experimental heuristic that
+	shifts the hunk boundary in an attempt to make the resulting
+	patch easier to read.
+
 diff.algorithm::
 	Choose a diff algorithm.  The variants are as follows:
 +
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 3cb3015..d9ae681 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -63,6 +63,13 @@
 	Synonym for `-p --raw`.
 endif::git-format-patch[]
 
+--compaction-heuristic::
+--no-compaction-heuristic::
+	These are to help debugging and tuning an experimental
+	heuristic (which is off by default) that shifts the hunk
+	boundary in an attempt to make the resulting patch easier
+	to read.
+
 --minimal::
 	Spend extra time to make sure the smallest possible
 	diff is produced.
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index 6154e57..c104a59 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -128,7 +128,7 @@
 
 --allow-empty-message::
 	By default, cherry-picking a commit with an empty message will fail.
-	This option overrides that behaviour, allowing commits with empty
+	This option overrides that behavior, allowing commits with empty
 	messages to be cherry picked.
 
 --keep-redundant-commits::
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 03f9580..dec379b 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -29,12 +29,14 @@
 	(works only for a single file).
 
 --no-decorate::
---decorate[=short|full|no]::
+--decorate[=short|full|auto|no]::
 	Print out the ref names of any commits that are shown. If 'short' is
 	specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
 	'refs/remotes/' will not be printed. If 'full' is specified, the
-	full ref name (including prefix) will be printed. The default option
-	is 'short'.
+	full ref name (including prefix) will be printed. If 'auto' is
+	specified, then if the output is going to a terminal, the ref names
+	are shown as if 'short' were given, otherwise no ref names are
+	shown. The default option is 'short'.
 
 --source::
 	Print out the ref name given on the command line by which each
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 771a7b5..a88d186 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -450,6 +450,19 @@
 		smtpUser = yourname@gmail.com
 		smtpServerPort = 587
 
+If you have multifactor authentication setup on your gmail account, you will
+need to generate an app-specific password for use with 'git send-email'. Visit
+https://security.google.com/settings/security/apppasswords to setup an
+app-specific password.  Once setup, you can store it with the credentials
+helper:
+
+	$ git credential fill
+	protocol=smtp
+	host=smtp.gmail.com
+	username=youname@gmail.com
+	password=app-password
+
+
 Once your commits are ready to be sent to the mailing list, run the
 following commands:
 
diff --git a/Documentation/git.txt b/Documentation/git.txt
index dd6dbf7..5a10e9b 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -43,9 +43,10 @@
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v2.8.3/git.html[documentation for release 2.8.3]
+* link:v2.8.4/git.html[documentation for release 2.8.4]
 
 * release notes for
+  link:RelNotes/2.8.4.txt[2.8.4],
   link:RelNotes/2.8.3.txt[2.8.3],
   link:RelNotes/2.8.2.txt[2.8.2],
   link:RelNotes/2.8.1.txt[2.8.1],
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index e3d0bed..e1d8231 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v2.9.0-rc0
+DEF_VER=v2.9.0-rc2
 
 LF='
 '
diff --git a/Makefile b/Makefile
index 0d59718..de5a030 100644
--- a/Makefile
+++ b/Makefile
@@ -375,13 +375,7 @@
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
 CFLAGS = -g -O2 -Wall
-LDFLAGS =
-ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
-ALL_LDFLAGS = $(LDFLAGS)
-STRIP ?= strip
-
-ifdef DEVELOPER
-CFLAGS += -Werror \
+DEVELOPER_CFLAGS = -Werror \
 	-Wdeclaration-after-statement \
 	-Wno-format-zero-length \
 	-Wold-style-definition \
@@ -390,7 +384,10 @@
 	-Wstrict-prototypes \
 	-Wunused \
 	-Wvla
-endif
+LDFLAGS =
+ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS)
+ALL_LDFLAGS = $(LDFLAGS)
+STRIP ?= strip
 
 # Create as necessary, replace existing, make ranlib unneeded.
 ARFLAGS = rcs
@@ -951,6 +948,10 @@
 -include config.mak.autogen
 -include config.mak
 
+ifdef DEVELOPER
+CFLAGS += $(DEVELOPER_CFLAGS)
+endif
+
 ifndef sysconfdir
 ifeq ($(prefix),/usr)
 sysconfdir = /etc
diff --git a/README.md b/README.md
index 2087748..bd8a918 100644
--- a/README.md
+++ b/README.md
@@ -17,14 +17,14 @@
 
 See [Documentation/gittutorial.txt][] to get started, then see
 [Documentation/giteveryday.txt][] for a useful minimum set of commands, and
-Documentation/git-*commandname*.txt for documentation of each command.
+Documentation/git-<commandname>.txt for documentation of each command.
 If git has been correctly installed, then the tutorial can also be
-read with "man gittutorial" or "git help tutorial", and the
-documentation of each command with "man git-*commandname*" or "git help
-*commandname*".
+read with `man gittutorial` or `git help tutorial`, and the
+documentation of each command with `man git-<commandname>` or `git help
+<commandname>`.
 
 CVS users may also want to read [Documentation/gitcvs-migration.txt][]
-("man gitcvs-migration" or "git help cvs-migration" if git is
+(`man gitcvs-migration` or `git help cvs-migration` if git is
 installed).
 
 The user discussion and development of Git take place on the Git
diff --git a/archive-tar.c b/archive-tar.c
index 501ca97..cb99df2 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -181,7 +181,7 @@
 	memcpy(header->magic, "ustar", 6);
 	memcpy(header->version, "00", 2);
 
-	snprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
+	xsnprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
 }
 
 static int write_extended_header(struct archiver_args *args,
diff --git a/builtin/apply.c b/builtin/apply.c
index 8e4da2e..c770d7d 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -442,7 +442,7 @@
 #define TERM_SPACE	1
 #define TERM_TAB	2
 
-static int name_terminate(const char *name, int namelen, int c, int terminate)
+static int name_terminate(int c, int terminate)
 {
 	if (c == ' ' && !(terminate & TERM_SPACE))
 		return 0;
@@ -671,7 +671,7 @@
 		if (!end && isspace(c)) {
 			if (c == '\n')
 				break;
-			if (name_terminate(start, line-start, c, terminate))
+			if (name_terminate(c, terminate))
 				break;
 		}
 		line++;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 54db118..618103f 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -154,6 +154,13 @@
 	 * elements above, so you can retrieve the response from there.
 	 */
 	struct object_info info;
+
+	/*
+	 * This flag will be true if the requested batch format and options
+	 * don't require us to call sha1_object_info, which can then be
+	 * optimized out.
+	 */
+	unsigned skip_object_info : 1;
 };
 
 static int is_atom(const char *atom, const char *s, int slen)
@@ -258,7 +265,8 @@
 {
 	struct strbuf buf = STRBUF_INIT;
 
-	if (sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
+	if (!data->skip_object_info &&
+	    sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {
 		printf("%s missing\n", obj_name ? obj_name : sha1_to_hex(data->sha1));
 		fflush(stdout);
 		return;
@@ -369,6 +377,13 @@
 	strbuf_expand(&buf, opt->format, expand_format, &data);
 	data.mark_query = 0;
 
+	if (opt->all_objects) {
+		struct object_info empty;
+		memset(&empty, 0, sizeof(empty));
+		if (!memcmp(&data.info, &empty, sizeof(empty)))
+			data.skip_object_info = 1;
+	}
+
 	/*
 	 * If we are printing out the object, then always fill in the type,
 	 * since we will want to decide whether or not to stream.
@@ -489,6 +504,7 @@
 
 	git_config(git_cat_file_config, NULL);
 
+	batch.buffer_output = -1;
 	argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
 
 	if (opt) {
@@ -512,6 +528,9 @@
 		usage_with_options(cat_file_usage, options);
 	}
 
+	if (batch.buffer_output < 0)
+		batch.buffer_output = batch.all_objects;
+
 	if (batch.enabled)
 		return batch_objects(&batch);
 
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 366ce5a..a84d000 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -81,16 +81,13 @@
 
 	while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
 		char *line = line_buf->buf;
-		char *p = line;
+		const char *p = line;
 		int len;
 
-		if (!memcmp(line, "diff-tree ", 10))
-			p += 10;
-		else if (!memcmp(line, "commit ", 7))
-			p += 7;
-		else if (!memcmp(line, "From ", 5))
-			p += 5;
-		else if (!memcmp(line, "\\ ", 2) && 12 < strlen(line))
+		if (!skip_prefix(line, "diff-tree ", &p) &&
+		    !skip_prefix(line, "commit ", &p) &&
+		    !skip_prefix(line, "From ", &p) &&
+		    starts_with(line, "\\ ") && 12 < strlen(line))
 			continue;
 
 		if (!get_oid_hex(p, next_oid)) {
@@ -99,14 +96,14 @@
 		}
 
 		/* Ignore commit comments */
-		if (!patchlen && memcmp(line, "diff ", 5))
+		if (!patchlen && !starts_with(line, "diff "))
 			continue;
 
 		/* Parsing diff header?  */
 		if (before == -1) {
-			if (!memcmp(line, "index ", 6))
+			if (starts_with(line, "index "))
 				continue;
-			else if (!memcmp(line, "--- ", 4))
+			else if (starts_with(line, "--- "))
 				before = after = 1;
 			else if (!isalpha(line[0]))
 				break;
@@ -114,14 +111,14 @@
 
 		/* Looking for a valid hunk header?  */
 		if (before == 0 && after == 0) {
-			if (!memcmp(line, "@@ -", 4)) {
+			if (starts_with(line, "@@ -")) {
 				/* Parse next hunk, but ignore line numbers.  */
 				scan_hunk_header(line, &before, &after);
 				continue;
 			}
 
 			/* Split at the end of the patch.  */
-			if (memcmp(line, "diff ", 5))
+			if (!starts_with(line, "diff "))
 				break;
 
 			/* Else we're parsing another header.  */
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8da263f..926d205 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -287,10 +287,8 @@
 	argc = parse_options(argc, argv, prefix, module_list_options,
 			     git_submodule_helper_usage, 0);
 
-	if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
-		printf("#unmatched\n");
+	if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
 		return 1;
-	}
 
 	for (i = 0; i < list.nr; i++) {
 		const struct cache_entry *ce = list.entries[i];
@@ -833,6 +831,17 @@
 	return 0;
 }
 
+static int resolve_relative_path(int argc, const char **argv, const char *prefix)
+{
+	struct strbuf sb = STRBUF_INIT;
+	if (argc != 3)
+		die("submodule--helper relative_path takes exactly 2 arguments, got %d", argc);
+
+	printf("%s", relative_path(argv[1], argv[2], &sb));
+	strbuf_release(&sb);
+	return 0;
+}
+
 struct cmd_struct {
 	const char *cmd;
 	int (*fn)(int, const char **, const char *);
@@ -843,6 +852,7 @@
 	{"name", module_name},
 	{"clone", module_clone},
 	{"update-clone", update_clone},
+	{"relative-path", resolve_relative_path},
 	{"resolve-relative-url", resolve_relative_url},
 	{"resolve-relative-url-test", resolve_relative_url_test},
 	{"init", module_init}
diff --git a/compat/winansi.c b/compat/winansi.c
index 5dfa5ed..3be60ce 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -483,6 +483,7 @@
 #define IOINFO_L2E 5
 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
 
+#define FPIPE 0x08
 #define FDEV  0x40
 
 static inline ioinfo* _pioinfo(int fd)
@@ -530,6 +531,45 @@
 	return old_handle;
 }
 
+#ifdef DETECT_MSYS_TTY
+
+#include <winternl.h>
+#include <ntstatus.h>
+
+static void detect_msys_tty(int fd)
+{
+	ULONG result;
+	BYTE buffer[1024];
+	POBJECT_NAME_INFORMATION nameinfo = (POBJECT_NAME_INFORMATION) buffer;
+	PWSTR name;
+
+	/* check if fd is a pipe */
+	HANDLE h = (HANDLE) _get_osfhandle(fd);
+	if (GetFileType(h) != FILE_TYPE_PIPE)
+		return;
+
+	/* get pipe name */
+	if (!NT_SUCCESS(NtQueryObject(h, ObjectNameInformation,
+			buffer, sizeof(buffer) - 2, &result)))
+		return;
+	name = nameinfo->Name.Buffer;
+	name[nameinfo->Name.Length] = 0;
+
+	/* check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX') */
+	if (!wcsstr(name, L"msys-") || !wcsstr(name, L"-pty"))
+		return;
+
+	/* init ioinfo size if we haven't done so */
+	if (init_sizeof_ioinfo())
+		return;
+
+	/* set FDEV flag, reset FPIPE flag */
+	_pioinfo(fd)->osflags &= ~FPIPE;
+	_pioinfo(fd)->osflags |= FDEV;
+}
+
+#endif
+
 void winansi_init(void)
 {
 	int con1, con2;
@@ -538,8 +578,15 @@
 	/* check if either stdout or stderr is a console output screen buffer */
 	con1 = is_console(1);
 	con2 = is_console(2);
-	if (!con1 && !con2)
+	if (!con1 && !con2) {
+#ifdef DETECT_MSYS_TTY
+		/* check if stdin / stdout / stderr are MSYS2 pty pipes */
+		detect_msys_tty(0);
+		detect_msys_tty(1);
+		detect_msys_tty(2);
+#endif
 		return;
+	}
 
 	/* create a named pipe to communicate with the console thread */
 	xsnprintf(name, sizeof(name), "\\\\.\\pipe\\winansi%lu", GetCurrentProcessId());
@@ -575,8 +622,11 @@
 HANDLE winansi_get_osfhandle(int fd)
 {
 	HANDLE hnd = (HANDLE) _get_osfhandle(fd);
-	if ((fd == 1 || fd == 2) && isatty(fd)
-	    && GetFileType(hnd) == FILE_TYPE_PIPE)
-		return (fd == 1) ? hconsole1 : hconsole2;
+	if (isatty(fd) && GetFileType(hnd) == FILE_TYPE_PIPE) {
+		if (fd == 1 && hconsole1)
+			return hconsole1;
+		else if (fd == 2 && hconsole2)
+			return hconsole2;
+	}
 	return hnd;
 }
diff --git a/config.mak.uname b/config.mak.uname
index 40d6b29..a88f139 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -557,7 +557,8 @@
 			BASIC_LDFLAGS += -Wl,--large-address-aware
 		endif
 		CC = gcc
-		COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0
+		COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 -DDETECT_MSYS_TTY
+		EXTLIBS += -lntdll
 		INSTALL = /bin/install
 		NO_R_TO_GCC_LINKER = YesPlease
 		INTERNAL_QSORT = YesPlease
diff --git a/diff.c b/diff.c
index d3734d3..fa78fc1 100644
--- a/diff.c
+++ b/diff.c
@@ -26,7 +26,7 @@
 #endif
 
 static int diff_detect_rename_default;
-static int diff_compaction_heuristic = 1;
+static int diff_compaction_heuristic; /* experimental */
 static int diff_rename_limit_default = 400;
 static int diff_suppress_blank_empty;
 static int diff_use_color_default = -1;
diff --git a/fast-import.c b/fast-import.c
index 83558dc..c504ef7 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -329,6 +329,7 @@
 static const char *import_marks_file;
 static int import_marks_file_from_stream;
 static int import_marks_file_ignore_missing;
+static int import_marks_file_done;
 static int relative_marks_paths;
 
 /* Our last blob */
@@ -1802,7 +1803,7 @@
 	static struct lock_file mark_lock;
 	FILE *f;
 
-	if (!export_marks_file)
+	if (!export_marks_file || (import_marks_file && !import_marks_file_done))
 		return;
 
 	if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
@@ -1835,7 +1836,7 @@
 	if (f)
 		;
 	else if (import_marks_file_ignore_missing && errno == ENOENT)
-		return; /* Marks file does not exist */
+		goto done; /* Marks file does not exist */
 	else
 		die_errno("cannot read '%s'", import_marks_file);
 	while (fgets(line, sizeof(line), f)) {
@@ -1865,6 +1866,8 @@
 		insert_mark(mark, e);
 	}
 	fclose(f);
+done:
+	import_marks_file_done = 1;
 }
 
 
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 9d2bfb7..6e96abc 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -192,7 +192,6 @@
 die_with_patch () {
 	echo "$1" > "$state_dir"/stopped-sha
 	make_patch "$1"
-	git rerere
 	die "$2"
 }
 
diff --git a/git-submodule.sh b/git-submodule.sh
index 5a4dec0..7fe8a51 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -46,41 +46,6 @@
 custom_name=
 depth=
 
-# Resolve a path to be relative to another path.  This is intended for
-# converting submodule paths when git-submodule is run in a subdirectory
-# and only handles paths where the directory separator is '/'.
-#
-# The output is the first argument as a path relative to the second argument,
-# which defaults to $wt_prefix if it is omitted.
-relative_path ()
-{
-	local target curdir result
-	target=$1
-	curdir=${2-$wt_prefix}
-	curdir=${curdir%/}
-	result=
-
-	while test -n "$curdir"
-	do
-		case "$target" in
-		"$curdir/"*)
-			target=${target#"$curdir"/}
-			break
-			;;
-		esac
-
-		result="${result}../"
-		if test "$curdir" = "${curdir%/*}"
-		then
-			curdir=
-		else
-			curdir="${curdir%/*}"
-		fi
-	done
-
-	echo "$result$target"
-}
-
 die_if_unmatched ()
 {
 	if test "$1" = "#unmatched"
@@ -345,20 +310,23 @@
 	# command in the subshell (and a recursive call to this function)
 	exec 3<&0
 
-	git submodule--helper list --prefix "$wt_prefix"|
+	{
+		git submodule--helper list --prefix "$wt_prefix" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
 		if test -e "$sm_path"/.git
 		then
-			displaypath=$(relative_path "$prefix$sm_path")
+			displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
 			say "$(eval_gettext "Entering '\$displaypath'")"
 			name=$(git submodule--helper name "$sm_path")
 			(
 				prefix="$prefix$sm_path/"
 				sanitize_submodule_env
 				cd "$sm_path" &&
-				sm_path=$(relative_path "$sm_path") &&
+				sm_path=$(git submodule--helper relative-path "$sm_path" "$wt_prefix") &&
 				# we make $path available to scripts ...
 				path=$sm_path &&
 				if test $# -eq 1
@@ -453,13 +421,16 @@
 		die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")"
 	fi
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	{
+		git submodule--helper list --prefix "$wt_prefix" "$@" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
 		name=$(git submodule--helper name "$sm_path") || exit
 
-		displaypath=$(relative_path "$sm_path")
+		displaypath=$(git submodule--helper relative-path "$sm_path" "$wt_prefix")
 
 		# Remove the submodule work tree (unless the user already did it)
 		if test -d "$sm_path"
@@ -623,7 +594,7 @@
 			fi
 		fi
 
-		displaypath=$(relative_path "$prefix$sm_path")
+		displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
 
 		if test $just_cloned -eq 1
 		then
@@ -717,7 +688,7 @@
 		if test -n "$recursive"
 		then
 			(
-				prefix=$(relative_path "$prefix$sm_path/")
+				prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix")
 				wt_prefix=
 				sanitize_submodule_env
 				cd "$sm_path" &&
@@ -901,7 +872,7 @@
 		! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
 		missing_dst=t
 
-		display_name=$(relative_path "$name")
+		display_name=$(git submodule--helper relative-path "$name" "$wt_prefix")
 
 		total_commits=
 		case "$missing_src,$missing_dst" in
@@ -1013,13 +984,16 @@
 		shift
 	done
 
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	{
+		git submodule--helper list --prefix "$wt_prefix" "$@" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
 		name=$(git submodule--helper name "$sm_path") || exit
 		url=$(git config submodule."$name".url)
-		displaypath=$(relative_path "$prefix$sm_path")
+		displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
 		if test "$stage" = U
 		then
 			say "U$sha1 $displaypath"
@@ -1091,7 +1065,10 @@
 		esac
 	done
 	cd_to_toplevel
-	git submodule--helper list --prefix "$wt_prefix" "$@" |
+	{
+		git submodule--helper list --prefix "$wt_prefix" "$@" ||
+		echo "#unmatched"
+	} |
 	while read mode sha1 stage sm_path
 	do
 		die_if_unmatched "$mode"
@@ -1119,7 +1096,7 @@
 
 		if git config "submodule.$name.url" >/dev/null 2>/dev/null
 		then
-			displaypath=$(relative_path "$prefix$sm_path")
+			displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
 			say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
 			git config submodule."$name".url "$super_config_url"
 
diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh
index 5ef1744..18c363e 100644
--- a/t/perf/perf-lib.sh
+++ b/t/perf/perf-lib.sh
@@ -84,6 +84,7 @@
 	objects_dir="$(git -C "$source" rev-parse --git-path objects)"
 	mkdir -p "$repo/.git"
 	(
+		cd "$source" &&
 		{ cp -Rl "$objects_dir" "$repo/.git/" 2>/dev/null ||
 			cp -R "$objects_dir" "$repo/.git/"; } &&
 		for stuff in "$source_git"/*; do
@@ -94,7 +95,9 @@
 					cp -R "$stuff" "$repo/.git/" || exit 1
 					;;
 			esac
-		done &&
+		done
+	) &&
+	(
 		cd "$repo" &&
 		git init -q && {
 			test_have_prereq SYMLINKS ||
diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
index 89544dd..b425f3a 100755
--- a/t/t0008-ignores.sh
+++ b/t/t0008-ignores.sh
@@ -605,7 +605,7 @@
 	a/b/.gitignore:8:!on*	a/b/one
 	a/b/.gitignore:8:!on*	a/b/one one
 	a/b/.gitignore:8:!on*	a/b/one two
-	a/b/.gitignore:8:!on*	"a/b/one\"three"
+	a/b/.gitignore:8:!on*	"a/b/one\\"three"
 	a/b/.gitignore:9:!two	a/b/two
 	a/.gitignore:1:two*	a/b/twooo
 	$global_excludes:2:!globaltwo	globaltwo
@@ -686,7 +686,7 @@
 	a/b/.gitignore:8:!on*	b/one
 	a/b/.gitignore:8:!on*	b/one one
 	a/b/.gitignore:8:!on*	b/one two
-	a/b/.gitignore:8:!on*	"b/one\"three"
+	a/b/.gitignore:8:!on*	"b/one\\"three"
 	a/b/.gitignore:9:!two	b/two
 	::	b/not-ignored
 	a/.gitignore:1:two*	b/twooo
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 48ee077..038e24c 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -3,85 +3,88 @@
 test_description='test git rev-parse'
 . ./test-lib.sh
 
-test_rev_parse() {
+# usage: [options] label is-bare is-inside-git is-inside-work prefix git-dir
+test_rev_parse () {
+	d=
+	bare=
+	gitdir=
+	while :
+	do
+		case "$1" in
+		-C) d="$2"; shift; shift ;;
+		-b) case "$2" in
+		    [tfu]*) bare="$2"; shift; shift ;;
+		    *) error "test_rev_parse: bogus core.bare value '$2'" ;;
+		    esac ;;
+		-g) gitdir="$2"; shift; shift ;;
+		-*) error "test_rev_parse: unrecognized option '$1'" ;;
+		*) break ;;
+		esac
+	done
+
 	name=$1
 	shift
 
-	test_expect_success "$name: is-bare-repository" \
-	"test '$1' = \"\$(git rev-parse --is-bare-repository)\""
-	shift
-	[ $# -eq 0 ] && return
+	for o in --is-bare-repository \
+		 --is-inside-git-dir \
+		 --is-inside-work-tree \
+		 --show-prefix \
+		 --git-dir
+	do
+		test $# -eq 0 && break
+		expect="$1"
+		test_expect_success "$name: $o" '
+			if test -n "$gitdir"
+			then
+				test_when_finished "unset GIT_DIR" &&
+				GIT_DIR="$gitdir" &&
+				export GIT_DIR
+			fi &&
 
-	test_expect_success "$name: is-inside-git-dir" \
-	"test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
-	shift
-	[ $# -eq 0 ] && return
+			case "$bare" in
+			t*) test_config ${d:+-C} ${d:+"$d"} core.bare true ;;
+			f*) test_config ${d:+-C} ${d:+"$d"} core.bare false ;;
+			u*) test_unconfig ${d:+-C} ${d:+"$d"} core.bare ;;
+			esac &&
 
-	test_expect_success "$name: is-inside-work-tree" \
-	"test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
-	shift
-	[ $# -eq 0 ] && return
-
-	test_expect_success "$name: prefix" \
-	"test '$1' = \"\$(git rev-parse --show-prefix)\""
-	shift
-	[ $# -eq 0 ] && return
-
-	test_expect_success "$name: git-dir" \
-	"test '$1' = \"\$(git rev-parse --git-dir)\""
-	shift
-	[ $# -eq 0 ] && return
+			echo "$expect" >expect &&
+			git ${d:+-C} ${d:+"$d"} rev-parse $o >actual &&
+			test_cmp expect actual
+		'
+		shift
+	done
 }
 
-# label is-bare is-inside-git is-inside-work prefix git-dir
-
 ROOT=$(pwd)
 
+test_expect_success 'setup' '
+	mkdir -p sub/dir work &&
+	cp -R .git repo.git
+'
+
 test_rev_parse toplevel false false true '' .git
 
-cd .git || exit 1
-test_rev_parse .git/ false true false '' .
-cd objects || exit 1
-test_rev_parse .git/objects/ false true false '' "$ROOT/.git"
-cd ../.. || exit 1
+test_rev_parse -C .git .git/ false true false '' .
+test_rev_parse -C .git/objects .git/objects/ false true false '' "$ROOT/.git"
 
-mkdir -p sub/dir || exit 1
-cd sub/dir || exit 1
-test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git"
-cd ../.. || exit 1
+test_rev_parse -C sub/dir subdirectory false false true sub/dir/ "$ROOT/.git"
 
-git config core.bare true
-test_rev_parse 'core.bare = true' true false false
+test_rev_parse -b t 'core.bare = true' true false false
 
-git config --unset core.bare
-test_rev_parse 'core.bare undefined' false false true
+test_rev_parse -b u 'core.bare undefined' false false true
 
-mkdir work || exit 1
-cd work || exit 1
-GIT_DIR=../.git
-GIT_CONFIG="$(pwd)"/../.git/config
-export GIT_DIR GIT_CONFIG
 
-git config core.bare false
-test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
+test_rev_parse -C work -g ../.git -b f 'GIT_DIR=../.git, core.bare = false' false false true ''
 
-git config core.bare true
-test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
+test_rev_parse -C work -g ../.git -b t 'GIT_DIR=../.git, core.bare = true' true false false ''
 
-git config --unset core.bare
-test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
+test_rev_parse -C work -g ../.git -b u 'GIT_DIR=../.git, core.bare undefined' false false true ''
 
-mv ../.git ../repo.git || exit 1
-GIT_DIR=../repo.git
-GIT_CONFIG="$(pwd)"/../repo.git/config
 
-git config core.bare false
-test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
+test_rev_parse -C work -g ../repo.git -b f 'GIT_DIR=../repo.git, core.bare = false' false false true ''
 
-git config core.bare true
-test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
+test_rev_parse -C work -g ../repo.git -b t 'GIT_DIR=../repo.git, core.bare = true' true false false ''
 
-git config --unset core.bare
-test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
+test_rev_parse -C work -g ../repo.git -b u 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
 
 test_done
diff --git a/t/t2300-cd-to-toplevel.sh b/t/t2300-cd-to-toplevel.sh
index 9965bc5..cccd7d9 100755
--- a/t/t2300-cd-to-toplevel.sh
+++ b/t/t2300-cd-to-toplevel.sh
@@ -8,7 +8,8 @@
 	test_expect_success $3 "$2" '
 		(
 			cd '"'$1'"' &&
-			. "$(git --exec-path)"/git-sh-setup &&
+			PATH="$(git --exec-path):$PATH" &&
+			. git-sh-setup &&
 			cd_to_toplevel &&
 			[ "$(pwd -P)" = "$TOPLEVEL" ]
 		)
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 8049cad..805dc90 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1072,7 +1072,7 @@
 '
 
 test_expect_success 'in-body headers trigger content encoding' '
-	GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
+	test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
 	test_when_finished "git reset --hard HEAD^" &&
 	git format-patch -1 --stdout --from >patch &&
 	cat >expect <<-\EOF &&
diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh
index baa9d3c..84a8096 100755
--- a/t/t4204-patch-id.sh
+++ b/t/t4204-patch-id.sh
@@ -30,11 +30,11 @@
 
 #calculate patch id. Make sure output is not empty.
 calc_patch_id () {
-	name="$1"
+	patch_name="$1"
 	shift
 	git patch-id "$@" |
-	sed "s/ .*//" >patch-id_"$name" &&
-	test_line_count -gt 0 patch-id_"$name"
+	sed "s/ .*//" >patch-id_"$patch_name" &&
+	test_line_count -gt 0 patch-id_"$patch_name"
 }
 
 get_top_diff () {
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 91a69fc..82d913a 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -558,7 +558,6 @@
 }
 
 check_prot_host_port_path () {
-	local diagport
 	case "$2" in
 		*ssh*)
 		pp=ssh
diff --git a/t/t6044-merge-unrelated-index-changes.sh b/t/t6044-merge-unrelated-index-changes.sh
index 20a3ffe..0102348 100755
--- a/t/t6044-merge-unrelated-index-changes.sh
+++ b/t/t6044-merge-unrelated-index-changes.sh
@@ -20,7 +20,7 @@
 #   Commit E: renames a->subdir/a, adds subdir/e
 
 test_expect_success 'setup trivial merges' '
-	seq 1 10 >a &&
+	test_seq 1 10 >a &&
 	git add a &&
 	test_tick && git commit -m A &&
 
@@ -42,7 +42,7 @@
 	test_tick && git commit -m C &&
 
 	git checkout D &&
-	seq 2 10 >a &&
+	test_seq 2 10 >a &&
 	echo d >d &&
 	git add a d &&
 	test_tick && git commit -m D &&
diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh
index 79bc135..5503ec0 100755
--- a/t/t7403-submodule-sync.sh
+++ b/t/t7403-submodule-sync.sh
@@ -62,13 +62,13 @@
 '
 
 reset_submodule_urls () {
-	local root
-	root=$(pwd) &&
 	(
+		root=$(pwd) &&
 		cd super-clone/submodule &&
 		git config remote.origin.url "$root/submodule"
 	) &&
 	(
+		root=$(pwd) &&
 		cd super-clone/submodule/sub-submodule &&
 		git config remote.origin.url "$root/submodule"
 	)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 25bb60b..4bca35c 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -2650,6 +2650,21 @@
 	git fast-import <input
 '
 
+test_expect_success 'R: corrupt lines do not mess marks file' '
+	rm -f io.marks &&
+	blob=$(echo hi | git hash-object --stdin) &&
+	cat >expect <<-EOF &&
+	:3 0000000000000000000000000000000000000000
+	:1 $blob
+	:2 $blob
+	EOF
+	cp expect io.marks &&
+	test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
+
+	EOF
+	test_cmp expect io.marks
+'
+
 ##
 ## R: very large blobs
 ##
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 3978fc0..48884d5 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -939,3 +939,25 @@
 		eval "$1=\$$1\$line"
 	done
 }
+
+# Like "env FOO=BAR some-program", but run inside a subshell, which means
+# it also works for shell functions (though those functions cannot impact
+# the environment outside of the test_env invocation).
+test_env () {
+	(
+		while test $# -gt 0
+		do
+			case "$1" in
+			*=*)
+				eval "${1%%=*}=\${1#*=}"
+				eval "export ${1%%=*}"
+				shift
+				;;
+			*)
+				"$@"
+				exit
+				;;
+			esac
+		done
+	)
+}