Merge branch 'tr/perl-keep-stderr-open'
authorJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2013 19:40:41 +0000 (12:40 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2013 19:40:41 +0000 (12:40 -0700)
Closing (not redirecting to /dev/null) the standard error stream is
not a very smart thing to do. Later open may return file
descriptor #2 for unrelated purpose, and error reporting code may
write into them.

* tr/perl-keep-stderr-open:
t9700: do not close STDERR
perl: redirect stderr to /dev/null instead of closing

229 files changed:
Documentation/RelNotes/1.8.1.6.txt
Documentation/RelNotes/1.8.2.1.txt
Documentation/RelNotes/1.8.3.txt [new file with mode: 0644]
Documentation/cat-texi.perl
Documentation/config.txt
Documentation/git-archive.txt
Documentation/git-commit-tree.txt
Documentation/git-commit.txt
Documentation/git-count-objects.txt
Documentation/git-credential.txt
Documentation/git-difftool.txt
Documentation/git-fast-export.txt
Documentation/git-help.txt
Documentation/git-push.txt
Documentation/git-remote-ext.txt
Documentation/git-rev-parse.txt
Documentation/git-rm.txt
Documentation/git-send-email.txt
Documentation/git-sh-setup.txt
Documentation/git-shell.txt
Documentation/git-submodule.txt
Documentation/git-svn.txt
Documentation/git-tools.txt
Documentation/git.txt
Documentation/gitremote-helpers.txt
Documentation/merge-options.txt
Documentation/pretty-formats.txt
Documentation/revisions.txt
Documentation/technical/api-argv-array.txt
Documentation/technical/api-credentials.txt
Documentation/technical/api-ref-iteration.txt
Documentation/technical/pack-format.txt
GIT-VERSION-GEN
INSTALL
Makefile
RelNotes
advice.c
advice.h
archive-zip.c
attr.c
bisect.c
branch.c
builtin/apply.c
builtin/archive.c
builtin/branch.c
builtin/checkout.c
builtin/clone.c
builtin/commit-tree.c
builtin/commit.c
builtin/count-objects.c
builtin/fast-export.c
builtin/fetch-pack.c
builtin/help.c
builtin/log.c
builtin/merge.c
builtin/push.c
builtin/receive-pack.c
builtin/rm.c
builtin/send-pack.c
builtin/upload-archive.c
cache.h
combine-diff.c
commit.c
commit.h
compat/cygwin.c
compat/cygwin.h
compat/msvc.h
compat/nedmalloc/malloc.c.h
compat/obstack.h
compat/precompose_utf8.c
compat/regex/regcomp.c
compat/regex/regex.c
compat/regex/regex_internal.c
compat/vcbuild/include/sys/poll.h [deleted file]
compat/vcbuild/include/unistd.h
config.mak.in
config.mak.uname
connect.c
contrib/completion/git-completion.bash
contrib/completion/git-prompt.sh
contrib/credential/netrc/Makefile [new file with mode: 0644]
contrib/credential/netrc/git-credential-netrc [new file with mode: 0755]
contrib/credential/netrc/test.netrc [new file with mode: 0644]
contrib/credential/netrc/test.pl [new file with mode: 0755]
contrib/mw-to-git/git-remote-mediawiki.perl
contrib/mw-to-git/t/README
contrib/mw-to-git/t/install-wiki/LocalSettings.php
contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
contrib/remote-helpers/Makefile
contrib/remote-helpers/git-remote-bzr
contrib/remote-helpers/test-bzr.sh
contrib/remote-helpers/test-hg-hg-git.sh
contrib/remote-helpers/test-hg.sh
contrib/subtree/t/t7900-subtree.sh
daemon.c
date.c
diff.c
diffcore-break.c
diffcore-pickaxe.c
diffcore-rename.c
dir.c
entry.c
fetch-pack.c
fetch-pack.h
git-add--interactive.perl
git-am.sh
git-compat-util.h
git-cvsserver.perl
git-difftool.perl
git-filter-branch.sh
git-merge-one-file.sh
git-p4.py
git-pull.sh
git-quiltimport.sh
git-send-email.perl
git-sh-setup.sh
git-submodule.sh
git-web--browse.sh
git.c
gitweb/INSTALL
gitweb/gitweb.perl
gpg-interface.h
grep.c
grep.h
hash.h
http-backend.c
http.c
kwset.c
log-tree.c
match-trees.c
mergetools/p4merge
name-hash.c
path.c
perl/Git.pm
perl/Git/I18N.pm
perl/Git/SVN/Ra.pm
perl/private-Error.pm
pkt-line.c
pkt-line.h
po/README
pretty.c
refs.c
refs.h
remote-curl.c
remote.c
remote.h
rerere.c
resolve-undo.c
resolve-undo.h
revision.c
revision.h
send-pack.c
sequencer.c
sequencer.h
sha1_file.c
sha1_name.c
shell.c
sideband.c
sideband.h
streaming.c
submodule.c
t/README
t/lib-gpg/pubring.gpg
t/lib-gpg/random_seed
t/lib-gpg/secring.gpg
t/lib-gpg/trustdb.gpg
t/t1006-cat-file.sh
t/t1060-object-corruption.sh [new file with mode: 0755]
t/t1300-repo-config.sh
t/t2022-checkout-paths.sh
t/t2030-unresolve-info.sh
t/t2200-add-update.sh
t/t3200-branch.sh
t/t3203-branch-output.sh
t/t3400-rebase.sh
t/t3404-rebase-interactive.sh
t/t3511-cherry-pick-x.sh [new file with mode: 0755]
t/t3600-rm.sh
t/t3701-add-interactive.sh
t/t4014-format-patch.sh
t/t4034-diff-words.sh
t/t4038-diff-combined.sh
t/t4124-apply-ws-rule.sh
t/t4150-am.sh
t/t4202-log.sh
t/t4209-log-pickaxe.sh
t/t5002-archive-attr-pattern.sh
t/t5304-prune.sh
t/t5503-tagfollow.sh
t/t5516-fetch-push.sh
t/t5520-pull.sh
t/t5521-pull-options.sh
t/t5541-http-push.sh
t/t5700-clone-reference.sh
t/t5710-info-alternate.sh
t/t6012-rev-list-simplify.sh
t/t6030-bisect-porcelain.sh
t/t6200-fmt-merge-msg.sh
t/t7003-filter-branch.sh
t/t7400-submodule-basic.sh
t/t7406-submodule-update.sh
t/t7500-commit.sh
t/t7502-commit.sh
t/t7508-status.sh
t/t7512-status-help.sh
t/t7600-merge.sh
t/t7601-merge-pull-config.sh
t/t7610-mergetool.sh
t/t7612-merge-verify-signatures.sh [new file with mode: 0755]
t/t7800-difftool.sh
t/t9001-send-email.sh
t/t9010-svn-fe.sh
t/t9300-fast-import.sh
t/t9500-gitweb-standalone-no-errors.sh
t/t9808-git-p4-chdir.sh
t/test-lib-functions.sh
t/test-lib.sh
t/valgrind/valgrind.sh
test-svn-fe.c
transport-helper.c
transport.c
transport.h
upload-pack.c
write_or_die.c
wt-status.c
wt-status.h
xdiff/xdiffi.c
xdiff/xhistogram.c
zlib.c
index d9de6390809b476d3ee191b8f77fea450337f18f..c15cf2e80545bbcf1556209bbb078688a544e732 100644 (file)
@@ -4,6 +4,11 @@ Git 1.8.1.6 Release Notes
 Fixes since v1.8.1.5
 --------------------
 
+ * An earlier change to the attribute system introduced at v1.8.1.2 by
+   mistake stopped a pattern "dir" (without trailing slash) from
+   matching a directory "dir" (it only wanted to allow pattern "dir/"
+   to also match).
+
  * The code to keep track of what directory names are known to Git on
    platforms with case insensitive filesystems can get confused upon a
    hash collision between these pathnames and looped forever.
index 1ded500fc34a9d4da164e74c2ff433dc764d7e57..1354ad03f5e65cf85ec4c1e2b68c6152c3f295b8 100644 (file)
@@ -4,6 +4,11 @@ Git v1.8.2.1 Release Notes
 Fixes since v1.8.2
 ------------------
 
+ * An earlier change to the attribute system introduced at v1.8.1.2 by
+   mistake stopped a pattern "dir" (without trailing slash) from
+   matching a directory "dir" (it only wanted to allow pattern "dir/"
+   to also match).
+
  * Verification of signed tags were not done correctly when not in C
    or en/US locale.
 
diff --git a/Documentation/RelNotes/1.8.3.txt b/Documentation/RelNotes/1.8.3.txt
new file mode 100644 (file)
index 0000000..bcbcf15
--- /dev/null
@@ -0,0 +1,312 @@
+Git v1.8.3 Release Notes
+========================
+
+Backward compatibility notes (for Git 2.0)
+------------------------------------------
+
+When "git push [$there]" does not say what to push, we have used the
+traditional "matching" semantics so far (all your branches were sent
+to the remote as long as there already are branches of the same name
+over there).  In Git 2.0, the default will change to the "simple"
+semantics that pushes the current branch to the branch with the same
+name, only when the current branch is set to integrate with that
+remote branch.  There is a user preference configuration variable
+"push.default" to change this.  If you are an old-timer who is used
+to the "matching" semantics, you can set it to "matching" to keep the
+traditional behaviour.  If you want to live in the future early,
+you can set it to "simple" today without waiting for Git 2.0.
+
+When "git add -u" and "git add -A", that does not specify what paths
+to add on the command line is run from inside a subdirectory, these
+commands will operate on the entire tree in Git 2.0 for consistency
+with "git commit -a" and other commands. Because there will be no
+mechanism to make "git add -u" behave as if "git add -u .", it is
+important for those who are used to "git add -u" (without pathspec)
+updating the index only for paths in the current subdirectory to start
+training their fingers to explicitly say "git add -u ." when they mean
+it before Git 2.0 comes.
+
+
+Updates since v1.8.2
+--------------------
+
+UI, Workflows & Features
+
+ * "git help" learned "-g" option to show the list of guides just like
+   list of commands are given with "-a".
+
+ * A triangular "pull from one place, push to another place" workflow
+   is supported better by new remote.pushdefault (overrides the
+   "origin" thing) and branch.*.pushremote (overrides the
+   branch.*.remote) configuration variables.
+
+ * "git status" learned to report that you are in the middle of a
+   revert session, just like it does for a cherry-pick and a bisect
+   session.
+
+ * The handling by "git branch --set-upstream-to" against various forms
+   of erroneous inputs was suboptimal and has been improved.
+
+ * When the interactive access to git-shell is not enabled, it issues
+   a message meant to help the system administrator to enable it.
+   An explicit way to help the end users who connect to the service by
+   issuing custom messages to refuse such an access has been added.
+
+ * In addition to the case where the user edits the log message with
+   the "e)dit" option of "am -i", replace the "Applying: this patch"
+   message with the final log message contents after applymsg hook
+   munges it.
+
+ * "git status" suggests users to look into using --untracked=no option
+   when it takes too long.
+
+ * "git status" shows a bit more information to "git status" during a
+   rebase/bisect session.
+
+ * "git fetch" learned to fetch a commit at the tip of an unadvertised
+   ref by specifying a raw object name from the command line when the
+   server side supports this feature.
+
+ * "git count-objects -v" learned to report leftover temporary
+   packfiles and other garbage in the object store.
+
+ * A new read-only credential helper (in contrib/) to interact with
+   the .netrc/.authinfo files has been added.
+
+ * "git send-email" can be used with the credential helper system.
+
+ * There was no Porcelain way to say "I no longer am interested in
+   this submodule", once you express your interest in a submodule with
+   "submodule init".  "submodule deinit" is the way to do so.
+
+ * "git pull --rebase" learned to pass "-v/-q" options to underlying
+   "git rebase".
+
+ * The new "--follow-tags" option tells "git push" to push relevant
+   annotated tags when pushing branches out.
+
+ * "git merge" and "git pull" can optionally be told to inspect and
+   reject when merging a commit that does not carry a trusted GPG
+   signature.
+
+ * "git mergetool" now feeds files to the "p4merge" backend in the
+   order that matches the p4 convention, where "theirs" is usually
+   shown on the left side, which is the opposite from other backend
+   expects.
+
+ * "show/log" now honors gpg.program configuration just like other
+   parts of the code that use GnuPG.
+
+ * "git log" that shows the difference between the parent and the
+   child has been optimized somewhat.
+
+ * "git difftool" allows the user to write into the temporary files
+   being shown; if the user makes changes to the working tree at the
+   same time, one of the changes has to be lost in such a case, but it
+   tells the user what happened and refrains from overwriting the copy
+   in the working tree.
+
+ * There was no good way to ask "I have a random string that came from
+   outside world. I want to turn it into a 40-hex object name while
+   making sure such an object exists".  A new peeling suffix ^{object}
+   can be used for that purpose, together with "rev-parse --verify".
+
+
+Performance, Internal Implementation, etc.
+
+ * Updates for building under msvc.
+
+ * The logic to coalesce the same lines removed from the parents in
+   the output from "diff -c/--cc" has been updated, but with an O(n^2)
+   complexity, so this might turn out to be undesirable.
+
+ * The code to enforce permission bits on files in $GIT_DIR/ for
+   shared repositories have been simplified.
+
+ * A few codepaths knew how much data they need to put in the
+   hashtables they use upfront, but still started from a small table
+   repeatedly growing and rehashing.
+
+ * The API to walk reflog entries from the latest to older, which was
+   necessary for operations such as "git checkout -", was cumbersome
+   to use correctly and also inefficient.
+
+ * Codepaths that inspect log-message-to-be and decide when to add a
+   new Signed-off-by line in various commands have been consolidated.
+
+ * The pkt-line API, implementation and its callers have been cleaned
+   up to make them more robust.
+
+ * Cygwin port has a faster-but-lying lstat(2) emulation whose
+   incorrectness does not matter in practice except for a few
+   codepaths, and setting permission bits to directories is a codepath
+   that needs to use a more correct one.
+
+ * "git checkout" had repeated pathspec matches on the same paths,
+   which have been consolidated.  Also a bug in "git checkout dir/"
+   that is started from an unmerged index has been fixed.
+
+ * A few bugfixes to "git rerere" working on corner case merge
+   conflicts have been applied.
+
+
+Also contains minor documentation updates and code clean-ups.
+
+
+Fixes since v1.8.2
+------------------
+
+Unless otherwise noted, all the fixes since v1.8.2 in the maintenance
+track are contained in this release (see release notes to them for
+details).
+
+ * "git log -S/-G" started paying attention to textconv filter, but
+   there was no way to disable this.  Make it honor --no-textconv
+   option.
+   (merge 61690bf sr/log-SG-no-textconv later to maint).
+
+ * When used with "-d temporary-directory" option, "git filter-branch"
+   failed to come back to the original working tree to perform the
+   final clean-up procedure.
+   (merge 9727601 jk/filter-branch-come-back-to-original later to maint).
+
+ * "git merge $(git rev-parse v1.8.2)" behaved quite differently from
+   "git merge v1.8.2", as if v1.8.2 were written as v1.8.2^0 and did
+   not pay much attention to the annotated tag payload.  Make the code
+   notice the type of the tag object, in addition to the dwim_ref()
+   based classification the current code uses (i.e. the name appears
+   in refs/tags/) to decide when to special case merging of tags.
+   (merge a38d3d7 jc/merge-tag-object later to maint).
+
+ * Fix 1.8.1.x regression that stopped matching "dir" (without
+   trailing slash) to a directory "dir".
+   (merge efa5f82 jc/directory-attrs-regression-fix later to maint-1.8.1).
+
+ * "git apply --whitespace=fix" was not prepared to see a line getting
+   longer after fixing whitespaces (e.g. tab-in-indent aka Python).
+   (merge 329b26e jc/apply-ws-fix-tab-in-indent later to maint-1.8.1).
+
+ * The prompt string generator (in contrib/completion/) did not notice
+   when we are in a middle of a "git revert" session.
+   (merge 3ee4452 rr/prompt-revert-head later to maint).
+
+ * "submodule summary --summary-limit" option did not support
+   "--option=value" form.
+   (merge 862ae6c rs/submodule-summary-limit later to maint).
+
+ * "index-pack --fix-thin" used an uninitialized value to compute
+   delta depths of objects it appends to the resulting pack.
+   (merge 57165db jk/index-pack-correct-depth-fix later to maint).
+
+ * "index-pack --verify-stat" used a few counters outside protection
+   of mutex, possibly showing incorrect numbers.
+   (merge 8f82aad nd/index-pack-threaded-fixes later to maint).
+
+ * The code to keep track of what directory names are known to Git on
+   platforms with case insensitive filesystems can get confused upon a
+   hash collision between these pathnames and looped forever.
+
+ * Annotated tags outside refs/tags/ hierarchy were not advertised
+   correctly to the ls-remote and fetch with recent version of Git.
+
+ * Recent optimization broke shallow clones.
+   (merge f59de5d jk/peel-ref later to maint).
+
+ * "git cmd -- ':(top'" was not diagnosed as an invalid syntax, and
+   instead the parser kept reading beyond the end of the string.
+
+ * "git tag -f <tag>" always said "Updated tag '<tag>'" even when
+   creating a new tag (i.e. not overwriting nor updating).
+
+ * "git p4" did not behave well when the path to the root of the P4
+   client was not its real path.
+   (merge bbd8486 pw/p4-symlinked-root later to maint).
+
+ * "git archive" reports a failure when asked to create an archive out
+   of an empty tree.  It would be more intuitive to give an empty
+   archive back in such a case.
+
+ * When "format-patch" quoted a non-ascii strings on the header files,
+   it incorrectly applied rfc2047 and chopped a single character in
+   the middle of it.
+
+ * An aliased command spawned from a bare repository that does not say
+   it is bare with "core.bare = yes" is treated as non-bare by mistake.
+
+ * In "git reflog expire", REACHABLE bit was not cleared from the
+   correct objects.
+
+ * The logic used by "git diff -M --stat" to shorten the names of
+   files before and after a rename did not work correctly when the
+   common prefix and suffix between the two filenames overlapped.
+
+ * The "--match=<pattern>" option of "git describe", when used with
+   "--all" to allow refs that are not annotated tags to be used as a
+   base of description, did not restrict the output from the command
+   to those that match the given pattern.
+
+ * Clarify in the documentation "what" gets pushed to "where" when the
+   command line to "git push" does not say these explicitly.
+
+ * The "--color=<when>" argument to the commands in the diff family
+   was described poorly.
+
+ * The arguments given to pre-rebase hook were not documented.
+
+ * The v4 index format was not documented.
+
+ * The "--match=<pattern>" argument "git describe" takes uses glob
+   pattern but it wasn't obvious from the documentation.
+
+ * Some sources failed to compile on systems that lack NI_MAXHOST in
+   their system header (e.g. z/OS).
+
+ * Add an example use of "--env-filter" in "filter-branch"
+   documentation.
+
+ * "git bundle verify" did not say "records a complete history" for a
+   bundle that does not have any prerequisites.
+
+ * In the v1.8.0 era, we changed symbols that do not have to be global
+   to file scope static, but a few functions in graph.c were used by
+   CGit from sideways bypassing the entry points of the API the
+   in-tree users use.
+
+ * "git update-index -h" did not do the usual "-h(elp)" thing.
+
+ * "git index-pack" had a buffer-overflow while preparing an
+   informational message when the translated version of it was too
+   long.
+
+ * 'git commit -m "$msg"' used to add an extra newline even when
+   $msg already ended with one.
+
+ * The SSL peer verification done by "git imap-send" did not ask for
+   Server Name Indication (RFC 4366), failing to connect SSL/TLS
+   sites that serve multiple hostnames on a single IP.
+
+ * perl/Git.pm::cat_blob slurped everything in core only to write it
+   out to a file descriptor, which was not a very smart thing to do.
+
+ * "git branch" did not bother to check nonsense command line
+   parameters and issue errors in many cases.
+
+ * Verification of signed tags were not done correctly when not in C
+   or en/US locale.
+
+ * Some platforms and users spell UTF-8 differently; retry with the
+   most official "UTF-8" when the system does not understand the
+   user-supplied encoding name that are the common alternative
+   spellings of UTF-8.
+
+ * When export-subst is used, "zip" output recorded incorrect
+   size of the file.
+
+ * "git am $maildir/" applied messages in an unexpected order; sort
+   filenames read from the maildir/ in a way that is more likely to
+   sort messages in the order the writing MUA meant to, by sorting
+   numeric segment in numeric order and non-numeric segment in
+   alphabetical order.
+
+ * "git submodule update", when recursed into sub-submodules, did not
+   accumulate the prefix paths.
index 828ec62554fe927eb16a03f835448e6db0c303a1..87437f8a95768595e040b8c4c1d48e5c29ada087 100755 (executable)
@@ -12,6 +12,7 @@
                push @menu, $1;
        }
        s/\(\@pxref{\[(URLS|REMOTES)\]}\)//;
+       s/\@anchor\{[^{}]*\}//g;
        print TMP;
 }
 close TMP;
index bc750d579464a8c6c2e534e17ecae6d3a66287a9..3d750e0452308a4d3bf15053bfc5131d43c8c913 100644 (file)
@@ -727,9 +727,22 @@ branch.autosetuprebase::
        This option defaults to never.
 
 branch.<name>.remote::
-       When in branch <name>, it tells 'git fetch' and 'git push' which
-       remote to fetch from/push to.  It defaults to `origin` if no remote is
-       configured. `origin` is also used if you are not on any branch.
+       When on branch <name>, it tells 'git fetch' and 'git push'
+       which remote to fetch from/push to.  The remote to push to
+       may be overridden with `remote.pushdefault` (for all branches).
+       The remote to push to, for the current branch, may be further
+       overridden by `branch.<name>.pushremote`.  If no remote is
+       configured, or if you are not on any branch, it defaults to
+       `origin` for fetching and `remote.pushdefault` for pushing.
+
+branch.<name>.pushremote::
+       When on branch <name>, it overrides `branch.<name>.remote` for
+       pushing.  It also overrides `remote.pushdefault` for pushing
+       from branch <name>.  When you pull from one place (e.g. your
+       upstream) and push to another place (e.g. your own publishing
+       repository), you would want to set `remote.pushdefault` to
+       specify the remote to push to for all branches, and use this
+       option to override it for a specific branch.
 
 branch.<name>.merge::
        Defines, together with branch.<name>.remote, the upstream branch
@@ -1898,6 +1911,11 @@ receive.updateserverinfo::
        If set to true, git-receive-pack will run git-update-server-info
        after receiving data from git-push and updating refs.
 
+remote.pushdefault::
+       The remote to push to by default.  Overrides
+       `branch.<name>.remote` for all branches, and is overridden by
+       `branch.<name>.pushremote` for specific branches.
+
 remote.<name>.url::
        The URL of a remote repository.  See linkgit:git-fetch[1] or
        linkgit:git-push[1].
@@ -2123,7 +2141,13 @@ uploadpack.hiderefs::
        are under the hierarchies listed on the value of this
        variable is excluded, and is hidden from `git ls-remote`,
        `git fetch`, etc.  An attempt to fetch a hidden ref by `git
-       fetch` will fail.
+       fetch` will fail.  See also `uploadpack.allowtipsha1inwant`.
+
+uploadpack.allowtipsha1inwant::
+       When `uploadpack.hiderefs` is in effect, allow `upload-pack`
+       to accept a fetch request that asks for an object at the tip
+       of a hidden ref (by default, such a request is rejected).
+       see also `uploadpack.hiderefs`.
 
 url.<base>.insteadOf::
        Any URL that starts with this value will be rewritten to
index b4c2e24849b1154fb55608fa95cead9e405a03bf..250e5228a35165e72f2f55fd347941c3a2a1d08c 100644 (file)
@@ -56,7 +56,8 @@ OPTIONS
        Write the archive to <file> instead of stdout.
 
 --worktree-attributes::
-       Look for attributes in .gitattributes in working directory too.
+       Look for attributes in .gitattributes files in the working tree
+       as well (see <<ATTRIBUTES>>).
 
 <extra>::
        This can be any options that the archiver backend understands.
@@ -120,6 +121,7 @@ tar.<format>.remote::
        user-defined formats, but true for the "tar.gz" and "tgz"
        formats.
 
+[[ATTRIBUTES]]
 ATTRIBUTES
 ----------
 
index 86ef56e7c8760d622848da4131ebf231d27eb873..cafdc9642d312776b0122c4d010a9e9246bad8ff 100644 (file)
@@ -10,7 +10,9 @@ SYNOPSIS
 --------
 [verse]
 'git commit-tree' <tree> [(-p <parent>)...] < changelog
-'git commit-tree' [(-p <parent>)...] [(-m <message>)...] [(-F <file>)...] <tree>
+'git commit-tree' [(-p <parent>)...] [-S[<keyid>]] [(-m <message>)...]
+                 [(-F <file>)...] <tree>
+
 
 DESCRIPTION
 -----------
@@ -52,6 +54,9 @@ OPTIONS
        Read the commit log message from the given file. Use `-` to read
        from the standard input.
 
+-S[<keyid>]::
+       GPG-sign commit.
+
 
 Commit Information
 ------------------
index 05f82973687bb3fd7fbb066f725d72d386cd446f..9b1be5581d34b9911e3d60f23dcdda440d3bc17f 100644 (file)
@@ -207,14 +207,15 @@ variable (see linkgit:git-config[1]).
        without changing its commit message.
 
 --amend::
-       Used to amend the tip of the current branch. Prepare the tree
-       object you would want to replace the latest commit as usual
-       (this includes the usual -i/-o and explicit paths), and the
-       commit log editor is seeded with the commit message from the
-       tip of the current branch. The commit you create replaces the
-       current tip -- if it was a merge, it will have the parents of
-       the current tip as parents -- so the current top commit is
-       discarded.
+       Replace the tip of the current branch by creating a new
+       commit. The recorded tree is prepared as usual (including
+       the effect of the `-i` and `-o` options and explicit
+       pathspec), and the message from the original commit is used
+       as the starting point, instead of an empty message, when no
+       other message is specified from the command line via options
+       such as `-m`, `-F`, `-c`, etc.  The new commit has the same
+       parents and author as the current one (the `--reset-author`
+       option can countermand this).
 +
 --
 It is a rough equivalent for:
index 23c80cea6465d23476935abcfabba8e1deb915ee..da6e72e696d4af013b3c717d31a0e98cd41922d4 100644 (file)
@@ -20,11 +20,23 @@ OPTIONS
 -------
 -v::
 --verbose::
-       In addition to the number of loose objects and disk
-       space consumed, it reports the number of in-pack
-       objects, number of packs, disk space consumed by those packs,
-       and number of objects that can be removed by running
-       `git prune-packed`.
+       Report in more detail:
++
+count: the number of loose objects
++
+size: disk space consumed by loose objects, in KiB
++
+in-pack: the number of in-pack objects
++
+size-pack: disk space consumed by the packs, in KiB
++
+prune-packable: the number of loose objects that are also present in
+the packs. These objects could be pruned using `git prune-packed`.
++
+garbage: the number of files in object database that are not valid
+loose objects nor valid packs
++
+size-garbage: disk space consumed by garbage files, in KiB
 
 GIT
 ---
index 472f00f607850d7298535eead2982915412400d9..7da0f13a5cb26e9e5d1cb7d9c73fd4af57443d72 100644 (file)
@@ -56,7 +56,7 @@ For example, if we want a password for
 `https://example.com/foo.git`, we might generate the following
 credential description (don't forget the blank line at the end; it
 tells `git credential` that the application finished feeding all the
-infomation it has):
+information it has):
 
         protocol=https
         host=example.com
index e0e12e947034b3f690d7f103ee90e0bc1a21f926..8361e6e4e3d2d4829d3ce3c6f3ec4a2ac974e86e 100644 (file)
@@ -72,10 +72,12 @@ with custom merge tool commands and has the same value as `$MERGED`.
 --symlinks::
 --no-symlinks::
        'git difftool''s default behavior is create symlinks to the
-       working tree when run in `--dir-diff` mode.
+       working tree when run in `--dir-diff` mode and the right-hand
+       side of the comparison yields the same content as the file in
+       the working tree.
 +
-       Specifying `--no-symlinks` instructs 'git difftool' to create
-       copies instead.  `--no-symlinks` is the default on Windows.
+Specifying `--no-symlinks` instructs 'git difftool' to create copies
+instead.  `--no-symlinks` is the default on Windows.
 
 -x <command>::
 --extcmd=<command>::
index d6487e1ce03a9c060ae41b7b7455c442c6ea58f3..feab7a3e4ecb56aa17c32bd555e907a51001ef1f 100644 (file)
@@ -66,6 +66,8 @@ produced incorrect results if you gave these options.
        incremental runs.  As <file> is only opened and truncated
        at completion, the same path can also be safely given to
        \--import-marks.
+       The file will not be written if no new object has been
+       marked/exported.
 
 --import-marks=<file>::
        Before processing any input, load the marks specified in
index e07b6dc19ada9f3bb2ff4a6ae66eb587455fab11..b21e9d79be22cf134cf4e5f009fc8d71a635cc73 100644 (file)
@@ -8,31 +8,45 @@ git-help - Display help information about Git
 SYNOPSIS
 --------
 [verse]
-'git help' [-a|--all|-i|--info|-m|--man|-w|--web] [COMMAND]
+'git help' [-a|--all] [-g|--guide]
+          [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
 
 DESCRIPTION
 -----------
 
-With no options and no COMMAND given, the synopsis of the 'git'
+With no options and no COMMAND or GUIDE given, the synopsis of the 'git'
 command and a list of the most commonly used Git commands are printed
 on the standard output.
 
-If the option '--all' or '-a' is given, then all available commands are
+If the option '--all' or '-a' is given, all available commands are
 printed on the standard output.
 
-If a Git subcommand is named, a manual page for that subcommand is brought
-up. The 'man' program is used by default for this purpose, but this
-can be overridden by other options or configuration variables.
+If the option '--guide' or '-g' is given, a list of the useful
+Git guides is also printed on the standard output.
+
+If a command, or a guide, is given, a manual page for that command or
+guide is brought up. The 'man' program is used by default for this
+purpose, but this can be overridden by other options or configuration
+variables.
 
 Note that `git --help ...` is identical to `git help ...` because the
 former is internally converted into the latter.
 
+To display the linkgit:git[1] man page, use `git help git`.
+
+This page can be displayed with 'git help help' or `git help --help`
+
 OPTIONS
 -------
 -a::
 --all::
        Prints all the available commands on the standard output. This
-       option supersedes any other option.
+       option overrides any given command or guide name.
+
+-g::
+--guides::
+       Prints a list of useful guides on the standard output. This
+       option overrides any given command or guide name.
 
 -i::
 --info::
index 577d201c006ab6c72acef9bd800aa36f6cc356d3..eb2883c94cfad91efcc1f70bbdbc1609a3702d3b 100644 (file)
@@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects
 SYNOPSIS
 --------
 [verse]
-'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
+'git push' [--all | --mirror | --tags] [--follow-tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
           [--repo=<repository>] [-f | --force] [--prune] [-v | --verbose] [-u | --set-upstream]
           [<repository> [<refspec>...]]
 
@@ -117,6 +117,12 @@ already exists on the remote side.
        addition to refspecs explicitly listed on the command
        line.
 
+--follow-tags::
+       Push all the refs that would be pushed without this option,
+       and also push annotated tags in `refs/tags` that are missing
+       from the remote but are pointing at committish that are
+       reachable from the refs being pushed.
+
 --receive-pack=<git-receive-pack>::
 --exec=<git-receive-pack>::
        Path to the 'git-receive-pack' program on the remote
index 58b7facb09915a1856613dfcfd32b28d30cf896c..8cfc748ae2da4fce4c7ef804dcd50d2d923068d5 100644 (file)
@@ -86,7 +86,7 @@ begins with `ext::`.  Examples:
        edit .ssh/config.
 
 "ext::socat -t3600 - ABSTRACT-CONNECT:/git-server %G/somerepo"::
-       Represents repository with path /somerepo accessable over
+       Represents repository with path /somerepo accessible over
        git protocol at abstract namespace address /git-server.
 
 "ext::git-server-alias foo %G/repo"::
index 10a116faf8f681c9984c9b52949e84c227fdc26e..1f9ed6cfd28622afcf269eb8dac05fb9414d9901 100644 (file)
@@ -60,8 +60,19 @@ OPTIONS
        instead.
 
 --verify::
-       The parameter given must be usable as a single, valid
-       object name.  Otherwise barf and abort.
+       Verify that exactly one parameter is provided, and that it
+       can be turned into a raw 20-byte SHA-1 that can be used to
+       access the object database. If so, emit it to the standard
+       output; otherwise, error out.
++
+If you want to make sure that the output actually names an object in
+your object database and/or can be used as a specific type of object
+you require, you can add "^{type}" peeling operator to the parmeter.
+For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
+names an existing object that is a commit-ish (i.e. a commit, or an
+annotated tag that points at a commit).  To make sure that `$VAR`
+names an existing object of any type, `git rev-parse "$VAR^{object}"`
+can be used.
 
 -q::
 --quiet::
@@ -308,12 +319,12 @@ $ git rev-parse --verify HEAD
 * Print the commit object name from the revision in the $REV shell variable:
 +
 ------------
-$ git rev-parse --verify $REV
+$ git rev-parse --verify $REV^{commit}
 ------------
 +
 This will error out if $REV is empty or not a valid revision.
 
-* Same as above:
+* Similar to above:
 +
 ------------
 $ git rev-parse --default master --verify $REV
index 92bac27e05fca2f532fd2ae309dbc9f7b160c3d2..1d876c2619a414159a121868c5dbaab48e55a708 100644 (file)
@@ -149,6 +149,10 @@ files that aren't ignored are present in the submodules work tree.
 Ignored files are deemed expendable and won't stop a submodule's work
 tree from being removed.
 
+If you only want to remove the local checkout of a submodule from your
+work tree without committing the removal,
+use linkgit:git-submodule[1] `deinit` instead.
+
 EXAMPLES
 --------
 `git rm Documentation/\*.txt`::
index 44a1f7c4e8efbc78813de7c3ba13816e68c984cd..0cffef8aa51cc5c2f34393e39e45e84c4997b195 100644 (file)
@@ -164,8 +164,8 @@ Sending
 Furthermore, passwords need not be specified in configuration files
 or on the command line. If a username has been specified (with
 '--smtp-user' or a 'sendemail.smtpuser'), but no password has been
-specified (with '--smtp-pass' or 'sendemail.smtppass'), then the
-user is prompted for a password while the input is masked for privacy.
+specified (with '--smtp-pass' or 'sendemail.smtppass'), then
+a password is obtained using 'git-credential'.
 
 --smtp-server=<host>::
        If set, specifies the outgoing SMTP server to use (e.g.
index 6a9f66d1d920f0bfce1db823e2de3f696ce99f23..5d709d02c39e10ac946c3870a10d959a4c12a5d4 100644 (file)
@@ -82,6 +82,12 @@ get_author_ident_from_commit::
        outputs code for use with eval to set the GIT_AUTHOR_NAME,
        GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit.
 
+create_virtual_base::
+       modifies the first file so only lines in common with the
+       second file remain. If there is insufficient common material,
+       then the first file is left empty. The result is suitable
+       as a virtual base input for a 3-way merge.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index 9b9250600f651eac7d6e2fd6ca7ff320a64de67c..c35051ba58b63cdc489b0ee3f4ffb72631b619e3 100644 (file)
@@ -9,25 +9,81 @@ git-shell - Restricted login shell for Git-only SSH access
 SYNOPSIS
 --------
 [verse]
-'git shell' [-c <command> <argument>]
+'chsh' -s $(command -v git-shell) <user>
+'git clone' <user>`@localhost:/path/to/repo.git`
+'ssh' <user>`@localhost`
 
 DESCRIPTION
 -----------
 
-A login shell for SSH accounts to provide restricted Git access. When
-'-c' is given, the program executes <command> non-interactively;
-<command> can be one of 'git receive-pack', 'git upload-pack', 'git
-upload-archive', 'cvs server', or a command in COMMAND_DIR. The shell
-is started in interactive mode when no arguments are given; in this
-case, COMMAND_DIR must exist, and any of the executables in it can be
-invoked.
+This is a login shell for SSH accounts to provide restricted Git access.
+It permits execution only of server-side Git commands implementing the
+pull/push functionality, plus custom commands present in a subdirectory
+named `git-shell-commands` in the user's home directory.
 
-'cvs server' is a special command which executes git-cvsserver.
+COMMANDS
+--------
+
+'git shell' accepts the following commands after the '-c' option:
+
+'git receive-pack <argument>'::
+'git upload-pack <argument>'::
+'git upload-archive <argument>'::
+       Call the corresponding server-side command to support
+       the client's 'git push', 'git fetch', or 'git archive --remote'
+       request.
+'cvs server'::
+       Imitate a CVS server.  See linkgit:git-cvsserver[1].
+
+If a `~/git-shell-commands` directory is present, 'git shell' will
+also handle other, custom commands by running
+"`git-shell-commands/<command> <arguments>`" from the user's home
+directory.
+
+INTERACTIVE USE
+---------------
+
+By default, the commands above can be executed only with the '-c'
+option; the shell is not interactive.
 
-COMMAND_DIR is the path "$HOME/git-shell-commands". The user must have
-read and execute permissions to the directory in order to execute the
-programs in it. The programs are executed with a cwd of $HOME, and
-<argument> is parsed as a command-line string.
+If a `~/git-shell-commands` directory is present, 'git shell'
+can also be run interactively (with no arguments).  If a `help`
+command is present in the `git-shell-commands` directory, it is
+run to provide the user with an overview of allowed actions.  Then a
+"git> " prompt is presented at which one can enter any of the
+commands from the `git-shell-commands` directory, or `exit` to close
+the connection.
+
+Generally this mode is used as an administrative interface to allow
+users to list repositories they have access to, create, delete, or
+rename repositories, or change repository descriptions and
+permissions.
+
+If a `no-interactive-login` command exists, then it is run and the
+interactive shell is aborted.
+
+EXAMPLE
+-------
+
+To disable interactive logins, displaying a greeting instead:
++
+----------------
+$ chsh -s /usr/bin/git-shell
+$ mkdir $HOME/git-shell-commands
+$ cat >$HOME/git-shell-commands/no-interactive-login <<\EOF
+#!/bin/sh
+printf '%s\n' "Hi $USER! You've successfully authenticated, but I do not"
+printf '%s\n' "provide interactive shell access."
+exit 128
+EOF
+$ chmod +x $HOME/git-shell-commands/no-interactive-login
+----------------
+
+SEE ALSO
+--------
+ssh(1),
+linkgit:git-daemon[1],
+contrib/git-shell-commands/README
 
 GIT
 ---
index c99d795618f59bf98969b551f2a931680534f18e..74d5bdc59d58f743bc6f5cb5f7f9ee24d384d5c8 100644 (file)
@@ -13,6 +13,7 @@ SYNOPSIS
              [--reference <repository>] [--] <repository> [<path>]
 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
+'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
              [-f|--force] [--rebase] [--reference <repository>]
              [--merge] [--recursive] [--] [<path>...]
@@ -135,6 +136,19 @@ init::
        the explicit 'init' step if you do not intend to customize
        any submodule locations.
 
+deinit::
+       Unregister the given submodules, i.e. remove the whole
+       `submodule.$name` section from .git/config together with their work
+       tree. Further calls to `git submodule update`, `git submodule foreach`
+       and `git submodule sync` will skip any unregistered submodules until
+       they are initialized again, so use this command if you don't want to
+       have a local checkout of the submodule in your work tree anymore. If
+       you really want to remove a submodule from the repository and commit
+       that use linkgit:git-rm[1] instead.
++
+If `--force` is specified, the submodule's work tree will be removed even if
+it contains local modifications.
+
 update::
        Update the registered submodules, i.e. clone missing submodules and
        checkout the commit specified in the index of the containing repository.
@@ -214,8 +228,10 @@ OPTIONS
 
 -f::
 --force::
-       This option is only valid for add and update commands.
+       This option is only valid for add, deinit and update commands.
        When running add, allow adding an otherwise ignored submodule path.
+       When running deinit the submodule work trees will be removed even if
+       they contain local changes.
        When running update, throw away local changes in submodules when
        switching to a different commit; and always run a checkout operation
        in the submodule, even if the commit listed in the index of the
index 1b8b6498cd8afa4e2581e3597c4787981dc042df..7706d41c8704679c00a302306651628e5b99d1c1 100644 (file)
@@ -245,7 +245,7 @@ first have already been pushed into SVN.
        patch), "all" (accept all patches), or "quit".
        +
        'git svn dcommit' returns immediately if answer if "no" or "quit", without
-       commiting anything to SVN.
+       committing anything to SVN.
 
 'branch'::
        Create a branch in the SVN repository.
@@ -856,7 +856,7 @@ HANDLING OF SVN BRANCHES
 ------------------------
 If 'git svn' is configured to fetch branches (and --follow-branches
 is in effect), it sometimes creates multiple Git branches for one
-SVN branch, where the addtional branches have names of the form
+SVN branch, where the additional branches have names of the form
 'branchname@nnn' (with nnn an SVN revision number).  These additional
 branches are created if 'git svn' cannot find a parent commit for the
 first commit in an SVN branch, to connect the branch to the history of
index ad8b823f7732fe05e911fe5e8f2a1d60983c7a26..78a0d955ec22e22fbb1028f4eb6bfceeafc976f7 100644 (file)
@@ -109,7 +109,7 @@ Others
 
    - *git.el* (contrib/)
 
-   This is an Emacs interface for Git. The user interface is modeled on
+   This is an Emacs interface for Git. The user interface is modelled on
    pcl-cvs. It has been developed on Emacs 21 and will probably need some
    tweaking to work on XEmacs.
 
index 4307d62bd4a4e4b5361200ef54d8ecba60e4f1b0..6a875f2adefe34e27bc0fc3b6fdb9d7bcfd23301 100644 (file)
@@ -43,14 +43,16 @@ unreleased) version of Git, that is available from 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v1.8.2/git.html[documentation for release 1.8.2]
+* link:v1.8.2.1/git.html[documentation for release 1.8.2.1]
 
 * release notes for
+  link:RelNotes/1.8.2.1.txt[1.8.2.1].
   link:RelNotes/1.8.2.txt[1.8.2].
 
-* link:v1.8.1.5/git.html[documentation for release 1.8.1.5]
+* link:v1.8.1.6/git.html[documentation for release 1.8.1.6]
 
 * release notes for
+  link:RelNotes/1.8.1.6.txt[1.8.1.6],
   link:RelNotes/1.8.1.5.txt[1.8.1.5],
   link:RelNotes/1.8.1.4.txt[1.8.1.4],
   link:RelNotes/1.8.1.3.txt[1.8.1.3],
index 0c91aba86182f91206fcba5470b7202e4496f073..f506031ae49070e216e71914d8ef241da58430e1 100644 (file)
@@ -174,8 +174,8 @@ ref.
 This capability can be advertised multiple times.  The first
 applicable refspec takes precedence.  The left-hand of refspecs
 advertised with this capability must cover all refs reported by
-the list command.  If no 'refspec' capability is advertised,
-there is an implied `refspec *:*`.
+the list command.  If a helper does not need a specific 'refspec'
+capability then it should advertise `refspec *:*`.
 
 'bidi-import'::
        This modifies the 'import' capability.
index 34a844582846ae409e17347a65ac6cbeb28202a5..2adccf8fec71c10f8223490f1be4b2a215ace5ea 100644 (file)
@@ -84,6 +84,11 @@ option can be used to override --squash.
        Pass merge strategy specific option through to the merge
        strategy.
 
+--verify-signatures::
+--no-verify-signatures::
+       Verify that the commits being merged have good and trusted GPG signatures
+       and abort the merge in case they do not.
+
 --summary::
 --no-summary::
        Synonyms to --stat and --no-stat; these are deprecated and will be
index 293965524e81b240996a795498ba127f723d18eb..afac703f21245b6fa34af90b1da4b3194372a81d 100644 (file)
@@ -131,7 +131,8 @@ The placeholders are:
 - '%B': raw body (unwrapped subject and body)
 - '%N': commit notes
 - '%GG': raw verification message from GPG for a signed commit
-- '%G?': show either "G" for Good or "B" for Bad for a signed commit
+- '%G?': show "G" for a Good signature, "B" for a Bad signature, "U" for a good,
+  untrusted signature and "N" for no signature
 - '%GS': show the name of the signer for a signed commit
 - '%GK': show the key used to sign a signed commit
 - '%gD': reflog selector, e.g., `refs/stash@{1}`
index 314e25da7344dda459ca5b3292aaaabdfc0d6495..8855b1a0ac99012fcd98fcb3272b39e465d84626 100644 (file)
@@ -55,7 +55,7 @@ when you run `git cherry-pick`.
 +
 Note that any of the 'refs/*' cases above may come either from
 the '$GIT_DIR/refs' directory or from the '$GIT_DIR/packed-refs' file.
-While the ref name encoding is unspecified, UTF-8 is prefered as
+While the ref name encoding is unspecified, UTF-8 is preferred as
 some output processing may assume ref names in UTF-8.
 
 '<refname>@\{<date>\}', e.g. 'master@\{yesterday\}', 'HEAD@\{5 minutes ago\}'::
@@ -116,6 +116,11 @@ some output processing may assume ref names in UTF-8.
   object of that type is found or the object cannot be
   dereferenced anymore (in which case, barf).  '<rev>{caret}0'
   is a short-hand for '<rev>{caret}\{commit\}'.
++
+'rev{caret}\{object\}' can be used to make sure 'rev' names an
+object that exists, without requiring 'rev' to be a tag, and
+without dereferencing 'rev'; because a tag is already an object,
+it does not have to be dereferenced even once to get to an object.
 
 '<rev>{caret}\{\}', e.g. 'v0.99.8{caret}\{\}'::
   A suffix '{caret}' followed by an empty brace pair
index a959517b2339847e92464c86a73f9c472bfdb2d0..a6b7d83a8eb05086cb88a9168117aa54cf018551 100644 (file)
@@ -55,7 +55,7 @@ Functions
        initial, empty state.
 
 `argv_array_detach`::
-       Detach the argv array from the `struct argv_array`, transfering
+       Detach the argv array from the `struct argv_array`, transferring
        ownership of the allocated array and strings.
 
 `argv_array_free_detached`::
index 516fda74120c18f4d124ee8e5402dda39b72777a..c1b42a40d3c0c297994cd2966b60cd48629e57fa 100644 (file)
@@ -160,7 +160,7 @@ int foo_login(struct foo_connection *f)
                break;
        default:
                /*
-                * Some other error occured. We don't know if the
+                * Some other error occurred. We don't know if the
                 * credential is good or bad, so report nothing to the
                 * credential subsystem.
                 */
index dbbea95db7a8104dcd5de4b1ac59235f2eadaaa8..aa1c50f181eb20e27a8299ca8ec691eeffa9d51b 100644 (file)
@@ -35,7 +35,7 @@ Iteration functions
 * `head_ref_submodule()`, `for_each_ref_submodule()`,
   `for_each_ref_in_submodule()`, `for_each_tag_ref_submodule()`,
   `for_each_branch_ref_submodule()`, `for_each_remote_ref_submodule()`
-  do the same as the functions descibed above but for a specified
+  do the same as the functions described above but for a specified
   submodule.
 
 * `for_each_rawref()` can be used to learn about broken ref and symref.
index 0e37ec9de51bd4ecb99cecce1958c6cea9bea715..a37f1378d05d6def0ea3cac840acf62875536a70 100644 (file)
@@ -26,7 +26,9 @@ Git pack format
 
      (deltified representation)
      n-byte type and length (3-bit type, (n-1)*7+4-bit length)
-     20-byte base object name
+     20-byte base object name if OBJ_REF_DELTA or a negative relative
+        offset from the delta object's position in the pack if this
+        is an OBJ_OFS_DELTA object
      compressed delta data
 
      Observation: length of each object is encoded in a variable
index f189b7889e7b19fd1e8a5412c899d8b70fab9d9d..6722e621d119dbefeda2e8ea02dfcc0ebb2b4a5a 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 GVF=GIT-VERSION-FILE
-DEF_VER=v1.8.2
+DEF_VER=v1.8.2.GIT
 
 LF='
 '
diff --git a/INSTALL b/INSTALL
index 2dc3b61d1fe1b675377a6ece96feaddf8a0721ba..ba01e7421eb892cfe2b86c4b26786ae9e5bb00af 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -101,7 +101,7 @@ Issues of note:
        - "openssl" library is used by git-imap-send to use IMAP over SSL.
          If you don't need it, use NO_OPENSSL.
 
-         By default, git uses OpenSSL for SHA1 but it will use it's own
+         By default, git uses OpenSSL for SHA1 but it will use its own
          library (inspired by Mozilla's) with either NO_OPENSSL or
          BLK_SHA1.  Also included is a version optimized for PowerPC
          (PPC_SHA1).
index 598d6313da96f8ba8f76fbd982f491077b6d5d97..0f931a203002aec397f8b454f93df9aee97a21ad 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -358,33 +358,39 @@ STRIP ?= strip
 # Among the variables below, these:
 #   gitexecdir
 #   template_dir
-#   mandir
-#   infodir
-#   htmldir
 #   sysconfdir
 # can be specified as a relative path some/where/else;
 # this is interpreted as relative to $(prefix) and "git" at
 # runtime figures out where they are based on the path to the executable.
+# Additionally, the following will be treated as relative by "git" if they
+# begin with "$(prefix)/":
+#   mandir
+#   infodir
+#   htmldir
 # This can help installing the suite in a relocatable way.
 
 prefix = $(HOME)
 bindir_relative = bin
 bindir = $(prefix)/$(bindir_relative)
-mandir = share/man
-infodir = share/info
+mandir = $(prefix)/share/man
+infodir = $(prefix)/share/info
 gitexecdir = libexec/git-core
 mergetoolsdir = $(gitexecdir)/mergetools
 sharedir = $(prefix)/share
 gitwebdir = $(sharedir)/gitweb
 localedir = $(sharedir)/locale
 template_dir = share/git-core/templates
-htmldir = share/doc/git-doc
+htmldir = $(prefix)/share/doc/git-doc
 ETC_GITCONFIG = $(sysconfdir)/gitconfig
 ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
 lib = lib
 # DESTDIR =
 pathsep = :
 
+mandir_relative = $(patsubst $(prefix)/%,%,$(mandir))
+infodir_relative = $(patsubst $(prefix)/%,%,$(infodir))
+htmldir_relative = $(patsubst $(prefix)/%,%,$(htmldir))
+
 export prefix bindir sharedir sysconfdir gitwebdir localedir
 
 CC = cc
@@ -1539,12 +1545,12 @@ ETC_GITATTRIBUTES_SQ = $(subst ','\'',$(ETC_GITATTRIBUTES))
 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 bindir_SQ = $(subst ','\'',$(bindir))
 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
-mandir_SQ = $(subst ','\'',$(mandir))
-infodir_SQ = $(subst ','\'',$(infodir))
+mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
+infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
 localedir_SQ = $(subst ','\'',$(localedir))
 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
-htmldir_SQ = $(subst ','\'',$(htmldir))
+htmldir_relative_SQ = $(subst ','\'',$(htmldir_relative))
 prefix_SQ = $(subst ','\'',$(prefix))
 gitwebdir_SQ = $(subst ','\'',$(gitwebdir))
 
@@ -1676,9 +1682,9 @@ strip: $(PROGRAMS) git$X
 
 git.sp git.s git.o: GIT-PREFIX
 git.sp git.s git.o: EXTRA_CPPFLAGS = \
-       '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
-       '-DGIT_MAN_PATH="$(mandir_SQ)"' \
-       '-DGIT_INFO_PATH="$(infodir_SQ)"'
+       '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
+       '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
+       '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
 
 git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
@@ -1688,9 +1694,9 @@ help.sp help.s help.o: common-cmds.h
 
 builtin/help.sp builtin/help.s builtin/help.o: common-cmds.h GIT-PREFIX
 builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
-       '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
-       '-DGIT_MAN_PATH="$(mandir_SQ)"' \
-       '-DGIT_INFO_PATH="$(infodir_SQ)"'
+       '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
+       '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
+       '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'
 
 version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
 version.sp version.s version.o: EXTRA_CPPFLAGS = \
index 7a99a15f2fd9141247b100eb9a5d0b9b88b0f2b9..80b7e388ad321ea679e2b14ce4f18972da35156c 120000 (symlink)
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/1.8.2.1.txt
\ No newline at end of file
+Documentation/RelNotes/1.8.3.txt
\ No newline at end of file
index 3bc86260b8a2a809a379c91627f919ef0a529aa1..a8deee6e6419a1e867e06e90a70300cd2e01b556 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -13,6 +13,7 @@ int advice_commit_before_merge = 1;
 int advice_resolve_conflict = 1;
 int advice_implicit_identity = 1;
 int advice_detached_head = 1;
+int advice_set_upstream_failure = 1;
 
 static struct {
        const char *name;
@@ -31,6 +32,7 @@ static struct {
        { "resolveconflict", &advice_resolve_conflict },
        { "implicitidentity", &advice_implicit_identity },
        { "detachedhead", &advice_detached_head },
+       { "setupstreamfailure", &advice_set_upstream_failure },
 
        /* make this an alias for backward compatibility */
        { "pushnonfastforward", &advice_push_update_rejected }
index af0c983c686b9ca5be2e8631562e60bd19656c22..94caa32f9213f59a627176ec8b4aea022f6b0f8f 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -16,6 +16,7 @@ extern int advice_commit_before_merge;
 extern int advice_resolve_conflict;
 extern int advice_implicit_identity;
 extern int advice_detached_head;
+extern int advice_set_upstream_failure;
 
 int git_default_advice_config(const char *var, const char *value);
 void advise(const char *advice, ...);
index a8d119305ff5c0161e7239a8ad70a92c76122631..b2c4fe0e9f9816a6cb79aa8f7a0cb59ae5bf7f8d 100644 (file)
@@ -111,8 +111,9 @@ static void copy_le32(unsigned char *dest, unsigned int n)
        dest[3] = 0xff & (n >> 030);
 }
 
-static void *zlib_deflate(void *data, unsigned long size,
-               int compression_level, unsigned long *compressed_size)
+static void *zlib_deflate_raw(void *data, unsigned long size,
+                             int compression_level,
+                             unsigned long *compressed_size)
 {
        git_zstream stream;
        unsigned long maxsize;
@@ -120,7 +121,7 @@ static void *zlib_deflate(void *data, unsigned long size,
        int result;
 
        memset(&stream, 0, sizeof(stream));
-       git_deflate_init(&stream, compression_level);
+       git_deflate_init_raw(&stream, compression_level);
        maxsize = git_deflate_bound(&stream, size);
        buffer = xmalloc(maxsize);
 
@@ -265,14 +266,11 @@ static int write_zip_entry(struct archiver_args *args,
        }
 
        if (buffer && method == 8) {
-               deflated = zlib_deflate(buffer, size, args->compression_level,
-                               &compressed_size);
-               if (deflated && compressed_size - 6 < size) {
-                       /* ZLIB --> raw compressed data (see RFC 1950) */
-                       /* CMF and FLG ... */
-                       out = (unsigned char *)deflated + 2;
-                       compressed_size -= 6;   /* ... and ADLER32 */
-               } else {
+               out = deflated = zlib_deflate_raw(buffer, size,
+                                                 args->compression_level,
+                                                 &compressed_size);
+               if (!out || compressed_size >= size) {
+                       out = buffer;
                        method = 0;
                        compressed_size = size;
                }
@@ -353,7 +351,7 @@ static int write_zip_entry(struct archiver_args *args,
                unsigned char compressed[STREAM_BUFFER_SIZE * 2];
 
                memset(&zstream, 0, sizeof(zstream));
-               git_deflate_init(&zstream, args->compression_level);
+               git_deflate_init_raw(&zstream, args->compression_level);
 
                compressed_size = 0;
                zstream.next_out = compressed;
@@ -370,13 +368,10 @@ static int write_zip_entry(struct archiver_args *args,
                        result = git_deflate(&zstream, 0);
                        if (result != Z_OK)
                                die("deflate error (%d)", result);
-                       out = compressed;
-                       if (!compressed_size)
-                               out += 2;
-                       out_len = zstream.next_out - out;
+                       out_len = zstream.next_out - compressed;
 
                        if (out_len > 0) {
-                               write_or_die(1, out, out_len);
+                               write_or_die(1, compressed, out_len);
                                compressed_size += out_len;
                                zstream.next_out = compressed;
                                zstream.avail_out = sizeof(compressed);
@@ -394,11 +389,8 @@ static int write_zip_entry(struct archiver_args *args,
                        die("deflate error (%d)", result);
 
                git_deflate_end(&zstream);
-               out = compressed;
-               if (!compressed_size)
-                       out += 2;
-               out_len = zstream.next_out - out - 4;
-               write_or_die(1, out, out_len);
+               out_len = zstream.next_out - compressed;
+               write_or_die(1, compressed, out_len);
                compressed_size += out_len;
                zip_offset += compressed_size;
 
diff --git a/attr.c b/attr.c
index e2f9377891a7f6e0d56803016726e3cd3137fdc2..689bc2a8961fac72a01e615764af53f49d01c3ec 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -657,24 +657,24 @@ static void prepare_attr_stack(const char *path, int dirlen)
 }
 
 static int path_matches(const char *pathname, int pathlen,
-                       const char *basename,
+                       int basename_offset,
                        const struct pattern *pat,
                        const char *base, int baselen)
 {
        const char *pattern = pat->pattern;
        int prefix = pat->nowildcardlen;
+       int isdir = (pathlen && pathname[pathlen - 1] == '/');
 
-       if ((pat->flags & EXC_FLAG_MUSTBEDIR) &&
-           ((!pathlen) || (pathname[pathlen-1] != '/')))
+       if ((pat->flags & EXC_FLAG_MUSTBEDIR) && !isdir)
                return 0;
 
        if (pat->flags & EXC_FLAG_NODIR) {
-               return match_basename(basename,
-                                     pathlen - (basename - pathname),
+               return match_basename(pathname + basename_offset,
+                                     pathlen - basename_offset - isdir,
                                      pattern, prefix,
                                      pat->patternlen, pat->flags);
        }
-       return match_pathname(pathname, pathlen,
+       return match_pathname(pathname, pathlen - isdir,
                              base, baselen,
                              pattern, prefix, pat->patternlen, pat->flags);
 }
@@ -703,7 +703,7 @@ static int fill_one(const char *what, struct match_attr *a, int rem)
        return rem;
 }
 
-static int fill(const char *path, int pathlen, const char *basename,
+static int fill(const char *path, int pathlen, int basename_offset,
                struct attr_stack *stk, int rem)
 {
        int i;
@@ -713,7 +713,7 @@ static int fill(const char *path, int pathlen, const char *basename,
                struct match_attr *a = stk->attrs[i];
                if (a->is_macro)
                        continue;
-               if (path_matches(path, pathlen, basename,
+               if (path_matches(path, pathlen, basename_offset,
                                 &a->u.pat, base, stk->originlen))
                        rem = fill_one("fill", a, rem);
        }
@@ -752,7 +752,8 @@ static void collect_all_attrs(const char *path)
 {
        struct attr_stack *stk;
        int i, pathlen, rem, dirlen;
-       const char *basename, *cp, *last_slash = NULL;
+       const char *cp, *last_slash = NULL;
+       int basename_offset;
 
        for (cp = path; *cp; cp++) {
                if (*cp == '/' && cp[1])
@@ -760,10 +761,10 @@ static void collect_all_attrs(const char *path)
        }
        pathlen = cp - path;
        if (last_slash) {
-               basename = last_slash + 1;
+               basename_offset = last_slash + 1 - path;
                dirlen = last_slash - path;
        } else {
-               basename = path;
+               basename_offset = 0;
                dirlen = 0;
        }
 
@@ -773,7 +774,7 @@ static void collect_all_attrs(const char *path)
 
        rem = attr_nr;
        for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
-               rem = fill(path, pathlen, basename, stk, rem);
+               rem = fill(path, pathlen, basename_offset, stk, rem);
 }
 
 int git_check_attr(const char *path, int num, struct git_attr_check *check)
index bd1b7b5dac81ada592a16630214d1f2cbb655b88..374d9e24bd0a18b0453f3e948db93251a859ba18 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -525,9 +525,9 @@ struct commit_list *filter_skipped(struct commit_list *list,
  * is increased by one between each call, but that should not matter
  * for this application.
  */
-static int get_prn(int count) {
+static unsigned get_prn(unsigned count) {
        count = count * 1103515245 + 12345;
-       return ((unsigned)(count/65536) % PRN_MODULO);
+       return (count/65536) % PRN_MODULO;
 }
 
 /*
index 2bef1e7e71b7cb3375b3d96fab5c4f20e0c3adff..6ae6a4c321ab8866a3e21f15302b5549a95b4646 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -197,6 +197,20 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
        return 1;
 }
 
+static const char upstream_not_branch[] =
+N_("Cannot setup tracking information; starting point '%s' is not a branch.");
+static const char upstream_missing[] =
+N_("the requested upstream branch '%s' does not exist");
+static const char upstream_advice[] =
+N_("\n"
+"If you are planning on basing your work on an upstream\n"
+"branch that already exists at the remote, you may need to\n"
+"run \"git fetch\" to retrieve it.\n"
+"\n"
+"If you are planning to push out a new local branch that\n"
+"will track its remote counterpart, you may want to use\n"
+"\"git push -u\" to set the upstream config as you push.");
+
 void create_branch(const char *head,
                   const char *name, const char *start_name,
                   int force, int reflog, int clobber_head,
@@ -224,21 +238,30 @@ void create_branch(const char *head,
        }
 
        real_ref = NULL;
-       if (get_sha1(start_name, sha1))
+       if (get_sha1(start_name, sha1)) {
+               if (explicit_tracking) {
+                       if (advice_set_upstream_failure) {
+                               error(_(upstream_missing), start_name);
+                               advise(_(upstream_advice));
+                               exit(1);
+                       }
+                       die(_(upstream_missing), start_name);
+               }
                die("Not a valid object name: '%s'.", start_name);
+       }
 
        switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) {
        case 0:
                /* Not branching from any existing branch */
                if (explicit_tracking)
-                       die("Cannot setup tracking information; starting point is not a branch.");
+                       die(_(upstream_not_branch), start_name);
                break;
        case 1:
                /* Unique completion -- good, only if it is a real branch */
                if (prefixcmp(real_ref, "refs/heads/") &&
                    prefixcmp(real_ref, "refs/remotes/")) {
                        if (explicit_tracking)
-                               die("Cannot setup tracking information; starting point is not a branch.");
+                               die(_(upstream_not_branch), start_name);
                        else
                                real_ref = NULL;
                }
index 06f5320b18bc5690ae944a722d19ec5496687228..30eefc3c7b390800e9452a06da18208d2fef4f11 100644 (file)
@@ -1921,7 +1921,7 @@ static int parse_binary(char *buffer, unsigned long size, struct patch *patch)
 }
 
 /*
- * Read the patch text in "buffer" taht extends for "size" bytes; stop
+ * Read the patch text in "buffer" that extends for "size" bytes; stop
  * reading after seeing a single patch (i.e. changes to a single file).
  * Create fragments (i.e. patch hunks) and hang them to the given patch.
  * Return the number of bytes consumed, so that the caller can call us
@@ -2117,10 +2117,10 @@ static void update_pre_post_images(struct image *preimage,
 
        /*
         * Adjust the common context lines in postimage. This can be
-        * done in-place when we are just doing whitespace fixing,
-        * which does not make the string grow, but needs a new buffer
-        * when ignoring whitespace causes the update, since in this case
-        * we could have e.g. tabs converted to multiple spaces.
+        * done in-place when we are shrinking it with whitespace
+        * fixing, but needs a new buffer when ignoring whitespace or
+        * expanding leading tabs to spaces.
+        *
         * We trust the caller to tell us if the update can be done
         * in place (postlen==0) or not.
         */
@@ -2185,7 +2185,7 @@ static int match_fragment(struct image *img,
        int i;
        char *fixed_buf, *buf, *orig, *target;
        struct strbuf fixed;
-       size_t fixed_len;
+       size_t fixed_len, postlen;
        int preimage_limit;
 
        if (preimage->nr + try_lno <= img->nr) {
@@ -2335,6 +2335,7 @@ static int match_fragment(struct image *img,
        strbuf_init(&fixed, preimage->len + 1);
        orig = preimage->buf;
        target = img->buf + try;
+       postlen = 0;
        for (i = 0; i < preimage_limit; i++) {
                size_t oldlen = preimage->line[i].len;
                size_t tgtlen = img->line[try_lno + i].len;
@@ -2362,6 +2363,7 @@ static int match_fragment(struct image *img,
                match = (tgtfix.len == fixed.len - fixstart &&
                         !memcmp(tgtfix.buf, fixed.buf + fixstart,
                                             fixed.len - fixstart));
+               postlen += tgtfix.len;
 
                strbuf_release(&tgtfix);
                if (!match)
@@ -2399,8 +2401,10 @@ static int match_fragment(struct image *img,
         * hunk match.  Update the context lines in the postimage.
         */
        fixed_buf = strbuf_detach(&fixed, &fixed_len);
+       if (postlen < postimage->len)
+               postlen = 0;
        update_pre_post_images(preimage, postimage,
-                              fixed_buf, fixed_len, 0);
+                              fixed_buf, fixed_len, postlen);
        return 1;
 
  unmatch_exit:
@@ -3025,7 +3029,7 @@ static struct patch *in_fn_table(const char *name)
  *
  * The latter is needed to deal with a case where two paths A and B
  * are swapped by first renaming A to B and then renaming B to A;
- * moving A to B should not be prevented due to presense of B as we
+ * moving A to B should not be prevented due to presence of B as we
  * will remove it in a later patch.
  */
 #define PATH_TO_BE_DELETED ((struct patch *) -2)
@@ -3509,7 +3513,7 @@ static int check_patch(struct patch *patch)
         *
         * A patch to swap-rename between A and B would first rename A
         * to B and then rename B to A.  While applying the first one,
-        * the presense of B should not stop A from getting renamed to
+        * the presence of B should not stop A from getting renamed to
         * B; ask to_be_deleted() about the later rename.  Removal of
         * B and rename from A to B is handled the same way by asking
         * was_deleted().
index 9a1cfd3dac0123cb65d3db7597221a29e9010bd9..49178f159e246c9a99805d806fa5f096337e8d2f 100644 (file)
@@ -27,8 +27,8 @@ static int run_remote_archiver(int argc, const char **argv,
                               const char *remote, const char *exec,
                               const char *name_hint)
 {
-       char buf[LARGE_PACKET_MAX];
-       int fd[2], i, len, rv;
+       char *buf;
+       int fd[2], i, rv;
        struct transport *transport;
        struct remote *_remote;
 
@@ -53,21 +53,18 @@ static int run_remote_archiver(int argc, const char **argv,
                packet_write(fd[1], "argument %s\n", argv[i]);
        packet_flush(fd[1]);
 
-       len = packet_read_line(fd[0], buf, sizeof(buf));
-       if (!len)
+       buf = packet_read_line(fd[0], NULL);
+       if (!buf)
                die(_("git archive: expected ACK/NAK, got EOF"));
-       if (buf[len-1] == '\n')
-               buf[--len] = 0;
        if (strcmp(buf, "ACK")) {
-               if (len > 5 && !prefixcmp(buf, "NACK "))
+               if (!prefixcmp(buf, "NACK "))
                        die(_("git archive: NACK %s"), buf + 5);
-               if (len > 4 && !prefixcmp(buf, "ERR "))
+               if (!prefixcmp(buf, "ERR "))
                        die(_("remote error: %s"), buf + 4);
                die(_("git archive: protocol error"));
        }
 
-       len = packet_read_line(fd[0], buf, sizeof(buf));
-       if (len)
+       if (packet_read_line(fd[0], NULL))
                die(_("git archive: expected a flush"));
 
        /* Now, start reading from fd[0] and spit it out to stdout */
index 00d17d25d1866323f9e1dffcb334a573f5de5221..3f0fbc082aef95b3d02a8b677116264eea892369 100644 (file)
@@ -18,6 +18,7 @@
 #include "string-list.h"
 #include "column.h"
 #include "utf8.h"
+#include "wt-status.h"
 
 static const char * const builtin_branch_usage[] = {
        N_("git branch [options] [-r | -a] [--merged | --no-merged]"),
@@ -550,6 +551,29 @@ static int calc_maxwidth(struct ref_list *refs)
        return w;
 }
 
+static char *get_head_description(void)
+{
+       struct strbuf desc = STRBUF_INIT;
+       struct wt_status_state state;
+       memset(&state, 0, sizeof(state));
+       wt_status_get_state(&state, 1);
+       if (state.rebase_in_progress ||
+           state.rebase_interactive_in_progress)
+               strbuf_addf(&desc, _("(no branch, rebasing %s)"),
+                           state.branch);
+       else if (state.bisect_in_progress)
+               strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
+                           state.branch);
+       else if (state.detached_from)
+               strbuf_addf(&desc, _("(detached from %s)"),
+                           state.detached_from);
+       else
+               strbuf_addstr(&desc, _("(no branch)"));
+       free(state.branch);
+       free(state.onto);
+       free(state.detached_from);
+       return strbuf_detach(&desc, NULL);
+}
 
 static void show_detached(struct ref_list *ref_list)
 {
@@ -557,7 +581,7 @@ static void show_detached(struct ref_list *ref_list)
 
        if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
                struct ref_item item;
-               item.name = xstrdup(_("(no branch)"));
+               item.name = get_head_description();
                item.width = utf8_strwidth(item.name);
                item.kind = REF_LOCAL_BRANCH;
                item.dest = NULL;
@@ -880,7 +904,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                if (edit_branch_description(branch_name))
                        return 1;
        } else if (rename) {
-               if (argc == 1)
+               if (!argc)
+                       die(_("branch name required"));
+               else if (argc == 1)
                        rename_branch(head, argv[0], rename > 1);
                else if (argc == 2)
                        rename_branch(argv[0], argv[1], rename > 1);
index a9c1b5a95fea0a805819f995da2d2f1ba194433d..f8033f446e8f9ef1807aa28c2f9eca4e821c42c9 100644 (file)
@@ -271,24 +271,55 @@ static int checkout_paths(const struct checkout_opts *opts,
                ;
        ps_matched = xcalloc(1, pos);
 
+       /*
+        * Make sure all pathspecs participated in locating the paths
+        * to be checked out.
+        */
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
+               ce->ce_flags &= ~CE_MATCHED;
                if (opts->source_tree && !(ce->ce_flags & CE_UPDATE))
+                       /*
+                        * "git checkout tree-ish -- path", but this entry
+                        * is in the original index; it will not be checked
+                        * out to the working tree and it does not matter
+                        * if pathspec matched this entry.  We will not do
+                        * anything to this entry at all.
+                        */
                        continue;
-               match_pathspec(opts->pathspec, ce->name, ce_namelen(ce), 0, ps_matched);
+               /*
+                * Either this entry came from the tree-ish we are
+                * checking the paths out of, or we are checking out
+                * of the index.
+                *
+                * If it comes from the tree-ish, we already know it
+                * matches the pathspec and could just stamp
+                * CE_MATCHED to it from update_some(). But we still
+                * need ps_matched and read_tree_recursive (and
+                * eventually tree_entry_interesting) cannot fill
+                * ps_matched yet. Once it can, we can avoid calling
+                * match_pathspec() for _all_ entries when
+                * opts->source_tree != NULL.
+                */
+               if (match_pathspec(opts->pathspec, ce->name, ce_namelen(ce),
+                                  0, ps_matched))
+                       ce->ce_flags |= CE_MATCHED;
        }
 
-       if (report_path_error(ps_matched, opts->pathspec, opts->prefix))
+       if (report_path_error(ps_matched, opts->pathspec, opts->prefix)) {
+               free(ps_matched);
                return 1;
+       }
+       free(ps_matched);
 
        /* "checkout -m path" to recreate conflicted state */
        if (opts->merge)
-               unmerge_cache(opts->pathspec);
+               unmerge_marked_index(&the_index);
 
        /* Any unmerged paths? */
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
-               if (match_pathspec(opts->pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
+               if (ce->ce_flags & CE_MATCHED) {
                        if (!ce_stage(ce))
                                continue;
                        if (opts->force) {
@@ -313,9 +344,7 @@ static int checkout_paths(const struct checkout_opts *opts,
        state.refresh_cache = 1;
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
-               if (opts->source_tree && !(ce->ce_flags & CE_UPDATE))
-                       continue;
-               if (match_pathspec(opts->pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
+               if (ce->ce_flags & CE_MATCHED) {
                        if (!ce_stage(ce)) {
                                errs |= checkout_entry(ce, &state, NULL);
                                continue;
index e0aaf13583376c7adf49f504cc9e7e1303fb4a4d..f9c380eb6c536b657ddc65b88f6839ec761f7f25 100644 (file)
@@ -23,6 +23,7 @@
 #include "branch.h"
 #include "remote.h"
 #include "run-command.h"
+#include "connected.h"
 
 /*
  * Overall FIXMEs:
@@ -376,10 +377,32 @@ static void clone_local(const char *src_repo, const char *dest_repo)
 static const char *junk_work_tree;
 static const char *junk_git_dir;
 static pid_t junk_pid;
+enum {
+       JUNK_LEAVE_NONE,
+       JUNK_LEAVE_REPO,
+       JUNK_LEAVE_ALL
+} junk_mode = JUNK_LEAVE_NONE;
+
+static const char junk_leave_repo_msg[] =
+N_("Clone succeeded, but checkout failed.\n"
+   "You can inspect what was checked out with 'git status'\n"
+   "and retry the checkout with 'git checkout -f HEAD'\n");
 
 static void remove_junk(void)
 {
        struct strbuf sb = STRBUF_INIT;
+
+       switch (junk_mode) {
+       case JUNK_LEAVE_REPO:
+               warning("%s", _(junk_leave_repo_msg));
+               /* fall-through */
+       case JUNK_LEAVE_ALL:
+               return;
+       default:
+               /* proceed to removal */
+               break;
+       }
+
        if (getpid() != junk_pid)
                return;
        if (junk_git_dir) {
@@ -485,12 +508,37 @@ static void write_followtags(const struct ref *refs, const char *msg)
        }
 }
 
+static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
+{
+       struct ref **rm = cb_data;
+       struct ref *ref = *rm;
+
+       /*
+        * Skip anything missing a peer_ref, which we are not
+        * actually going to write a ref for.
+        */
+       while (ref && !ref->peer_ref)
+               ref = ref->next;
+       /* Returning -1 notes "end of list" to the caller. */
+       if (!ref)
+               return -1;
+
+       hashcpy(sha1, ref->old_sha1);
+       *rm = ref->next;
+       return 0;
+}
+
 static void update_remote_refs(const struct ref *refs,
                               const struct ref *mapped_refs,
                               const struct ref *remote_head_points_at,
                               const char *branch_top,
                               const char *msg)
 {
+       const struct ref *rm = mapped_refs;
+
+       if (check_everything_connected(iterate_ref_map, 0, &rm))
+               die(_("remote did not send all necessary objects"));
+
        if (refs) {
                write_remote_refs(mapped_refs);
                if (option_single_branch)
@@ -579,7 +627,8 @@ static int checkout(void)
        tree = parse_tree_indirect(sha1);
        parse_tree(tree);
        init_tree_desc(&t, tree->buffer, tree->size);
-       unpack_trees(1, &t, &opts);
+       if (unpack_trees(1, &t, &opts) < 0)
+               die(_("unable to checkout working tree"));
 
        if (write_cache(fd, active_cache, active_nr) ||
            commit_locked_index(lock_file))
@@ -898,12 +947,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        transport_unlock_pack(transport);
        transport_disconnect(transport);
 
+       junk_mode = JUNK_LEAVE_REPO;
        err = checkout();
 
        strbuf_release(&reflog_msg);
        strbuf_release(&branch_top);
        strbuf_release(&key);
        strbuf_release(&value);
-       junk_pid = 0;
+       junk_mode = JUNK_LEAVE_ALL;
        return err;
 }
index eac901a0ee15f72eacffea32d1b327c7a336f19c..f641ff2a898cf76d288ed139772e247015ca554b 100644 (file)
@@ -10,7 +10,7 @@
 #include "utf8.h"
 #include "gpg-interface.h"
 
-static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-S<signer>] [-m <message>] [-F <file>] <sha1> <changelog";
+static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-S[<keyid>]] [-m <message>] [-F <file>] <sha1> <changelog";
 
 static void new_parent(struct commit *parent, struct commit_list **parents_p)
 {
index d21d07a1a8e9fbc365a4555a0f9e81d0c1f2a7d0..46204375e786ea583ca1a7eabc3060611adc3d04 100644 (file)
@@ -702,7 +702,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                        previous = eol;
                }
 
-               append_signoff(&sb, ignore_footer);
+               append_signoff(&sb, ignore_footer, 0);
        }
 
        if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
index 9afaa88f776468a0de33dd153eadae7621cf6267..3a01a8d08591d93426d436ce2e1e17fccd3ebf78 100644 (file)
@@ -9,11 +9,22 @@
 #include "builtin.h"
 #include "parse-options.h"
 
+static unsigned long garbage;
+static off_t size_garbage;
+
+static void real_report_garbage(const char *desc, const char *path)
+{
+       struct stat st;
+       if (!stat(path, &st))
+               size_garbage += st.st_size;
+       warning("%s: %s", desc, path);
+       garbage++;
+}
+
 static void count_objects(DIR *d, char *path, int len, int verbose,
                          unsigned long *loose,
                          off_t *loose_size,
-                         unsigned long *packed_loose,
-                         unsigned long *garbage)
+                         unsigned long *packed_loose)
 {
        struct dirent *ent;
        while ((ent = readdir(d)) != NULL) {
@@ -46,9 +57,11 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
                }
                if (bad) {
                        if (verbose) {
-                               error("garbage found: %.*s/%s",
-                                     len + 2, path, ent->d_name);
-                               (*garbage)++;
+                               struct strbuf sb = STRBUF_INIT;
+                               strbuf_addf(&sb, "%.*s/%s",
+                                           len + 2, path, ent->d_name);
+                               report_garbage("garbage found", sb.buf);
+                               strbuf_release(&sb);
                        }
                        continue;
                }
@@ -76,7 +89,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
        const char *objdir = get_object_directory();
        int len = strlen(objdir);
        char *path = xmalloc(len + 50);
-       unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0;
+       unsigned long loose = 0, packed = 0, packed_loose = 0;
        off_t loose_size = 0;
        struct option opts[] = {
                OPT__VERBOSE(&verbose, N_("be verbose")),
@@ -87,6 +100,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
        /* we do not take arguments other than flags for now */
        if (argc)
                usage_with_options(count_objects_usage, opts);
+       if (verbose)
+               report_garbage = real_report_garbage;
        memcpy(path, objdir, len);
        if (len && objdir[len-1] != '/')
                path[len++] = '/';
@@ -97,7 +112,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
                if (!d)
                        continue;
                count_objects(d, path, len, verbose,
-                             &loose, &loose_size, &packed_loose, &garbage);
+                             &loose, &loose_size, &packed_loose);
                closedir(d);
        }
        if (verbose) {
@@ -122,6 +137,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
                printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
                printf("prune-packable: %lu\n", packed_loose);
                printf("garbage: %lu\n", garbage);
+               printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024));
        }
        else
                printf("%lu objects, %lu kilobytes\n",
index 77dffd1ce3a5f809a81793f67b9297a555bab1fa..725c0a7dca70ae8cbb31f571e0284f5c31a61cff 100644 (file)
@@ -43,7 +43,7 @@ static int parse_opt_signed_tag_mode(const struct option *opt,
        else if (!strcmp(arg, "strip"))
                signed_tag_mode = STRIP;
        else
-               return error("Unknown signed-tag mode: %s", arg);
+               return error("Unknown signed-tags mode: %s", arg);
        return 0;
 }
 
@@ -113,12 +113,13 @@ static void show_progress(void)
                printf("progress %d objects\n", counter);
 }
 
-static void handle_object(const unsigned char *sha1)
+static void export_blob(const unsigned char *sha1)
 {
        unsigned long size;
        enum object_type type;
        char *buf;
        struct object *object;
+       int eaten;
 
        if (no_data)
                return;
@@ -126,16 +127,18 @@ static void handle_object(const unsigned char *sha1)
        if (is_null_sha1(sha1))
                return;
 
-       object = parse_object(sha1);
-       if (!object)
-               die ("Could not read blob %s", sha1_to_hex(sha1));
-
-       if (object->flags & SHOWN)
+       object = lookup_object(sha1);
+       if (object && object->flags & SHOWN)
                return;
 
        buf = read_sha1_file(sha1, &type, &size);
        if (!buf)
                die ("Could not read blob %s", sha1_to_hex(sha1));
+       if (check_sha1_signature(sha1, buf, size, typename(type)) < 0)
+               die("sha1 mismatch in blob %s", sha1_to_hex(sha1));
+       object = parse_object_buffer(sha1, type, size, buf, &eaten);
+       if (!object)
+               die("Could not read blob %s", sha1_to_hex(sha1));
 
        mark_next_object(object);
 
@@ -147,7 +150,8 @@ static void handle_object(const unsigned char *sha1)
        show_progress();
 
        object->flags |= SHOWN;
-       free(buf);
+       if (!eaten)
+               free(buf);
 }
 
 static int depth_first(const void *a_, const void *b_)
@@ -312,7 +316,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
        /* Export the referenced blobs, and remember the marks. */
        for (i = 0; i < diff_queued_diff.nr; i++)
                if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
-                       handle_object(diff_queued_diff.queue[i]->two->sha1);
+                       export_blob(diff_queued_diff.queue[i]->two->sha1);
 
        mark_next_object(&commit->object);
        if (!is_encoding_utf8(encoding))
@@ -416,7 +420,7 @@ static void handle_tag(const char *name, struct tag *tag)
                        switch(signed_tag_mode) {
                        case ABORT:
                                die ("Encountered signed tag %s; use "
-                                    "--signed-tag=<mode> to handle it.",
+                                    "--signed-tags=<mode> to handle it.",
                                     sha1_to_hex(tag->object.sha1));
                        case WARN:
                                warning ("Exporting signed tag %s",
@@ -512,7 +516,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info,
                                commit = (struct commit *)tag;
                                break;
                        case OBJ_BLOB:
-                               handle_object(tag->object.sha1);
+                               export_blob(tag->object.sha1);
                                continue;
                        default: /* OBJ_TAG (nested tags) is already handled */
                                warning("Tag points to object of unexpected type %s, skipping.",
@@ -614,9 +618,12 @@ static void import_marks(char *input_file)
                        || *mark_end != ' ' || get_sha1(mark_end + 1, sha1))
                        die("corrupt mark line: %s", line);
 
+               if (last_idnum < mark)
+                       last_idnum = mark;
+
                object = parse_object(sha1);
                if (!object)
-                       die ("Could not read blob %s", sha1_to_hex(sha1));
+                       continue;
 
                if (object->flags & SHOWN)
                        error("Object %s already has a mark", sha1_to_hex(sha1));
@@ -626,8 +633,6 @@ static void import_marks(char *input_file)
                        continue;
 
                mark_object(object, mark);
-               if (last_idnum < mark)
-                       last_idnum = mark;
 
                object->flags |= SHOWN;
        }
@@ -641,6 +646,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        struct string_list extra_refs = STRING_LIST_INIT_NODUP;
        struct commit *commit;
        char *export_filename = NULL, *import_filename = NULL;
+       uint32_t lastimportid;
        struct option options[] = {
                OPT_INTEGER(0, "progress", &progress,
                            N_("show progress after <n> objects")),
@@ -684,6 +690,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 
        if (import_filename)
                import_marks(import_filename);
+       lastimportid = last_idnum;
 
        if (import_filename && revs.prune_data.nr)
                full_tree = 1;
@@ -706,7 +713,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 
        handle_tags_and_duplicates(&extra_refs);
 
-       if (export_filename)
+       if (export_filename && lastimportid != last_idnum)
                export_marks(export_filename);
 
        if (use_done_feature)
index 940ae35dc2ce4923a248896eb764f145312d71b4..aba44655524ff722d90de09760945f5f30088752 100644 (file)
@@ -7,12 +7,31 @@ static const char fetch_pack_usage[] =
 "[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
 "[--no-progress] [-v] [<host>:]<directory> [<refs>...]";
 
+static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
+                                const char *name, int namelen)
+{
+       struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1);
+
+       memcpy(ref->name, name, namelen);
+       ref->name[namelen] = '\0';
+       (*nr)++;
+       ALLOC_GROW(*sought, *nr, *alloc);
+       (*sought)[*nr - 1] = ref;
+}
+
+static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
+                            const char *string)
+{
+       add_sought_entry_mem(sought, nr, alloc, string, strlen(string));
+}
+
 int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 {
        int i, ret;
        struct ref *ref = NULL;
        const char *dest = NULL;
-       struct string_list sought = STRING_LIST_INIT_DUP;
+       struct ref **sought = NULL;
+       int nr_sought = 0, alloc_sought = 0;
        int fd[2];
        char *pack_lockfile = NULL;
        char **pack_lockfile_ptr = NULL;
@@ -94,27 +113,24 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
         * refs from the standard input:
         */
        for (; i < argc; i++)
-               string_list_append(&sought, xstrdup(argv[i]));
+               add_sought_entry(&sought, &nr_sought, &alloc_sought, argv[i]);
        if (args.stdin_refs) {
                if (args.stateless_rpc) {
                        /* in stateless RPC mode we use pkt-line to read
                         * from stdin, until we get a flush packet
                         */
-                       static char line[1000];
                        for (;;) {
-                               int n = packet_read_line(0, line, sizeof(line));
-                               if (!n)
+                               char *line = packet_read_line(0, NULL);
+                               if (!line)
                                        break;
-                               if (line[n-1] == '\n')
-                                       n--;
-                               string_list_append(&sought, xmemdupz(line, n));
+                               add_sought_entry(&sought, &nr_sought,  &alloc_sought, line);
                        }
                }
                else {
                        /* read from stdin one ref per line, until EOF */
                        struct strbuf line = STRBUF_INIT;
                        while (strbuf_getline(&line, stdin, '\n') != EOF)
-                               string_list_append(&sought, strbuf_detach(&line, NULL));
+                               add_sought_entry(&sought, &nr_sought, &alloc_sought, line.buf);
                        strbuf_release(&line);
                }
        }
@@ -128,10 +144,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
                                   args.verbose ? CONNECT_VERBOSE : 0);
        }
 
-       get_remote_heads(fd[0], &ref, 0, NULL);
+       get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
 
        ref = fetch_pack(&args, fd, conn, ref, dest,
-                        &sought, pack_lockfile_ptr);
+                        sought, nr_sought, pack_lockfile_ptr);
        if (pack_lockfile) {
                printf("lock %s\n", pack_lockfile);
                fflush(stdout);
@@ -141,7 +157,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
        if (finish_connect(conn))
                return 1;
 
-       ret = !ref || sought.nr;
+       ret = !ref;
 
        /*
         * If the heads to pull were given, we should have consumed
@@ -149,8 +165,13 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
         * remote no-such-ref' would silently succeed without issuing
         * an error.
         */
-       for (i = 0; i < sought.nr; i++)
-               error("no such remote ref %s", sought.items[i].string);
+       for (i = 0; i < nr_sought; i++) {
+               if (!sought[i] || sought[i]->matched)
+                       continue;
+               error("no such remote ref %s", sought[i]->name);
+               ret = 1;
+       }
+
        while (ref) {
                printf("%s %s\n",
                       sha1_to_hex(ref->old_sha1), ref->name);
index d1d71816a9df67721578bc29665c15887575caec..062957f629af09db81d78b9cb0be1ce60fd75ec4 100644 (file)
@@ -36,10 +36,12 @@ enum help_format {
 static const char *html_path;
 
 static int show_all = 0;
+static int show_guides = 0;
 static unsigned int colopts;
 static enum help_format help_format = HELP_FORMAT_NONE;
 static struct option builtin_help_options[] = {
-       OPT_BOOLEAN('a', "all", &show_all, N_("print all available commands")),
+       OPT_BOOL('a', "all", &show_all, N_("print all available commands")),
+       OPT_BOOL('g', "guides", &show_guides, N_("print list of useful guides")),
        OPT_SET_INT('m', "man", &help_format, N_("show man page"), HELP_FORMAT_MAN),
        OPT_SET_INT('w', "web", &help_format, N_("show manual in web browser"),
                        HELP_FORMAT_WEB),
@@ -49,7 +51,7 @@ static struct option builtin_help_options[] = {
 };
 
 static const char * const builtin_help_usage[] = {
-       N_("git help [--all] [--man|--web|--info] [command]"),
+       N_("git help [--all] [--guides] [--man|--web|--info] [command]"),
        NULL
 };
 
@@ -413,6 +415,37 @@ static void show_html_page(const char *git_cmd)
        open_html(page_path.buf);
 }
 
+static struct {
+       const char *name;
+       const char *help;
+} common_guides[] = {
+       { "attributes", N_("Defining attributes per path") },
+       { "glossary", N_("A Git glossary") },
+       { "ignore", N_("Specifies intentionally untracked files to ignore") },
+       { "modules", N_("Defining submodule properties") },
+       { "revisions", N_("Specifying revisions and ranges for Git") },
+       { "tutorial", N_("A tutorial introduction to Git (for version 1.5.1 or newer)") },
+       { "workflows", N_("An overview of recommended workflows with Git") },
+};
+
+static void list_common_guides_help(void)
+{
+       int i, longest = 0;
+
+       for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
+               if (longest < strlen(common_guides[i].name))
+                       longest = strlen(common_guides[i].name);
+       }
+
+       puts(_("The common Git guides are:\n"));
+       for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
+               printf("   %s   ", common_guides[i].name);
+               mput_char(' ', longest - strlen(common_guides[i].name));
+               puts(_(common_guides[i].help));
+       }
+       putchar('\n');
+}
+
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
        int nongit;
@@ -428,7 +461,16 @@ int cmd_help(int argc, const char **argv, const char *prefix)
                git_config(git_help_config, NULL);
                printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
                list_commands(colopts, &main_cmds, &other_cmds);
+       }
+
+       if (show_guides)
+               list_common_guides_help();
+
+       if (show_all || show_guides) {
                printf("%s\n", _(git_more_info_string));
+               /*
+               * We're done. Ignore any remaining args
+               */
                return 0;
        }
 
index 8f0b2e84fef5d1b9c07ea8846c9fbc1318d8d51b..0f318107e5732a08bc6f979633829ea958d8f9b0 100644 (file)
@@ -23,6 +23,7 @@
 #include "streaming.h"
 #include "version.h"
 #include "mailmap.h"
+#include "gpg-interface.h"
 
 /* Set a default date-time format for git log ("log.date" config variable) */
 static const char *default_date_mode = NULL;
@@ -367,6 +368,8 @@ static int git_log_config(const char *var, const char *value, void *cb)
 
        if (grep_config(var, value, cb) < 0)
                return -1;
+       if (git_gpg_config(var, value, cb) < 0)
+               return -1;
        return git_diff_ui_config(var, value, cb);
 }
 
@@ -1086,7 +1089,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        struct commit *origin = NULL, *head = NULL;
        const char *in_reply_to = NULL;
        struct patch_ids ids;
-       char *add_signoff = NULL;
        struct strbuf buf = STRBUF_INIT;
        int use_patch_format = 0;
        int quiet = 0;
@@ -1193,16 +1195,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                rev.subject_prefix = strbuf_detach(&sprefix, NULL);
        }
 
-       if (do_signoff) {
-               const char *committer;
-               const char *endpos;
-               committer = git_committer_info(IDENT_STRICT);
-               endpos = strchr(committer, '>');
-               if (!endpos)
-                       die(_("bogus committer info %s"), committer);
-               add_signoff = xmemdupz(committer, endpos - committer + 1);
-       }
-
        for (i = 0; i < extra_hdr.nr; i++) {
                strbuf_addstr(&buf, extra_hdr.items[i].string);
                strbuf_addch(&buf, '\n');
@@ -1393,7 +1385,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                total++;
                start_number--;
        }
-       rev.add_signoff = add_signoff;
+       rev.add_signoff = do_signoff;
        while (0 <= --nr) {
                int shown;
                commit = list[nr];
index 7c8922c8b0b44307a0dbb43329301ad7d1654a46..3e2daa37c367560450217cfae5cbb717bfb508af 100644 (file)
@@ -49,7 +49,7 @@ static const char * const builtin_merge_usage[] = {
 static int show_diffstat = 1, shortlog_len = -1, squash;
 static int option_commit = 1, allow_fast_forward = 1;
 static int fast_forward_only, option_edit = -1;
-static int allow_trivial = 1, have_message;
+static int allow_trivial = 1, have_message, verify_signatures;
 static int overwrite_ignore = 1;
 static struct strbuf merge_msg = STRBUF_INIT;
 static struct strategy **use_strategies;
@@ -199,6 +199,8 @@ static struct option builtin_merge_options[] = {
        OPT_BOOLEAN(0, "ff-only", &fast_forward_only,
                N_("abort if fast-forward is not possible")),
        OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
+       OPT_BOOL(0, "verify-signatures", &verify_signatures,
+               N_("Verify that the named commit has a valid GPG signature")),
        OPT_CALLBACK('s', "strategy", &use_strategies, N_("strategy"),
                N_("merge strategy to use"), option_parse_strategy),
        OPT_CALLBACK('X', "strategy-option", &xopts, N_("option=value"),
@@ -516,6 +518,19 @@ static void merge_name(const char *remote, struct strbuf *msg)
                strbuf_release(&line);
                goto cleanup;
        }
+
+       if (remote_head->util) {
+               struct merge_remote_desc *desc;
+               desc = merge_remote_util(remote_head);
+               if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
+                       strbuf_addf(msg, "%s\t\t%s '%s'\n",
+                                   sha1_to_hex(desc->obj->sha1),
+                                   typename(desc->obj->type),
+                                   remote);
+                       goto cleanup;
+               }
+       }
+
        strbuf_addf(msg, "%s\t\tcommit '%s'\n",
                sha1_to_hex(remote_head->object.sha1), remote);
 cleanup:
@@ -1233,6 +1248,39 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                usage_with_options(builtin_merge_usage,
                        builtin_merge_options);
 
+       if (verify_signatures) {
+               for (p = remoteheads; p; p = p->next) {
+                       struct commit *commit = p->item;
+                       char hex[41];
+                       struct signature_check signature_check;
+                       memset(&signature_check, 0, sizeof(signature_check));
+
+                       check_commit_signature(commit, &signature_check);
+
+                       strcpy(hex, find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+                       switch (signature_check.result) {
+                       case 'G':
+                               break;
+                       case 'U':
+                               die(_("Commit %s has an untrusted GPG signature, "
+                                     "allegedly by %s."), hex, signature_check.signer);
+                       case 'B':
+                               die(_("Commit %s has a bad GPG signature "
+                                     "allegedly by %s."), hex, signature_check.signer);
+                       default: /* 'N' */
+                               die(_("Commit %s does not have a GPG signature."), hex);
+                       }
+                       if (verbosity >= 0 && signature_check.result == 'G')
+                               printf(_("Commit %s has a good GPG signature by %s\n"),
+                                      hex, signature_check.signer);
+
+                       free(signature_check.gpg_output);
+                       free(signature_check.gpg_status);
+                       free(signature_check.signer);
+                       free(signature_check.key);
+               }
+       }
+
        strbuf_addstr(&buf, "merge");
        for (p = remoteheads; p; p = p->next)
                strbuf_addf(&buf, " %s", merge_remote_util(p->item)->name);
index 42b129d36cf615ed264be0f1bff523a7fc327b12..909c34dfda984be86fba2013fedc3fdb10b5e2f1 100644 (file)
@@ -322,7 +322,7 @@ static int push_with_options(struct transport *transport, int flags)
 static int do_push(const char *repo, int flags)
 {
        int i, errs;
-       struct remote *remote = remote_get(repo);
+       struct remote *remote = pushremote_get(repo);
        const char **url;
        int url_nr;
 
@@ -437,6 +437,8 @@ int cmd_push(int argc, const char **argv, const char *prefix)
                OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"),
                        TRANSPORT_PUSH_PRUNE),
                OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
+               OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
+                       TRANSPORT_PUSH_FOLLOW_TAGS),
                OPT_END()
        };
 
index 62ba6e7a3d014be01fe01ed497c083f7e44e9d34..ccebd74f166f5d02e8e6a0bb6033d741f8580f7b 100644 (file)
@@ -754,17 +754,15 @@ static struct command *read_head_info(void)
        struct command *commands = NULL;
        struct command **p = &commands;
        for (;;) {
-               static char line[1000];
+               char *line;
                unsigned char old_sha1[20], new_sha1[20];
                struct command *cmd;
                char *refname;
                int len, reflen;
 
-               len = packet_read_line(0, line, sizeof(line));
-               if (!len)
+               line = packet_read_line(0, &len);
+               if (!line)
                        break;
-               if (line[len-1] == '\n')
-                       line[--len] = 0;
                if (len < 83 ||
                    line[40] != ' ' ||
                    line[81] != ' ' ||
@@ -932,7 +930,7 @@ static void report(struct command *commands, const char *unpack_status)
        if (use_sideband)
                send_sideband(1, 1, buf.buf, buf.len, use_sideband);
        else
-               safe_write(1, buf.buf, buf.len);
+               write_or_die(1, buf.buf, buf.len);
        strbuf_release(&buf);
 }
 
index dabfcf689068804f2b352d200b35770b467a27e8..7b91d52f39004dbfcc9b0dc5b8aadf3df5c6d320 100644 (file)
@@ -110,7 +110,7 @@ static int check_local_mod(unsigned char *head, int index_only)
                ce = active_cache[pos];
 
                if (lstat(ce->name, &st) < 0) {
-                       if (errno != ENOENT)
+                       if (errno != ENOENT && errno != ENOTDIR)
                                warning("'%s': %s", ce->name, strerror(errno));
                        /* It already vanished from the working tree */
                        continue;
index 57a46b2654aa82b154d32eb77addd6a4f89c8e8d..152c4ea092a44ff9e70e293ddeecb4ad7105e25d 100644 (file)
@@ -79,7 +79,7 @@ static void print_helper_status(struct ref *ref)
                }
                strbuf_addch(&buf, '\n');
 
-               safe_write(1, buf.buf, buf.len);
+               write_or_die(1, buf.buf, buf.len);
        }
        strbuf_release(&buf);
 }
@@ -207,7 +207,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
 
        memset(&extra_have, 0, sizeof(extra_have));
 
-       get_remote_heads(fd[0], &remote_refs, REF_NORMAL, &extra_have);
+       get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have);
 
        transport_verify_remote_names(nr_refspecs, refspecs);
 
index b928beb8ed51c9af9aa4f640e80443a5e059d505..af2da35e7d05f4de2d7a77a708ee3cf6f490266e 100644 (file)
@@ -7,6 +7,7 @@
 #include "pkt-line.h"
 #include "sideband.h"
 #include "run-command.h"
+#include "argv-array.h"
 
 static const char upload_archive_usage[] =
        "git upload-archive <repo>";
@@ -18,51 +19,31 @@ static const char deadchild[] =
 
 int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix)
 {
-       const char *sent_argv[MAX_ARGS];
+       struct argv_array sent_argv = ARGV_ARRAY_INIT;
        const char *arg_cmd = "argument ";
-       char *p, buf[4096];
-       int sent_argc;
-       int len;
 
        if (argc != 2)
                usage(upload_archive_usage);
 
-       if (strlen(argv[1]) + 1 > sizeof(buf))
-               die("insanely long repository name");
-
-       strcpy(buf, argv[1]); /* enter-repo smudges its argument */
-
-       if (!enter_repo(buf, 0))
-               die("'%s' does not appear to be a git repository", buf);
+       if (!enter_repo(argv[1], 0))
+               die("'%s' does not appear to be a git repository", argv[1]);
 
        /* put received options in sent_argv[] */
-       sent_argc = 1;
-       sent_argv[0] = "git-upload-archive";
-       for (p = buf;;) {
-               /* This will die if not enough free space in buf */
-               len = packet_read_line(0, p, (buf + sizeof buf) - p);
-               if (len == 0)
+       argv_array_push(&sent_argv, "git-upload-archive");
+       for (;;) {
+               char *buf = packet_read_line(0, NULL);
+               if (!buf)
                        break;  /* got a flush */
-               if (sent_argc > MAX_ARGS - 2)
-                       die("Too many options (>%d)", MAX_ARGS - 2);
+               if (sent_argv.argc > MAX_ARGS)
+                       die("Too many options (>%d)", MAX_ARGS - 1);
 
-               if (p[len-1] == '\n') {
-                       p[--len] = 0;
-               }
-               if (len < strlen(arg_cmd) ||
-                   strncmp(arg_cmd, p, strlen(arg_cmd)))
+               if (prefixcmp(buf, arg_cmd))
                        die("'argument' token or flush expected");
-
-               len -= strlen(arg_cmd);
-               memmove(p, p + strlen(arg_cmd), len);
-               sent_argv[sent_argc++] = p;
-               p += len;
-               *p++ = 0;
+               argv_array_push(&sent_argv, buf + strlen(arg_cmd));
        }
-       sent_argv[sent_argc] = NULL;
 
        /* parse all options sent by the client */
-       return write_archive(sent_argc, sent_argv, prefix, 0, NULL, 1);
+       return write_archive(sent_argv.argc, sent_argv.argv, prefix, 0, NULL, 1);
 }
 
 __attribute__((format (printf, 1, 2)))
diff --git a/cache.h b/cache.h
index bb71bf8a7f92bafb16699e7a53cd206042d0465a..e1e8ce80ed11efb9483fca3205f383a3f0825cd7 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -34,6 +34,7 @@ int git_inflate(git_zstream *, int flush);
 
 void git_deflate_init(git_zstream *, int level);
 void git_deflate_init_gzip(git_zstream *, int level);
+void git_deflate_init_raw(git_zstream *, int level);
 void git_deflate_end(git_zstream *);
 int git_deflate_abort(git_zstream *);
 int git_deflate_end_gently(git_zstream *);
@@ -161,6 +162,9 @@ struct cache_entry {
 #define CE_UNPACKED          (1 << 24)
 #define CE_NEW_SKIP_WORKTREE (1 << 25)
 
+/* used to temporarily mark paths matched by pathspecs */
+#define CE_MATCHED           (1 << 26)
+
 /*
  * Extended on-disk flags
  */
@@ -715,8 +719,7 @@ enum sharedrepo {
        PERM_EVERYBODY      = 0664
 };
 int git_config_perm(const char *var, const char *value);
-int set_shared_perm(const char *path, int mode);
-#define adjust_shared_perm(path) set_shared_perm((path), 0)
+int adjust_shared_perm(const char *path);
 int safe_create_leading_directories(char *path);
 int safe_create_leading_directories_const(const char *path);
 int mkdir_in_gitdir(const char *path);
@@ -1019,7 +1022,8 @@ struct ref {
                force:1,
                forced_update:1,
                merge:1,
-               deletion:1;
+               deletion:1,
+               matched:1;
        enum {
                REF_STATUS_NONE = 0,
                REF_STATUS_OK,
@@ -1051,7 +1055,9 @@ struct extra_have_objects {
        int nr, alloc;
        unsigned char (*array)[20];
 };
-extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *);
+extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
+                                    struct ref **list, unsigned int flags,
+                                    struct extra_have_objects *);
 extern int server_supports(const char *feature);
 extern int parse_feature_request(const char *features, const char *feature);
 extern const char *server_feature_value(const char *feature, int *len_ret);
@@ -1059,6 +1065,9 @@ extern const char *parse_feature_value(const char *feature_list, const char *fea
 
 extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
 
+/* A hook for count-objects to report invalid files in pack directory */
+extern void (*report_garbage)(const char *desc, const char *path);
+
 extern void prepare_packed_git(void);
 extern void reprepare_packed_git(void);
 extern void install_packed_git(struct packed_git *pack);
index 35d41cd56d2ddb8df416e5e422552ec473294055..77d7872aafe659045e9ec228de97e87c9cea00a1 100644 (file)
@@ -5,6 +5,7 @@
 #include "diffcore.h"
 #include "quote.h"
 #include "xdiff-interface.h"
+#include "xdiff/xmacros.h"
 #include "log-tree.h"
 #include "refs.h"
 #include "userdiff.h"
@@ -73,16 +74,24 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
 
 /* Lines lost from parent */
 struct lline {
-       struct lline *next;
+       struct lline *next, *prev;
        int len;
        unsigned long parent_map;
        char line[FLEX_ARRAY];
 };
 
+/* Lines lost from current parent (before coalescing) */
+struct plost {
+       struct lline *lost_head, *lost_tail;
+       int len;
+};
+
 /* Lines surviving in the merge result */
 struct sline {
-       struct lline *lost_head, **lost_tail;
-       struct lline *next_lost;
+       /* Accumulated and coalesced lost lines */
+       struct lline *lost;
+       int lenlost;
+       struct plost plost;
        char *bol;
        int len;
        /* bit 0 up to (N-1) are on if the parent has this line (i.e.
@@ -94,6 +103,172 @@ struct sline {
        unsigned long *p_lno;
 };
 
+static int match_string_spaces(const char *line1, int len1,
+                              const char *line2, int len2,
+                              long flags)
+{
+       if (flags & XDF_WHITESPACE_FLAGS) {
+               for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
+               for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
+       }
+
+       if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)))
+               return (len1 == len2 && !memcmp(line1, line2, len1));
+
+       while (len1 > 0 && len2 > 0) {
+               len1--;
+               len2--;
+               if (XDL_ISSPACE(line1[len1]) || XDL_ISSPACE(line2[len2])) {
+                       if ((flags & XDF_IGNORE_WHITESPACE_CHANGE) &&
+                           (!XDL_ISSPACE(line1[len1]) || !XDL_ISSPACE(line2[len2])))
+                               return 0;
+
+                       for (; len1 > 0 && XDL_ISSPACE(line1[len1]); len1--);
+                       for (; len2 > 0 && XDL_ISSPACE(line2[len2]); len2--);
+               }
+               if (line1[len1] != line2[len2])
+                       return 0;
+       }
+
+       if (flags & XDF_IGNORE_WHITESPACE) {
+               /* Consume remaining spaces */
+               for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
+               for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
+       }
+
+       /* We matched full line1 and line2 */
+       if (!len1 && !len2)
+               return 1;
+
+       return 0;
+}
+
+enum coalesce_direction { MATCH, BASE, NEW };
+
+/* Coalesce new lines into base by finding LCS */
+static struct lline *coalesce_lines(struct lline *base, int *lenbase,
+                                   struct lline *new, int lennew,
+                                   unsigned long parent, long flags)
+{
+       int **lcs;
+       enum coalesce_direction **directions;
+       struct lline *baseend, *newend = NULL;
+       int i, j, origbaselen = *lenbase;
+
+       if (new == NULL)
+               return base;
+
+       if (base == NULL) {
+               *lenbase = lennew;
+               return new;
+       }
+
+       /*
+        * Coalesce new lines into base by finding the LCS
+        * - Create the table to run dynamic programing
+        * - Compute the LCS
+        * - Then reverse read the direction structure:
+        *   - If we have MATCH, assign parent to base flag, and consume
+        *   both baseend and newend
+        *   - Else if we have BASE, consume baseend
+        *   - Else if we have NEW, insert newend lline into base and
+        *   consume newend
+        */
+       lcs = xcalloc(origbaselen + 1, sizeof(int*));
+       directions = xcalloc(origbaselen + 1, sizeof(enum coalesce_direction*));
+       for (i = 0; i < origbaselen + 1; i++) {
+               lcs[i] = xcalloc(lennew + 1, sizeof(int));
+               directions[i] = xcalloc(lennew + 1, sizeof(enum coalesce_direction));
+               directions[i][0] = BASE;
+       }
+       for (j = 1; j < lennew + 1; j++)
+               directions[0][j] = NEW;
+
+       for (i = 1, baseend = base; i < origbaselen + 1; i++) {
+               for (j = 1, newend = new; j < lennew + 1; j++) {
+                       if (match_string_spaces(baseend->line, baseend->len,
+                                               newend->line, newend->len, flags)) {
+                               lcs[i][j] = lcs[i - 1][j - 1] + 1;
+                               directions[i][j] = MATCH;
+                       } else if (lcs[i][j - 1] >= lcs[i - 1][j]) {
+                               lcs[i][j] = lcs[i][j - 1];
+                               directions[i][j] = NEW;
+                       } else {
+                               lcs[i][j] = lcs[i - 1][j];
+                               directions[i][j] = BASE;
+                       }
+                       if (newend->next)
+                               newend = newend->next;
+               }
+               if (baseend->next)
+                       baseend = baseend->next;
+       }
+
+       for (i = 0; i < origbaselen + 1; i++)
+               free(lcs[i]);
+       free(lcs);
+
+       /* At this point, baseend and newend point to the end of each lists */
+       i--;
+       j--;
+       while (i != 0 || j != 0) {
+               if (directions[i][j] == MATCH) {
+                       baseend->parent_map |= 1<<parent;
+                       baseend = baseend->prev;
+                       newend = newend->prev;
+                       i--;
+                       j--;
+               } else if (directions[i][j] == NEW) {
+                       struct lline *lline;
+
+                       lline = newend;
+                       /* Remove lline from new list and update newend */
+                       if (lline->prev)
+                               lline->prev->next = lline->next;
+                       else
+                               new = lline->next;
+                       if (lline->next)
+                               lline->next->prev = lline->prev;
+
+                       newend = lline->prev;
+                       j--;
+
+                       /* Add lline to base list */
+                       if (baseend) {
+                               lline->next = baseend->next;
+                               lline->prev = baseend;
+                               if (lline->prev)
+                                       lline->prev->next = lline;
+                       }
+                       else {
+                               lline->next = base;
+                               base = lline;
+                       }
+                       (*lenbase)++;
+
+                       if (lline->next)
+                               lline->next->prev = lline;
+
+               } else {
+                       baseend = baseend->prev;
+                       i--;
+               }
+       }
+
+       newend = new;
+       while (newend) {
+               struct lline *lline = newend;
+               newend = newend->next;
+               free(lline);
+       }
+
+       for (i = 0; i < origbaselen + 1; i++)
+               free(directions[i]);
+       free(directions);
+
+       return base;
+}
+
 static char *grab_blob(const unsigned char *sha1, unsigned int mode,
                       unsigned long *size, struct userdiff_driver *textconv,
                       const char *path)
@@ -129,29 +304,19 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
        if (line[len-1] == '\n')
                len--;
 
-       /* Check to see if we can squash things */
-       if (sline->lost_head) {
-               lline = sline->next_lost;
-               while (lline) {
-                       if (lline->len == len &&
-                           !memcmp(lline->line, line, len)) {
-                               lline->parent_map |= this_mask;
-                               sline->next_lost = lline->next;
-                               return;
-                       }
-                       lline = lline->next;
-               }
-       }
-
        lline = xmalloc(sizeof(*lline) + len + 1);
        lline->len = len;
        lline->next = NULL;
+       lline->prev = sline->plost.lost_tail;
+       if (lline->prev)
+               lline->prev->next = lline;
+       else
+               sline->plost.lost_head = lline;
+       sline->plost.lost_tail = lline;
+       sline->plost.len++;
        lline->parent_map = this_mask;
        memcpy(lline->line, line, len);
        lline->line[len] = 0;
-       *sline->lost_tail = lline;
-       sline->lost_tail = &lline->next;
-       sline->next_lost = NULL;
 }
 
 struct combine_diff_state {
@@ -194,7 +359,6 @@ static void consume_line(void *state_, char *line, unsigned long len)
                                xcalloc(state->num_parent,
                                        sizeof(unsigned long));
                state->sline[state->nb-1].p_lno[state->n] = state->ob;
-               state->lost_bucket->next_lost = state->lost_bucket->lost_head;
                return;
        }
        if (!state->lost_bucket)
@@ -215,7 +379,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
                         struct sline *sline, unsigned int cnt, int n,
                         int num_parent, int result_deleted,
                         struct userdiff_driver *textconv,
-                        const char *path)
+                        const char *path, long flags)
 {
        unsigned int p_lno, lno;
        unsigned long nmask = (1UL << n);
@@ -231,7 +395,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
        parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
        parent_file.size = sz;
        memset(&xpp, 0, sizeof(xpp));
-       xpp.flags = 0;
+       xpp.flags = flags;
        memset(&xecfg, 0, sizeof(xecfg));
        memset(&state, 0, sizeof(state));
        state.nmask = nmask;
@@ -255,8 +419,18 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
                struct lline *ll;
                sline[lno].p_lno[n] = p_lno;
 
+               /* Coalesce new lines */
+               if (sline[lno].plost.lost_head) {
+                       struct sline *sl = &sline[lno];
+                       sl->lost = coalesce_lines(sl->lost, &sl->lenlost,
+                                                 sl->plost.lost_head,
+                                                 sl->plost.len, n, flags);
+                       sl->plost.lost_head = sl->plost.lost_tail = NULL;
+                       sl->plost.len = 0;
+               }
+
                /* How many lines would this sline advance the p_lno? */
-               ll = sline[lno].lost_head;
+               ll = sline[lno].lost;
                while (ll) {
                        if (ll->parent_map & nmask)
                                p_lno++; /* '-' means parent had it */
@@ -276,7 +450,7 @@ static int interesting(struct sline *sline, unsigned long all_mask)
        /* If some parents lost lines here, or if we have added to
         * some parent, it is interesting.
         */
-       return ((sline->flag & all_mask) || sline->lost_head);
+       return ((sline->flag & all_mask) || sline->lost);
 }
 
 static unsigned long adjust_hunk_tail(struct sline *sline,
@@ -459,7 +633,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
                has_interesting = 0;
                for (j = i; j < hunk_end && !has_interesting; j++) {
                        unsigned long this_diff = sline[j].flag & all_mask;
-                       struct lline *ll = sline[j].lost_head;
+                       struct lline *ll = sline[j].lost;
                        if (this_diff) {
                                /* This has some changes.  Is it the
                                 * same as others?
@@ -613,7 +787,7 @@ static void dump_sline(struct sline *sline, const char *line_prefix,
                        int j;
                        unsigned long p_mask;
                        struct sline *sl = &sline[lno++];
-                       ll = (sl->flag & no_pre_delete) ? NULL : sl->lost_head;
+                       ll = (sl->flag & no_pre_delete) ? NULL : sl->lost;
                        while (ll) {
                                printf("%s%s", line_prefix, c_old);
                                for (j = 0; j < num_parent; j++) {
@@ -664,7 +838,7 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
        jmask = (1UL<<j);
 
        for (lno = 0; lno <= cnt; lno++) {
-               struct lline *ll = sline->lost_head;
+               struct lline *ll = sline->lost;
                sline->p_lno[i] = sline->p_lno[j];
                while (ll) {
                        if (ll->parent_map & jmask)
@@ -923,10 +1097,6 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 
        sline = xcalloc(cnt+2, sizeof(*sline));
        sline[0].bol = result;
-       for (lno = 0; lno <= cnt + 1; lno++) {
-               sline[lno].lost_tail = &sline[lno].lost_head;
-               sline[lno].flag = 0;
-       }
        for (lno = 0, cp = result; cp < result + result_size; cp++) {
                if (*cp == '\n') {
                        sline[lno].len = cp - sline[lno].bol;
@@ -962,7 +1132,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
                                     elem->parent[i].mode,
                                     &result_file, sline,
                                     cnt, i, num_parent, result_deleted,
-                                    textconv, elem->path);
+                                    textconv, elem->path, opt->xdl_opts);
        }
 
        show_hunks = make_hunks(sline, cnt, num_parent, dense);
@@ -976,8 +1146,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        free(result);
 
        for (lno = 0; lno < cnt; lno++) {
-               if (sline[lno].lost_head) {
-                       struct lline *ll = sline[lno].lost_head;
+               if (sline[lno].lost) {
+                       struct lline *ll = sline[lno].lost;
                        while (ll) {
                                struct lline *tmp = ll;
                                ll = ll->next;
index e8eb0aec5509a4fd09698bd15a37d1f4e8341f5e..888e02ae2f65ab566555465e5d88d02bbe52420f 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -463,14 +463,23 @@ static void clear_commit_marks_1(struct commit_list **plist,
        }
 }
 
-void clear_commit_marks(struct commit *commit, unsigned int mark)
+void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark)
 {
        struct commit_list *list = NULL;
-       commit_list_insert(commit, &list);
+
+       while (nr--) {
+               commit_list_insert(*commit, &list);
+               commit++;
+       }
        while (list)
                clear_commit_marks_1(&list, pop_commit(&list), mark);
 }
 
+void clear_commit_marks(struct commit *commit, unsigned int mark)
+{
+       clear_commit_marks_many(1, &commit, mark);
+}
+
 void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark)
 {
        struct object *object;
@@ -797,8 +806,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
        if (!result || !result->next) {
                if (cleanup) {
                        clear_commit_marks(one, all_flags);
-                       for (i = 0; i < n; i++)
-                               clear_commit_marks(twos[i], all_flags);
+                       clear_commit_marks_many(n, twos, all_flags);
                }
                return result;
        }
@@ -816,8 +824,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
        free_commit_list(result);
 
        clear_commit_marks(one, all_flags);
-       for (i = 0; i < n; i++)
-               clear_commit_marks(twos[i], all_flags);
+       clear_commit_marks_many(n, twos, all_flags);
 
        cnt = remove_redundant(rslt, cnt);
        result = NULL;
@@ -834,7 +841,7 @@ struct commit_list *get_merge_bases(struct commit *one, struct commit *two,
 }
 
 /*
- * Is "commit" a decendant of one of the elements on the "with_commit" list?
+ * Is "commit" a descendant of one of the elements on the "with_commit" list?
  */
 int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
 {
@@ -852,25 +859,36 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
 }
 
 /*
- * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
+ * Is "commit" an ancestor of one of the "references"?
  */
-int in_merge_bases(struct commit *commit, struct commit *reference)
+int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference)
 {
        struct commit_list *bases;
-       int ret = 0;
+       int ret = 0, i;
 
-       if (parse_commit(commit) || parse_commit(reference))
+       if (parse_commit(commit))
                return ret;
+       for (i = 0; i < nr_reference; i++)
+               if (parse_commit(reference[i]))
+                       return ret;
 
-       bases = paint_down_to_common(commit, 1, &reference);
+       bases = paint_down_to_common(commit, nr_reference, reference);
        if (commit->object.flags & PARENT2)
                ret = 1;
        clear_commit_marks(commit, all_flags);
-       clear_commit_marks(reference, all_flags);
+       clear_commit_marks_many(nr_reference, reference, all_flags);
        free_commit_list(bases);
        return ret;
 }
 
+/*
+ * Is "commit" an ancestor of (i.e. reachable from) the "reference"?
+ */
+int in_merge_bases(struct commit *commit, struct commit *reference)
+{
+       return in_merge_bases_many(commit, 1, &reference);
+}
+
 struct commit_list *reduce_heads(struct commit_list *heads)
 {
        struct commit_list *p;
@@ -1023,6 +1041,76 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
        free(buf);
 }
 
+static struct {
+       char result;
+       const char *check;
+} sigcheck_gpg_status[] = {
+       { 'G', "\n[GNUPG:] GOODSIG " },
+       { 'B', "\n[GNUPG:] BADSIG " },
+       { 'U', "\n[GNUPG:] TRUST_NEVER" },
+       { 'U', "\n[GNUPG:] TRUST_UNDEFINED" },
+};
+
+static void parse_gpg_output(struct signature_check *sigc)
+{
+       const char *buf = sigc->gpg_status;
+       int i;
+
+       /* Iterate over all search strings */
+       for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
+               const char *found, *next;
+
+               if (!prefixcmp(buf, sigcheck_gpg_status[i].check + 1)) {
+                       /* At the very beginning of the buffer */
+                       found = buf + strlen(sigcheck_gpg_status[i].check + 1);
+               } else {
+                       found = strstr(buf, sigcheck_gpg_status[i].check);
+                       if (!found)
+                               continue;
+                       found += strlen(sigcheck_gpg_status[i].check);
+               }
+               sigc->result = sigcheck_gpg_status[i].result;
+               /* The trust messages are not followed by key/signer information */
+               if (sigc->result != 'U') {
+                       sigc->key = xmemdupz(found, 16);
+                       found += 17;
+                       next = strchrnul(found, '\n');
+                       sigc->signer = xmemdupz(found, next - found);
+               }
+       }
+}
+
+void check_commit_signature(const struct commit* commit, struct signature_check *sigc)
+{
+       struct strbuf payload = STRBUF_INIT;
+       struct strbuf signature = STRBUF_INIT;
+       struct strbuf gpg_output = STRBUF_INIT;
+       struct strbuf gpg_status = STRBUF_INIT;
+       int status;
+
+       sigc->result = 'N';
+
+       if (parse_signed_commit(commit->object.sha1,
+                               &payload, &signature) <= 0)
+               goto out;
+       status = verify_signed_buffer(payload.buf, payload.len,
+                                     signature.buf, signature.len,
+                                     &gpg_output, &gpg_status);
+       if (status && !gpg_output.len)
+               goto out;
+       sigc->gpg_output = strbuf_detach(&gpg_output, NULL);
+       sigc->gpg_status = strbuf_detach(&gpg_status, NULL);
+       parse_gpg_output(sigc);
+
+ out:
+       strbuf_release(&gpg_status);
+       strbuf_release(&gpg_output);
+       strbuf_release(&payload);
+       strbuf_release(&signature);
+}
+
+
+
 void append_merge_tag_headers(struct commit_list *parents,
                              struct commit_extra_header ***tail)
 {
index 4138bb4c0850f95ba7215cb62f457cd682495968..057ff8045efb2cc80f747ee15b2a308a6dead5e5 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -5,6 +5,7 @@
 #include "tree.h"
 #include "strbuf.h"
 #include "decorate.h"
+#include "gpg-interface.h"
 
 struct commit_list {
        struct commit *item;
@@ -137,6 +138,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
 struct commit *pop_commit(struct commit_list **stack);
 
 void clear_commit_marks(struct commit *commit, unsigned int mark);
+void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark);
 void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark);
 
 /*
@@ -164,7 +166,7 @@ extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *r
 extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
 extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
 
-/* largest postive number a signed 32-bit integer can contain */
+/* largest positive number a signed 32-bit integer can contain */
 #define INFINITE_DEPTH 0x7fffffff
 
 extern int register_shallow(const unsigned char *sha1);
@@ -176,6 +178,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 
 int is_descendant_of(struct commit *, struct commit_list *);
 int in_merge_bases(struct commit *, struct commit *);
+int in_merge_bases_many(struct commit *, int, struct commit **);
 
 extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
 extern int run_add_interactive(const char *revision, const char *patch_mode,
@@ -230,4 +233,13 @@ extern void print_commit_list(struct commit_list *list,
                              const char *format_cur,
                              const char *format_last);
 
+/*
+ * Check the signature of the given commit. The result of the check is stored
+ * in sig->check_result, 'G' for a good signature, 'U' for a good signature
+ * from an untrusted signer, 'B' for a bad signature and 'N' for no signature
+ * at all.  This may allocate memory for sig->gpg_output, sig->gpg_status,
+ * sig->signer and sig->key.
+ */
+extern void check_commit_signature(const struct commit* commit, struct signature_check *sigc);
+
 #endif /* COMMIT_H */
index 5428858875a20b89411d3662e777586d9d798fab..871b41d23a7471724a0446ff3333b577a175c579 100644 (file)
@@ -1,3 +1,4 @@
+#define CYGWIN_C
 #define WIN32_LEAN_AND_MEAN
 #ifdef CYGWIN_V15_WIN32API
 #include "../git-compat-util.h"
 #endif
 #include "../cache.h" /* to read configuration */
 
+/*
+ * Return POSIX permission bits, regardless of core.ignorecygwinfstricks
+ */
+int cygwin_get_st_mode_bits(const char *path, int *mode)
+{
+       struct stat st;
+       if (lstat(path, &st) < 0)
+               return -1;
+       *mode = st.st_mode;
+       return 0;
+}
+
 static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
 {
        long long winTime = ((long long)ft->dwHighDateTime << 32) +
index a3229f5b4fbb819ba1beabcf560725e80ad51bb4..c04965a2e0e259d3bded51730f699bde5c4262e6 100644 (file)
@@ -4,6 +4,11 @@
 typedef int (*stat_fn_t)(const char*, struct stat*);
 extern stat_fn_t cygwin_stat_fn;
 extern stat_fn_t cygwin_lstat_fn;
+int cygwin_get_st_mode_bits(const char *path, int *mode);
 
+#define get_st_mode_bits(p,m) cygwin_get_st_mode_bits((p),(m))
+#ifndef CYGWIN_C
+/* cygwin.c needs the original lstat() */
 #define stat(path, buf) (*cygwin_stat_fn)(path, buf)
 #define lstat(path, buf) (*cygwin_lstat_fn)(path, buf)
+#endif
index aa4b56315ae2488ea656d695f0f660e4dbd745ef..96b6d605dad3872f02933581e501ee4380cb8f68 100644 (file)
@@ -12,6 +12,8 @@
 #define __attribute__(x)
 #define strncasecmp  _strnicmp
 #define ftruncate    _chsize
+#define strtoull     _strtoui64
+#define strtoll      _strtoi64
 
 static __inline int strcasecmp (const char *s1, const char *s2)
 {
index ff7c2c4fd8642da754b1c85a9e177baf4ddc7136..1401a6727414480e181023f8de974bad76a04d24 100644 (file)
@@ -4778,7 +4778,7 @@ void* dlmalloc(size_t bytes) {
 
 void dlfree(void* mem) {
   /*
-     Consolidate freed chunks with preceeding or succeeding bordering
+     Consolidate freed chunks with preceding or succeeding bordering
      free chunks, if they exist, and then place in a bin.  Intermixed
      with special cases for top, dv, mmapped chunks, and usage errors.
   */
@@ -5680,10 +5680,10 @@ int mspace_mallopt(int param_number, int value) {
        Wolfram Gloger (Gloger@lrz.uni-muenchen.de).
       * Use last_remainder in more cases.
       * Pack bins using idea from  colin@nyx10.cs.du.edu
-      * Use ordered bins instead of best-fit threshhold
+      * Use ordered bins instead of best-fit threshold
       * Eliminate block-local decls to simplify tracing and debugging.
       * Support another case of realloc via move into top
-      * Fix error occuring when initial sbrk_base not word-aligned.
+      * Fix error occurring when initial sbrk_base not word-aligned.
       * Rely on page size for units instead of SBRK_UNIT to
        avoid surprises about sbrk alignment conventions.
       * Add mallinfo, mallopt. Thanks to Raymond Nijssen
index d178bd67162fd2b566364ac6dff84cecdcaa9473..ceb4bdbcdd6ed583ab3b7c9cc5d9d2783128dee6 100644 (file)
@@ -128,7 +128,7 @@ extern "C" {
 
 #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
 
-/* Similiar to _BPTR_ALIGN (B, P, A), except optimize the common case
+/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case
    where pointers can be converted to integers, aligned as integers,
    and converted back again.  If PTR_INT_TYPE is narrower than a
    pointer (e.g., the AS/400), play it safe and compute the alignment
index 8cf59558e1c6fcc6782b8eaf94534ea041599191..030174db515e764aa883b21afe9be8fb3ae41f2e 100644 (file)
@@ -134,7 +134,7 @@ struct dirent_prec_psx *precompose_utf8_readdir(PREC_DIR *prec_dir)
                        if (prec_dir->ic_precompose == (iconv_t)-1) {
                                die("iconv_open(%s,%s) failed, but needed:\n"
                                                "    precomposed unicode is not supported.\n"
-                                               "    If you wnat to use decomposed unicode, run\n"
+                                               "    If you want to use decomposed unicode, run\n"
                                                "    \"git config core.precomposeunicode false\"\n",
                                                repo_encoding, path_encoding);
                        } else {
index 8c96ed942c3f7139a4b161c75c6c81e42530c085..d0025bd58d48cfcf137e5ef3bba90881dc00ec68 100644 (file)
@@ -2095,7 +2095,7 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
 
 /* Entry point of the parser.
    Parse the regular expression REGEXP and return the structure tree.
-   If an error is occured, ERR is set by error code, and return NULL.
+   If an error has occurred, ERR is set by error code, and return NULL.
    This function build the following tree, from regular expression <reg_exp>:
           CAT
           / \
@@ -3715,7 +3715,7 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
 /* This is intended for the expressions like "a{1,3}".
    Fetch a number from `input', and return the number.
    Return -1, if the number field is empty like "{,1}".
-   Return -2, If an error is occured.  */
+   Return -2, if an error has occurred.  */
 
 static int
 fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
index 3dd8dfa01f2a6ab7a197ecddd481704150253c36..6aaae003274e268f274df4b76e02609d5f27e457 100644 (file)
@@ -22,7 +22,7 @@
 #include "config.h"
 #endif
 
-/* Make sure noone compiles this code with a C++ compiler.  */
+/* Make sure no one compiles this code with a C++ compiler.  */
 #ifdef __cplusplus
 # error "This is C code, use a C compiler"
 #endif
index 193854cf5b609d714b03218bd507af840d478c6e..d4121f2f4f1cfa9bf90c22b6e3c944f451225fdf 100644 (file)
@@ -1284,7 +1284,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
 
 /* Insert the new element ELEM to the re_node_set* SET.
    SET should not already have ELEM.
-   return -1 if an error is occured, return 1 otherwise.  */
+   return -1 if an error has occurred, return 1 otherwise.  */
 
 static int
 internal_function
@@ -1341,7 +1341,7 @@ re_node_set_insert (re_node_set *set, int elem)
 
 /* Insert the new element ELEM to the re_node_set* SET.
    SET should not already have any element greater than or equal to ELEM.
-   Return -1 if an error is occured, return 1 otherwise.  */
+   Return -1 if an error has occurred, return 1 otherwise.  */
 
 static int
 internal_function
@@ -1416,7 +1416,7 @@ re_node_set_remove_at (re_node_set *set, int idx)
 \f
 
 /* Add the token TOKEN to dfa->nodes, and return the index of the token.
-   Or return -1, if an error will be occured.  */
+   Or return -1, if an error has occurred.  */
 
 static int
 internal_function
diff --git a/compat/vcbuild/include/sys/poll.h b/compat/vcbuild/include/sys/poll.h
deleted file mode 100644 (file)
index 0d8552a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* Intentionally empty file to support building git with MSVC */
index b14fcf94da405c6f3267437e59936d598168e00f..c65c2cd566b51473da12786f28074040c410f343 100644 (file)
@@ -49,6 +49,9 @@ typedef int64_t off64_t;
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
+#define UINT32_MAX 0xffffffff  /* 4294967295U */
+
+#define STDIN_FILENO  0
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
 
index fa02bdd82ada7c45b2c666438aa2df9407f5c1af..e6a6d0f941cb2d61586c5d5eddb2ccf27c6439db 100644 (file)
@@ -22,9 +22,3 @@ docdir = @docdir@
 
 mandir = @mandir@
 htmldir = @htmldir@
-
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-export exec_prefix mandir
-export srcdir VPATH
index e09af8fc13ec4c3c6fa326e8208c98be52347a10..9080054f7617017a67ca0ae8414f829a01d3d546 100644 (file)
@@ -326,7 +326,6 @@ ifeq ($(uname_S),Windows)
        # NEEDS_LIBICONV = YesPlease
        NO_ICONV = YesPlease
        NO_STRTOUMAX = YesPlease
-       NO_STRTOULL = YesPlease
        NO_MKDTEMP = YesPlease
        NO_MKSTEMPS = YesPlease
        SNPRINTF_RETURNS_BOGUS = YesPlease
@@ -343,6 +342,9 @@ ifeq ($(uname_S),Windows)
        NO_CURL = YesPlease
        NO_PYTHON = YesPlease
        BLK_SHA1 = YesPlease
+       ETAGS_TARGET = ETAGS
+       NO_INET_PTON = YesPlease
+       NO_INET_NTOP = YesPlease
        NO_POSIX_GOODIES = UnfortunatelyYes
        NATIVE_CRLF = YesPlease
        DEFAULT_HELP_FORMAT = html
index 49e56ba35a645359b0d7c1f7bbc9e2108b3424d9..f57efd06c1d7ab01076b67d37ed24e34e17c4ebb 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -62,8 +62,8 @@ static void die_initial_contact(int got_at_least_one_head)
 /*
  * Read all the refs from the other end
  */
-struct ref **get_remote_heads(int in, struct ref **list,
-                             unsigned int flags,
+struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
+                             struct ref **list, unsigned int flags,
                              struct extra_have_objects *extra_have)
 {
        int got_at_least_one_head = 0;
@@ -72,18 +72,19 @@ struct ref **get_remote_heads(int in, struct ref **list,
        for (;;) {
                struct ref *ref;
                unsigned char old_sha1[20];
-               static char buffer[1000];
                char *name;
                int len, name_len;
+               char *buffer = packet_buffer;
 
-               len = packet_read(in, buffer, sizeof(buffer));
+               len = packet_read(in, &src_buf, &src_len,
+                                 packet_buffer, sizeof(packet_buffer),
+                                 PACKET_READ_GENTLE_ON_EOF |
+                                 PACKET_READ_CHOMP_NEWLINE);
                if (len < 0)
                        die_initial_contact(got_at_least_one_head);
 
                if (!len)
                        break;
-               if (buffer[len-1] == '\n')
-                       buffer[--len] = 0;
 
                if (len > 4 && !prefixcmp(buffer, "ERR "))
                        die("remote error: %s", buffer + 4);
index 93eba467502282db2697e1cf6c93a6909d35ee5c..2ba1461422c4e6c16e6c85ed3914536e1f4aa56e 100644 (file)
@@ -2419,7 +2419,7 @@ _git_submodule ()
 {
        __git_has_doubledash && return
 
-       local subcommands="add status init update summary foreach sync"
+       local subcommands="add status init deinit update summary foreach sync"
        if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
                case "$cur" in
                --*)
index 341422a766efe70580817d98a574d95bd9ddebf9..756a9514591c7664c82c93d3a6d50d91f46857d8 100644 (file)
@@ -282,6 +282,8 @@ __git_ps1 ()
                                r="|MERGING"
                        elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
                                r="|CHERRY-PICKING"
+                       elif [ -f "$g/REVERT_HEAD" ]; then
+                               r="|REVERTING"
                        elif [ -f "$g/BISECT_LOG" ]; then
                                r="|BISECTING"
                        fi
diff --git a/contrib/credential/netrc/Makefile b/contrib/credential/netrc/Makefile
new file mode 100644 (file)
index 0000000..51b7613
--- /dev/null
@@ -0,0 +1,5 @@
+test:
+       ./test.pl
+
+testverbose:
+       ./test.pl -d -v
diff --git a/contrib/credential/netrc/git-credential-netrc b/contrib/credential/netrc/git-credential-netrc
new file mode 100755 (executable)
index 0000000..6c51c43
--- /dev/null
@@ -0,0 +1,421 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+use File::Basename;
+
+my $VERSION = "0.1";
+
+my %options = (
+              help => 0,
+              debug => 0,
+              verbose => 0,
+              insecure => 0,
+              file => [],
+
+              # identical token maps, e.g. host -> host, will be inserted later
+              tmap => {
+                       port => 'protocol',
+                       machine => 'host',
+                       path => 'path',
+                       login => 'username',
+                       user => 'username',
+                       password => 'password',
+                      }
+             );
+
+# Map each credential protocol token to itself on the netrc side.
+foreach (values %{$options{tmap}}) {
+       $options{tmap}->{$_} = $_;
+}
+
+# Now, $options{tmap} has a mapping from the netrc format to the Git credential
+# helper protocol.
+
+# Next, we build the reverse token map.
+
+# When $rmap{foo} contains 'bar', that means that what the Git credential helper
+# protocol calls 'bar' is found as 'foo' in the netrc/authinfo file.  Keys in
+# %rmap are what we expect to read from the netrc/authinfo file.
+
+my %rmap;
+foreach my $k (keys %{$options{tmap}}) {
+       push @{$rmap{$options{tmap}->{$k}}}, $k;
+}
+
+Getopt::Long::Configure("bundling");
+
+# TODO: maybe allow the token map $options{tmap} to be configurable.
+GetOptions(\%options,
+           "help|h",
+           "debug|d",
+           "insecure|k",
+           "verbose|v",
+           "file|f=s@",
+          );
+
+if ($options{help}) {
+       my $shortname = basename($0);
+       $shortname =~ s/git-credential-//;
+
+       print <<EOHIPPUS;
+
+$0 [-f AUTHFILE1] [-f AUTHFILEN] [-d] [-v] [-k] get
+
+Version $VERSION by tzz\@lifelogs.com.  License: BSD.
+
+Options:
+
+  -f|--file AUTHFILE : specify netrc-style files.  Files with the .gpg extension
+                       will be decrypted by GPG before parsing.  Multiple -f
+                       arguments are OK.  They are processed in order, and the
+                       first matching entry found is returned via the credential
+                       helper protocol (see below).
+
+                       When no -f option is given, .authinfo.gpg, .netrc.gpg,
+                      .authinfo, and .netrc files in your home directory are used
+                      in this order.
+
+  -k|--insecure      : ignore bad file ownership or permissions
+
+  -d|--debug         : turn on debugging (developer info)
+
+  -v|--verbose       : be more verbose (show files and information found)
+
+To enable this credential helper:
+
+  git config credential.helper '$shortname -f AUTHFILE1 -f AUTHFILE2'
+
+(Note that Git will prepend "git-credential-" to the helper name and look for it
+in the path.)
+
+...and if you want lots of debugging info:
+
+  git config credential.helper '$shortname -f AUTHFILE -d'
+
+...or to see the files opened and data found:
+
+  git config credential.helper '$shortname -f AUTHFILE -v'
+
+Only "get" mode is supported by this credential helper.  It opens every AUTHFILE
+and looks for the first entry that matches the requested search criteria:
+
+ 'port|protocol':
+   The protocol that will be used (e.g., https). (protocol=X)
+
+ 'machine|host':
+   The remote hostname for a network credential. (host=X)
+
+ 'path':
+   The path with which the credential will be used. (path=X)
+
+ 'login|user|username':
+   The credential’s username, if we already have one. (username=X)
+
+Thus, when we get this query on STDIN:
+
+host=github.com
+protocol=https
+username=tzz
+
+this credential helper will look for the first entry in every AUTHFILE that
+matches
+
+machine github.com port https login tzz
+
+OR
+
+machine github.com protocol https login tzz
+
+OR... etc. acceptable tokens as listed above.  Any unknown tokens are
+simply ignored.
+
+Then, the helper will print out whatever tokens it got from the entry, including
+"password" tokens, mapping back to Git's helper protocol; e.g. "port" is mapped
+back to "protocol".  Any redundant entry tokens (part of the original query) are
+skipped.
+
+Again, note that only the first matching entry from all the AUTHFILEs, processed
+in the sequence given on the command line, is used.
+
+Netrc/authinfo tokens can be quoted as 'STRING' or "STRING".
+
+No caching is performed by this credential helper.
+
+EOHIPPUS
+
+       exit 0;
+}
+
+my $mode = shift @ARGV;
+
+# Credentials must get a parameter, so die if it's missing.
+die "Syntax: $0 [-f AUTHFILE1] [-f AUTHFILEN] [-d] get" unless defined $mode;
+
+# Only support 'get' mode; with any other unsupported ones we just exit.
+exit 0 unless $mode eq 'get';
+
+my $files = $options{file};
+
+# if no files were given, use a predefined list.
+# note that .gpg files come first
+unless (scalar @$files) {
+       my @candidates = qw[
+                                  ~/.authinfo.gpg
+                                  ~/.netrc.gpg
+                                  ~/.authinfo
+                                  ~/.netrc
+                         ];
+
+       $files = $options{file} = [ map { glob $_ } @candidates ];
+}
+
+my $query = read_credential_data_from_stdin();
+
+FILE:
+foreach my $file (@$files) {
+       my $gpgmode = $file =~ m/\.gpg$/;
+       unless (-r $file) {
+               log_verbose("Unable to read $file; skipping it");
+               next FILE;
+       }
+
+       # the following check is copied from Net::Netrc, for non-GPG files
+       # OS/2 and Win32 do not handle stat in a way compatible with this check :-(
+       unless ($gpgmode || $options{insecure} ||
+               $^O eq 'os2'
+               || $^O eq 'MSWin32'
+               || $^O eq 'MacOS'
+               || $^O =~ /^cygwin/) {
+               my @stat = stat($file);
+
+               if (@stat) {
+                       if ($stat[2] & 077) {
+                               log_verbose("Insecure $file (mode=%04o); skipping it",
+                                           $stat[2] & 07777);
+                               next FILE;
+                       }
+
+                       if ($stat[4] != $<) {
+                               log_verbose("Not owner of $file; skipping it");
+                               next FILE;
+                       }
+               }
+       }
+
+       my @entries = load_netrc($file, $gpgmode);
+
+       unless (scalar @entries) {
+               if ($!) {
+                       log_verbose("Unable to open $file: $!");
+               } else {
+                       log_verbose("No netrc entries found in $file");
+               }
+
+               next FILE;
+       }
+
+       my $entry = find_netrc_entry($query, @entries);
+       if ($entry) {
+               print_credential_data($entry, $query);
+               # we're done!
+               last FILE;
+       }
+}
+
+exit 0;
+
+sub load_netrc {
+       my $file = shift @_;
+       my $gpgmode = shift @_;
+
+       my $io;
+       if ($gpgmode) {
+               my @cmd = (qw(gpg --decrypt), $file);
+               log_verbose("Using GPG to open $file: [@cmd]");
+               open $io, "-|", @cmd;
+       } else {
+               log_verbose("Opening $file...");
+               open $io, '<', $file;
+       }
+
+       # nothing to do if the open failed (we log the error later)
+       return unless $io;
+
+       # Net::Netrc does this, but the functionality is merged with the file
+       # detection logic, so we have to extract just the part we need
+       my @netrc_entries = net_netrc_loader($io);
+
+       # these entries will use the credential helper protocol token names
+       my @entries;
+
+       foreach my $nentry (@netrc_entries) {
+               my %entry;
+               my $num_port;
+
+               if (!defined $nentry->{machine}) {
+                       next;
+               }
+               if (defined $nentry->{port} && $nentry->{port} =~ m/^\d+$/) {
+                       $num_port = $nentry->{port};
+                       delete $nentry->{port};
+               }
+
+               # create the new entry for the credential helper protocol
+               $entry{$options{tmap}->{$_}} = $nentry->{$_} foreach keys %$nentry;
+
+               # for "host X port Y" where Y is an integer (captured by
+               # $num_port above), set the host to "X:Y"
+               if (defined $entry{host} && defined $num_port) {
+                       $entry{host} = join(':', $entry{host}, $num_port);
+               }
+
+               push @entries, \%entry;
+       }
+
+       return @entries;
+}
+
+sub net_netrc_loader {
+       my $fh = shift @_;
+       my @entries;
+       my ($mach, $macdef, $tok, @tok);
+
+    LINE:
+       while (<$fh>) {
+               undef $macdef if /\A\n\Z/;
+
+               if ($macdef) {
+                       next LINE;
+               }
+
+               s/^\s*//;
+               chomp;
+
+               while (length && s/^("((?:[^"]+|\\.)*)"|((?:[^\\\s]+|\\.)*))\s*//) {
+                       (my $tok = $+) =~ s/\\(.)/$1/g;
+                       push(@tok, $tok);
+               }
+
+           TOKEN:
+               while (@tok) {
+                       if ($tok[0] eq "default") {
+                               shift(@tok);
+                               $mach = { machine => undef };
+                               next TOKEN;
+                       }
+
+                       $tok = shift(@tok);
+
+                       if ($tok eq "machine") {
+                               my $host = shift @tok;
+                               $mach = { machine => $host };
+                               push @entries, $mach;
+                       } elsif (exists $options{tmap}->{$tok}) {
+                               unless ($mach) {
+                                       log_debug("Skipping token $tok because no machine was given");
+                                       next TOKEN;
+                               }
+
+                               my $value = shift @tok;
+                               unless (defined $value) {
+                                       log_debug("Token $tok had no value, skipping it.");
+                                       next TOKEN;
+                               }
+
+                               # Following line added by rmerrell to remove '/' escape char in .netrc
+                               $value =~ s/\/\\/\\/g;
+                               $mach->{$tok} = $value;
+                       } elsif ($tok eq "macdef") { # we ignore macros
+                               next TOKEN unless $mach;
+                               my $value = shift @tok;
+                               $macdef = 1;
+                       }
+               }
+       }
+
+       return @entries;
+}
+
+sub read_credential_data_from_stdin {
+       # the query: start with every token with no value
+       my %q = map { $_ => undef } values(%{$options{tmap}});
+
+       while (<STDIN>) {
+               next unless m/^([^=]+)=(.+)/;
+
+               my ($token, $value) = ($1, $2);
+               die "Unknown search token $token" unless exists $q{$token};
+               $q{$token} = $value;
+               log_debug("We were given search token $token and value $value");
+       }
+
+       foreach (sort keys %q) {
+               log_debug("Searching for %s = %s", $_, $q{$_} || '(any value)');
+       }
+
+       return \%q;
+}
+
+# takes the search tokens and then a list of entries
+# each entry is a hash reference
+sub find_netrc_entry {
+       my $query = shift @_;
+
+    ENTRY:
+       foreach my $entry (@_)
+       {
+               my $entry_text = join ', ', map { "$_=$entry->{$_}" } keys %$entry;
+               foreach my $check (sort keys %$query) {
+                       if (defined $query->{$check}) {
+                               log_debug("compare %s [%s] to [%s] (entry: %s)",
+                                         $check,
+                                         $entry->{$check},
+                                         $query->{$check},
+                                         $entry_text);
+                               unless ($query->{$check} eq $entry->{$check}) {
+                                       next ENTRY;
+                               }
+                       } else {
+                               log_debug("OK: any value satisfies check $check");
+                       }
+               }
+
+               return $entry;
+       }
+
+       # nothing was found
+       return;
+}
+
+sub print_credential_data {
+       my $entry = shift @_;
+       my $query = shift @_;
+
+       log_debug("entry has passed all the search checks");
+ TOKEN:
+       foreach my $git_token (sort keys %$entry) {
+               log_debug("looking for useful token $git_token");
+               # don't print unknown (to the credential helper protocol) tokens
+               next TOKEN unless exists $query->{$git_token};
+
+               # don't print things asked in the query (the entry matches them)
+               next TOKEN if defined $query->{$git_token};
+
+               log_debug("FOUND: $git_token=$entry->{$git_token}");
+               printf "%s=%s\n", $git_token, $entry->{$git_token};
+       }
+}
+sub log_verbose {
+       return unless $options{verbose};
+       printf STDERR @_;
+       printf STDERR "\n";
+}
+
+sub log_debug {
+       return unless $options{debug};
+       printf STDERR @_;
+       printf STDERR "\n";
+}
diff --git a/contrib/credential/netrc/test.netrc b/contrib/credential/netrc/test.netrc
new file mode 100644 (file)
index 0000000..ba119a9
--- /dev/null
@@ -0,0 +1,13 @@
+machine imap login tzz@lifelogs.com port imaps password letmeknow
+machine imap login bob port imaps password bobwillknow
+
+# comment test
+
+machine imap2 login tzz port 1099 password tzzknow
+machine imap2 login bob password bobwillknow
+
+# another command
+
+machine github.com
+  multilinetoken anothervalue
+  login carol password carolknows
diff --git a/contrib/credential/netrc/test.pl b/contrib/credential/netrc/test.pl
new file mode 100755 (executable)
index 0000000..169b646
--- /dev/null
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Test;
+use IPC::Open2;
+
+BEGIN { plan tests => 15 }
+
+my @global_credential_args = @ARGV;
+my $netrc = './test.netrc';
+print "# Testing insecure file, nothing should be found\n";
+chmod 0644, $netrc;
+my $cred = run_credential(['-f', $netrc, 'get'],
+                         { host => 'github.com' });
+
+ok(scalar keys %$cred, 0, "Got 0 keys from insecure file");
+
+print "# Testing missing file, nothing should be found\n";
+chmod 0644, $netrc;
+$cred = run_credential(['-f', '///nosuchfile///', 'get'],
+                      { host => 'github.com' });
+
+ok(scalar keys %$cred, 0, "Got 0 keys from missing file");
+
+chmod 0600, $netrc;
+
+print "# Testing with invalid data\n";
+$cred = run_credential(['-f', $netrc, 'get'],
+                      "bad data");
+ok(scalar keys %$cred, 4, "Got first found keys with bad data");
+
+print "# Testing netrc file for a missing corovamilkbar entry\n";
+$cred = run_credential(['-f', $netrc, 'get'],
+                      { host => 'corovamilkbar' });
+
+ok(scalar keys %$cred, 0, "Got no corovamilkbar keys");
+
+print "# Testing netrc file for a github.com entry\n";
+$cred = run_credential(['-f', $netrc, 'get'],
+                      { host => 'github.com' });
+
+ok(scalar keys %$cred, 2, "Got 2 Github keys");
+
+ok($cred->{password}, 'carolknows', "Got correct Github password");
+ok($cred->{username}, 'carol', "Got correct Github username");
+
+print "# Testing netrc file for a username-specific entry\n";
+$cred = run_credential(['-f', $netrc, 'get'],
+                      { host => 'imap', username => 'bob' });
+
+ok(scalar keys %$cred, 2, "Got 2 username-specific keys");
+
+ok($cred->{password}, 'bobwillknow', "Got correct user-specific password");
+ok($cred->{protocol}, 'imaps', "Got correct user-specific protocol");
+
+print "# Testing netrc file for a host:port-specific entry\n";
+$cred = run_credential(['-f', $netrc, 'get'],
+                      { host => 'imap2:1099' });
+
+ok(scalar keys %$cred, 2, "Got 2 host:port-specific keys");
+
+ok($cred->{password}, 'tzzknow', "Got correct host:port-specific password");
+ok($cred->{username}, 'tzz', "Got correct host:port-specific username");
+
+print "# Testing netrc file that 'host:port kills host' entry\n";
+$cred = run_credential(['-f', $netrc, 'get'],
+                      { host => 'imap2' });
+
+ok(scalar keys %$cred, 2, "Got 2 'host:port kills host' keys");
+
+ok($cred->{password}, 'bobwillknow', "Got correct 'host:port kills host' password");
+ok($cred->{username}, 'bob', "Got correct 'host:port kills host' username");
+
+sub run_credential
+{
+       my $args = shift @_;
+       my $data = shift @_;
+       my $pid = open2(my $chld_out, my $chld_in,
+                       './git-credential-netrc', @global_credential_args,
+                       @$args);
+
+       die "Couldn't open pipe to netrc credential helper: $!" unless $pid;
+
+       if (ref $data eq 'HASH')
+       {
+               print $chld_in "$_=$data->{$_}\n" foreach sort keys %$data;
+       }
+       else
+       {
+               print $chld_in "$data\n";
+       }
+
+       close $chld_in;
+       my %ret;
+
+       while (<$chld_out>)
+       {
+               chomp;
+               next unless m/^([^=]+)=(.+)/;
+
+               $ret{$1} = $2;
+       }
+
+       return \%ret;
+}
index 094129de09ca92643d98f34f20a35479089bcbcb..9c14c1f88d3a8f23df54db2adc7985eb00722c12 100755 (executable)
@@ -28,7 +28,7 @@
 use constant SLASH_REPLACEMENT => "%2F";
 
 # It's not always possible to delete pages (may require some
-# priviledges). Deleted pages are replaced with this content.
+# privileges). Deleted pages are replaced with this content.
 use constant DELETED_CONTENT => "[[Category:Deleted]]\n";
 
 # It's not possible to create empty pages. New empty files in Git are
@@ -841,7 +841,7 @@ sub mw_import_ref {
        if ($fetch_from == 1 && $n == 0) {
                print STDERR "You appear to have cloned an empty MediaWiki.\n";
                # Something has to be done remote-helper side. If nothing is done, an error is
-               # thrown saying that HEAD is refering to unknown object 0000000000000000000
+               # thrown saying that HEAD is referring to unknown object 0000000000000000000
                # and the clone fails.
        }
 }
@@ -1067,7 +1067,7 @@ sub mw_push_file {
                my $file_content;
                if ($page_deleted) {
                        # Deleting a page usually requires
-                       # special priviledges. A common
+                       # special privileges. A common
                        # convention is to replace the page
                        # with this content instead:
                        $file_content = DELETED_CONTENT;
index 96e97390cf90822e771bc8ccf600c394792f2b96..03f6ee5d72f5096e287c23e048746fe1f756f062 100644 (file)
@@ -25,7 +25,7 @@ Principles and Technical Choices
 
 The test environment makes it easy to install and manipulate one or
 several MediaWiki instances. To allow developers to run the testsuite
-easily, the environment does not require root priviledge (except to
+easily, the environment does not require root privilege (except to
 install the required packages if needed). It starts a webserver
 instance on the user's account (using lighttpd greatly helps for
 that), and does not need a separate database daemon (thanks to the use
@@ -81,7 +81,7 @@ parameters, please refer to the `test-gitmw-lib.sh` and
 
 ** `test_check_wiki_precond`:
 Check if the tests must be skipped or not. Please use this function
-at the beggining of each new test file.
+at the beginning of each new test file.
 
 ** `wiki_getpage`:
 Fetch a given page from the wiki and puts its content in the
@@ -113,7 +113,7 @@ Tests if a given page exists on the wiki.
 
 ** `wiki_reset`:
 Reset the wiki, i.e. flush the database. Use this function at the
-begining of each new test, except if the test re-uses the same wiki
+beginning of each new test, except if the test re-uses the same wiki
 (and history) as the previous test.
 
 How to write a new test
index 29f125116b59ed408339a37dbf82f2d913877d78..745e47e88173cac83c65b1c47d087cc98ec28621 100644 (file)
@@ -88,7 +88,7 @@ $wgShellLocale = "en_US.utf8";
 
 ## Set $wgCacheDirectory to a writable directory on the web server
 ## to make your wiki go slightly faster. The directory should not
-## be publically accessible from the web.
+## be publicly accessible from the web.
 #$wgCacheDirectory = "$IP/cache";
 
 # Site language code, should be one of the list in ./languages/Names.php
index b6405ce2628480240fc92ac5d69307991f2d5c69..37021e200a32d36e37f5c0ca7f6cacdca7d80187 100755 (executable)
@@ -139,7 +139,7 @@ test_expect_success 'character $ in file name (git -> mw) ' '
 '
 
 
-test_expect_failure 'capital at the begining of file names' '
+test_expect_failure 'capital at the beginning of file names' '
        wiki_reset &&
        git clone mediawiki::'"$WIKI_URL"' mw_dir_10 &&
        (
@@ -156,7 +156,7 @@ test_expect_failure 'capital at the begining of file names' '
 '
 
 
-test_expect_failure 'special character at the begining of file name from mw to git' '
+test_expect_failure 'special character at the beginning of file name from mw to git' '
        wiki_reset &&
        git clone mediawiki::'"$WIKI_URL"' mw_dir_11 &&
        wiki_editpage {char_1 "expect to be renamed {char_1" false &&
@@ -189,7 +189,7 @@ test_expect_success 'Push page with title containing ":" other than namespace se
        wiki_page_exist NotANameSpace:Page
 '
 
-test_expect_success 'test of correct formating for file name from mw to git' '
+test_expect_success 'test of correct formatting for file name from mw to git' '
        wiki_reset &&
        git clone mediawiki::'"$WIKI_URL"' mw_dir_12 &&
        wiki_editpage char_%_7b_1 "expect to be renamed char{_1" false &&
@@ -207,7 +207,7 @@ test_expect_success 'test of correct formating for file name from mw to git' '
 '
 
 
-test_expect_failure 'test of correct formating for file name begining with special character' '
+test_expect_failure 'test of correct formatting for file name beginning with special character' '
        wiki_reset &&
        git clone mediawiki::'"$WIKI_URL"' mw_dir_13 &&
        (
@@ -215,7 +215,7 @@ test_expect_failure 'test of correct formating for file name begining with speci
                echo "my new file {char_1" >\{char_1.mw &&
                echo "my new file [char_2" >\[char_2.mw &&
                git add . &&
-               git commit -am "commiting some exotic file name..." &&
+               git commit -am "committing some exotic file name..." &&
                git push &&
                git pull
        ) &&
@@ -226,7 +226,7 @@ test_expect_failure 'test of correct formating for file name begining with speci
 '
 
 
-test_expect_success 'test of correct formating for file name from git to mw' '
+test_expect_success 'test of correct formatting for file name from git to mw' '
        wiki_reset &&
        git clone mediawiki::'"$WIKI_URL"' mw_dir_14 &&
        (
@@ -234,7 +234,7 @@ test_expect_success 'test of correct formating for file name from git to mw' '
                echo "my new file char{_1" >Char\{_1.mw &&
                echo "my new file char[_2" >Char\[_2.mw &&
                git add . &&
-               git commit -m "commiting some exotic file name..." &&
+               git commit -m "committing some exotic file name..." &&
                git push
        ) &&
        wiki_getallpage ref_page_14 &&
index 9a76575f78f7c2cc6154c0a0d57f732de1e7f5d9..239161de33373d4ca97581a242cac848463fbbf3 100644 (file)
@@ -3,6 +3,7 @@ TESTS := $(wildcard test*.sh)
 export T := $(addprefix $(CURDIR)/,$(TESTS))
 export MAKE := $(MAKE) -e
 export PATH := $(CURDIR):$(PATH)
+export TEST_LINT := test-lint-executable test-lint-shell-syntax
 
 test:
        $(MAKE) -C ../../t $@
index c5822e4ac97ed3640c81cb645509346489199379..bd25e082027f90e614f3f265b94b49979d96e49f 100755 (executable)
@@ -25,6 +25,7 @@ bzrlib.plugin.load_plugins()
 
 import bzrlib.generate_ids
 import bzrlib.transport
+import bzrlib.errors
 
 import sys
 import os
@@ -183,15 +184,24 @@ def get_filechanges(cur, prev):
 
     changes = cur.changes_from(prev)
 
+    def u(s):
+        return s.encode('utf-8')
+
     for path, fid, kind in changes.added:
-        modified[path] = fid
+        modified[u(path)] = fid
     for path, fid, kind in changes.removed:
-        removed[path] = None
+        removed[u(path)] = None
     for path, fid, kind, mod, _ in changes.modified:
-        modified[path] = fid
+        modified[u(path)] = fid
     for oldpath, newpath, fid, kind, mod, _ in changes.renamed:
-        removed[oldpath] = None
-        modified[newpath] = fid
+        removed[u(oldpath)] = None
+        if kind == 'directory':
+            lst = cur.list_files(from_dir=newpath, recursive=True)
+            for path, file_class, kind, fid, entry in lst:
+                if kind != 'directory':
+                    modified[u(newpath + '/' + path)] = fid
+        else:
+            modified[u(newpath)] = fid
 
     return modified, removed
 
@@ -260,7 +270,12 @@ def export_branch(branch, name):
         tz = rev.timezone
         committer = rev.committer.encode('utf-8')
         committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz))
-        author = committer
+        authors = rev.get_apparent_authors()
+        if authors:
+            author = authors[0].encode('utf-8')
+            author = "%s %u %s" % (fixup_user(author), time, gittz(tz))
+        else:
+            author = committer
         msg = rev.message.encode('utf-8')
 
         msg += '\n'
@@ -297,10 +312,10 @@ def export_branch(branch, name):
             else:
                 print "merge :%s" % m
 
+        for f in removed:
+            print "D %s" % (f,)
         for f in modified_final:
             print "M %s :%u %s" % f
-        for f in removed:
-            print "D %s" % (f)
         print
 
         count += 1
@@ -321,12 +336,9 @@ def export_branch(branch, name):
 
 def export_tag(repo, name):
     global tags
-    try:
-        print "reset refs/tags/%s" % name
-        print "from :%u" % rev_to_mark(tags[name])
-        print
-    except KeyError:
-        warn("TODO: fetch tag '%s'" % name)
+    print "reset refs/tags/%s" % name
+    print "from :%u" % rev_to_mark(tags[name])
+    print
 
 def do_import(parser):
     global dirname
@@ -501,6 +513,11 @@ class CustomTree():
     def get_symlink_target(self, file_id):
         return self.updates[file_id]['data']
 
+def c_style_unescape(string):
+    if string[0] == string[-1] == '"':
+        return string.decode('string-escape')[1:-1]
+    return string
+
 def parse_commit(parser):
     global marks, blob_marks, bmarks, parsed_refs
     global mode
@@ -540,6 +557,7 @@ def parse_commit(parser):
             f = { 'deleted' : True }
         else:
             die('Unknown file command: %s' % line)
+        path = c_style_unescape(path).decode('utf-8')
         files[path] = f
 
     repo = parser.repo
@@ -619,10 +637,9 @@ def do_export(parser):
                     peer.import_last_revision_info_and_tags(repo, revno, revid)
                 else:
                     peer.import_last_revision_info(repo.repository, revno, revid)
-                wt = peer.bzrdir.open_workingtree()
             else:
                 wt = repo.bzrdir.open_workingtree()
-            wt.update()
+                wt.update()
         print "ok %s" % ref
     print
 
@@ -641,12 +658,25 @@ def do_capabilities(parser):
 
     print
 
+def ref_is_valid(name):
+    return not True in [c in name for c in '~^: \\']
+
 def do_list(parser):
     global tags
     print "? refs/heads/%s" % 'master'
-    for tag, revid in parser.repo.tags.get_tag_dict().items():
+
+    branch = parser.repo
+    branch.lock_read()
+    for tag, revid in branch.tags.get_tag_dict().items():
+        try:
+            branch.revision_id_to_dotted_revno(revid)
+        except bzrlib.errors.NoSuchRevision:
+            continue
+        if not ref_is_valid(tag):
+            continue
         print "? refs/tags/%s" % tag
         tags[tag] = revid
+    branch.unlock()
     print "@refs/heads/%s HEAD" % 'master'
     print
 
index 70aa8a010a6bc00a131860f2db509e56a7f75797..34666e1d0f60813abf65fa231dc13f2b4c080440 100755 (executable)
@@ -17,20 +17,6 @@ if ! "$PYTHON_PATH" -c 'import bzrlib'; then
        test_done
 fi
 
-cmd='
-import bzrlib
-bzrlib.initialize()
-import bzrlib.plugin
-bzrlib.plugin.load_plugins()
-import bzrlib.plugins.fastimport
-'
-
-if ! "$PYTHON_PATH" -c "$cmd"; then
-       echo "consider setting BZR_PLUGIN_PATH=$HOME/.bazaar/plugins" 1>&2
-       skip_all='skipping remote-bzr tests; bzr-fastimport not available'
-       test_done
-fi
-
 check () {
        (cd $1 &&
        git log --format='%s' -1 &&
@@ -136,7 +122,109 @@ test_expect_success 'special modes' '
   (cd gitrepo &&
   git cat-file -p HEAD:link > ../actual) &&
 
-  echo -n content > expected &&
+  printf content > expected &&
+  test_cmp expected actual
+'
+
+cat > expected <<EOF
+100644 blob 54f9d6da5c91d556e6b54340b1327573073030af   content
+100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb   executable
+120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea   link
+040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b   movedir-new
+EOF
+
+test_expect_success 'moving directory' '
+  (cd bzrrepo &&
+  mkdir movedir &&
+  echo one > movedir/one &&
+  echo two > movedir/two &&
+  bzr add movedir &&
+  bzr commit -m movedir &&
+  bzr mv movedir movedir-new &&
+  bzr commit -m movedir-new) &&
+
+  (cd gitrepo &&
+  git pull &&
+  git ls-tree HEAD > ../actual) &&
+
+  test_cmp expected actual
+'
+
+test_expect_success 'different authors' '
+  (cd bzrrepo &&
+  echo john >> content &&
+  bzr commit -m john \
+    --author "Jane Rey <jrey@example.com>" \
+    --author "John Doe <jdoe@example.com>") &&
+
+  (cd gitrepo &&
+  git pull &&
+  git show --format="%an <%ae>, %cn <%ce>" --quiet > ../actual) &&
+
+  echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" > expected &&
+  test_cmp expected actual
+'
+
+test_expect_success 'fetch utf-8 filenames' '
+  mkdir -p tmp && cd tmp &&
+  test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" &&
+
+  LC_ALL=en_US.UTF-8
+  export LC_ALL
+  (
+  bzr init bzrrepo &&
+  cd bzrrepo &&
+
+  echo test >> "ærø" &&
+  bzr add "ærø" &&
+  echo test >> "ø~?" &&
+  bzr add "ø~?" &&
+  bzr commit -m add-utf-8 &&
+  echo test >> "ærø" &&
+  bzr commit -m test-utf-8 &&
+  bzr rm "ø~?" &&
+  bzr mv "ærø" "ø~?" &&
+  bzr commit -m bzr-mv-utf-8
+  ) &&
+
+  (
+  git clone "bzr::$PWD/bzrrepo" gitrepo &&
+  cd gitrepo &&
+  git -c core.quotepath=false ls-files > ../actual
+  ) &&
+  echo "ø~?" > expected &&
+  test_cmp expected actual
+'
+
+test_expect_success 'push utf-8 filenames' '
+  mkdir -p tmp && cd tmp &&
+  test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" &&
+
+  LC_ALL=en_US.UTF-8
+  export LC_ALL
+
+  (
+  bzr init bzrrepo &&
+  cd bzrrepo &&
+
+  echo one >> content &&
+  bzr add content &&
+  bzr commit -m one
+  ) &&
+
+  (
+  git clone "bzr::$PWD/bzrrepo" gitrepo &&
+  cd gitrepo &&
+
+  echo test >> "ærø" &&
+  git add "ærø" &&
+  git commit -m utf-8 &&
+
+  git push
+  ) &&
+
+  (cd bzrrepo && bzr ls > ../actual) &&
+  printf "content\nærø\n" > expected &&
   test_cmp expected actual
 '
 
index 7e3967f5b6f0c19939bf1c0c30be0d756ec6aa04..3f253b7de75a6fa44c4cff3b2e1f53f9feffcf5d 100755 (executable)
@@ -140,7 +140,6 @@ test_expect_success 'executable bit' '
                git_clone_$x hgrepo-$x gitrepo2-$x &&
                git_log gitrepo2-$x > log-$x
        done &&
-       cp -r log-* output-* /tmp/foo/ &&
 
        test_cmp output-hg output-git &&
        test_cmp log-hg log-git
index 5f81dfae6c4a31f11ed766dd467fdd4a542afdf3..7bb81f2f8e0e288eb7e392075491fc1df0bd91d1 100755 (executable)
@@ -115,7 +115,7 @@ test_expect_success 'update bookmark' '
   git push
   ) &&
 
-  hg -R hgrepo bookmarks | grep "devel\s\+3:"
+  hg -R hgrepo bookmarks | egrep "devel[        ]+3:"
 '
 
 test_done
index 80d339960bbd5f70d17472a6f39f715dd8ec9182..b0f8536fca58d910f85334727b89925651bfa8ae 100755 (executable)
@@ -419,7 +419,7 @@ test_expect_success 'add main-sub5' '
 test_expect_success 'split for main-sub5 without --onto' '
         # also test that we still can split out an entirely new subtree
         # if the parent of the first commit in the tree is not empty,
-        # then the new subtree has accidently been attached to something
+       # then the new subtree has accidentally been attached to something
         git subtree split --prefix subdir2 --branch mainsub5 &&
         check_equal ''"$(git log --pretty=format:%P -1 mainsub5)"'' ""
 '
index df8c0ab0588e70ad6e6f56195535030055782d85..6aeddcb98d2694a705d34e80293fc81a20bc39a8 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -600,7 +600,7 @@ static void parse_host_arg(char *extra_args, int buflen)
 
 static int execute(void)
 {
-       static char line[1000];
+       char *line = packet_buffer;
        int pktlen, len, i;
        char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT");
 
@@ -608,7 +608,7 @@ static int execute(void)
                loginfo("Connection from %s:%s", addr, port);
 
        alarm(init_timeout ? init_timeout : timeout);
-       pktlen = packet_read_line(0, line, sizeof(line));
+       pktlen = packet_read(0, NULL, NULL, packet_buffer, sizeof(packet_buffer), 0);
        alarm(0);
 
        len = strlen(line);
diff --git a/date.c b/date.c
index 57331ed406e2391e0a2bf327fbb86d3b62012324..df20d0ba1d9c5d9fa03316968c1b7038659add05 100644 (file)
--- a/date.c
+++ b/date.c
@@ -383,7 +383,7 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
                 * sense to specify timestamp way into the future.  Make
                 * sure it is not later than ten days from now...
                 */
-               if (now + 10*24*3600 < specified)
+               if ((specified != -1) && (now + 10*24*3600 < specified))
                        return 0;
                tm->tm_mon = r->tm_mon;
                tm->tm_mday = r->tm_mday;
@@ -694,8 +694,14 @@ int parse_date_basic(const char *date, unsigned long *timestamp, int *offset)
 
        /* mktime uses local timezone */
        *timestamp = tm_to_time_t(&tm);
-       if (*offset == -1)
-               *offset = ((time_t)*timestamp - mktime(&tm)) / 60;
+       if (*offset == -1) {
+               time_t temp_time = mktime(&tm);
+               if ((time_t)*timestamp > temp_time) {
+                       *offset = ((time_t)*timestamp - temp_time) / 60;
+               } else {
+                       *offset = -(int)((temp_time - (time_t)*timestamp) / 60);
+               }
+       }
 
        if (*timestamp == -1)
                return -1;
diff --git a/diff.c b/diff.c
index db952a5bc71ac967cb045bada8c71f5fda218ca2..0eb26535f52adf516961672628f2810e55a31a9d 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1565,7 +1565,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
         * Binary files are displayed with "Bin XXX -> YYY bytes"
         * instead of the change count and graph. This part is treated
         * similarly to the graph part, except that it is not
-        * "scaled". If total width is too small to accomodate the
+        * "scaled". If total width is too small to accommodate the
         * guaranteed minimum width of the filename part and the
         * separators and this message, this message will "overflow"
         * making the line longer than the maximum width.
index 44f8678d22ea466b0867591429bbcc3285cdaf91..1d9e530a84758e34d616690684c4842cd1af4cfc 100644 (file)
@@ -68,6 +68,9 @@ static int should_break(struct diff_filespec *src,
        if (max_size < MINIMUM_BREAK_SIZE)
                return 0; /* we do not break too small filepair */
 
+       if (!src->size)
+               return 0; /* we do not let empty files get renamed */
+
        if (diffcore_count_changes(src, dst,
                                   &src->cnt_data, &dst->cnt_data,
                                   0,
index b097fa766177f90e4b7983789a9286506664b2fd..63722f86dca4c00389d6f305fd8aa1af8ef8ed6c 100644 (file)
@@ -8,7 +8,12 @@
 #include "xdiff-interface.h"
 #include "kwset.h"
 
-typedef int (*pickaxe_fn)(struct diff_filepair *p, struct diff_options *o, regex_t *regexp, kwset_t kws);
+typedef int (*pickaxe_fn)(mmfile_t *one, mmfile_t *two,
+                         struct diff_options *o,
+                         regex_t *regexp, kwset_t kws);
+
+static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
+                        regex_t *regexp, kwset_t kws, pickaxe_fn fn);
 
 static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
                    regex_t *regexp, kwset_t kws, pickaxe_fn fn)
@@ -22,7 +27,7 @@ static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
                /* Showing the whole changeset if needle exists */
                for (i = 0; i < q->nr; i++) {
                        struct diff_filepair *p = q->queue[i];
-                       if (fn(p, o, regexp, kws))
+                       if (pickaxe_match(p, o, regexp, kws, fn))
                                return; /* do not munge the queue */
                }
 
@@ -37,7 +42,7 @@ static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
                /* Showing only the filepairs that has the needle */
                for (i = 0; i < q->nr; i++) {
                        struct diff_filepair *p = q->queue[i];
-                       if (fn(p, o, regexp, kws))
+                       if (pickaxe_match(p, o, regexp, kws, fn))
                                diff_q(&outq, p);
                        else
                                diff_free_filepair(p);
@@ -74,64 +79,33 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
        line[len] = hold;
 }
 
-static void fill_one(struct diff_filespec *one,
-                    mmfile_t *mf, struct userdiff_driver **textconv)
-{
-       if (DIFF_FILE_VALID(one)) {
-               *textconv = get_textconv(one);
-               mf->size = fill_textconv(*textconv, one, &mf->ptr);
-       } else {
-               memset(mf, 0, sizeof(*mf));
-       }
-}
-
-static int diff_grep(struct diff_filepair *p, struct diff_options *o,
+static int diff_grep(mmfile_t *one, mmfile_t *two,
+                    struct diff_options *o,
                     regex_t *regexp, kwset_t kws)
 {
        regmatch_t regmatch;
-       struct userdiff_driver *textconv_one = NULL;
-       struct userdiff_driver *textconv_two = NULL;
-       mmfile_t mf1, mf2;
-       int hit;
+       struct diffgrep_cb ecbdata;
+       xpparam_t xpp;
+       xdemitconf_t xecfg;
 
-       if (diff_unmodified_pair(p))
-               return 0;
+       if (!one)
+               return !regexec(regexp, two->ptr, 1, &regmatch, 0);
+       if (!two)
+               return !regexec(regexp, one->ptr, 1, &regmatch, 0);
 
-       fill_one(p->one, &mf1, &textconv_one);
-       fill_one(p->two, &mf2, &textconv_two);
-
-       if (!mf1.ptr) {
-               if (!mf2.ptr)
-                       return 0; /* ignore unmerged */
-               /* created "two" -- does it have what we are looking for? */
-               hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);
-       } else if (!mf2.ptr) {
-               /* removed "one" -- did it have what we are looking for? */
-               hit = !regexec(regexp, mf1.ptr, 1, &regmatch, 0);
-       } else {
-               /*
-                * We have both sides; need to run textual diff and see if
-                * the pattern appears on added/deleted lines.
-                */
-               struct diffgrep_cb ecbdata;
-               xpparam_t xpp;
-               xdemitconf_t xecfg;
-
-               memset(&xpp, 0, sizeof(xpp));
-               memset(&xecfg, 0, sizeof(xecfg));
-               ecbdata.regexp = regexp;
-               ecbdata.hit = 0;
-               xecfg.ctxlen = o->context;
-               xecfg.interhunkctxlen = o->interhunkcontext;
-               xdi_diff_outf(&mf1, &mf2, diffgrep_consume, &ecbdata,
-                             &xpp, &xecfg);
-               hit = ecbdata.hit;
-       }
-       if (textconv_one)
-               free(mf1.ptr);
-       if (textconv_two)
-               free(mf2.ptr);
-       return hit;
+       /*
+        * We have both sides; need to run textual diff and see if
+        * the pattern appears on added/deleted lines.
+        */
+       memset(&xpp, 0, sizeof(xpp));
+       memset(&xecfg, 0, sizeof(xecfg));
+       ecbdata.regexp = regexp;
+       ecbdata.hit = 0;
+       xecfg.ctxlen = o->context;
+       xecfg.interhunkctxlen = o->interhunkcontext;
+       xdi_diff_outf(one, two, diffgrep_consume, &ecbdata,
+                     &xpp, &xecfg);
+       return ecbdata.hit;
 }
 
 static void diffcore_pickaxe_grep(struct diff_options *o)
@@ -198,17 +172,37 @@ static unsigned int contains(mmfile_t *mf, struct diff_options *o,
        return cnt;
 }
 
-static int has_changes(struct diff_filepair *p, struct diff_options *o,
+static int has_changes(mmfile_t *one, mmfile_t *two,
+                      struct diff_options *o,
                       regex_t *regexp, kwset_t kws)
 {
-       struct userdiff_driver *textconv_one = get_textconv(p->one);
-       struct userdiff_driver *textconv_two = get_textconv(p->two);
+       if (!one)
+               return contains(two, o, regexp, kws) != 0;
+       if (!two)
+               return contains(one, o, regexp, kws) != 0;
+       return contains(one, o, regexp, kws) != contains(two, o, regexp, kws);
+}
+
+static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
+                        regex_t *regexp, kwset_t kws, pickaxe_fn fn)
+{
+       struct userdiff_driver *textconv_one = NULL;
+       struct userdiff_driver *textconv_two = NULL;
        mmfile_t mf1, mf2;
        int ret;
 
        if (!o->pickaxe[0])
                return 0;
 
+       /* ignore unmerged */
+       if (!DIFF_FILE_VALID(p->one) && !DIFF_FILE_VALID(p->two))
+               return 0;
+
+       if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
+               textconv_one = get_textconv(p->one);
+               textconv_two = get_textconv(p->two);
+       }
+
        /*
         * If we have an unmodified pair, we know that the count will be the
         * same and don't even have to load the blobs. Unless textconv is in
@@ -219,20 +213,12 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
        if (textconv_one == textconv_two && diff_unmodified_pair(p))
                return 0;
 
-       fill_one(p->one, &mf1, &textconv_one);
-       fill_one(p->two, &mf2, &textconv_two);
+       mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
+       mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
 
-       if (!mf1.ptr) {
-               if (!mf2.ptr)
-                       ret = 0; /* ignore unmerged */
-               /* created */
-               ret = contains(&mf2, o, regexp, kws) != 0;
-       }
-       else if (!mf2.ptr) /* removed */
-               ret = contains(&mf1, o, regexp, kws) != 0;
-       else
-               ret = contains(&mf1, o, regexp, kws) !=
-                     contains(&mf2, o, regexp, kws);
+       ret = fn(DIFF_FILE_VALID(p->one) ? &mf1 : NULL,
+                DIFF_FILE_VALID(p->two) ? &mf2 : NULL,
+                o, regexp, kws);
 
        if (textconv_one)
                free(mf1.ptr);
index 512d0ac5fd2bc0acfb57147a6eb77f61f92b7c7e..6c7a72fbe74e8dd6fca07d2555cdea62c16b8b1e 100644 (file)
@@ -389,6 +389,7 @@ static int find_exact_renames(struct diff_options *options)
        struct hash_table file_table;
 
        init_hash(&file_table);
+       preallocate_hash(&file_table, rename_src_nr + rename_dst_nr);
        for (i = 0; i < rename_src_nr; i++)
                insert_file_table(&file_table, -1, i, rename_src[i].p->one);
 
diff --git a/dir.c b/dir.c
index 57394e452eb0de117b27f64804e529b617a6c7e0..91cfd996711f8b9523da92ff75088292e16d316c 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -59,6 +59,35 @@ inline int git_fnmatch(const char *pattern, const char *string,
        return fnmatch(pattern, string, fnm_flags);
 }
 
+static int fnmatch_icase_mem(const char *pattern, int patternlen,
+                            const char *string, int stringlen,
+                            int flags)
+{
+       int match_status;
+       struct strbuf pat_buf = STRBUF_INIT;
+       struct strbuf str_buf = STRBUF_INIT;
+       const char *use_pat = pattern;
+       const char *use_str = string;
+
+       if (pattern[patternlen]) {
+               strbuf_add(&pat_buf, pattern, patternlen);
+               use_pat = pat_buf.buf;
+       }
+       if (string[stringlen]) {
+               strbuf_add(&str_buf, string, stringlen);
+               use_str = str_buf.buf;
+       }
+
+       if (ignore_case)
+               flags |= WM_CASEFOLD;
+       match_status = wildmatch(use_pat, use_str, flags, NULL);
+
+       strbuf_release(&pat_buf);
+       strbuf_release(&str_buf);
+
+       return match_status;
+}
+
 static size_t common_prefix_len(const char **pathspec)
 {
        const char *n, *first;
@@ -626,15 +655,20 @@ int match_basename(const char *basename, int basenamelen,
                   int flags)
 {
        if (prefix == patternlen) {
-               if (!strcmp_icase(pattern, basename))
+               if (patternlen == basenamelen &&
+                   !strncmp_icase(pattern, basename, basenamelen))
                        return 1;
        } else if (flags & EXC_FLAG_ENDSWITH) {
+               /* "*literal" matching against "fooliteral" */
                if (patternlen - 1 <= basenamelen &&
-                   !strcmp_icase(pattern + 1,
-                                 basename + basenamelen - patternlen + 1))
+                   !strncmp_icase(pattern + 1,
+                                  basename + basenamelen - (patternlen - 1),
+                                  patternlen - 1))
                        return 1;
        } else {
-               if (fnmatch_icase(pattern, basename, 0) == 0)
+               if (fnmatch_icase_mem(pattern, patternlen,
+                                     basename, basenamelen,
+                                     0) == 0)
                        return 1;
        }
        return 0;
@@ -654,6 +688,7 @@ int match_pathname(const char *pathname, int pathlen,
         */
        if (*pattern == '/') {
                pattern++;
+               patternlen--;
                prefix--;
        }
 
@@ -680,13 +715,22 @@ int match_pathname(const char *pathname, int pathlen,
                if (strncmp_icase(pattern, name, prefix))
                        return 0;
                pattern += prefix;
+               patternlen -= prefix;
                name    += prefix;
                namelen -= prefix;
+
+               /*
+                * If the whole pattern did not have a wildcard,
+                * then our prefix match is all we need; we
+                * do not need to call fnmatch at all.
+                */
+               if (!patternlen && !namelen)
+                       return 1;
        }
 
-       return wildmatch(pattern, name,
-                        WM_PATHNAME | (ignore_case ? WM_CASEFOLD : 0),
-                        NULL) == 0;
+       return fnmatch_icase_mem(pattern, patternlen,
+                                name, namelen,
+                                WM_PATHNAME) == 0;
 }
 
 /*
@@ -1603,7 +1647,7 @@ int remove_path(const char *name)
 {
        char *slash;
 
-       if (unlink(name) && errno != ENOENT)
+       if (unlink(name) && errno != ENOENT && errno != ENOTDIR)
                return -1;
 
        slash = strrchr(name, '/');
diff --git a/entry.c b/entry.c
index 63c52edf600b5fd966e24cc5758bdab7dbeaf41b..d7c131d45309a496714221616244a70569155913 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -120,16 +120,18 @@ static int streaming_write_entry(struct cache_entry *ce, char *path,
                                 const struct checkout *state, int to_tempfile,
                                 int *fstat_done, struct stat *statbuf)
 {
-       int result = -1;
+       int result = 0;
        int fd;
 
        fd = open_output_fd(path, ce, to_tempfile);
-       if (0 <= fd) {
-               result = stream_blob_to_fd(fd, ce->sha1, filter, 1);
-               *fstat_done = fstat_output(fd, state, statbuf);
-               result = close(fd);
-       }
-       if (result && 0 <= fd)
+       if (fd < 0)
+               return -1;
+
+       result |= stream_blob_to_fd(fd, ce->sha1, filter, 1);
+       *fstat_done = fstat_output(fd, state, statbuf);
+       result |= close(fd);
+
+       if (result)
                unlink(path);
        return result;
 }
index 6d8926a5504a6cd93e19860f85d58816bdd5c222..f156dd4fac30cda4e09c508b7091cdb8d96917e2 100644 (file)
@@ -36,7 +36,7 @@ static int marked;
 #define MAX_IN_VAIN 256
 
 static struct commit_list *rev_list;
-static int non_common_revs, multi_ack, use_sideband;
+static int non_common_revs, multi_ack, use_sideband, allow_tip_sha1_in_want;
 
 static void rev_list_push(struct commit *commit, int mark)
 {
@@ -172,8 +172,8 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
                 * shallow and unshallow commands every time there
                 * is a block of have lines exchanged.
                 */
-               char line[1000];
-               while (packet_read_line(fd, line, sizeof(line))) {
+               char *line;
+               while ((line = packet_read_line(fd, NULL))) {
                        if (!prefixcmp(line, "shallow "))
                                continue;
                        if (!prefixcmp(line, "unshallow "))
@@ -215,17 +215,17 @@ static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
 
 static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 {
-       static char line[1000];
-       int len = packet_read_line(fd, line, sizeof(line));
+       int len;
+       char *line = packet_read_line(fd, &len);
 
        if (!len)
                die("git fetch-pack: expected ACK/NAK, got EOF");
-       if (line[len-1] == '\n')
-               line[--len] = 0;
        if (!strcmp(line, "NAK"))
                return NAK;
        if (!prefixcmp(line, "ACK ")) {
                if (!get_sha1_hex(line+4, result_sha1)) {
+                       if (len < 45)
+                               return ACK;
                        if (strstr(line+45, "continue"))
                                return ACK_continue;
                        if (strstr(line+45, "common"))
@@ -245,7 +245,7 @@ static void send_request(struct fetch_pack_args *args,
                send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
                packet_flush(fd);
        } else
-               safe_write(fd, buf->buf, buf->len);
+               write_or_die(fd, buf->buf, buf->len);
 }
 
 static void insert_one_alternate_ref(const struct ref *ref, void *unused)
@@ -346,11 +346,11 @@ static int find_common(struct fetch_pack_args *args,
        state_len = req_buf.len;
 
        if (args->depth > 0) {
-               char line[1024];
+               char *line;
                unsigned char sha1[20];
 
                send_request(args, fd[1], &req_buf);
-               while (packet_read_line(fd[0], line, sizeof(line))) {
+               while ((line = packet_read_line(fd[0], NULL))) {
                        if (!prefixcmp(line, "shallow ")) {
                                if (get_sha1_hex(line + 8, sha1))
                                        die("invalid shallow line: %s", line);
@@ -520,47 +520,37 @@ static void mark_recent_complete_commits(struct fetch_pack_args *args,
        }
 }
 
-static int non_matching_ref(struct string_list_item *item, void *unused)
-{
-       if (item->util) {
-               item->util = NULL;
-               return 0;
-       }
-       else
-               return 1;
-}
-
 static void filter_refs(struct fetch_pack_args *args,
-                       struct ref **refs, struct string_list *sought)
+                       struct ref **refs,
+                       struct ref **sought, int nr_sought)
 {
        struct ref *newlist = NULL;
        struct ref **newtail = &newlist;
        struct ref *ref, *next;
-       int sought_pos;
+       int i;
 
-       sought_pos = 0;
+       i = 0;
        for (ref = *refs; ref; ref = next) {
                int keep = 0;
                next = ref->next;
+
                if (!memcmp(ref->name, "refs/", 5) &&
                    check_refname_format(ref->name + 5, 0))
                        ; /* trash */
                else {
-                       while (sought_pos < sought->nr) {
-                               int cmp = strcmp(ref->name, sought->items[sought_pos].string);
+                       while (i < nr_sought) {
+                               int cmp = strcmp(ref->name, sought[i]->name);
                                if (cmp < 0)
                                        break; /* definitely do not have it */
                                else if (cmp == 0) {
                                        keep = 1; /* definitely have it */
-                                       sought->items[sought_pos++].util = "matched";
-                                       break;
+                                       sought[i]->matched = 1;
                                }
-                               else
-                                       sought_pos++; /* might have it; keep looking */
+                               i++;
                        }
                }
 
-               if (! keep && args->fetch_all &&
+               if (!keep && args->fetch_all &&
                    (!args->depth || prefixcmp(ref->name, "refs/tags/")))
                        keep = 1;
 
@@ -573,7 +563,21 @@ static void filter_refs(struct fetch_pack_args *args,
                }
        }
 
-       filter_string_list(sought, 0, non_matching_ref, NULL);
+       /* Append unmatched requests to the list */
+       if (allow_tip_sha1_in_want) {
+               for (i = 0; i < nr_sought; i++) {
+                       ref = sought[i];
+                       if (ref->matched)
+                               continue;
+                       if (get_sha1_hex(ref->name, ref->old_sha1))
+                               continue;
+
+                       ref->matched = 1;
+                       *newtail = ref;
+                       ref->next = NULL;
+                       newtail = &ref->next;
+               }
+       }
        *refs = newlist;
 }
 
@@ -583,7 +587,8 @@ static void mark_alternate_complete(const struct ref *ref, void *unused)
 }
 
 static int everything_local(struct fetch_pack_args *args,
-                           struct ref **refs, struct string_list *sought)
+                           struct ref **refs,
+                           struct ref **sought, int nr_sought)
 {
        struct ref *ref;
        int retval;
@@ -637,7 +642,7 @@ static int everything_local(struct fetch_pack_args *args,
                }
        }
 
-       filter_refs(args, refs, sought);
+       filter_refs(args, refs, sought, nr_sought);
 
        for (retval = 1, ref = *refs; ref ; ref = ref->next) {
                const unsigned char *remote = ref->old_sha1;
@@ -767,10 +772,17 @@ static int get_pack(struct fetch_pack_args *args,
        return 0;
 }
 
+static int cmp_ref_by_name(const void *a_, const void *b_)
+{
+       const struct ref *a = *((const struct ref **)a_);
+       const struct ref *b = *((const struct ref **)b_);
+       return strcmp(a->name, b->name);
+}
+
 static struct ref *do_fetch_pack(struct fetch_pack_args *args,
                                 int fd[2],
                                 const struct ref *orig_ref,
-                                struct string_list *sought,
+                                struct ref **sought, int nr_sought,
                                 char **pack_lockfile)
 {
        struct ref *ref = copy_ref_list(orig_ref);
@@ -779,6 +791,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        int agent_len;
 
        sort_ref_list(&ref, ref_compare_name);
+       qsort(sought, nr_sought, sizeof(*sought), cmp_ref_by_name);
 
        if (is_repository_shallow() && !server_supports("shallow"))
                die("Server does not support shallow clients");
@@ -808,6 +821,11 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
                        fprintf(stderr, "Server supports side-band\n");
                use_sideband = 1;
        }
+       if (server_supports("allow-tip-sha1-in-want")) {
+               if (args->verbose)
+                       fprintf(stderr, "Server supports allow-tip-sha1-in-want\n");
+               allow_tip_sha1_in_want = 1;
+       }
        if (!server_supports("thin-pack"))
                args->use_thin_pack = 0;
        if (!server_supports("no-progress"))
@@ -827,7 +845,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
                                agent_len, agent_feature);
        }
 
-       if (everything_local(args, &ref, sought)) {
+       if (everything_local(args, &ref, sought, nr_sought)) {
                packet_flush(fd[1]);
                goto all_done;
        }
@@ -890,11 +908,32 @@ static void fetch_pack_setup(void)
        did_setup = 1;
 }
 
+static int remove_duplicates_in_refs(struct ref **ref, int nr)
+{
+       struct string_list names = STRING_LIST_INIT_NODUP;
+       int src, dst;
+
+       for (src = dst = 0; src < nr; src++) {
+               struct string_list_item *item;
+               item = string_list_insert(&names, ref[src]->name);
+               if (item->util)
+                       continue; /* already have it */
+               item->util = ref[src];
+               if (src != dst)
+                       ref[dst] = ref[src];
+               dst++;
+       }
+       for (src = dst; src < nr; src++)
+               ref[src] = NULL;
+       string_list_clear(&names, 0);
+       return dst;
+}
+
 struct ref *fetch_pack(struct fetch_pack_args *args,
                       int fd[], struct child_process *conn,
                       const struct ref *ref,
                       const char *dest,
-                      struct string_list *sought,
+                      struct ref **sought, int nr_sought,
                       char **pack_lockfile)
 {
        struct stat st;
@@ -906,16 +945,14 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
                        st.st_mtime = 0;
        }
 
-       if (sought->nr) {
-               sort_string_list(sought);
-               string_list_remove_duplicates(sought, 0);
-       }
+       if (nr_sought)
+               nr_sought = remove_duplicates_in_refs(sought, nr_sought);
 
        if (!ref) {
                packet_flush(fd[1]);
                die("no matching remote head");
        }
-       ref_cpy = do_fetch_pack(args, fd, ref, sought, pack_lockfile);
+       ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
 
        if (args->depth > 0) {
                static struct lock_file lock;
index cb148719bfd3bace27a0ca9611f1c38066fb6ed4..dc5266c970655a9fe4f971a0132c14e1cf731acc 100644 (file)
@@ -20,17 +20,16 @@ struct fetch_pack_args {
 };
 
 /*
- * sought contains the full names of remote references that should be
- * updated from.  On return, the names that were found on the remote
- * will have been removed from the list.  The util members of the
- * string_list_items are used internally; they must be NULL on entry
- * (and will be NULL on exit).
+ * sought represents remote references that should be updated from.
+ * On return, the names that were found on the remote will have been
+ * marked as such.
  */
 struct ref *fetch_pack(struct fetch_pack_args *args,
                       int fd[], struct child_process *conn,
                       const struct ref *ref,
                       const char *dest,
-                      struct string_list *sought,
+                      struct ref **sought,
+                      int nr_sought,
                       char **pack_lockfile);
 
 #endif
index 710764abb132f16e393fd16178b845d8160e37cf..d2c4ce6e1e88f543bd06cd8347e8949fef11a381 100755 (executable)
@@ -1247,7 +1247,7 @@ sub summarize_hunk {
 
 
 # Print a one-line summary of each hunk in the array ref in
-# the first argument, starting wih the index in the 2nd.
+# the first argument, starting with the index in the 2nd.
 sub display_hunks {
        my ($hunks, $i) = @_;
        my $ctr = 0;
index 202130f888bee14e73b8cc108f39f2da8a14d23b..c092855dd7c277d41288ee89f033bef0a8677a9f 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -778,13 +778,6 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
            action=yes
        fi
 
-       if test -f "$dotest/final-commit"
-       then
-               FIRSTLINE=$(sed 1q "$dotest/final-commit")
-       else
-               FIRSTLINE=""
-       fi
-
        if test $action = skip
        then
                go_next
@@ -797,6 +790,13 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
                stop_here $this
        fi
 
+       if test -f "$dotest/final-commit"
+       then
+               FIRSTLINE=$(sed 1q "$dotest/final-commit")
+       else
+               FIRSTLINE=""
+       fi
+
        say "$(eval_gettext "Applying: \$FIRSTLINE")"
 
        case "$resolved" in
index e715285e7c2e0a3d0b959505921b344dda55089d..cde442fb5f47cd13757e09ae435963bc061db083 100644 (file)
@@ -86,6 +86,9 @@
 #define _SGI_SOURCE 1
 
 #ifdef WIN32 /* Both MinGW and MSVC */
+# if defined (_MSC_VER)
+#  define _WIN32_WINNT 0x0502
+# endif
 #define WIN32_LEAN_AND_MEAN  /* stops windows.h including winsock.h */
 #include <winsock2.h>
 #include <windows.h>
 typedef long intptr_t;
 typedef unsigned long uintptr_t;
 #endif
+int get_st_mode_bits(const char *path, int *mode);
 #if defined(__CYGWIN__)
 #undef _XOPEN_SOURCE
 #include <grp.h>
index f1c3f49a836a8cf7f980bd3bc99d4fe9c2d49b65..a0d796e57087e0ca5bac94520997ecacec9fd295 100755 (executable)
@@ -2911,7 +2911,7 @@ sub filenamesplit
 }
 
 # Cleanup various junk in filename (try to canonicalize it), and
-# add prependdir to accomodate running CVS client from a
+# add prependdir to accommodate running CVS client from a
 # subdirectory (so the output is relative to top directory of the project).
 sub filecleanup
 {
@@ -4583,7 +4583,7 @@ sub getmeta
     #     the numerical value of the corresponding byte plus
     #     100.
     #      - "plus 100" avoids "0"s, and also reduces the
-    #        likelyhood of a collision in the case that someone someday
+    #        likelihood of a collision in the case that someone someday
     #        writes an import tool that tries to preserve original
     #        CVS revision numbers, and the original CVS data had done
     #        lots of branches off of branches and other strangeness to
index 0a90de414646b901e13abbf89aa78ae71e8b12f0..67802922ccc41fa2993c1bce4ea1a3d2899c7a40 100755 (executable)
@@ -13,9 +13,9 @@
 use 5.008;
 use strict;
 use warnings;
+use Error qw(:try);
 use File::Basename qw(dirname);
 use File::Copy;
-use File::Compare;
 use File::Find;
 use File::stat;
 use File::Path qw(mkpath rmtree);
@@ -83,6 +83,52 @@ sub exit_cleanup
        exit($status | ($status >> 8));
 }
 
+sub use_wt_file
+{
+       my ($repo, $workdir, $file, $sha1, $symlinks) = @_;
+       my $null_sha1 = '0' x 40;
+
+       if ($sha1 ne $null_sha1 and not $symlinks) {
+               return 0;
+       }
+
+       my $wt_sha1 = $repo->command_oneline('hash-object', "$workdir/$file");
+       my $use = ($sha1 eq $null_sha1) || ($sha1 eq $wt_sha1);
+       return ($use, $wt_sha1);
+}
+
+sub changed_files
+{
+       my ($repo_path, $index, $worktree) = @_;
+       $ENV{GIT_INDEX_FILE} = $index;
+       $ENV{GIT_WORK_TREE} = $worktree;
+       my $must_unset_git_dir = 0;
+       if (not defined($ENV{GIT_DIR})) {
+               $must_unset_git_dir = 1;
+               $ENV{GIT_DIR} = $repo_path;
+       }
+
+       my @refreshargs = qw/update-index --really-refresh -q --unmerged/;
+       my @gitargs = qw/diff-files --name-only -z/;
+       try {
+               Git::command_oneline(@refreshargs);
+       } catch Git::Error::Command with {};
+
+       my $line = Git::command_oneline(@gitargs);
+       my @files;
+       if (defined $line) {
+               @files = split('\0', $line);
+       } else {
+               @files = ();
+       }
+
+       delete($ENV{GIT_INDEX_FILE});
+       delete($ENV{GIT_WORK_TREE});
+       delete($ENV{GIT_DIR}) if ($must_unset_git_dir);
+
+       return map { $_ => 1 } @files;
+}
+
 sub setup_dir_diff
 {
        my ($repo, $workdir, $symlinks) = @_;
@@ -106,6 +152,7 @@ sub setup_dir_diff
        my $null_sha1 = '0' x 40;
        my $lindex = '';
        my $rindex = '';
+       my $wtindex = '';
        my %submodule;
        my %symlink;
        my @working_tree = ();
@@ -159,10 +206,14 @@ sub setup_dir_diff
                }
 
                if ($rmode ne $null_mode) {
-                       if ($rsha1 ne $null_sha1) {
-                               $rindex .= "$rmode $rsha1\t$dst_path\0";
+                       my ($use, $wt_sha1) = use_wt_file($repo, $workdir,
+                                                         $dst_path, $rsha1,
+                                                         $symlinks);
+                       if ($use) {
+                               push @working_tree, $dst_path;
+                               $wtindex .= "$rmode $wt_sha1\t$dst_path\0";
                        } else {
-                               push(@working_tree, $dst_path);
+                               $rindex .= "$rmode $rsha1\t$dst_path\0";
                        }
                }
        }
@@ -203,13 +254,21 @@ sub setup_dir_diff
        $rc = system('git', 'checkout-index', '--all', "--prefix=$rdir/");
        exit_cleanup($tmpdir, $rc) if $rc != 0;
 
+       $ENV{GIT_INDEX_FILE} = "$tmpdir/wtindex";
+       ($inpipe, $ctx) =
+               $repo->command_input_pipe(qw(update-index --info-only -z --index-info));
+       print($inpipe $wtindex);
+       $repo->command_close_pipe($inpipe, $ctx);
+
        # If $GIT_DIR was explicitly set just for the update/checkout
        # commands, then it should be unset before continuing.
        delete($ENV{GIT_DIR}) if ($must_unset_git_dir);
        delete($ENV{GIT_INDEX_FILE});
 
        # Changes in the working tree need special treatment since they are
-       # not part of the index
+       # not part of the index. Remove any trailing slash from $workdir
+       # before starting to avoid double slashes in symlink targets.
+       $workdir =~ s|/$||;
        for my $file (@working_tree) {
                my $dir = dirname($file);
                unless (-d "$rdir/$dir") {
@@ -336,7 +395,7 @@ sub main
        }
        if ($opts{gui}) {
                my $guitool = Git::config('diff.guitool');
-               if (length($guitool) > 0) {
+               if (defined($guitool) && length($guitool) > 0) {
                        $ENV{GIT_DIFF_TOOL} = $guitool;
                }
        }
@@ -373,19 +432,34 @@ sub dir_diff
        # should be copied back to the working tree.
        # Do not copy back files when symlinks are used and the
        # external tool did not replace the original link with a file.
+       #
+       # These hashes are loaded lazily since they aren't needed
+       # in the common case of --symlinks and the difftool updating
+       # files through the symlink.
+       my %wt_modified;
+       my %tmp_modified;
+       my $indices_loaded = 0;
+
        for my $file (@worktree) {
                next if $symlinks && -l "$b/$file";
                next if ! -f "$b/$file";
 
-               my $diff = compare("$b/$file", "$workdir/$file");
-               if ($diff == 0) {
-                       next;
-               } elsif ($diff == -1) {
-                       my $errmsg = "warning: Could not compare ";
-                       $errmsg += "'$b/$file' with '$workdir/$file'\n";
+               if (!$indices_loaded) {
+                       %wt_modified = changed_files($repo->repo_path(),
+                               "$tmpdir/wtindex", "$workdir");
+                       %tmp_modified = changed_files($repo->repo_path(),
+                               "$tmpdir/wtindex", "$b");
+                       $indices_loaded = 1;
+               }
+
+               if (exists $wt_modified{$file} and exists $tmp_modified{$file}) {
+                       my $errmsg = "warning: Both files modified: ";
+                       $errmsg .= "'$workdir/$file' and '$b/$file'.\n";
+                       $errmsg .= "warning: Working tree file has been left.\n";
+                       $errmsg .= "warning:\n";
                        warn $errmsg;
                        $error = 1;
-               } elsif ($diff == 1) {
+               } elsif (exists $tmp_modified{$file}) {
                        my $mode = stat("$b/$file")->mode;
                        copy("$b/$file", "$workdir/$file") or
                        exit_cleanup($tmpdir, 1);
index 53142492afcfb92f0453359af9a00a045c51e7e9..ac2a005fdb23c48d8451188ffd7b1c8194b0295f 100755 (executable)
@@ -199,6 +199,7 @@ t)
        test -d "$tempdir" &&
                die "$tempdir already exists, please remove it"
 esac
+orig_dir=$(pwd)
 mkdir -p "$tempdir/t" &&
 tempdir="$(cd "$tempdir"; pwd)" &&
 cd "$tempdir/t" &&
@@ -206,7 +207,7 @@ workdir="$(pwd)" ||
 die ""
 
 # Remove tempdir on exit
-trap 'cd ../..; rm -rf "$tempdir"' 0
+trap 'cd "$orig_dir"; rm -rf "$tempdir"' 0
 
 ORIG_GIT_DIR="$GIT_DIR"
 ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
@@ -469,7 +470,7 @@ if [ "$filter_tag_name" ]; then
        done
 fi
 
-cd ../..
+cd "$orig_dir"
 rm -rf "$tempdir"
 
 trap - 0
index 3373c040d4aae221386fac5ec2cd9a29344c1840..07dfeb8df4bf910c5c79fb4c3dd3345ba4719da0 100755 (executable)
@@ -27,7 +27,7 @@ SUBDIRECTORY_OK=Yes
 cd_to_toplevel
 require_work_tree
 
-if ! test "$#" -eq 7
+if test $# != 7
 then
        echo "$LONG_USAGE"
        exit 1
@@ -38,7 +38,8 @@ case "${1:-.}${2:-.}${3:-.}" in
 # Deleted in both or deleted in one and unchanged in the other
 #
 "$1.." | "$1.$1" | "$1$1.")
-       if [ "$2" ]; then
+       if test -n "$2"
+       then
                echo "Removing $4"
        else
                # read-tree checked that index matches HEAD already,
@@ -48,7 +49,8 @@ case "${1:-.}${2:-.}${3:-.}" in
                # we do not have it in the index, though.
                exec git update-index --remove -- "$4"
        fi
-       if test -f "$4"; then
+       if test -f "$4"
+       then
                rm -f -- "$4" &&
                rmdir -p "$(expr "z$4" : 'z\(.*\)/')" 2>/dev/null || :
        fi &&
@@ -67,7 +69,7 @@ case "${1:-.}${2:-.}${3:-.}" in
        echo "Adding $4"
        if test -f "$4"
        then
-               echo "ERROR: untracked $4 is overwritten by the merge."
+               echo "ERROR: untracked $4 is overwritten by the merge." >&2
                exit 1
        fi
        git update-index --add --cacheinfo "$7" "$3" "$4" &&
@@ -78,9 +80,10 @@ case "${1:-.}${2:-.}${3:-.}" in
 # Added in both, identically (check for same permissions).
 #
 ".$3$2")
-       if [ "$6" != "$7" ]; then
-               echo "ERROR: File $4 added identically in both branches,"
-               echo "ERROR: but permissions conflict $6->$7."
+       if test "$6" != "$7"
+       then
+               echo "ERROR: File $4 added identically in both branches," >&2
+               echo "ERROR: but permissions conflict $6->$7." >&2
                exit 1
        fi
        echo "Adding $4"
@@ -95,44 +98,36 @@ case "${1:-.}${2:-.}${3:-.}" in
 
        case ",$6,$7," in
        *,120000,*)
-               echo "ERROR: $4: Not merging symbolic link changes."
+               echo "ERROR: $4: Not merging symbolic link changes." >&2
                exit 1
                ;;
        *,160000,*)
-               echo "ERROR: $4: Not merging conflicting submodule changes."
+               echo "ERROR: $4: Not merging conflicting submodule changes." >&2
                exit 1
                ;;
        esac
 
-       src2=`git-unpack-file $3`
+       src1=$(git-unpack-file $2)
+       src2=$(git-unpack-file $3)
        case "$1" in
        '')
                echo "Added $4 in both, but differently."
-               # This extracts OUR file in $orig, and uses git apply to
-               # remove lines that are unique to ours.
-               orig=`git-unpack-file $2`
-               sz0=`wc -c <"$orig"`
-               @@DIFF@@ -u -La/$orig -Lb/$orig $orig $src2 | git apply --no-add
-               sz1=`wc -c <"$orig"`
-
-               # If we do not have enough common material, it is not
-               # worth trying two-file merge using common subsections.
-               expr $sz0 \< $sz1 \* 2 >/dev/null || : >$orig
+               orig=$(git-unpack-file $2)
+               create_virtual_base "$orig" "$src2"
                ;;
        *)
                echo "Auto-merging $4"
-               orig=`git-unpack-file $1`
+               orig=$(git-unpack-file $1)
                ;;
        esac
 
-       # Be careful for funny filename such as "-L" in "$4", which
-       # would confuse "merge" greatly.
-       src1=`git-unpack-file $2`
        git merge-file "$src1" "$orig" "$src2"
        ret=$?
        msg=
-       if [ $ret -ne 0 ]; then
+       if test $ret != 0 || test -z "$1"
+       then
                msg='content conflict'
+               ret=1
        fi
 
        # Create the working tree file, using "our tree" version from the
@@ -140,26 +135,26 @@ case "${1:-.}${2:-.}${3:-.}" in
        git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4" || exit 1
        rm -f -- "$orig" "$src1" "$src2"
 
-       if [ "$6" != "$7" ]; then
-               if [ -n "$msg" ]; then
+       if test "$6" != "$7"
+       then
+               if test -n "$msg"
+               then
                        msg="$msg, "
                fi
                msg="${msg}permissions conflict: $5->$6,$7"
                ret=1
        fi
-       if [ "$1" = '' ]; then
-               ret=1
-       fi
 
-       if [ $ret -ne 0 ]; then
-               echo "ERROR: $msg in $4"
+       if test $ret != 0
+       then
+               echo "ERROR: $msg in $4" >&2
                exit 1
        fi
        exec git update-index -- "$4"
        ;;
 
 *)
-       echo "ERROR: $4: Not handling case $1 -> $2 -> $3"
+       echo "ERROR: $4: Not handling case $1 -> $2 -> $3" >&2
        ;;
 esac
 exit 1
index 647f11020257598a8245eb1e84f64b80a2c55aca..911bbce6c5d4e19243e50d5916005872ac672961 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -79,12 +79,27 @@ def p4_build_cmd(cmd):
         real_cmd += cmd
     return real_cmd
 
-def chdir(dir):
-    # P4 uses the PWD environment variable rather than getcwd(). Since we're
-    # not using the shell, we have to set it ourselves.  This path could
-    # be relative, so go there first, then figure out where we ended up.
-    os.chdir(dir)
-    os.environ['PWD'] = os.getcwd()
+def chdir(path, is_client_path=False):
+    """Do chdir to the given path, and set the PWD environment
+       variable for use by P4.  It does not look at getcwd() output.
+       Since we're not using the shell, it is necessary to set the
+       PWD environment variable explicitly.
+
+       Normally, expand the path to force it to be absolute.  This
+       addresses the use of relative path names inside P4 settings,
+       e.g. P4CONFIG=.p4config.  P4 does not simply open the filename
+       as given; it looks for .p4config using PWD.
+
+       If is_client_path, the path was handed to us directly by p4,
+       and may be a symbolic link.  Do not call os.getcwd() in this
+       case, because it will cause p4 to think that PWD is not inside
+       the client path.
+       """
+
+    os.chdir(path)
+    if not is_client_path:
+        path = os.getcwd()
+    os.environ['PWD'] = path
 
 def die(msg):
     if verbose:
@@ -1624,7 +1639,7 @@ def run(self, args):
             new_client_dir = True
             os.makedirs(self.clientPath)
 
-        chdir(self.clientPath)
+        chdir(self.clientPath, is_client_path=True)
         if self.dry_run:
             print "Would synchronize p4 checkout in %s" % self.clientPath
         else:
index 266e682f6c518ab72dc710d52ed4f1dbe22881b5..638aabb7b347e2afeb9bf327902de9e3702cd9d4 100755 (executable)
@@ -39,7 +39,7 @@ test -z "$(git ls-files -u)" || die_conflict
 test -f "$GIT_DIR/MERGE_HEAD" && die_merge
 
 strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
-log_arg= verbosity= progress= recurse_submodules=
+log_arg= verbosity= progress= recurse_submodules= verify_signatures=
 merge_args= edit=
 curr_branch=$(git symbolic-ref -q HEAD)
 curr_branch_short="${curr_branch#refs/heads/}"
@@ -125,6 +125,12 @@ do
        --no-recurse-submodules)
                recurse_submodules=--no-recurse-submodules
                ;;
+       --verify-signatures)
+               verify_signatures=--verify-signatures
+               ;;
+       --no-verify-signatures)
+               verify_signatures=--no-verify-signatures
+               ;;
        --d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
                dry_run=--dry-run
                ;;
@@ -279,11 +285,11 @@ fi
 merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
 case "$rebase" in
 true)
-       eval="git-rebase $diffstat $strategy_args $merge_args"
+       eval="git-rebase $diffstat $strategy_args $merge_args $verbosity"
        eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
        ;;
 *)
-       eval="git-merge $diffstat $no_commit $edit $squash $no_ff $ff_only"
+       eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
        eval="$eval  $log_arg $strategy_args $merge_args $verbosity $progress"
        eval="$eval \"\$merge_name\" HEAD $merge_head"
        ;;
index 9a6ba2b9874e12d31adeba354d8d44436ceadaf3..8e17525dd86aa614000d9b335f9671a829678901 100755 (executable)
@@ -59,7 +59,7 @@ tmp_patch="$tmp_dir/patch"
 tmp_info="$tmp_dir/info"
 
 
-# Find the intial commit
+# Find the initial commit
 commit=$(git rev-parse HEAD)
 
 mkdir $tmp_dir || exit 2
index be809e5b59394a4fd2f4f2b73cad6bac47a39600..729747281864155bee7ef009de3ab92cc7643a89 100755 (executable)
@@ -512,8 +512,9 @@ sub split_addrs {
 
 ($sender) = expand_aliases($sender) if defined $sender;
 
-# returns 1 if the conflict must be solved using it as a format-patch argument
-sub check_file_rev_conflict($) {
+# is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if
+# $f is a revision list specification to be passed to format-patch.
+sub is_format_patch_arg {
        return unless $repo;
        my $f = shift;
        try {
@@ -529,6 +530,7 @@ ($)
     * Giving --format-patch option if you mean a range.
 EOF
        } catch Git::Error::Command with {
+               # Not a valid revision.  Treat it as a filename.
                return 0;
        }
 }
@@ -540,14 +542,14 @@ ($)
        if ($f eq "--") {
                push @rev_list_opts, "--", @ARGV;
                @ARGV = ();
-       } elsif (-d $f and !check_file_rev_conflict($f)) {
+       } elsif (-d $f and !is_format_patch_arg($f)) {
                opendir my $dh, $f
                        or die "Failed to opendir $f: $!";
 
                push @files, grep { -f $_ } map { catfile($f, $_) }
                                sort readdir $dh;
                closedir $dh;
-       } elsif ((-f $f or -p $f) and !check_file_rev_conflict($f)) {
+       } elsif ((-f $f or -p $f) and !is_format_patch_arg($f)) {
                push @files, $f;
        } else {
                push @rev_list_opts, $f;
@@ -711,7 +713,7 @@ sub ask {
                        }
                }
        }
-       return undef;
+       return;
 }
 
 my %broken_encoding;
@@ -833,7 +835,7 @@ sub extract_valid_address {
        # less robust/correct than the monster regexp in Email::Valid,
        # but still does a 99% job, and one less dependency
        return $1 if $address =~ /($local_part_regexp\@$domain_regexp)/;
-       return undef;
+       return;
 }
 
 sub extract_valid_address_or_die {
@@ -1045,6 +1047,47 @@ sub maildomain {
        return maildomain_net() || maildomain_mta() || 'localhost.localdomain';
 }
 
+sub smtp_host_string {
+       if (defined $smtp_server_port) {
+               return "$smtp_server:$smtp_server_port";
+       } else {
+               return $smtp_server;
+       }
+}
+
+# Returns 1 if authentication succeeded or was not necessary
+# (smtp_user was not specified), and 0 otherwise.
+
+sub smtp_auth_maybe {
+       if (!defined $smtp_authuser || $auth) {
+               return 1;
+       }
+
+       # Workaround AUTH PLAIN/LOGIN interaction defect
+       # with Authen::SASL::Cyrus
+       eval {
+               require Authen::SASL;
+               Authen::SASL->import(qw(Perl));
+       };
+
+       # TODO: Authentication may fail not because credentials were
+       # invalid but due to other reasons, in which we should not
+       # reject credentials.
+       $auth = Git::credential({
+               'protocol' => 'smtp',
+               'host' => smtp_host_string(),
+               'username' => $smtp_authuser,
+               # if there's no password, "git credential fill" will
+               # give us one, otherwise it'll just pass this one.
+               'password' => $smtp_authpass
+       }, sub {
+               my $cred = shift;
+               return !!$smtp->auth($cred->{'username'}, $cred->{'password'});
+       });
+
+       return $auth;
+}
+
 # Returns 1 if the message was sent, and 0 otherwise.
 # In actuality, the whole program dies when there
 # is an error sending a message.
@@ -1155,9 +1198,7 @@ sub send_message {
                else {
                        require Net::SMTP;
                        $smtp_domain ||= maildomain();
-                       $smtp ||= Net::SMTP->new((defined $smtp_server_port)
-                                                ? "$smtp_server:$smtp_server_port"
-                                                : $smtp_server,
+                       $smtp ||= Net::SMTP->new(smtp_host_string(),
                                                 Hello => $smtp_domain,
                                                 Debug => $debug_net_smtp);
                        if ($smtp_encryption eq 'tls' && $smtp) {
@@ -1185,31 +1226,7 @@ sub send_message {
                            defined $smtp_server_port ? " port=$smtp_server_port" : "";
                }
 
-               if (defined $smtp_authuser) {
-                       # Workaround AUTH PLAIN/LOGIN interaction defect
-                       # with Authen::SASL::Cyrus
-                       eval {
-                               require Authen::SASL;
-                               Authen::SASL->import(qw(Perl));
-                       };
-
-                       if (!defined $smtp_authpass) {
-
-                               system "stty -echo";
-
-                               do {
-                                       print "Password: ";
-                                       $_ = <STDIN>;
-                                       print "\n";
-                               } while (!defined $_);
-
-                               chomp($smtp_authpass = $_);
-
-                               system "stty echo";
-                       }
-
-                       $auth ||= $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
-               }
+               smtp_auth_maybe or die $smtp->message;
 
                $smtp->mail( $raw_from ) or die $smtp->message;
                $smtp->to( @recipients ) or die $smtp->message;
@@ -1438,7 +1455,7 @@ sub recipients_cmd {
 
        my $sanitized_sender = sanitize_address($sender);
        my @addresses = ();
-       open my $fh, "$cmd \Q$file\E |"
+       open my $fh, "-|", "$cmd \Q$file\E"
            or die "($prefix) Could not execute '$cmd'";
        while (my $address = <$fh>) {
                $address =~ s/^\s*//g;
@@ -1484,7 +1501,7 @@ sub validate_patch {
                        return "$.: patch contains a line longer than 998 characters";
                }
        }
-       return undef;
+       return;
 }
 
 sub file_has_nonascii {
index 9cfbe7f1435e073eeb39ab2190eda2d2dda300a5..2f7835941ecaa48be17b6dd64e64fb0df3db37e2 100644 (file)
@@ -249,6 +249,18 @@ clear_local_git_env() {
        unset $(git rev-parse --local-env-vars)
 }
 
+# Generate a virtual base file for a two-file merge. Uses git apply to
+# remove lines from $1 that are not in $2, leaving only common lines.
+create_virtual_base() {
+       sz0=$(wc -c <"$1")
+       @@DIFF@@ -u -La/"$1" -Lb/"$1" "$1" "$2" | git apply --no-add
+       sz1=$(wc -c <"$1")
+
+       # If we do not have enough common material, it is not
+       # worth trying two-file merge using common subsections.
+       expr $sz0 \< $sz1 \* 2 >/dev/null || : >"$1"
+}
+
 
 # Platform specific tweaks to work around some commands
 case $(uname -s) in
index b3108b8ea9983c524eb06831972c22773b3a56b1..79bfaac9d4cb9a04e5e1fd7675d740cf9fc27e87 100755 (executable)
@@ -8,6 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
 USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
+   or: $dashless [--quiet] deinit [-f|--force] [--] <path>...
    or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
@@ -551,6 +552,82 @@ cmd_init()
        done
 }
 
+#
+# Unregister submodules from .git/config and remove their work tree
+#
+# $@ = requested paths (use '.' to deinit all submodules)
+#
+cmd_deinit()
+{
+       # parse $args after "submodule ... deinit".
+       while test $# -ne 0
+       do
+               case "$1" in
+               -f|--force)
+                       force=$1
+                       ;;
+               -q|--quiet)
+                       GIT_QUIET=1
+                       ;;
+               --)
+                       shift
+                       break
+                       ;;
+               -*)
+                       usage
+                       ;;
+               *)
+                       break
+                       ;;
+               esac
+               shift
+       done
+
+       if test $# = 0
+       then
+               die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
+       fi
+
+       module_list "$@" |
+       while read mode sha1 stage sm_path
+       do
+               die_if_unmatched "$mode"
+               name=$(module_name "$sm_path") || exit
+
+               # Remove the submodule work tree (unless the user already did it)
+               if test -d "$sm_path"
+               then
+                       # Protect submodules containing a .git directory
+                       if test -d "$sm_path/.git"
+                       then
+                               echo >&2 "$(eval_gettext "Submodule work tree '\$sm_path' contains a .git directory")"
+                               die "$(eval_gettext "(use 'rm -rf' if you really want to remove it including all of its history)")"
+                       fi
+
+                       if test -z "$force"
+                       then
+                               git rm -qn "$sm_path" ||
+                               die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
+                       fi
+                       rm -rf "$sm_path" &&
+                       say "$(eval_gettext "Cleared directory '\$sm_path'")" ||
+                       say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
+               fi
+
+               mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"
+
+               # Remove the .git/config entries (unless the user already did it)
+               if test -n "$(git config --get-regexp submodule."$name\.")"
+               then
+                       # Remove the whole section so we have a clean state when
+                       # the user later decides to init this submodule again
+                       url=$(git config submodule."$name".url)
+                       git config --remove-section submodule."$name" 2>/dev/null &&
+                       say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$sm_path'")"
+               fi
+       done
+}
+
 #
 # Update each submodule path to correct revision, using clone and checkout as needed
 #
@@ -1167,7 +1244,7 @@ cmd_sync()
 while test $# != 0 && test -z "$command"
 do
        case "$1" in
-       add | foreach | init | update | status | summary | sync)
+       add | foreach | init | deinit | update | status | summary | sync)
                command=$1
                ;;
        -q|--quiet)
index 1e827264b4cab04a801804b8d066f9d2cbb85edc..9f446798d473cee7dedc82d5d2c820cb0967b375 100755 (executable)
@@ -119,8 +119,8 @@ if test -z "$browser" ; then
                browser_candidates="w3m elinks links lynx"
        fi
        # SECURITYSESSIONID indicates an OS X GUI login session
-       if test -n "$SECURITYSESSIONID" \
-               -o "$TERM_PROGRAM" = "Apple_Terminal" ; then
+       if test -n "$SECURITYSESSIONID" || test -n "$TERM_PROGRAM"
+       then
                browser_candidates="open $browser_candidates"
        fi
        # /bin/start indicates MinGW
diff --git a/git.c b/git.c
index 850d3f5527f4100f45cb5eb1a7d8772e04ae4443..1ada169d5cff3051effee33c6f9ba5b9be15b2e6 100644 (file)
--- a/git.c
+++ b/git.c
@@ -13,7 +13,9 @@ const char git_usage_string[] =
        "           <command> [<args>]";
 
 const char git_more_info_string[] =
-       N_("See 'git help <command>' for more information on a specific command.");
+       N_("'git help -a' and 'git help -g' lists available subcommands and some\n"
+          "concept guides. See 'git help <command>' or 'git help <concept>'\n"
+          "to read about a specific subcommand or concept.");
 
 static struct startup_info git_startup_info;
 static int use_pager = -1;
index 6d4540679731bdfd33af61635c59b798b19a8888..08f3dda02d43f9b2e994ee2f7a8dccaecb82733e 100644 (file)
@@ -244,7 +244,7 @@ for gitweb (in gitweb/README), and gitweb.conf(5) manpage.
   through the GITWEB_CONFIG_SYSTEM environment variable.
 
   Note that if per-instance configuration file exists, then system-wide
-  configuration is _not used at all_.  This is quite untypical and suprising
+  configuration is _not used at all_.  This is quite untypical and surprising
   behavior.  On the other hand changing current behavior would break backwards
   compatibility and can lead to unexpected changes in gitweb behavior.
   Therefore gitweb also looks for common system-wide configuration file,
index 1309196d27e675013825cdac8afd6d7328e44b1f..80950c018d54f3bbb7b700286b4923d39cbe2d00 100755 (executable)
@@ -683,7 +683,7 @@ sub evaluate_gitweb_config {
        our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
        our $GITWEB_CONFIG_COMMON = $ENV{'GITWEB_CONFIG_COMMON'} || "++GITWEB_CONFIG_COMMON++";
 
-       # Protect agains duplications of file names, to not read config twice.
+       # Protect against duplications of file names, to not read config twice.
        # Only one of $GITWEB_CONFIG and $GITWEB_CONFIG_SYSTEM is used, so
        # there possibility of duplication of filename there doesn't matter.
        $GITWEB_CONFIG = ""        if ($GITWEB_CONFIG eq $GITWEB_CONFIG_COMMON);
@@ -1136,7 +1136,7 @@ sub handle_errors_html {
 
        # to avoid infinite loop where error occurs in die_error,
        # change handler to default handler, disabling handle_errors_html
-       set_message("Error occured when inside die_error:\n$msg");
+       set_message("Error occurred when inside die_error:\n$msg");
 
        # you cannot jump out of die_error when called as error handler;
        # the subroutine set via CGI::Carp::set_message is called _after_
@@ -7485,7 +7485,7 @@ sub git_object {
                system(git_cmd(), "cat-file", '-e', $hash_base) == 0
                        or die_error(404, "Base object does not exist");
 
-               # here errors should not hapen
+               # here errors should not happen
                open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
                        or die_error(500, "Open git-ls-tree failed");
                my $line = <$fd>;
index cf9902184272d20c6d5826cf9f10dcaebeb3e6e8..a85cb5bc97cdd61000b4c48c54faa656aa3cfaca 100644 (file)
@@ -1,6 +1,18 @@
 #ifndef GPG_INTERFACE_H
 #define GPG_INTERFACE_H
 
+struct signature_check {
+       char *gpg_output;
+       char *gpg_status;
+       char result; /* 0 (not checked),
+                     * N (checked but no further result),
+                     * U (untrusted good),
+                     * G (good)
+                     * B (bad) */
+       char *signer;
+       char *key;
+};
+
 extern int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *signing_key);
 extern int verify_signed_buffer(const char *payload, size_t payload_size, const char *signature, size_t signature_size, struct strbuf *gpg_output, struct strbuf *gpg_status);
 extern int git_gpg_config(const char *, const char *, void *);
diff --git a/grep.c b/grep.c
index 4bd1b8b1dd67e4f5c2223536b435198ce67463ba..bb548cae69d1eece8832c97332a91daac5f8dceb 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -625,7 +625,8 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
        for (p = opt->header_list; p; p = p->next) {
                if (p->token != GREP_PATTERN_HEAD)
                        die("bug: a non-header pattern in grep header list.");
-               if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
+               if (p->field < GREP_HEADER_FIELD_MIN ||
+                   GREP_HEADER_FIELD_MAX <= p->field)
                        die("bug: unknown header field %d", p->field);
                compile_regexp(p, opt);
        }
diff --git a/grep.h b/grep.h
index 8fc854f400802c3329fc3c028942de55b820ac90..e4a1df56a423548af4cba728811eb21b62518e15 100644 (file)
--- a/grep.h
+++ b/grep.h
@@ -28,7 +28,8 @@ enum grep_context {
 };
 
 enum grep_header_field {
-       GREP_HEADER_AUTHOR = 0,
+       GREP_HEADER_FIELD_MIN = 0,
+       GREP_HEADER_AUTHOR = GREP_HEADER_FIELD_MIN,
        GREP_HEADER_COMMITTER,
        GREP_HEADER_REFLOG,
 
diff --git a/hash.h b/hash.h
index b875ce67c49eb39a8ca8ad6a688a334985db0534..1d43ac0ba0120e947e40476946360efbdee80a93 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -40,4 +40,11 @@ static inline void init_hash(struct hash_table *table)
        table->array = NULL;
 }
 
+static inline void preallocate_hash(struct hash_table *table, unsigned int elts)
+{
+       assert(table->size == 0 && table->nr == 0 && table->array == NULL);
+       table->size = elts * 2;
+       table->array = xcalloc(sizeof(struct hash_table_entry), table->size);
+}
+
 #endif
index f50e77fb2890207bd7385b59bdd561133991c910..8144f3ad5eb68c789fd031921e6e702170310d68 100644 (file)
@@ -70,7 +70,7 @@ static void format_write(int fd, const char *fmt, ...)
        if (n >= sizeof(buffer))
                die("protocol error: impossibly long line");
 
-       safe_write(fd, buffer, n);
+       write_or_die(fd, buffer, n);
 }
 
 static void http_status(unsigned code, const char *msg)
@@ -111,7 +111,7 @@ static void hdr_cache_forever(void)
 
 static void end_headers(void)
 {
-       safe_write(1, "\r\n", 2);
+       write_or_die(1, "\r\n", 2);
 }
 
 __attribute__((format (printf, 1, 2)))
@@ -157,7 +157,7 @@ static void send_strbuf(const char *type, struct strbuf *buf)
        hdr_int(content_length, buf->len);
        hdr_str(content_type, type);
        end_headers();
-       safe_write(1, buf->buf, buf->len);
+       write_or_die(1, buf->buf, buf->len);
 }
 
 static void send_local_file(const char *the_type, const char *name)
@@ -185,7 +185,7 @@ static void send_local_file(const char *the_type, const char *name)
                        die_errno("Cannot read '%s'", p);
                if (!n)
                        break;
-               safe_write(1, buf, n);
+               write_or_die(1, buf, n);
        }
        close(fd);
        free(buf);
diff --git a/http.c b/http.c
index d9d1aad3be468394e39966c0b45e7e101b387b0c..8803c70825ac8aefb619b6c56d6015573eb5d227 100644 (file)
--- a/http.c
+++ b/http.c
@@ -5,6 +5,7 @@
 #include "url.h"
 #include "credential.h"
 #include "version.h"
+#include "pkt-line.h"
 
 int active_requests;
 int http_is_verbose;
diff --git a/kwset.c b/kwset.c
index 51b2ab6c7e61413851a958f7a4009a0194744b68..5800999b4c16cd8f5eeb2301f72c33ec62c5ea71 100644 (file)
--- a/kwset.c
+++ b/kwset.c
@@ -26,7 +26,7 @@
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation. */
 
-/* The algorithm implemented by these routines bears a startling resemblence
+/* The algorithm implemented by these routines bears a startling resemblance
    to one discovered by Beate Commentz-Walter, although it is not identical.
    See "A String Matching Algorithm Fast on the Average," Technical Report,
    IBM-Germany, Scientific Center Heidelberg, Tiergartenstrasse 15, D-6900
@@ -435,7 +435,7 @@ kwsprep (kwset_t kws)
          /* Update the delta table for the descendents of this node. */
          treedelta(curr->links, curr->depth, delta);
 
-         /* Compute the failure function for the decendents of this node. */
+         /* Compute the failure function for the descendants of this node. */
          treefails(curr->links, curr->fail, kwset->trie);
 
          /* Update the shifts at each node in the current node's chain
index 3d888238711364338a83e7d81bf27f555352bdca..7cc7d598e712fab531f7c6f938be17c317161f3e 100644 (file)
@@ -9,6 +9,7 @@
 #include "string-list.h"
 #include "color.h"
 #include "gpg-interface.h"
+#include "sequencer.h"
 
 struct decoration name_decoration = { "object names" };
 
@@ -206,89 +207,6 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
        putchar(')');
 }
 
-/*
- * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
- * Signed-off-by: and Acked-by: lines.
- */
-static int detect_any_signoff(char *letter, int size)
-{
-       char *cp;
-       int seen_colon = 0;
-       int seen_at = 0;
-       int seen_name = 0;
-       int seen_head = 0;
-
-       cp = letter + size;
-       while (letter <= --cp && *cp == '\n')
-               continue;
-
-       while (letter <= cp) {
-               char ch = *cp--;
-               if (ch == '\n')
-                       break;
-
-               if (!seen_at) {
-                       if (ch == '@')
-                               seen_at = 1;
-                       continue;
-               }
-               if (!seen_colon) {
-                       if (ch == '@')
-                               return 0;
-                       else if (ch == ':')
-                               seen_colon = 1;
-                       else
-                               seen_name = 1;
-                       continue;
-               }
-               if (('A' <= ch && ch <= 'Z') ||
-                   ('a' <= ch && ch <= 'z') ||
-                   ch == '-') {
-                       seen_head = 1;
-                       continue;
-               }
-               /* no empty last line doesn't match */
-               return 0;
-       }
-       return seen_head && seen_name;
-}
-
-static void append_signoff(struct strbuf *sb, const char *signoff)
-{
-       static const char signed_off_by[] = "Signed-off-by: ";
-       size_t signoff_len = strlen(signoff);
-       int has_signoff = 0;
-       char *cp;
-
-       cp = sb->buf;
-
-       /* First see if we already have the sign-off by the signer */
-       while ((cp = strstr(cp, signed_off_by))) {
-
-               has_signoff = 1;
-
-               cp += strlen(signed_off_by);
-               if (cp + signoff_len >= sb->buf + sb->len)
-                       break;
-               if (strncmp(cp, signoff, signoff_len))
-                       continue;
-               if (!isspace(cp[signoff_len]))
-                       continue;
-               /* we already have him */
-               return;
-       }
-
-       if (!has_signoff)
-               has_signoff = detect_any_signoff(sb->buf, sb->len);
-
-       if (!has_signoff)
-               strbuf_addch(sb, '\n');
-
-       strbuf_addstr(sb, signed_off_by);
-       strbuf_add(sb, signoff, signoff_len);
-       strbuf_addch(sb, '\n');
-}
-
 static unsigned int digits_in_number(unsigned int number)
 {
        unsigned int i = 10, result = 1;
@@ -669,8 +587,10 @@ void show_log(struct rev_info *opt)
        /*
         * And then the pretty-printed message itself
         */
-       if (ctx.need_8bit_cte >= 0)
-               ctx.need_8bit_cte = has_non_ascii(opt->add_signoff);
+       if (ctx.need_8bit_cte >= 0 && opt->add_signoff)
+               ctx.need_8bit_cte =
+                       has_non_ascii(fmt_name(getenv("GIT_COMMITTER_NAME"),
+                                              getenv("GIT_COMMITTER_EMAIL")));
        ctx.date_mode = opt->date_mode;
        ctx.date_mode_explicit = opt->date_mode_explicit;
        ctx.abbrev = opt->diffopt.abbrev;
@@ -683,7 +603,7 @@ void show_log(struct rev_info *opt)
        pretty_print_commit(&ctx, commit, &msgbuf);
 
        if (opt->add_signoff)
-               append_signoff(&msgbuf, opt->add_signoff);
+               append_signoff(&msgbuf, 0, APPEND_SIGNOFF_DEDUP);
 
        if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
            ctx.notes_message && *ctx.notes_message) {
@@ -789,11 +709,14 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 {
        int showed_log;
        struct commit_list *parents;
-       unsigned const char *sha1 = commit->object.sha1;
+       unsigned const char *sha1;
 
        if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
                return 0;
 
+       parse_commit(commit);
+       sha1 = commit->tree->object.sha1;
+
        /* Root commit? */
        parents = commit->parents;
        if (!parents) {
@@ -816,7 +739,9 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
                         * parent, showing summary diff of the others
                         * we merged _in_.
                         */
-                       diff_tree_sha1(parents->item->object.sha1, sha1, "", &opt->diffopt);
+                       parse_commit(parents->item);
+                       diff_tree_sha1(parents->item->tree->object.sha1,
+                                      sha1, "", &opt->diffopt);
                        log_tree_diff_flush(opt);
                        return !opt->loginfo;
                }
@@ -829,7 +754,9 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        for (;;) {
                struct commit *parent = parents->item;
 
-               diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
+               parse_commit(parent);
+               diff_tree_sha1(parent->tree->object.sha1,
+                              sha1, "", &opt->diffopt);
                log_tree_diff_flush(opt);
 
                showed_log |= !opt->loginfo;
index 26f7ed143e0649b6377ea427b5c57ca7ddb663d3..2bb734d51cbe59e3eed7c82e7522c594d5efa579 100644 (file)
@@ -47,6 +47,13 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
        return score;
 }
 
+static int base_name_entries_compare(const struct name_entry *a,
+                                    const struct name_entry *b)
+{
+       return base_name_compare(a->path, tree_entry_len(a), a->mode,
+                                b->path, tree_entry_len(b), b->mode);
+}
+
 /*
  * Inspect two trees, and give a score that tells how similar they are.
  */
@@ -71,54 +78,35 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
        if (type != OBJ_TREE)
                die("%s is not a tree", sha1_to_hex(hash2));
        init_tree_desc(&two, two_buf, size);
-       while (one.size | two.size) {
-               const unsigned char *elem1 = elem1;
-               const unsigned char *elem2 = elem2;
-               const char *path1 = path1;
-               const char *path2 = path2;
-               unsigned mode1 = mode1;
-               unsigned mode2 = mode2;
+       for (;;) {
+               struct name_entry e1, e2;
+               int got_entry_from_one = tree_entry(&one, &e1);
+               int got_entry_from_two = tree_entry(&two, &e2);
                int cmp;
 
-               if (one.size)
-                       elem1 = tree_entry_extract(&one, &path1, &mode1);
-               if (two.size)
-                       elem2 = tree_entry_extract(&two, &path2, &mode2);
-
-               if (!one.size) {
-                       /* two has more entries */
-                       score += score_missing(mode2, path2);
-                       update_tree_entry(&two);
-                       continue;
-               }
-               if (!two.size) {
+               if (got_entry_from_one && got_entry_from_two)
+                       cmp = base_name_entries_compare(&e1, &e2);
+               else if (got_entry_from_one)
                        /* two lacks this entry */
-                       score += score_missing(mode1, path1);
-                       update_tree_entry(&one);
-                       continue;
-               }
-               cmp = base_name_compare(path1, strlen(path1), mode1,
-                                       path2, strlen(path2), mode2);
-               if (cmp < 0) {
+                       cmp = -1;
+               else if (got_entry_from_two)
+                       /* two has more entries */
+                       cmp = 1;
+               else
+                       break;
+
+               if (cmp < 0)
                        /* path1 does not appear in two */
-                       score += score_missing(mode1, path1);
-                       update_tree_entry(&one);
-                       continue;
-               }
-               else if (cmp > 0) {
+                       score += score_missing(e1.mode, e1.path);
+               else if (cmp > 0)
                        /* path2 does not appear in one */
-                       score += score_missing(mode2, path2);
-                       update_tree_entry(&two);
-                       continue;
-               }
-               else if (hashcmp(elem1, elem2))
+                       score += score_missing(e2.mode, e2.path);
+               else if (hashcmp(e1.sha1, e2.sha1))
                        /* they are different */
-                       score += score_differs(mode1, mode2, path1);
+                       score += score_differs(e1.mode, e2.mode, e1.path);
                else
                        /* same subtree or blob */
-                       score += score_matches(mode1, mode2, path1);
-               update_tree_entry(&one);
-               update_tree_entry(&two);
+                       score += score_matches(e1.mode, e2.mode, e1.path);
        }
        free(one_buf);
        free(two_buf);
index 8a36916567a234c354af9994df9c28788749e7fa..5a608abf9c77f436ab1472592e3d5777ef83805d 100644 (file)
@@ -21,8 +21,12 @@ diff_cmd () {
 
 merge_cmd () {
        touch "$BACKUP"
-       $base_present || >"$BASE"
-       "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
+       if ! $base_present
+       then
+               cp -- "$LOCAL" "$BASE"
+               create_virtual_base "$BASE" "$REMOTE"
+       fi
+       "$merge_tool_path" "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
        check_unchanged
 }
 
index 6d7e1980c62f96fc3614ddd130ce25a765fceae5..617c86c53762575373d0bcbf3d8bab09cb042caa 100644 (file)
@@ -150,6 +150,8 @@ static void lazy_init_name_hash(struct index_state *istate)
 
        if (istate->name_hash_initialized)
                return;
+       if (istate->cache_nr)
+               preallocate_hash(&istate->name_hash, istate->cache_nr);
        for (nr = 0; nr < istate->cache_nr; nr++)
                hash_index_entry(istate, istate->cache[nr]);
        istate->name_hash_initialized = 1;
diff --git a/path.c b/path.c
index d3d3f8b8ad75b9817df3014296aabc34b6a4eb14..04ff1487ed31685b6b3f7923f9bfbfc7217f70a0 100644 (file)
--- a/path.c
+++ b/path.c
@@ -1,19 +1,26 @@
 /*
- * I'm tired of doing "vsnprintf()" etc just to open a
- * file, so here's a "return static buffer with printf"
- * interface for paths.
- *
- * It's obviously not thread-safe. Sue me. But it's quite
- * useful for doing things like
- *
- *   f = open(mkpath("%s/%s.git", base, name), O_RDONLY);
- *
- * which is what it's designed for.
+ * Utilities for paths and pathnames
  */
 #include "cache.h"
 #include "strbuf.h"
 #include "string-list.h"
 
+#ifndef get_st_mode_bits
+/*
+ * The replacement lstat(2) we use on Cygwin is incomplete and
+ * may return wrong permission bits. Most of the time we do not care,
+ * but the callsites of this wrapper do care.
+ */
+int get_st_mode_bits(const char *path, int *mode)
+{
+       struct stat st;
+       if (lstat(path, &st) < 0)
+               return -1;
+       *mode = st.st_mode;
+       return 0;
+}
+#endif
+
 static char bad_path[] = "/bad-path/";
 
 static char *get_pathname(void)
@@ -389,28 +396,14 @@ const char *enter_repo(const char *path, int strict)
        return NULL;
 }
 
-int set_shared_perm(const char *path, int mode)
+static int calc_shared_perm(int mode)
 {
-       struct stat st;
-       int tweak, shared, orig_mode;
+       int tweak;
 
-       if (!shared_repository) {
-               if (mode)
-                       return chmod(path, mode & ~S_IFMT);
-               return 0;
-       }
-       if (!mode) {
-               if (lstat(path, &st) < 0)
-                       return -1;
-               mode = st.st_mode;
-               orig_mode = mode;
-       } else
-               orig_mode = 0;
        if (shared_repository < 0)
-               shared = -shared_repository;
+               tweak = -shared_repository;
        else
-               shared = shared_repository;
-       tweak = shared;
+               tweak = shared_repository;
 
        if (!(mode & S_IWUSR))
                tweak &= ~0222;
@@ -422,16 +415,28 @@ int set_shared_perm(const char *path, int mode)
        else
                mode |= tweak;
 
-       if (S_ISDIR(mode)) {
+       return mode;
+}
+
+
+int adjust_shared_perm(const char *path)
+{
+       int old_mode, new_mode;
+
+       if (!shared_repository)
+               return 0;
+       if (get_st_mode_bits(path, &old_mode) < 0)
+               return -1;
+
+       new_mode = calc_shared_perm(old_mode);
+       if (S_ISDIR(old_mode)) {
                /* Copy read bits to execute bits */
-               mode |= (shared & 0444) >> 2;
-               mode |= FORCE_DIR_SET_GID;
+               new_mode |= (new_mode & 0444) >> 2;
+               new_mode |= FORCE_DIR_SET_GID;
        }
 
-       if (((shared_repository < 0
-             ? (orig_mode & (FORCE_DIR_SET_GID | 0777))
-             : (orig_mode & mode)) != mode) &&
-           chmod(path, (mode & ~S_IFMT)) < 0)
+       if (((old_mode ^ new_mode) & ~S_IFMT) &&
+                       chmod(path, (new_mode & ~S_IFMT)) < 0)
                return -2;
        return 0;
 }
index 4778428830a5eaf6fb9773b18a18f02f934c8820..dc48159ccab1cf2f888a6169460c5fc60d0d1bab 100644 (file)
@@ -60,6 +60,7 @@ =head1 SYNOPSIS
                 version exec_path html_path hash_object git_cmd_try
                 remote_refs prompt
                 get_tz_offset
+                credential credential_read credential_write
                 temp_acquire temp_release temp_reset temp_path);
 
 
@@ -269,13 +270,13 @@ sub command {
 
        if (not defined wantarray) {
                # Nothing to pepper the possible exception with.
-               _cmd_close($fh, $ctx);
+               _cmd_close($ctx, $fh);
 
        } elsif (not wantarray) {
                local $/;
                my $text = <$fh>;
                try {
-                       _cmd_close($fh, $ctx);
+                       _cmd_close($ctx, $fh);
                } catch Git::Error::Command with {
                        # Pepper with the output:
                        my $E = shift;
@@ -288,7 +289,7 @@ sub command {
                my @lines = <$fh>;
                defined and chomp for @lines;
                try {
-                       _cmd_close($fh, $ctx);
+                       _cmd_close($ctx, $fh);
                } catch Git::Error::Command with {
                        my $E = shift;
                        $E->{'-outputref'} = \@lines;
@@ -315,7 +316,7 @@ sub command_oneline {
        my $line = <$fh>;
        defined $line and chomp $line;
        try {
-               _cmd_close($fh, $ctx);
+               _cmd_close($ctx, $fh);
        } catch Git::Error::Command with {
                # Pepper with the output:
                my $E = shift;
@@ -383,7 +384,7 @@ sub command_input_pipe {
 sub command_close_pipe {
        my ($self, $fh, $ctx) = _maybe_self(@_);
        $ctx ||= '<unknown>';
-       _cmd_close($fh, $ctx);
+       _cmd_close($ctx, $fh);
 }
 
 =item command_bidi_pipe ( COMMAND [, ARGUMENTS... ] )
@@ -420,7 +421,7 @@ sub command_bidi_pipe {
 is:
 
        my ($pid, $in, $out, $ctx) = $r->command_bidi_pipe('cat-file --batch-check');
-       print "000000000\n" $out;
+       print $out "000000000\n";
        while (<$in>) { ... }
        $r->command_close_bidi_pipe($pid, $in, $out, $ctx);
 
@@ -428,23 +429,26 @@ sub command_bidi_pipe {
 currently it is simply the command name but in future the context might
 have more complicated structure.
 
+C<PIPE_IN> and C<PIPE_OUT> may be C<undef> if they have been closed prior to
+calling this function.  This may be useful in a query-response type of
+commands where caller first writes a query and later reads response, eg:
+
+       my ($pid, $in, $out, $ctx) = $r->command_bidi_pipe('cat-file --batch-check');
+       print $out "000000000\n";
+       close $out;
+       while (<$in>) { ... }
+       $r->command_close_bidi_pipe($pid, $in, undef, $ctx);
+
+This idiom may prevent potential dead locks caused by data sent to the output
+pipe not being flushed and thus not reaching the executed command.
+
 =cut
 
 sub command_close_bidi_pipe {
        local $?;
-       my ($pid, $in, $out, $ctx) = @_;
-       foreach my $fh ($in, $out) {
-               unless (close $fh) {
-                       if ($!) {
-                               carp "error closing pipe: $!";
-                       } elsif ($? >> 8) {
-                               throw Git::Error::Command($ctx, $? >>8);
-                       }
-               }
-       }
-
+       my ($self, $pid, $in, $out, $ctx) = _maybe_self(@_);
+       _cmd_close($ctx, (grep { defined } ($in, $out)));
        waitpid $pid, 0;
-
        if ($? >> 8) {
                throw Git::Error::Command($ctx, $? >>8);
        }
@@ -1020,13 +1024,163 @@ sub _close_cat_blob {
 }
 
 
+=item credential_read( FILEHANDLE )
+
+Reads credential key-value pairs from C<FILEHANDLE>.  Reading stops at EOF or
+when an empty line is encountered.  Each line must be of the form C<key=value>
+with a non-empty key.  Function returns hash with all read values.  Any white
+space (other than new-line character) is preserved.
+
+=cut
+
+sub credential_read {
+       my ($self, $reader) = _maybe_self(@_);
+       my %credential;
+       while (<$reader>) {
+               chomp;
+               if ($_ eq '') {
+                       last;
+               } elsif (!/^([^=]+)=(.*)$/) {
+                       throw Error::Simple("unable to parse git credential data:\n$_");
+               }
+               $credential{$1} = $2;
+       }
+       return %credential;
+}
+
+=item credential_write( FILEHANDLE, CREDENTIAL_HASHREF )
+
+Writes credential key-value pairs from hash referenced by
+C<CREDENTIAL_HASHREF> to C<FILEHANDLE>.  Keys and values cannot contain
+new-lines or NUL bytes characters, and key cannot contain equal signs nor be
+empty (if they do Error::Simple is thrown).  Any white space is preserved.  If
+value for a key is C<undef>, it will be skipped.
+
+If C<'url'> key exists it will be written first.  (All the other key-value
+pairs are written in sorted order but you should not depend on that).  Once
+all lines are written, an empty line is printed.
+
+=cut
+
+sub credential_write {
+       my ($self, $writer, $credential) = _maybe_self(@_);
+       my ($key, $value);
+
+       # Check if $credential is valid prior to writing anything
+       while (($key, $value) = each %$credential) {
+               if (!defined $key || !length $key) {
+                       throw Error::Simple("credential key empty or undefined");
+               } elsif ($key =~ /[=\n\0]/) {
+                       throw Error::Simple("credential key contains invalid characters: $key");
+               } elsif (defined $value && $value =~ /[\n\0]/) {
+                       throw Error::Simple("credential value for key=$key contains invalid characters: $value");
+               }
+       }
+
+       for $key (sort {
+               # url overwrites other fields, so it must come first
+               return -1 if $a eq 'url';
+               return  1 if $b eq 'url';
+               return $a cmp $b;
+       } keys %$credential) {
+               if (defined $credential->{$key}) {
+                       print $writer $key, '=', $credential->{$key}, "\n";
+               }
+       }
+       print $writer "\n";
+}
+
+sub _credential_run {
+       my ($self, $credential, $op) = _maybe_self(@_);
+       my ($pid, $reader, $writer, $ctx) = command_bidi_pipe('credential', $op);
+
+       credential_write $writer, $credential;
+       close $writer;
+
+       if ($op eq "fill") {
+               %$credential = credential_read $reader;
+       }
+       if (<$reader>) {
+               throw Error::Simple("unexpected output from git credential $op response:\n$_\n");
+       }
+
+       command_close_bidi_pipe($pid, $reader, undef, $ctx);
+}
+
+=item credential( CREDENTIAL_HASHREF [, OPERATION ] )
+
+=item credential( CREDENTIAL_HASHREF, CODE )
+
+Executes C<git credential> for a given set of credentials and specified
+operation.  In both forms C<CREDENTIAL_HASHREF> needs to be a reference to
+a hash which stores credentials.  Under certain conditions the hash can
+change.
+
+In the first form, C<OPERATION> can be C<'fill'>, C<'approve'> or C<'reject'>,
+and function will execute corresponding C<git credential> sub-command.  If
+it's omitted C<'fill'> is assumed.  In case of C<'fill'> the values stored in
+C<CREDENTIAL_HASHREF> will be changed to the ones returned by the C<git
+credential fill> command.  The usual usage would look something like:
+
+       my %cred = (
+               'protocol' => 'https',
+               'host' => 'example.com',
+               'username' => 'bob'
+       );
+       Git::credential \%cred;
+       if (try_to_authenticate($cred{'username'}, $cred{'password'})) {
+               Git::credential \%cred, 'approve';
+               ... do more stuff ...
+       } else {
+               Git::credential \%cred, 'reject';
+       }
+
+In the second form, C<CODE> needs to be a reference to a subroutine.  The
+function will execute C<git credential fill> to fill the provided credential
+hash, then call C<CODE> with C<CREDENTIAL_HASHREF> as the sole argument.  If
+C<CODE>'s return value is defined, the function will execute C<git credential
+approve> (if return value yields true) or C<git credential reject> (if return
+value is false).  If the return value is undef, nothing at all is executed;
+this is useful, for example, if the credential could neither be verified nor
+rejected due to an unrelated network error.  The return value is the same as
+what C<CODE> returns.  With this form, the usage might look as follows:
+
+       if (Git::credential {
+               'protocol' => 'https',
+               'host' => 'example.com',
+               'username' => 'bob'
+       }, sub {
+               my $cred = shift;
+               return !!try_to_authenticate($cred->{'username'},
+                                            $cred->{'password'});
+       }) {
+               ... do more stuff ...
+       }
+
+=cut
+
+sub credential {
+       my ($self, $credential, $op_or_code) = (_maybe_self(@_), 'fill');
+
+       if ('CODE' eq ref $op_or_code) {
+               _credential_run $credential, 'fill';
+               my $ret = $op_or_code->($credential);
+               if (defined $ret) {
+                       _credential_run $credential, $ret ? 'approve' : 'reject';
+               }
+               return $ret;
+       } else {
+               _credential_run $credential, $op_or_code;
+       }
+}
+
 { # %TEMP_* Lexical Context
 
 my (%TEMP_FILEMAP, %TEMP_FILES);
 
 =item temp_acquire ( NAME )
 
-Attempts to retreive the temporary file mapped to the string C<NAME>. If an
+Attempts to retrieve the temporary file mapped to the string C<NAME>. If an
 associated temp file has not been created this session or was closed, it is
 created, cached, and set for autoflush and binmode.
 
@@ -1375,9 +1529,11 @@ sub _setup_git_cmd_env {
 
 # Close pipe to a subprocess.
 sub _cmd_close {
-       my ($fh, $ctx) = @_;
-       if (not close $fh) {
-               if ($!) {
+       my $ctx = shift @_;
+       foreach my $fh (@_) {
+               if (close $fh) {
+                       # nop
+               } elsif ($!) {
                        # It's just close, no point in fatalities
                        carp "error closing pipe: $!";
                } elsif ($? >> 8) {
index 40dd8971912d6b387bde7c9bb04cc6896521acec..f889fd6da91d2d9b6a7469442a02e5478f094f8d 100644 (file)
@@ -68,7 +68,7 @@ =head1 SYNOPSIS
 
        print __("Welcome to Git!\n");
 
-       printf __("The following error occured: %s\n"), $error;
+       printf __("The following error occurred: %s\n"), $error;
 
 =head1 DESCRIPTION
 
index 049c97bfafac143e552f2e8ddb988292a6328df2..6a212eb7a8182acc00eb597d2100310b7855738a 100644 (file)
@@ -295,7 +295,7 @@ sub gs_do_switch {
        my $full_url = add_path_to_url( $self->url, $path );
        my ($ra, $reparented);
 
-       if ($old_url =~ m#^svn(\+ssh)?://# ||
+       if ($old_url =~ m#^svn(\+\w+)?://# ||
            ($full_url =~ m#^https?://# &&
             canonicalize_url($full_url) ne $full_url)) {
                $_[0] = undef;
index 11e9cd9a02eb3f85a9150c6fb06d1fc76abd9b09..6098135ae2b2d473729373b69e776f475cf919dd 100644 (file)
@@ -630,7 +630,7 @@ =head1 CLASS INTERFACE
 =head2 CONSTRUCTORS
 
 The C<Error> object is implemented as a HASH. This HASH is initialized
-with the arguments that are passed to it's constructor. The elements
+with the arguments that are passed to its constructor. The elements
 that are used by, or are retrievable by the C<Error> class are listed
 below, other classes may add to these.
 
@@ -763,13 +763,13 @@ =head1 PRE-DEFINED ERROR CLASSES
 
 =item Error::Simple
 
-This class can be used to hold simple error strings and values. It's
+This class can be used to hold simple error strings and values. Its
 constructor takes two arguments. The first is a text value, the second
 is a numeric value. These values are what will be returned by the
 overload methods.
 
 If the text value ends with C<at file line 1> as $@ strings do, then
-this infomation will be used to set the C<-file> and C<-line> arguments
+this information will be used to set the C<-file> and C<-line> arguments
 of the error object.
 
 This class is used internally if an eval'd block die's with an error
index eaba15f124b5d8247d39bd0844967cb5a9101ba8..70f19501d0e0c0dd625976519fd039d5c7a8b314 100644 (file)
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "pkt-line.h"
 
+char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
 static const char trace_key[] = "GIT_TRACE_PACKET";
 
@@ -46,38 +47,6 @@ static void packet_trace(const char *buf, unsigned int len, int write)
        strbuf_release(&out);
 }
 
-/*
- * Write a packetized stream, where each line is preceded by
- * its length (including the header) as a 4-byte hex number.
- * A length of 'zero' means end of stream (and a length of 1-3
- * would be an error).
- *
- * This is all pretty stupid, but we use this packetized line
- * format to make a streaming format possible without ever
- * over-running the read buffers. That way we'll never read
- * into what might be the pack data (which should go to another
- * process entirely).
- *
- * The writing side could use stdio, but since the reading
- * side can't, we stay with pure read/write interfaces.
- */
-ssize_t safe_write(int fd, const void *buf, ssize_t n)
-{
-       ssize_t nn = n;
-       while (n) {
-               int ret = xwrite(fd, buf, n);
-               if (ret > 0) {
-                       buf = (char *) buf + ret;
-                       n -= ret;
-                       continue;
-               }
-               if (!ret)
-                       die("write error (disk full?)");
-               die_errno("write error");
-       }
-       return nn;
-}
-
 /*
  * If we buffered things up above (we don't, but we should),
  * we'd flush it here
@@ -85,7 +54,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)
 void packet_flush(int fd)
 {
        packet_trace("0000", 4, 1);
-       safe_write(fd, "0000", 4);
+       write_or_die(fd, "0000", 4);
 }
 
 void packet_buf_flush(struct strbuf *buf)
@@ -121,7 +90,7 @@ void packet_write(int fd, const char *fmt, ...)
        va_start(args, fmt);
        n = format_packet(fmt, args);
        va_end(args);
-       safe_write(fd, buffer, n);
+       write_or_die(fd, buffer, n);
 }
 
 void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
@@ -135,13 +104,29 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
        strbuf_add(buf, buffer, n);
 }
 
-static int safe_read(int fd, void *buffer, unsigned size, int return_line_fail)
+static int get_packet_data(int fd, char **src_buf, size_t *src_size,
+                          void *dst, unsigned size, int options)
 {
-       ssize_t ret = read_in_full(fd, buffer, size);
-       if (ret < 0)
-               die_errno("read error");
-       else if (ret < size) {
-               if (return_line_fail)
+       ssize_t ret;
+
+       if (fd >= 0 && src_buf && *src_buf)
+               die("BUG: multiple sources given to packet_read");
+
+       /* Read up to "size" bytes from our source, whatever it is. */
+       if (src_buf && *src_buf) {
+               ret = size < *src_size ? size : *src_size;
+               memcpy(dst, *src_buf, ret);
+               *src_buf += ret;
+               *src_size -= ret;
+       } else {
+               ret = read_in_full(fd, dst, size);
+               if (ret < 0)
+                       die_errno("read error");
+       }
+
+       /* And complain if we didn't get enough bytes to satisfy the read. */
+       if (ret < size) {
+               if (options & PACKET_READ_GENTLE_ON_EOF)
                        return -1;
 
                die("The remote end hung up unexpectedly");
@@ -175,13 +160,14 @@ static int packet_length(const char *linelen)
        return len;
 }
 
-static int packet_read_internal(int fd, char *buffer, unsigned size, int return_line_fail)
+int packet_read(int fd, char **src_buf, size_t *src_len,
+               char *buffer, unsigned size, int options)
 {
        int len, ret;
        char linelen[4];
 
-       ret = safe_read(fd, linelen, 4, return_line_fail);
-       if (return_line_fail && ret < 0)
+       ret = get_packet_data(fd, src_buf, src_len, linelen, 4, options);
+       if (ret < 0)
                return ret;
        len = packet_length(linelen);
        if (len < 0)
@@ -193,50 +179,37 @@ static int packet_read_internal(int fd, char *buffer, unsigned size, int return_
        len -= 4;
        if (len >= size)
                die("protocol error: bad line length %d", len);
-       ret = safe_read(fd, buffer, len, return_line_fail);
-       if (return_line_fail && ret < 0)
+       ret = get_packet_data(fd, src_buf, src_len, buffer, len, options);
+       if (ret < 0)
                return ret;
+
+       if ((options & PACKET_READ_CHOMP_NEWLINE) &&
+           len && buffer[len-1] == '\n')
+               len--;
+
        buffer[len] = 0;
        packet_trace(buffer, len, 0);
        return len;
 }
 
-int packet_read(int fd, char *buffer, unsigned size)
+static char *packet_read_line_generic(int fd,
+                                     char **src, size_t *src_len,
+                                     int *dst_len)
 {
-       return packet_read_internal(fd, buffer, size, 1);
+       int len = packet_read(fd, src, src_len,
+                             packet_buffer, sizeof(packet_buffer),
+                             PACKET_READ_CHOMP_NEWLINE);
+       if (dst_len)
+               *dst_len = len;
+       return len ? packet_buffer : NULL;
 }
 
-int packet_read_line(int fd, char *buffer, unsigned size)
+char *packet_read_line(int fd, int *len_p)
 {
-       return packet_read_internal(fd, buffer, size, 0);
+       return packet_read_line_generic(fd, NULL, NULL, len_p);
 }
 
-int packet_get_line(struct strbuf *out,
-       char **src_buf, size_t *src_len)
+char *packet_read_line_buf(char **src, size_t *src_len, int *dst_len)
 {
-       int len;
-
-       if (*src_len < 4)
-               return -1;
-       len = packet_length(*src_buf);
-       if (len < 0)
-               return -1;
-       if (!len) {
-               *src_buf += 4;
-               *src_len -= 4;
-               packet_trace("0000", 4, 0);
-               return 0;
-       }
-       if (*src_len < len)
-               return -2;
-
-       *src_buf += 4;
-       *src_len -= 4;
-       len -= 4;
-
-       strbuf_add(out, *src_buf, len);
-       *src_buf += len;
-       *src_len -= len;
-       packet_trace(out->buf, out->len, 0);
-       return len;
+       return packet_read_line_generic(-1, src, src_len, dst_len);
 }
index 8cfeb0c31c8661bf11ce78d3679a21cd030ffb75..0a838d1656171019c07fe802d615ecaf78412003 100644 (file)
@@ -5,16 +5,78 @@
 #include "strbuf.h"
 
 /*
- * Silly packetized line writing interface
+ * Write a packetized stream, where each line is preceded by
+ * its length (including the header) as a 4-byte hex number.
+ * A length of 'zero' means end of stream (and a length of 1-3
+ * would be an error).
+ *
+ * This is all pretty stupid, but we use this packetized line
+ * format to make a streaming format possible without ever
+ * over-running the read buffers. That way we'll never read
+ * into what might be the pack data (which should go to another
+ * process entirely).
+ *
+ * The writing side could use stdio, but since the reading
+ * side can't, we stay with pure read/write interfaces.
  */
 void packet_flush(int fd);
 void packet_write(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 void packet_buf_flush(struct strbuf *buf);
 void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 
-int packet_read_line(int fd, char *buffer, unsigned size);
-int packet_read(int fd, char *buffer, unsigned size);
-int packet_get_line(struct strbuf *out, char **src_buf, size_t *src_len);
-ssize_t safe_write(int, const void *, ssize_t);
+/*
+ * Read a packetized line into the buffer, which must be at least size bytes
+ * long. The return value specifies the number of bytes read into the buffer.
+ *
+ * If src_buffer is not NULL (and nor is *src_buffer), it should point to a
+ * buffer containing the packet data to parse, of at least *src_len bytes.
+ * After the function returns, src_buf will be incremented and src_len
+ * decremented by the number of bytes consumed.
+ *
+ * If src_buffer (or *src_buffer) is NULL, then data is read from the
+ * descriptor "fd".
+ *
+ * If options does not contain PACKET_READ_GENTLE_ON_EOF, we will die under any
+ * of the following conditions:
+ *
+ *   1. Read error from descriptor.
+ *
+ *   2. Protocol error from the remote (e.g., bogus length characters).
+ *
+ *   3. Receiving a packet larger than "size" bytes.
+ *
+ *   4. Truncated output from the remote (e.g., we expected a packet but got
+ *      EOF, or we got a partial packet followed by EOF).
+ *
+ * If options does contain PACKET_READ_GENTLE_ON_EOF, we will not die on
+ * condition 4 (truncated input), but instead return -1. However, we will still
+ * die for the other 3 conditions.
+ *
+ * If options contains PACKET_READ_CHOMP_NEWLINE, a trailing newline (if
+ * present) is removed from the buffer before returning.
+ */
+#define PACKET_READ_GENTLE_ON_EOF (1u<<0)
+#define PACKET_READ_CHOMP_NEWLINE (1u<<1)
+int packet_read(int fd, char **src_buffer, size_t *src_len, char
+               *buffer, unsigned size, int options);
+
+/*
+ * Convenience wrapper for packet_read that is not gentle, and sets the
+ * CHOMP_NEWLINE option. The return value is NULL for a flush packet,
+ * and otherwise points to a static buffer (that may be overwritten by
+ * subsequent calls). If the size parameter is not NULL, the length of the
+ * packet is written to it.
+ */
+char *packet_read_line(int fd, int *size);
+
+/*
+ * Same as packet_read_line, but read from a buf rather than a descriptor;
+ * see packet_read for details on how src_* is used.
+ */
+char *packet_read_line_buf(char **src_buf, size_t *src_len, int *size);
+
+#define DEFAULT_PACKET_MAX 1000
+#define LARGE_PACKET_MAX 65520
+extern char packet_buffer[LARGE_PACKET_MAX];
 
 #endif
index c1520e8cdeaf5ab5c52d2ae057582cd8f32b7fe6..d8c9111c82a541a39d71465c9b18a626d2dea94e 100644 (file)
--- a/po/README
+++ b/po/README
@@ -232,7 +232,7 @@ Shell:
 
        # To interpolate variables:
        details="oh noes"
-       eval_gettext "An error occured: \$details"; echo
+       eval_gettext "An error occurred: \$details"; echo
 
    In addition we have wrappers for messages that end with a trailing
    newline. I.e. you could write the above as:
@@ -242,7 +242,7 @@ Shell:
 
        # To interpolate variables:
        details="oh noes"
-       eval_gettextln "An error occured: \$details"
+       eval_gettextln "An error occurred: \$details"
 
    More documentation about the interface is available in the GNU info
    page: `info '(gettext)sh'`. Looking at git-am.sh (the first shell
@@ -257,7 +257,7 @@ Perl:
 
        use Git::I18N;
        print __("Welcome to Git!\n");
-       printf __("The following error occured: %s\n"), $error;
+       printf __("The following error occurred: %s\n"), $error;
 
    Run `perldoc perl/Git/I18N.pm` for more info.
 
index 41f04e669d3b9c38f49e0853053a6ba27b97357a..d3a82d22d398ae7234f8917f4d8b0770ba4d0c47 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -766,14 +766,7 @@ struct format_commit_context {
        const struct pretty_print_context *pretty_ctx;
        unsigned commit_header_parsed:1;
        unsigned commit_message_parsed:1;
-       unsigned commit_signature_parsed:1;
-       struct {
-               char *gpg_output;
-               char *gpg_status;
-               char good_bad;
-               char *signer;
-               char *key;
-       } signature;
+       struct signature_check signature_check;
        char *message;
        size_t width, indent1, indent2;
 
@@ -956,64 +949,6 @@ static void rewrap_message_tail(struct strbuf *sb,
        c->indent2 = new_indent2;
 }
 
-static struct {
-       char result;
-       const char *check;
-} signature_check[] = {
-       { 'G', "\n[GNUPG:] GOODSIG " },
-       { 'B', "\n[GNUPG:] BADSIG " },
-};
-
-static void parse_signature_lines(struct format_commit_context *ctx)
-{
-       const char *buf = ctx->signature.gpg_status;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(signature_check); i++) {
-               const char *found = strstr(buf, signature_check[i].check);
-               const char *next;
-               if (!found)
-                       continue;
-               ctx->signature.good_bad = signature_check[i].result;
-               found += strlen(signature_check[i].check);
-               ctx->signature.key = xmemdupz(found, 16);
-               found += 17;
-               next = strchrnul(found, '\n');
-               ctx->signature.signer = xmemdupz(found, next - found);
-               break;
-       }
-}
-
-static void parse_commit_signature(struct format_commit_context *ctx)
-{
-       struct strbuf payload = STRBUF_INIT;
-       struct strbuf signature = STRBUF_INIT;
-       struct strbuf gpg_output = STRBUF_INIT;
-       struct strbuf gpg_status = STRBUF_INIT;
-       int status;
-
-       ctx->commit_signature_parsed = 1;
-
-       if (parse_signed_commit(ctx->commit->object.sha1,
-                               &payload, &signature) <= 0)
-               goto out;
-       status = verify_signed_buffer(payload.buf, payload.len,
-                                     signature.buf, signature.len,
-                                     &gpg_output, &gpg_status);
-       if (status && !gpg_output.len)
-               goto out;
-       ctx->signature.gpg_output = strbuf_detach(&gpg_output, NULL);
-       ctx->signature.gpg_status = strbuf_detach(&gpg_status, NULL);
-       parse_signature_lines(ctx);
-
- out:
-       strbuf_release(&gpg_status);
-       strbuf_release(&gpg_output);
-       strbuf_release(&payload);
-       strbuf_release(&signature);
-}
-
-
 static int format_reflog_person(struct strbuf *sb,
                                char part,
                                struct reflog_walk_info *log,
@@ -1199,27 +1134,29 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
        }
 
        if (placeholder[0] == 'G') {
-               if (!c->commit_signature_parsed)
-                       parse_commit_signature(c);
+               if (!c->signature_check.result)
+                       check_commit_signature(c->commit, &(c->signature_check));
                switch (placeholder[1]) {
                case 'G':
-                       if (c->signature.gpg_output)
-                               strbuf_addstr(sb, c->signature.gpg_output);
+                       if (c->signature_check.gpg_output)
+                               strbuf_addstr(sb, c->signature_check.gpg_output);
                        break;
                case '?':
-                       switch (c->signature.good_bad) {
+                       switch (c->signature_check.result) {
                        case 'G':
                        case 'B':
-                               strbuf_addch(sb, c->signature.good_bad);
+                       case 'U':
+                       case 'N':
+                               strbuf_addch(sb, c->signature_check.result);
                        }
                        break;
                case 'S':
-                       if (c->signature.signer)
-                               strbuf_addstr(sb, c->signature.signer);
+                       if (c->signature_check.signer)
+                               strbuf_addstr(sb, c->signature_check.signer);
                        break;
                case 'K':
-                       if (c->signature.key)
-                               strbuf_addstr(sb, c->signature.key);
+                       if (c->signature_check.key)
+                               strbuf_addstr(sb, c->signature_check.key);
                        break;
                }
                return 2;
@@ -1357,8 +1294,8 @@ void format_commit_message(const struct commit *commit,
        rewrap_message_tail(sb, &context, 0, 0, 0);
 
        logmsg_free(context.message, commit);
-       free(context.signature.gpg_output);
-       free(context.signature.signer);
+       free(context.signature_check.gpg_output);
+       free(context.signature_check.signer);
 }
 
 static void pp_header(const struct pretty_print_context *pp,
diff --git a/refs.c b/refs.c
index e2b760d0baffd6db6b49e6014a58efa062f1a119..de2d8eb866062649a0d0f23a77e350bca1a182cd 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2332,59 +2332,117 @@ int read_ref_at(const char *refname, unsigned long at_time, int cnt,
        return 1;
 }
 
-int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long ofs, void *cb_data)
+static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
+{
+       unsigned char osha1[20], nsha1[20];
+       char *email_end, *message;
+       unsigned long timestamp;
+       int tz;
+
+       /* old SP new SP name <email> SP time TAB msg LF */
+       if (sb->len < 83 || sb->buf[sb->len - 1] != '\n' ||
+           get_sha1_hex(sb->buf, osha1) || sb->buf[40] != ' ' ||
+           get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' ||
+           !(email_end = strchr(sb->buf + 82, '>')) ||
+           email_end[1] != ' ' ||
+           !(timestamp = strtoul(email_end + 2, &message, 10)) ||
+           !message || message[0] != ' ' ||
+           (message[1] != '+' && message[1] != '-') ||
+           !isdigit(message[2]) || !isdigit(message[3]) ||
+           !isdigit(message[4]) || !isdigit(message[5]))
+               return 0; /* corrupt? */
+       email_end[1] = '\0';
+       tz = strtol(message + 1, NULL, 10);
+       if (message[6] != '\t')
+               message += 6;
+       else
+               message += 7;
+       return fn(osha1, nsha1, sb->buf + 82, timestamp, tz, message, cb_data);
+}
+
+static char *find_beginning_of_line(char *bob, char *scan)
+{
+       while (bob < scan && *(--scan) != '\n')
+               ; /* keep scanning backwards */
+       /*
+        * Return either beginning of the buffer, or LF at the end of
+        * the previous line.
+        */
+       return scan;
+}
+
+int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void *cb_data)
 {
-       const char *logfile;
-       FILE *logfp;
        struct strbuf sb = STRBUF_INIT;
-       int ret = 0;
+       FILE *logfp;
+       long pos;
+       int ret = 0, at_tail = 1;
 
-       logfile = git_path("logs/%s", refname);
-       logfp = fopen(logfile, "r");
+       logfp = fopen(git_path("logs/%s", refname), "r");
        if (!logfp)
                return -1;
 
-       if (ofs) {
-               struct stat statbuf;
-               if (fstat(fileno(logfp), &statbuf) ||
-                   statbuf.st_size < ofs ||
-                   fseek(logfp, -ofs, SEEK_END) ||
-                   strbuf_getwholeline(&sb, logfp, '\n')) {
-                       fclose(logfp);
-                       strbuf_release(&sb);
-                       return -1;
+       /* Jump to the end */
+       if (fseek(logfp, 0, SEEK_END) < 0)
+               return error("cannot seek back reflog for %s: %s",
+                            refname, strerror(errno));
+       pos = ftell(logfp);
+       while (!ret && 0 < pos) {
+               int cnt;
+               size_t nread;
+               char buf[BUFSIZ];
+               char *endp, *scanp;
+
+               /* Fill next block from the end */
+               cnt = (sizeof(buf) < pos) ? sizeof(buf) : pos;
+               if (fseek(logfp, pos - cnt, SEEK_SET))
+                       return error("cannot seek back reflog for %s: %s",
+                                    refname, strerror(errno));
+               nread = fread(buf, cnt, 1, logfp);
+               if (nread != 1)
+                       return error("cannot read %d bytes from reflog for %s: %s",
+                                    cnt, refname, strerror(errno));
+               pos -= cnt;
+
+               scanp = endp = buf + cnt;
+               if (at_tail && scanp[-1] == '\n')
+                       /* Looking at the final LF at the end of the file */
+                       scanp--;
+               at_tail = 0;
+
+               while (buf < scanp) {
+                       /*
+                        * terminating LF of the previous line, or the beginning
+                        * of the buffer.
+                        */
+                       char *bp;
+
+                       bp = find_beginning_of_line(buf, scanp);
+
+                       if (*bp != '\n') {
+                               strbuf_splice(&sb, 0, 0, buf, endp - buf);
+                               if (pos)
+                                       break; /* need to fill another block */
+                               scanp = buf - 1; /* leave loop */
+                       } else {
+                               /*
+                                * (bp + 1) thru endp is the beginning of the
+                                * current line we have in sb
+                                */
+                               strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));
+                               scanp = bp;
+                               endp = bp + 1;
+                       }
+                       ret = show_one_reflog_ent(&sb, fn, cb_data);
+                       strbuf_reset(&sb);
+                       if (ret)
+                               break;
                }
-       }
 
-       while (!strbuf_getwholeline(&sb, logfp, '\n')) {
-               unsigned char osha1[20], nsha1[20];
-               char *email_end, *message;
-               unsigned long timestamp;
-               int tz;
-
-               /* old SP new SP name <email> SP time TAB msg LF */
-               if (sb.len < 83 || sb.buf[sb.len - 1] != '\n' ||
-                   get_sha1_hex(sb.buf, osha1) || sb.buf[40] != ' ' ||
-                   get_sha1_hex(sb.buf + 41, nsha1) || sb.buf[81] != ' ' ||
-                   !(email_end = strchr(sb.buf + 82, '>')) ||
-                   email_end[1] != ' ' ||
-                   !(timestamp = strtoul(email_end + 2, &message, 10)) ||
-                   !message || message[0] != ' ' ||
-                   (message[1] != '+' && message[1] != '-') ||
-                   !isdigit(message[2]) || !isdigit(message[3]) ||
-                   !isdigit(message[4]) || !isdigit(message[5]))
-                       continue; /* corrupt? */
-               email_end[1] = '\0';
-               tz = strtol(message + 1, NULL, 10);
-               if (message[6] != '\t')
-                       message += 6;
-               else
-                       message += 7;
-               ret = fn(osha1, nsha1, sb.buf + 82, timestamp, tz, message,
-                        cb_data);
-               if (ret)
-                       break;
        }
+       if (!ret && sb.len)
+               ret = show_one_reflog_ent(&sb, fn, cb_data);
+
        fclose(logfp);
        strbuf_release(&sb);
        return ret;
@@ -2392,9 +2450,20 @@ int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long
 
 int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data)
 {
-       return for_each_recent_reflog_ent(refname, fn, 0, cb_data);
-}
+       FILE *logfp;
+       struct strbuf sb = STRBUF_INIT;
+       int ret = 0;
+
+       logfp = fopen(git_path("logs/%s", refname), "r");
+       if (!logfp)
+               return -1;
 
+       while (!ret && !strbuf_getwholeline(&sb, logfp, '\n'))
+               ret = show_one_reflog_ent(&sb, fn, cb_data);
+       fclose(logfp);
+       strbuf_release(&sb);
+       return ret;
+}
 /*
  * Call fn for each reflog in the namespace indicated by name.  name
  * must be empty or end with '/'.  Name will be used as a scratch
diff --git a/refs.h b/refs.h
index 1b2e2d3a98dea86bbe54dd21782ce58681636c32..a35eafc4ee15493c1473d71b5c2e83a1f9137c1a 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -103,7 +103,7 @@ extern int read_ref_at(const char *refname, unsigned long at_time, int cnt,
 /* iterate over reflog entries */
 typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *);
 int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data);
-int for_each_recent_reflog_ent(const char *refname, each_reflog_ent_fn fn, long, void *cb_data);
+int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void *cb_data);
 
 /*
  * Calls the specified function for each reflog file until it returns nonzero,
index 933c69ac2627c1903276b92b457843e12649f39e..93a09a64c3b1689b0f29a26c6cdd601ef298b975 100644 (file)
@@ -76,21 +76,82 @@ struct discovery {
        char *buf_alloc;
        char *buf;
        size_t len;
+       struct ref *refs;
        unsigned proto_git : 1;
 };
 static struct discovery *last_discovery;
 
+static struct ref *parse_git_refs(struct discovery *heads, int for_push)
+{
+       struct ref *list = NULL;
+       get_remote_heads(-1, heads->buf, heads->len, &list,
+                        for_push ? REF_NORMAL : 0, NULL);
+       return list;
+}
+
+static struct ref *parse_info_refs(struct discovery *heads)
+{
+       char *data, *start, *mid;
+       char *ref_name;
+       int i = 0;
+
+       struct ref *refs = NULL;
+       struct ref *ref = NULL;
+       struct ref *last_ref = NULL;
+
+       data = heads->buf;
+       start = NULL;
+       mid = data;
+       while (i < heads->len) {
+               if (!start) {
+                       start = &data[i];
+               }
+               if (data[i] == '\t')
+                       mid = &data[i];
+               if (data[i] == '\n') {
+                       if (mid - start != 40)
+                               die("%sinfo/refs not valid: is this a git repository?", url);
+                       data[i] = 0;
+                       ref_name = mid + 1;
+                       ref = xmalloc(sizeof(struct ref) +
+                                     strlen(ref_name) + 1);
+                       memset(ref, 0, sizeof(struct ref));
+                       strcpy(ref->name, ref_name);
+                       get_sha1_hex(start, ref->old_sha1);
+                       if (!refs)
+                               refs = ref;
+                       if (last_ref)
+                               last_ref->next = ref;
+                       last_ref = ref;
+                       start = NULL;
+               }
+               i++;
+       }
+
+       ref = alloc_ref("HEAD");
+       if (!http_fetch_ref(url, ref) &&
+           !resolve_remote_symref(ref, refs)) {
+               ref->next = refs;
+               refs = ref;
+       } else {
+               free(ref);
+       }
+
+       return refs;
+}
+
 static void free_discovery(struct discovery *d)
 {
        if (d) {
                if (d == last_discovery)
                        last_discovery = NULL;
                free(d->buf_alloc);
+               free_refs(d->refs);
                free(d);
        }
 }
 
-static struct discovery* discover_refs(const char *service)
+static struct discovery* discover_refs(const char *service, int for_push)
 {
        struct strbuf exp = STRBUF_INIT;
        struct strbuf type = STRBUF_INIT;
@@ -138,32 +199,35 @@ static struct discovery* discover_refs(const char *service)
        if (maybe_smart &&
            (5 <= last->len && last->buf[4] == '#') &&
            !strbuf_cmp(&exp, &type)) {
+               char *line;
+
                /*
                 * smart HTTP response; validate that the service
                 * pkt-line matches our request.
                 */
-               if (packet_get_line(&buffer, &last->buf, &last->len) <= 0)
-                       die("%s has invalid packet header", refs_url);
-               if (buffer.len && buffer.buf[buffer.len - 1] == '\n')
-                       strbuf_setlen(&buffer, buffer.len - 1);
+               line = packet_read_line_buf(&last->buf, &last->len, NULL);
 
                strbuf_reset(&exp);
                strbuf_addf(&exp, "# service=%s", service);
-               if (strbuf_cmp(&exp, &buffer))
-                       die("invalid server response; got '%s'", buffer.buf);
+               if (strcmp(line, exp.buf))
+                       die("invalid server response; got '%s'", line);
                strbuf_release(&exp);
 
                /* The header can include additional metadata lines, up
                 * until a packet flush marker.  Ignore these now, but
                 * in the future we might start to scan them.
                 */
-               strbuf_reset(&buffer);
-               while (packet_get_line(&buffer, &last->buf, &last->len) > 0)
-                       strbuf_reset(&buffer);
+               while (packet_read_line_buf(&last->buf, &last->len, NULL))
+                       ;
 
                last->proto_git = 1;
        }
 
+       if (last->proto_git)
+               last->refs = parse_git_refs(last, for_push);
+       else
+               last->refs = parse_info_refs(last);
+
        free(refs_url);
        strbuf_release(&exp);
        strbuf_release(&type);
@@ -172,99 +236,16 @@ static struct discovery* discover_refs(const char *service)
        return last;
 }
 
-static int write_discovery(int in, int out, void *data)
-{
-       struct discovery *heads = data;
-       int err = 0;
-       if (write_in_full(out, heads->buf, heads->len) != heads->len)
-               err = 1;
-       close(out);
-       return err;
-}
-
-static struct ref *parse_git_refs(struct discovery *heads, int for_push)
-{
-       struct ref *list = NULL;
-       struct async async;
-
-       memset(&async, 0, sizeof(async));
-       async.proc = write_discovery;
-       async.data = heads;
-       async.out = -1;
-
-       if (start_async(&async))
-               die("cannot start thread to parse advertised refs");
-       get_remote_heads(async.out, &list,
-                       for_push ? REF_NORMAL : 0, NULL);
-       close(async.out);
-       if (finish_async(&async))
-               die("ref parsing thread failed");
-       return list;
-}
-
-static struct ref *parse_info_refs(struct discovery *heads)
-{
-       char *data, *start, *mid;
-       char *ref_name;
-       int i = 0;
-
-       struct ref *refs = NULL;
-       struct ref *ref = NULL;
-       struct ref *last_ref = NULL;
-
-       data = heads->buf;
-       start = NULL;
-       mid = data;
-       while (i < heads->len) {
-               if (!start) {
-                       start = &data[i];
-               }
-               if (data[i] == '\t')
-                       mid = &data[i];
-               if (data[i] == '\n') {
-                       if (mid - start != 40)
-                               die("%sinfo/refs not valid: is this a git repository?", url);
-                       data[i] = 0;
-                       ref_name = mid + 1;
-                       ref = xmalloc(sizeof(struct ref) +
-                                     strlen(ref_name) + 1);
-                       memset(ref, 0, sizeof(struct ref));
-                       strcpy(ref->name, ref_name);
-                       get_sha1_hex(start, ref->old_sha1);
-                       if (!refs)
-                               refs = ref;
-                       if (last_ref)
-                               last_ref->next = ref;
-                       last_ref = ref;
-                       start = NULL;
-               }
-               i++;
-       }
-
-       ref = alloc_ref("HEAD");
-       if (!http_fetch_ref(url, ref) &&
-           !resolve_remote_symref(ref, refs)) {
-               ref->next = refs;
-               refs = ref;
-       } else {
-               free(ref);
-       }
-
-       return refs;
-}
-
 static struct ref *get_refs(int for_push)
 {
        struct discovery *heads;
 
        if (for_push)
-               heads = discover_refs("git-receive-pack");
+               heads = discover_refs("git-receive-pack", for_push);
        else
-               heads = discover_refs("git-upload-pack");
+               heads = discover_refs("git-upload-pack", for_push);
 
-       if (heads->proto_git)
-               return parse_git_refs(heads, for_push);
-       return parse_info_refs(heads);
+       return heads->refs;
 }
 
 static void output_refs(struct ref *refs)
@@ -278,7 +259,6 @@ static void output_refs(struct ref *refs)
        }
        printf("\n");
        fflush(stdout);
-       free_refs(refs);
 }
 
 struct rpc_state {
@@ -308,7 +288,7 @@ static size_t rpc_out(void *ptr, size_t eltsize,
 
        if (!avail) {
                rpc->initial_buffer = 0;
-               avail = packet_read_line(rpc->out, rpc->buf, rpc->alloc);
+               avail = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
                if (!avail)
                        return 0;
                rpc->pos = 0;
@@ -425,7 +405,7 @@ static int post_rpc(struct rpc_state *rpc)
                        break;
                }
 
-               n = packet_read_line(rpc->out, buf, left);
+               n = packet_read(rpc->out, NULL, NULL, buf, left, 0);
                if (!n)
                        break;
                rpc->len += n;
@@ -579,7 +559,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
        rpc->hdr_accept = strbuf_detach(&buf, NULL);
 
        while (!err) {
-               int n = packet_read_line(rpc->out, rpc->buf, rpc->alloc);
+               int n = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
                if (!n)
                        break;
                rpc->pos = 0;
@@ -685,7 +665,7 @@ static int fetch_git(struct discovery *heads,
 
        err = rpc_service(&rpc, heads);
        if (rpc.result.len)
-               safe_write(1, rpc.result.buf, rpc.result.len);
+               write_or_die(1, rpc.result.buf, rpc.result.len);
        strbuf_release(&rpc.result);
        strbuf_release(&preamble);
        free(depth_arg);
@@ -694,7 +674,7 @@ static int fetch_git(struct discovery *heads,
 
 static int fetch(int nr_heads, struct ref **to_fetch)
 {
-       struct discovery *d = discover_refs("git-upload-pack");
+       struct discovery *d = discover_refs("git-upload-pack", 0);
        if (d->proto_git)
                return fetch_git(d, nr_heads, to_fetch);
        else
@@ -805,7 +785,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
 
        err = rpc_service(&rpc, heads);
        if (rpc.result.len)
-               safe_write(1, rpc.result.buf, rpc.result.len);
+               write_or_die(1, rpc.result.buf, rpc.result.len);
        strbuf_release(&rpc.result);
        free(argv);
        return err;
@@ -813,7 +793,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
 
 static int push(int nr_spec, char **specs)
 {
-       struct discovery *heads = discover_refs("git-receive-pack");
+       struct discovery *heads = discover_refs("git-receive-pack", 1);
        int ret;
 
        if (heads->proto_git)
index e53a6eb7769e2884f77819c73423c31e49b0114e..68eb99bdf0ca3fedd02ab1bc93db7549b21b62d4 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -15,6 +15,7 @@ static struct refspec s_tag_refspec = {
        0,
        1,
        0,
+       0,
        "refs/tags/*",
        "refs/tags/*"
 };
@@ -48,6 +49,7 @@ static int branches_nr;
 
 static struct branch *current_branch;
 static const char *default_remote_name;
+static const char *pushremote_name;
 static int explicit_default_remote_name;
 
 static struct rewrites rewrites;
@@ -356,13 +358,16 @@ static int handle_config(const char *key, const char *value, void *cb)
                        return 0;
                branch = make_branch(name, subkey - name);
                if (!strcmp(subkey, ".remote")) {
-                       if (!value)
-                               return config_error_nonbool(key);
-                       branch->remote_name = xstrdup(value);
+                       if (git_config_string(&branch->remote_name, key, value))
+                               return -1;
                        if (branch == current_branch) {
                                default_remote_name = branch->remote_name;
                                explicit_default_remote_name = 1;
                        }
+               } else if (!strcmp(subkey, ".pushremote")) {
+                       if (branch == current_branch)
+                               if (git_config_string(&pushremote_name, key, value))
+                                       return -1;
                } else if (!strcmp(subkey, ".merge")) {
                        if (!value)
                                return config_error_nonbool(key);
@@ -388,9 +393,16 @@ static int handle_config(const char *key, const char *value, void *cb)
                        add_instead_of(rewrite, xstrdup(value));
                }
        }
+
        if (prefixcmp(key,  "remote."))
                return 0;
        name = key + 7;
+
+       /* Handle remote.* variables */
+       if (!strcmp(name, "pushdefault"))
+               return git_config_string(&pushremote_name, key, value);
+
+       /* Handle remote.<name>.* variables */
        if (*name == '/') {
                warning("Config remote shorthand cannot begin with '/': %s",
                        name);
@@ -538,7 +550,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
 
                /*
                 * Before going on, special case ":" (or "+:") as a refspec
-                * for matching refs.
+                * for pushing matching refs.
                 */
                if (!fetch && rhs == lhs && rhs[1] == '\0') {
                        rs[i].matching = 1;
@@ -565,26 +577,25 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
                flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
 
                if (fetch) {
-                       /*
-                        * LHS
-                        * - empty is allowed; it means HEAD.
-                        * - otherwise it must be a valid looking ref.
-                        */
+                       unsigned char unused[40];
+
+                       /* LHS */
                        if (!*rs[i].src)
-                               ; /* empty is ok */
-                       else if (check_refname_format(rs[i].src, flags))
+                               ; /* empty is ok; it means "HEAD" */
+                       else if (llen == 40 && !get_sha1_hex(rs[i].src, unused))
+                               rs[i].exact_sha1 = 1; /* ok */
+                       else if (!check_refname_format(rs[i].src, flags))
+                               ; /* valid looking ref is ok */
+                       else
                                goto invalid;
-                       /*
-                        * RHS
-                        * - missing is ok, and is same as empty.
-                        * - empty is ok; it means not to store.
-                        * - otherwise it must be a valid looking ref.
-                        */
+                       /* RHS */
                        if (!rs[i].dst)
-                               ; /* ok */
+                               ; /* missing is ok; it is the same as empty */
                        else if (!*rs[i].dst)
-                               ; /* ok */
-                       else if (check_refname_format(rs[i].dst, flags))
+                               ; /* empty is ok; it means "do not store" */
+                       else if (!check_refname_format(rs[i].dst, flags))
+                               ; /* valid looking ref is ok */
+                       else
                                goto invalid;
                } else {
                        /*
@@ -671,17 +682,21 @@ static int valid_remote_nick(const char *name)
        return !strchr(name, '/'); /* no slash */
 }
 
-struct remote *remote_get(const char *name)
+static struct remote *remote_get_1(const char *name, const char *pushremote_name)
 {
        struct remote *ret;
        int name_given = 0;
 
-       read_config();
        if (name)
                name_given = 1;
        else {
-               name = default_remote_name;
-               name_given = explicit_default_remote_name;
+               if (pushremote_name) {
+                       name = pushremote_name;
+                       name_given = 1;
+               } else {
+                       name = default_remote_name;
+                       name_given = explicit_default_remote_name;
+               }
        }
 
        ret = make_remote(name, 0);
@@ -700,6 +715,18 @@ struct remote *remote_get(const char *name)
        return ret;
 }
 
+struct remote *remote_get(const char *name)
+{
+       read_config();
+       return remote_get_1(name, NULL);
+}
+
+struct remote *pushremote_get(const char *name)
+{
+       read_config();
+       return remote_get_1(name, pushremote_name);
+}
+
 int remote_is_configured(const char *name)
 {
        int i;
@@ -1195,6 +1222,101 @@ static struct ref **tail_ref(struct ref **head)
        return tail;
 }
 
+struct tips {
+       struct commit **tip;
+       int nr, alloc;
+};
+
+static void add_to_tips(struct tips *tips, const unsigned char *sha1)
+{
+       struct commit *commit;
+
+       if (is_null_sha1(sha1))
+               return;
+       commit = lookup_commit_reference_gently(sha1, 1);
+       if (!commit || (commit->object.flags & TMP_MARK))
+               return;
+       commit->object.flags |= TMP_MARK;
+       ALLOC_GROW(tips->tip, tips->nr + 1, tips->alloc);
+       tips->tip[tips->nr++] = commit;
+}
+
+static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***dst_tail)
+{
+       struct string_list dst_tag = STRING_LIST_INIT_NODUP;
+       struct string_list src_tag = STRING_LIST_INIT_NODUP;
+       struct string_list_item *item;
+       struct ref *ref;
+       struct tips sent_tips;
+
+       /*
+        * Collect everything we know they would have at the end of
+        * this push, and collect all tags they have.
+        */
+       memset(&sent_tips, 0, sizeof(sent_tips));
+       for (ref = *dst; ref; ref = ref->next) {
+               if (ref->peer_ref &&
+                   !is_null_sha1(ref->peer_ref->new_sha1))
+                       add_to_tips(&sent_tips, ref->peer_ref->new_sha1);
+               else
+                       add_to_tips(&sent_tips, ref->old_sha1);
+               if (!prefixcmp(ref->name, "refs/tags/"))
+                       string_list_append(&dst_tag, ref->name);
+       }
+       clear_commit_marks_many(sent_tips.nr, sent_tips.tip, TMP_MARK);
+
+       sort_string_list(&dst_tag);
+
+       /* Collect tags they do not have. */
+       for (ref = src; ref; ref = ref->next) {
+               if (prefixcmp(ref->name, "refs/tags/"))
+                       continue; /* not a tag */
+               if (string_list_has_string(&dst_tag, ref->name))
+                       continue; /* they already have it */
+               if (sha1_object_info(ref->new_sha1, NULL) != OBJ_TAG)
+                       continue; /* be conservative */
+               item = string_list_append(&src_tag, ref->name);
+               item->util = ref;
+       }
+       string_list_clear(&dst_tag, 0);
+
+       /*
+        * At this point, src_tag lists tags that are missing from
+        * dst, and sent_tips lists the tips we are pushing or those
+        * that we know they already have. An element in the src_tag
+        * that is an ancestor of any of the sent_tips needs to be
+        * sent to the other side.
+        */
+       if (sent_tips.nr) {
+               for_each_string_list_item(item, &src_tag) {
+                       struct ref *ref = item->util;
+                       struct ref *dst_ref;
+                       struct commit *commit;
+
+                       if (is_null_sha1(ref->new_sha1))
+                               continue;
+                       commit = lookup_commit_reference_gently(ref->new_sha1, 1);
+                       if (!commit)
+                               /* not pushing a commit, which is not an error */
+                               continue;
+
+                       /*
+                        * Is this tag, which they do not have, reachable from
+                        * any of the commits we are sending?
+                        */
+                       if (!in_merge_bases_many(commit, sent_tips.nr, sent_tips.tip))
+                               continue;
+
+                       /* Add it in */
+                       dst_ref = make_linked_ref(ref->name, dst_tail);
+                       hashcpy(dst_ref->new_sha1, ref->new_sha1);
+                       dst_ref->peer_ref = copy_ref(ref);
+               }
+       }
+       string_list_clear(&src_tag, 0);
+       free(sent_tips.tip);
+}
+
 /*
  * Given the set of refs the local repository has, the set of refs the
  * remote repository has, and the refspec used for push, determine
@@ -1227,9 +1349,6 @@ int match_push_refs(struct ref *src, struct ref **dst,
                const struct refspec *pat = NULL;
                char *dst_name;
 
-               if (ref->peer_ref)
-                       continue;
-
                dst_name = get_ref_match(rs, nr_refspec, ref, send_mirror, FROM_SRC, &pat);
                if (!dst_name)
                        continue;
@@ -1257,6 +1376,10 @@ int match_push_refs(struct ref *src, struct ref **dst,
        free_name:
                free(dst_name);
        }
+
+       if (flags & MATCH_REFS_FOLLOW_TAGS)
+               add_missing_tags(src, dst, &dst_tail);
+
        if (send_prune) {
                /* check for missing refs on the remote */
                for (ref = *dst; ref; ref = ref->next) {
@@ -1466,7 +1589,12 @@ int get_fetch_map(const struct ref *remote_refs,
        } else {
                const char *name = refspec->src[0] ? refspec->src : "HEAD";
 
-               ref_map = get_remote_ref(remote_refs, name);
+               if (refspec->exact_sha1) {
+                       ref_map = alloc_ref(name);
+                       get_sha1_hex(name, ref_map->old_sha1);
+               } else {
+                       ref_map = get_remote_ref(remote_refs, name);
+               }
                if (!missing_ok && !ref_map)
                        die("Couldn't find remote ref %s", name);
                if (ref_map) {
index 251d8fd9654f23e7a131765742803492fb0d9041..cf5672466151254b92582ba4729a2a95e670beff 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -51,6 +51,7 @@ struct remote {
 };
 
 struct remote *remote_get(const char *name);
+struct remote *pushremote_get(const char *name);
 int remote_is_configured(const char *name);
 
 typedef int each_remote_fn(struct remote *remote, void *priv);
@@ -62,6 +63,7 @@ struct refspec {
        unsigned force : 1;
        unsigned pattern : 1;
        unsigned matching : 1;
+       unsigned exact_sha1 : 1;
 
        char *src;
        char *dst;
@@ -148,7 +150,8 @@ enum match_refs_flags {
        MATCH_REFS_NONE         = 0,
        MATCH_REFS_ALL          = (1 << 0),
        MATCH_REFS_MIRROR       = (1 << 1),
-       MATCH_REFS_PRUNE        = (1 << 2)
+       MATCH_REFS_PRUNE        = (1 << 2),
+       MATCH_REFS_FOLLOW_TAGS  = (1 << 3)
 };
 
 /* Reporting of tracking info */
index a6a5cd57bef4aaf204f1bad293c18b5af6f57f53..98e3e294d0dc295290b7b891a834186c0791e43a 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -284,8 +284,10 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
        strbuf_release(sb);
        if (!io->input.len)
                return -1;
-       ep = strchrnul(io->input.buf, '\n');
-       if (*ep == '\n')
+       ep = memchr(io->input.buf, '\n', io->input.len);
+       if (!ep)
+               ep = io->input.buf + io->input.len;
+       else if (*ep == '\n')
                ep++;
        len = ep - io->input.buf;
        strbuf_add(sb, io->input.buf, len);
@@ -295,7 +297,7 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
 
 static int handle_cache(const char *path, unsigned char *sha1, const char *output)
 {
-       mmfile_t mmfile[3];
+       mmfile_t mmfile[3] = {{NULL}};
        mmbuffer_t result = {NULL, 0};
        struct cache_entry *ce;
        int pos, len, i, hunk_no;
@@ -314,17 +316,16 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
        for (i = 0; i < 3; i++) {
                enum object_type type;
                unsigned long size;
+               int j;
 
-               mmfile[i].size = 0;
-               mmfile[i].ptr = NULL;
                if (active_nr <= pos)
                        break;
                ce = active_cache[pos++];
-               if (ce_namelen(ce) != len || memcmp(ce->name, path, len)
-                   || ce_stage(ce) != i + 1)
-                       break;
-               mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
-               mmfile[i].size = size;
+               if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
+                       continue;
+               j = ce_stage(ce) - 1;
+               mmfile[j].ptr = read_sha1_file(ce->sha1, &type, &size);
+               mmfile[j].size = size;
        }
        for (i = 0; i < 3; i++) {
                if (!mmfile[i].ptr && !mmfile[i].size)
index 72b46125b719861641a55ee8fd534e0d1f47a94f..639eb9c59f355e46bdd53cf13fd94e8a6a9537da 100644 (file)
@@ -118,7 +118,7 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
        struct cache_entry *ce;
        struct string_list_item *item;
        struct resolve_undo_info *ru;
-       int i, err = 0;
+       int i, err = 0, matched;
 
        if (!istate->resolve_undo)
                return pos;
@@ -137,6 +137,7 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
        ru = item->util;
        if (!ru)
                return pos;
+       matched = ce->ce_flags & CE_MATCHED;
        remove_index_entry_at(istate, pos);
        for (i = 0; i < 3; i++) {
                struct cache_entry *nce;
@@ -144,6 +145,8 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
                        continue;
                nce = make_cache_entry(ru->mode[i], ru->sha1[i],
                                       ce->name, i + 1, 0);
+               if (matched)
+                       nce->ce_flags |= CE_MATCHED;
                if (add_index_entry(istate, nce, ADD_CACHE_OK_TO_ADD)) {
                        err = 1;
                        error("cannot unmerge '%s'", ce->name);
@@ -156,6 +159,20 @@ int unmerge_index_entry_at(struct index_state *istate, int pos)
        return unmerge_index_entry_at(istate, pos);
 }
 
+void unmerge_marked_index(struct index_state *istate)
+{
+       int i;
+
+       if (!istate->resolve_undo)
+               return;
+
+       for (i = 0; i < istate->cache_nr; i++) {
+               struct cache_entry *ce = istate->cache[i];
+               if (ce->ce_flags & CE_MATCHED)
+                       i = unmerge_index_entry_at(istate, i);
+       }
+}
+
 void unmerge_index(struct index_state *istate, const char **pathspec)
 {
        int i;
index 845876911db978c6262dacd9aa122ce9d55bf234..7a30206aad1fdee74f7e7b6e5967f9f8d9048dbf 100644 (file)
@@ -12,5 +12,6 @@ extern struct string_list *resolve_undo_read(const char *, unsigned long);
 extern void resolve_undo_clear_index(struct index_state *);
 extern int unmerge_index_entry_at(struct index_state *, int);
 extern void unmerge_index(struct index_state *, const char **);
+extern void unmerge_marked_index(struct index_state *);
 
 #endif
index cf620c6b3693e2d18b2cacd33574a03b34e4c48e..eb981288686a2c7cd8c854e3f414b606ed4f8c69 100644 (file)
@@ -2022,10 +2022,11 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
                if (revs->first_parent_only)
                        break;
        }
-       if (!revs->first_parent_only)
-               cnt = remove_duplicate_parents(commit);
-       else
+
+       if (revs->first_parent_only)
                cnt = 1;
+       else
+               cnt = remove_duplicate_parents(commit);
 
        /*
         * It is possible that we are a merge and one side branch
index 5da09ee3efa976b503cba5d13e347aad0f6c764c..01bd2b7c07719c9628bba13e34b581dc1fdbc0af 100644 (file)
@@ -138,7 +138,7 @@ struct rev_info {
        int             reroll_count;
        char            *message_id;
        struct string_list *ref_message_ids;
-       const char      *add_signoff;
+       int             add_signoff;
        const char      *extra_headers;
        const char      *log_reencode;
        const char      *subject_prefix;
index 97ab336097bfb45c63aec739a6eef2df26cc4790..7d172ef37f7b185f9586ce9015a08481d0bd259c 100644 (file)
@@ -106,15 +106,11 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
 static int receive_status(int in, struct ref *refs)
 {
        struct ref *hint;
-       char line[1000];
        int ret = 0;
-       int len = packet_read_line(in, line, sizeof(line));
-       if (len < 10 || memcmp(line, "unpack ", 7))
+       char *line = packet_read_line(in, NULL);
+       if (prefixcmp(line, "unpack "))
                return error("did not receive remote status");
-       if (memcmp(line, "unpack ok\n", 10)) {
-               char *p = line + strlen(line) - 1;
-               if (*p == '\n')
-                       *p = '\0';
+       if (strcmp(line, "unpack ok")) {
                error("unpack failed: %s", line + 7);
                ret = -1;
        }
@@ -122,17 +118,15 @@ static int receive_status(int in, struct ref *refs)
        while (1) {
                char *refname;
                char *msg;
-               len = packet_read_line(in, line, sizeof(line));
-               if (!len)
+               line = packet_read_line(in, NULL);
+               if (!line)
                        break;
-               if (len < 3 ||
-                   (memcmp(line, "ok ", 3) && memcmp(line, "ng ", 3))) {
-                       fprintf(stderr, "protocol error: %s\n", line);
+               if (prefixcmp(line, "ok ") && prefixcmp(line, "ng ")) {
+                       error("invalid ref status from remote: %s", line);
                        ret = -1;
                        break;
                }
 
-               line[strlen(line)-1] = '\0';
                refname = line + 3;
                msg = strchr(refname, ' ');
                if (msg)
@@ -281,7 +275,7 @@ int send_pack(struct send_pack_args *args,
                        send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
                }
        } else {
-               safe_write(out, req_buf.buf, req_buf.len);
+               write_or_die(out, req_buf.buf, req_buf.len);
                packet_flush(out);
        }
        strbuf_release(&req_buf);
index aef5e8a0170c5b337f1aa3ac7a35be3b54957729..ee4f8c6ed4f040072b4d706c26d04a07f665c9f6 100644 (file)
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
 
 const char sign_off_header[] = "Signed-off-by: ";
+static const char cherry_picked_prefix[] = "(cherry picked from commit ";
+
+static int is_rfc2822_line(const char *buf, int len)
+{
+       int i;
+
+       for (i = 0; i < len; i++) {
+               int ch = buf[i];
+               if (ch == ':')
+                       return 1;
+               if (!isalnum(ch) && ch != '-')
+                       break;
+       }
+
+       return 0;
+}
+
+static int is_cherry_picked_from_line(const char *buf, int len)
+{
+       /*
+        * We only care that it looks roughly like (cherry picked from ...)
+        */
+       return len > strlen(cherry_picked_prefix) + 1 &&
+               !prefixcmp(buf, cherry_picked_prefix) && buf[len - 1] == ')';
+}
+
+/*
+ * Returns 0 for non-conforming footer
+ * Returns 1 for conforming footer
+ * Returns 2 when sob exists within conforming footer
+ * Returns 3 when sob exists within conforming footer as last entry
+ */
+static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
+       int ignore_footer)
+{
+       char prev;
+       int i, k;
+       int len = sb->len - ignore_footer;
+       const char *buf = sb->buf;
+       int found_sob = 0;
+
+       /* footer must end with newline */
+       if (!len || buf[len - 1] != '\n')
+               return 0;
+
+       prev = '\0';
+       for (i = len - 1; i > 0; i--) {
+               char ch = buf[i];
+               if (prev == '\n' && ch == '\n') /* paragraph break */
+                       break;
+               prev = ch;
+       }
+
+       /* require at least one blank line */
+       if (prev != '\n' || buf[i] != '\n')
+               return 0;
+
+       /* advance to start of last paragraph */
+       while (i < len - 1 && buf[i] == '\n')
+               i++;
+
+       for (; i < len; i = k) {
+               int found_rfc2822;
+
+               for (k = i; k < len && buf[k] != '\n'; k++)
+                       ; /* do nothing */
+               k++;
+
+               found_rfc2822 = is_rfc2822_line(buf + i, k - i - 1);
+               if (found_rfc2822 && sob &&
+                   !strncmp(buf + i, sob->buf, sob->len))
+                       found_sob = k;
+
+               if (!(found_rfc2822 ||
+                     is_cherry_picked_from_line(buf + i, k - i - 1)))
+                       return 0;
+       }
+       if (found_sob == i)
+               return 3;
+       if (found_sob)
+               return 2;
+       return 1;
+}
 
 static void remove_sequencer_state(void)
 {
@@ -133,7 +216,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
        if (msg) {
                fprintf(stderr, "%s\n", msg);
                /*
-                * A conflict has occured but the porcelain
+                * A conflict has occurred but the porcelain
                 * (typically rebase --interactive) wants to take care
                 * of the commit itself so remove CHERRY_PICK_HEAD
                 */
@@ -237,7 +320,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
        rollback_lock_file(&index_lock);
 
        if (opts->signoff)
-               append_signoff(msgbuf, 0);
+               append_signoff(msgbuf, 0, 0);
 
        if (!clean) {
                int i;
@@ -496,7 +579,9 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
                }
 
                if (opts->record_origin) {
-                       strbuf_addstr(&msgbuf, "(cherry picked from commit ");
+                       if (!has_conforming_footer(&msgbuf, NULL, 0))
+                               strbuf_addch(&msgbuf, '\n');
+                       strbuf_addstr(&msgbuf, cherry_picked_prefix);
                        strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
                        strbuf_addstr(&msgbuf, ")\n");
                }
@@ -1021,62 +1106,67 @@ int sequencer_pick_revisions(struct replay_opts *opts)
        return pick_commits(todo_list, opts);
 }
 
-static int ends_rfc2822_footer(struct strbuf *sb, int ignore_footer)
-{
-       int ch;
-       int hit = 0;
-       int i, j, k;
-       int len = sb->len - ignore_footer;
-       int first = 1;
-       const char *buf = sb->buf;
-
-       for (i = len - 1; i > 0; i--) {
-               if (hit && buf[i] == '\n')
-                       break;
-               hit = (buf[i] == '\n');
-       }
-
-       while (i < len - 1 && buf[i] == '\n')
-               i++;
-
-       for (; i < len; i = k) {
-               for (k = i; k < len && buf[k] != '\n'; k++)
-                       ; /* do nothing */
-               k++;
-
-               if ((buf[k] == ' ' || buf[k] == '\t') && !first)
-                       continue;
-
-               first = 0;
-
-               for (j = 0; i + j < len; j++) {
-                       ch = buf[i + j];
-                       if (ch == ':')
-                               break;
-                       if (isalnum(ch) ||
-                           (ch == '-'))
-                               continue;
-                       return 0;
-               }
-       }
-       return 1;
-}
-
-void append_signoff(struct strbuf *msgbuf, int ignore_footer)
+void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
 {
+       unsigned no_dup_sob = flag & APPEND_SIGNOFF_DEDUP;
        struct strbuf sob = STRBUF_INIT;
-       int i;
+       int has_footer;
 
        strbuf_addstr(&sob, sign_off_header);
        strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
                                getenv("GIT_COMMITTER_EMAIL")));
        strbuf_addch(&sob, '\n');
-       for (i = msgbuf->len - 1 - ignore_footer; i > 0 && msgbuf->buf[i - 1] != '\n'; i--)
-               ; /* do nothing */
-       if (prefixcmp(msgbuf->buf + i, sob.buf)) {
-               if (!i || !ends_rfc2822_footer(msgbuf, ignore_footer))
-                       strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, "\n", 1);
-               strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0, sob.buf, sob.len);
+
+       /*
+        * If the whole message buffer is equal to the sob, pretend that we
+        * found a conforming footer with a matching sob
+        */
+       if (msgbuf->len - ignore_footer == sob.len &&
+           !strncmp(msgbuf->buf, sob.buf, sob.len))
+               has_footer = 3;
+       else
+               has_footer = has_conforming_footer(msgbuf, &sob, ignore_footer);
+
+       if (!has_footer) {
+               const char *append_newlines = NULL;
+               size_t len = msgbuf->len - ignore_footer;
+
+               if (!len) {
+                       /*
+                        * The buffer is completely empty.  Leave foom for
+                        * the title and body to be filled in by the user.
+                        */
+                       append_newlines = "\n\n";
+               } else if (msgbuf->buf[len - 1] != '\n') {
+                       /*
+                        * Incomplete line.  Complete the line and add a
+                        * blank one so that there is an empty line between
+                        * the message body and the sob.
+                        */
+                       append_newlines = "\n\n";
+               } else if (len == 1) {
+                       /*
+                        * Buffer contains a single newline.  Add another
+                        * so that we leave room for the title and body.
+                        */
+                       append_newlines = "\n";
+               } else if (msgbuf->buf[len - 2] != '\n') {
+                       /*
+                        * Buffer ends with a single newline.  Add another
+                        * so that there is an empty line between the message
+                        * body and the sob.
+                        */
+                       append_newlines = "\n";
+               } /* else, the buffer already ends with two newlines. */
+
+               if (append_newlines)
+                       strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
+                               append_newlines, strlen(append_newlines));
        }
+
+       if (has_footer != 3 && (!no_dup_sob || has_footer != 2))
+               strbuf_splice(msgbuf, msgbuf->len - ignore_footer, 0,
+                               sob.buf, sob.len);
+
        strbuf_release(&sob);
 }
index 9d57d57524d411c54d55346a5ecff67bc256595c..1fc22dcabe132cd437e7b0d3c56588c8cd7e63f2 100644 (file)
@@ -6,6 +6,8 @@
 #define SEQ_TODO_FILE  "sequencer/todo"
 #define SEQ_OPTS_FILE  "sequencer/opts"
 
+#define APPEND_SIGNOFF_DEDUP (1u << 0)
+
 enum replay_action {
        REPLAY_REVERT,
        REPLAY_PICK
@@ -48,6 +50,6 @@ int sequencer_pick_revisions(struct replay_opts *opts);
 
 extern const char sign_off_header[];
 
-void append_signoff(struct strbuf *msgbuf, int ignore_footer);
+void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag);
 
 #endif
index 40b23297b2e1e60a3719e9c67256303e39456604..0ed23981b363a07c6f4c5b930b1a5991d5c8a622 100644 (file)
@@ -21,6 +21,7 @@
 #include "sha1-lookup.h"
 #include "bulk-checkin.h"
 #include "streaming.h"
+#include "dir.h"
 
 #ifndef O_NOATIME
 #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))
@@ -123,8 +124,13 @@ int safe_create_leading_directories(char *path)
                        }
                }
                else if (mkdir(path, 0777)) {
-                       *pos = '/';
-                       return -1;
+                       if (errno == EEXIST &&
+                           !stat(path, &st) && S_ISDIR(st.st_mode)) {
+                               ; /* somebody created it since we checked */
+                       } else {
+                               *pos = '/';
+                               return -1;
+                       }
                }
                else if (adjust_shared_perm(path)) {
                        *pos = '/';
@@ -1000,6 +1006,63 @@ void install_packed_git(struct packed_git *pack)
        packed_git = pack;
 }
 
+void (*report_garbage)(const char *desc, const char *path);
+
+static void report_helper(const struct string_list *list,
+                         int seen_bits, int first, int last)
+{
+       const char *msg;
+       switch (seen_bits) {
+       case 0:
+               msg = "no corresponding .idx nor .pack";
+               break;
+       case 1:
+               msg = "no corresponding .idx";
+               break;
+       case 2:
+               msg = "no corresponding .pack";
+               break;
+       default:
+               return;
+       }
+       for (; first < last; first++)
+               report_garbage(msg, list->items[first].string);
+}
+
+static void report_pack_garbage(struct string_list *list)
+{
+       int i, baselen = -1, first = 0, seen_bits = 0;
+
+       if (!report_garbage)
+               return;
+
+       sort_string_list(list);
+
+       for (i = 0; i < list->nr; i++) {
+               const char *path = list->items[i].string;
+               if (baselen != -1 &&
+                   strncmp(path, list->items[first].string, baselen)) {
+                       report_helper(list, seen_bits, first, i);
+                       baselen = -1;
+                       seen_bits = 0;
+               }
+               if (baselen == -1) {
+                       const char *dot = strrchr(path, '.');
+                       if (!dot) {
+                               report_garbage("garbage found", path);
+                               continue;
+                       }
+                       baselen = dot - path + 1;
+                       first = i;
+               }
+               if (!strcmp(path + baselen, "pack"))
+                       seen_bits |= 1;
+               else if (!strcmp(path + baselen, "idx"))
+                       seen_bits |= 2;
+       }
+       report_helper(list, seen_bits, first, list->nr);
+}
+
 static void prepare_packed_git_one(char *objdir, int local)
 {
        /* Ensure that this buffer is large enough so that we can
@@ -1009,6 +1072,7 @@ static void prepare_packed_git_one(char *objdir, int local)
        int len;
        DIR *dir;
        struct dirent *de;
+       struct string_list garbage = STRING_LIST_INIT_DUP;
 
        sprintf(path, "%s/pack", objdir);
        len = strlen(path);
@@ -1024,29 +1088,49 @@ static void prepare_packed_git_one(char *objdir, int local)
                int namelen = strlen(de->d_name);
                struct packed_git *p;
 
-               if (!has_extension(de->d_name, ".idx"))
+               if (len + namelen + 1 > sizeof(path)) {
+                       if (report_garbage) {
+                               struct strbuf sb = STRBUF_INIT;
+                               strbuf_addf(&sb, "%.*s/%s", len - 1, path, de->d_name);
+                               report_garbage("path too long", sb.buf);
+                               strbuf_release(&sb);
+                       }
                        continue;
+               }
 
-               if (len + namelen + 1 > sizeof(path))
+               if (is_dot_or_dotdot(de->d_name))
                        continue;
 
-               /* Don't reopen a pack we already have. */
                strcpy(path + len, de->d_name);
-               for (p = packed_git; p; p = p->next) {
-                       if (!memcmp(path, p->pack_name, len + namelen - 4))
-                               break;
+
+               if (has_extension(de->d_name, ".idx")) {
+                       /* Don't reopen a pack we already have. */
+                       for (p = packed_git; p; p = p->next) {
+                               if (!memcmp(path, p->pack_name, len + namelen - 4))
+                                       break;
+                       }
+                       if (p == NULL &&
+                           /*
+                            * See if it really is a valid .idx file with
+                            * corresponding .pack file that we can map.
+                            */
+                           (p = add_packed_git(path, len + namelen, local)) != NULL)
+                               install_packed_git(p);
                }
-               if (p)
-                       continue;
-               /* See if it really is a valid .idx file with corresponding
-                * .pack file that we can map.
-                */
-               p = add_packed_git(path, len + namelen, local);
-               if (!p)
+
+               if (!report_garbage)
                        continue;
-               install_packed_git(p);
+
+               if (has_extension(de->d_name, ".idx") ||
+                   has_extension(de->d_name, ".pack") ||
+                   has_extension(de->d_name, ".keep"))
+                       string_list_append(&garbage, path);
+               else
+                       report_garbage("garbage found", path);
        }
        closedir(dir);
+       report_pack_garbage(&garbage);
+       string_list_clear(&garbage, 0);
 }
 
 static int sort_pack(const void *a_, const void *b_)
@@ -1187,6 +1271,10 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
                char buf[1024 * 16];
                ssize_t readlen = read_istream(st, buf, sizeof(buf));
 
+               if (readlen < 0) {
+                       close_istream(st);
+                       return -1;
+               }
                if (!readlen)
                        break;
                git_SHA1_Update(&c, buf, readlen);
index c50630a3ea793e0cfd2510b8813129a1685428f4..3820f28ae757cce54a95014629ade4f7feb56efc 100644 (file)
@@ -594,7 +594,7 @@ struct object *peel_to_type(const char *name, int namelen,
        while (1) {
                if (!o || (!o->parsed && !parse_object(o->sha1)))
                        return NULL;
-               if (o->type == expected_type)
+               if (expected_type == OBJ_ANY || o->type == expected_type)
                        return o;
                if (o->type == OBJ_TAG)
                        o = ((struct tag*) o)->tagged;
@@ -645,6 +645,8 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
                expected_type = OBJ_TREE;
        else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
                expected_type = OBJ_BLOB;
+       else if (!prefixcmp(sp, "object}"))
+               expected_type = OBJ_ANY;
        else if (sp[0] == '}')
                expected_type = OBJ_NONE;
        else if (sp[0] == '/')
@@ -654,6 +656,8 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
 
        if (expected_type == OBJ_COMMIT)
                lookup_flags = GET_SHA1_COMMITTISH;
+       else if (expected_type == OBJ_TREE)
+               lookup_flags = GET_SHA1_TREEISH;
 
        if (get_sha1_1(name, sp - name - 2, outer, lookup_flags))
                return -1;
@@ -856,8 +860,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 }
 
 struct grab_nth_branch_switch_cbdata {
-       long cnt, alloc;
-       struct strbuf *buf;
+       int remaining;
+       struct strbuf buf;
 };
 
 static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
@@ -867,7 +871,6 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
        struct grab_nth_branch_switch_cbdata *cb = cb_data;
        const char *match = NULL, *target = NULL;
        size_t len;
-       int nth;
 
        if (!prefixcmp(message, "checkout: moving from ")) {
                match = message + strlen("checkout: moving from ");
@@ -876,11 +879,12 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
 
        if (!match || !target)
                return 0;
-
-       len = target - match;
-       nth = cb->cnt++ % cb->alloc;
-       strbuf_reset(&cb->buf[nth]);
-       strbuf_add(&cb->buf[nth], match, len);
+       if (--(cb->remaining) == 0) {
+               len = target - match;
+               strbuf_reset(&cb->buf);
+               strbuf_add(&cb->buf, match, len);
+               return 1; /* we are done */
+       }
        return 0;
 }
 
@@ -891,7 +895,7 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
 static int interpret_nth_prior_checkout(const char *name, struct strbuf *buf)
 {
        long nth;
-       int i, retval;
+       int retval;
        struct grab_nth_branch_switch_cbdata cb;
        const char *brace;
        char *num_end;
@@ -901,34 +905,22 @@ static int interpret_nth_prior_checkout(const char *name, struct strbuf *buf)
        brace = strchr(name, '}');
        if (!brace)
                return -1;
-       nth = strtol(name+3, &num_end, 10);
+       nth = strtol(name + 3, &num_end, 10);
        if (num_end != brace)
                return -1;
        if (nth <= 0)
                return -1;
-       cb.alloc = nth;
-       cb.buf = xmalloc(nth * sizeof(struct strbuf));
-       for (i = 0; i < nth; i++)
-               strbuf_init(&cb.buf[i], 20);
-       cb.cnt = 0;
+       cb.remaining = nth;
+       strbuf_init(&cb.buf, 20);
+
        retval = 0;
-       for_each_recent_reflog_ent("HEAD", grab_nth_branch_switch, 40960, &cb);
-       if (cb.cnt < nth) {
-               cb.cnt = 0;
-               for_each_reflog_ent("HEAD", grab_nth_branch_switch, &cb);
+       if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+               strbuf_reset(buf);
+               strbuf_add(buf, cb.buf.buf, cb.buf.len);
+               retval = brace - name + 1;
        }
-       if (cb.cnt < nth)
-               goto release_return;
-       i = cb.cnt % nth;
-       strbuf_reset(buf);
-       strbuf_add(buf, cb.buf[i].buf, cb.buf[i].len);
-       retval = brace-name+1;
-
-release_return:
-       for (i = 0; i < nth; i++)
-               strbuf_release(&cb.buf[i]);
-       free(cb.buf);
 
+       strbuf_release(&cb.buf);
        return retval;
 }
 
diff --git a/shell.c b/shell.c
index 84b237fef352e2f94f853897dbb5f2364d50962d..1429870a8f29d3d8b8e4d1d7ba3e228d15a73759 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -6,6 +6,7 @@
 
 #define COMMAND_DIR "git-shell-commands"
 #define HELP_COMMAND COMMAND_DIR "/help"
+#define NOLOGIN_COMMAND COMMAND_DIR "/no-interactive-login"
 
 static int do_generic_cmd(const char *me, char *arg)
 {
@@ -65,6 +66,18 @@ static void run_shell(void)
 {
        int done = 0;
        static const char *help_argv[] = { HELP_COMMAND, NULL };
+
+       if (!access(NOLOGIN_COMMAND, F_OK)) {
+               /* Interactive login disabled. */
+               const char *argv[] = { NOLOGIN_COMMAND, NULL };
+               int status;
+
+               status = run_command_v_opt(argv, 0);
+               if (status < 0)
+                       exit(127);
+               exit(status);
+       }
+
        /* Print help if enabled */
        run_command_v_opt(help_argv, RUN_SILENT_EXEC_FAILURE);
 
index d5ffa1c8919a6db750606c78a1b44d8618fa35a5..d1125f5c528b680f915bb2fbf54231cc8c3b2ec0 100644 (file)
@@ -1,3 +1,4 @@
+#include "cache.h"
 #include "pkt-line.h"
 #include "sideband.h"
 
@@ -37,7 +38,7 @@ int recv_sideband(const char *me, int in_stream, int out)
 
        while (1) {
                int band, len;
-               len = packet_read_line(in_stream, buf + pf, LARGE_PACKET_MAX);
+               len = packet_read(in_stream, NULL, NULL, buf + pf, LARGE_PACKET_MAX, 0);
                if (len == 0)
                        break;
                if (len < 1) {
@@ -108,7 +109,7 @@ int recv_sideband(const char *me, int in_stream, int out)
                        } while (len);
                        continue;
                case 1:
-                       safe_write(out, buf + pf+1, len);
+                       write_or_die(out, buf + pf+1, len);
                        continue;
                default:
                        fprintf(stderr, "%s: protocol error: bad band #%d\n",
@@ -138,12 +139,12 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet
                if (0 <= band) {
                        sprintf(hdr, "%04x", n + 5);
                        hdr[4] = band;
-                       safe_write(fd, hdr, 5);
+                       write_or_die(fd, hdr, 5);
                } else {
                        sprintf(hdr, "%04x", n + 4);
-                       safe_write(fd, hdr, 4);
+                       write_or_die(fd, hdr, 4);
                }
-               safe_write(fd, p, n);
+               write_or_die(fd, p, n);
                p += n;
                sz -= n;
        }
index d72db35d1e0dc109f75b292762013c11b86426aa..e46bed0b0158c0253bacb2a3db028770ad221666 100644 (file)
@@ -4,9 +4,6 @@
 #define SIDEBAND_PROTOCOL_ERROR -2
 #define SIDEBAND_REMOTE_ERROR -1
 
-#define DEFAULT_PACKET_MAX 1000
-#define LARGE_PACKET_MAX 65520
-
 int recv_sideband(const char *me, int in_stream, int out);
 ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
 
index 4d978e54e4fb9d84e81977539ffa083534ef2968..cabcd9d1577d89c5e944a4c12e3a8e6af901078c 100644 (file)
@@ -237,7 +237,7 @@ static read_method_decl(filtered)
                if (!fs->input_finished) {
                        fs->i_end = read_istream(fs->upstream, fs->ibuf, FILTER_BUFFER);
                        if (fs->i_end < 0)
-                               break;
+                               return -1;
                        if (fs->i_end)
                                continue;
                }
@@ -309,7 +309,7 @@ static read_method_decl(loose)
                        st->z_state = z_done;
                        break;
                }
-               if (status != Z_OK && status != Z_BUF_ERROR) {
+               if (status != Z_OK && (status != Z_BUF_ERROR || total_read < sz)) {
                        git_inflate_end(&st->z);
                        st->z_state = z_error;
                        return -1;
@@ -514,6 +514,8 @@ int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *f
                ssize_t wrote, holeto;
                ssize_t readlen = read_istream(st, buf, sizeof(buf));
 
+               if (readlen < 0)
+                       goto close_and_exit;
                if (!readlen)
                        break;
                if (can_seek && sizeof(buf) == readlen) {
index 9ba149654322840323cf2d8f4980fa09e56f4068..975bc87e48b33e70bd7c38e82b7f59e34bb81ca3 100644 (file)
@@ -261,7 +261,7 @@ void show_submodule_summary(FILE *f, const char *path,
                const char *del, const char *add, const char *reset)
 {
        struct rev_info rev;
-       struct commit *left = left, *right = right;
+       struct commit *left = NULL, *right = NULL;
        const char *message = NULL;
        struct strbuf sb = STRBUF_INIT;
        int fast_forward = 0, fast_backward = 0;
@@ -275,10 +275,8 @@ void show_submodule_summary(FILE *f, const char *path,
        else if (!(left = lookup_commit_reference(one)) ||
                 !(right = lookup_commit_reference(two)))
                message = "(commits not present)";
-
-       if (!message &&
-           prepare_submodule_summary(&rev, path, left, right,
-                                       &fast_forward, &fast_backward))
+       else if (prepare_submodule_summary(&rev, path, left, right,
+                                          &fast_forward, &fast_backward))
                message = "(revision walker failed)";
 
        if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
@@ -302,11 +300,12 @@ void show_submodule_summary(FILE *f, const char *path,
                strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset);
        fwrite(sb.buf, sb.len, 1, f);
 
-       if (!message) {
+       if (!message) /* only NULL if we succeeded in setting up the walk */
                print_submodule_summary(&rev, f, del, add, reset);
+       if (left)
                clear_commit_marks(left, ~0);
+       if (right)
                clear_commit_marks(right, ~0);
-       }
 
        strbuf_release(&sb);
 }
index e4128e5769722473f7fd1024fdf8a5100bd8ccf6..e669bb31b9aa2513a6f71de9fd066a21a0a3bde7 100644 (file)
--- a/t/README
+++ b/t/README
@@ -86,23 +86,35 @@ appropriately before running "make".
 
 --immediate::
        This causes the test to immediately exit upon the first
-       failed test.
+       failed test. Cleanup commands requested with
+       test_when_finished are not executed if the test failed,
+       in order to keep the state for inspection by the tester
+       to diagnose the bug.
 
 --long-tests::
        This causes additional long-running tests to be run (where
        available), for more exhaustive testing.
 
---valgrind::
-       Execute all Git binaries with valgrind and exit with status
-       126 on errors (just like regular tests, this will only stop
-       the test script when running under -i).  Valgrind errors
-       go to stderr, so you might want to pass the -v option, too.
+--valgrind=<tool>::
+       Execute all Git binaries under valgrind tool <tool> and exit
+       with status 126 on errors (just like regular tests, this will
+       only stop the test script when running under -i).
 
        Since it makes no sense to run the tests with --valgrind and
        not see any output, this option implies --verbose.  For
        convenience, it also implies --tee.
 
-       Note that valgrind is run with the option --leak-check=no,
+       <tool> defaults to 'memcheck', just like valgrind itself.
+       Other particularly useful choices include 'helgrind' and
+       'drd', but you may use any tool recognized by your valgrind
+       installation.
+
+       As a special case, <tool> can be 'memcheck-fast', which uses
+       memcheck but disables --track-origins.  Use this if you are
+       running tests in bulk, to see if there are _any_ memory
+       issues.
+
+       Note that memcheck is run with the option --leak-check=no,
        as the git process is short-lived and some errors are not
        interesting. In order to run a single command under the same
        conditions manually, you should set GIT_VALGRIND to point to
@@ -610,6 +622,11 @@ use these, and "test_set_prereq" for how to define your own.
    The process retains the same pid across exec(2). See fb9a2bea for
    details.
 
+ - PIPE
+
+   The filesystem we're on supports creation of FIFOs (named pipes)
+   via mkfifo(1).
+
  - SYMLINKS
 
    The filesystem we're on supports symbolic links. E.g. a FAT
index 83855fa4e1c6c37afe550c17afa1e7971042ded5..1a3c2d487c2fda9169751a3068fa51e853a1e519 100644 (file)
Binary files a/t/lib-gpg/pubring.gpg and b/t/lib-gpg/pubring.gpg differ
index 8fed1339ed0a744e5663f4a5e6b6ac9bae3d8524..95d249f15fce980f0e8c1a8a18b085b3885708aa 100644 (file)
Binary files a/t/lib-gpg/random_seed and b/t/lib-gpg/random_seed differ
index d831cd9eb3eee613d3c0e1a71093ae01ea7347e3..82dca8f80bf170fde5705862c3eeb9d994725042 100644 (file)
Binary files a/t/lib-gpg/secring.gpg and b/t/lib-gpg/secring.gpg differ
index abace962b8bf84be688a6f27e4ebd0ee7052f210..4879ae9a84650a93a4d15bd6560c5d1b89eb4c2f 100644 (file)
Binary files a/t/lib-gpg/trustdb.gpg and b/t/lib-gpg/trustdb.gpg differ
index d8b7f2ffbcc0427b1ae9d48feb4387f580e81d61..9820f70c84d93b9461ae6663e6ab5b3cd735e3d5 100755 (executable)
@@ -116,9 +116,9 @@ tree_pretty_content="100644 blob $hello_sha1        hello"
 
 run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
 
-commit_message="Intial commit"
+commit_message="Initial commit"
 commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1)
-commit_size=176
+commit_size=177
 commit_content="tree $tree_sha1
 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
diff --git a/t/t1060-object-corruption.sh b/t/t1060-object-corruption.sh
new file mode 100755 (executable)
index 0000000..3f87051
--- /dev/null
@@ -0,0 +1,104 @@
+#!/bin/sh
+
+test_description='see how we handle various forms of corruption'
+. ./test-lib.sh
+
+# convert "1234abcd" to ".git/objects/12/34abcd"
+obj_to_file() {
+       echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
+}
+
+# Convert byte at offset "$2" of object "$1" into '\0'
+corrupt_byte() {
+       obj_file=$(obj_to_file "$1") &&
+       chmod +w "$obj_file" &&
+       printf '\0' | dd of="$obj_file" bs=1 seek="$2" conv=notrunc
+}
+
+test_expect_success 'setup corrupt repo' '
+       git init bit-error &&
+       (
+               cd bit-error &&
+               test_commit content &&
+               corrupt_byte HEAD:content.t 10
+       )
+'
+
+test_expect_success 'setup repo with missing object' '
+       git init missing &&
+       (
+               cd missing &&
+               test_commit content &&
+               rm -f "$(obj_to_file HEAD:content.t)"
+       )
+'
+
+test_expect_success 'setup repo with misnamed object' '
+       git init misnamed &&
+       (
+               cd misnamed &&
+               test_commit content &&
+               good=$(obj_to_file HEAD:content.t) &&
+               blob=$(echo corrupt | git hash-object -w --stdin) &&
+               bad=$(obj_to_file $blob) &&
+               rm -f "$good" &&
+               mv "$bad" "$good"
+       )
+'
+
+test_expect_success 'streaming a corrupt blob fails' '
+       (
+               cd bit-error &&
+               test_must_fail git cat-file blob HEAD:content.t
+       )
+'
+
+test_expect_success 'read-tree -u detects bit-errors in blobs' '
+       (
+               cd bit-error &&
+               rm -f content.t &&
+               test_must_fail git read-tree --reset -u HEAD
+       )
+'
+
+test_expect_success 'read-tree -u detects missing objects' '
+       (
+               cd missing &&
+               rm -f content.t &&
+               test_must_fail git read-tree --reset -u HEAD
+       )
+'
+
+# We use --bare to make sure that the transport detects it, not the checkout
+# phase.
+test_expect_success 'clone --no-local --bare detects corruption' '
+       test_must_fail git clone --no-local --bare bit-error corrupt-transport
+'
+
+test_expect_success 'clone --no-local --bare detects missing object' '
+       test_must_fail git clone --no-local --bare missing missing-transport
+'
+
+test_expect_success 'clone --no-local --bare detects misnamed object' '
+       test_must_fail git clone --no-local --bare misnamed misnamed-transport
+'
+
+# We do not expect --local to detect corruption at the transport layer,
+# so we are really checking the checkout() code path.
+test_expect_success 'clone --local detects corruption' '
+       test_must_fail git clone --local bit-error corrupt-checkout
+'
+
+test_expect_success 'error detected during checkout leaves repo intact' '
+       test_path_is_dir corrupt-checkout/.git
+'
+
+test_expect_success 'clone --local detects missing objects' '
+       test_must_fail git clone --local missing missing-checkout
+'
+
+test_expect_failure 'clone --local detects misnamed objects' '
+       test_must_fail git clone --local misnamed misnamed-checkout
+'
+
+test_done
index 3c96fda548709835e10f283df8cab667c280af81..c4a7d84f46fd218af1824ac1f78a1e9f4cb15cec 100755 (executable)
@@ -1087,4 +1087,39 @@ test_expect_success 'barf on incomplete string' '
        grep " line 3 " error
 '
 
+# good section hygiene
+test_expect_failure 'unsetting the last key in a section removes header' '
+       cat >.git/config <<-\EOF &&
+       # some generic comment on the configuration file itself
+       # a comment specific to this "section" section.
+       [section]
+       # some intervening lines
+       # that should also be dropped
+
+       key = value
+       # please be careful when you update the above variable
+       EOF
+
+       cat >expect <<-\EOF &&
+       # some generic comment on the configuration file itself
+       EOF
+
+       git config --unset section.key &&
+       test_cmp expect .git/config
+'
+
+test_expect_failure 'adding a key into an empty section reuses header' '
+       cat >.git/config <<-\EOF &&
+       [section]
+       EOF
+
+       q_to_tab >expect <<-\EOF &&
+       [section]
+       Qkey = value
+       EOF
+
+       git config section.key value
+       test_cmp expect .git/config
+'
+
 test_done
index 56090d2ebadcdfb127b9db005ae8d092b0255a75..8e3545d8680c5f5179977082849388b1b31c17d8 100755 (executable)
@@ -39,4 +39,26 @@ test_expect_success 'checking out paths out of a tree does not clobber unrelated
        test_cmp expect.next2 dir/next2
 '
 
+test_expect_success 'do not touch unmerged entries matching $path but not in $tree' '
+       git checkout next &&
+       git reset --hard &&
+
+       cat dir/common >expect.common &&
+       EMPTY_SHA1=$(git hash-object -w --stdin </dev/null) &&
+       git rm dir/next0 &&
+       cat >expect.next0 <<-EOF &&
+       100644 $EMPTY_SHA1 1    dir/next0
+       100644 $EMPTY_SHA1 2    dir/next0
+       EOF
+       git update-index --index-info <expect.next0 &&
+
+       git checkout master dir &&
+
+       test_cmp expect.common dir/common &&
+       test_path_is_file dir/master &&
+       git diff --exit-code master dir/master &&
+       git ls-files -s dir/next0 >actual.next0 &&
+       test_cmp expect.next0 actual.next0
+'
+
 test_done
index f2620650ce1d25252210c07db20e54f99bd515c6..309199bca272b63499ca69edbb953bcc8c770ecc 100755 (executable)
@@ -44,14 +44,21 @@ prime_resolve_undo () {
 
 test_expect_success setup '
        mkdir fi &&
+       printf "a\0a" >binary &&
+       git add binary &&
        test_commit initial fi/le first &&
        git branch side &&
        git branch another &&
+       printf "a\0b" >binary &&
+       git add binary &&
        test_commit second fi/le second &&
        git checkout side &&
        test_commit third fi/le third &&
+       git branch add-add &&
        git checkout another &&
        test_commit fourth fi/le fourth &&
+       git checkout add-add &&
+       test_commit fifth add-differently &&
        git checkout master
 '
 
@@ -167,4 +174,22 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
        test_cmp expect actual
 '
 
+test_expect_success 'rerere forget (binary)' '
+       git checkout -f side &&
+       printf "a\0c" >binary &&
+       git commit -a -m binary &&
+       test_must_fail git merge second &&
+       git rerere forget binary
+'
+
+test_expect_success 'rerere forget (add-add conflict)' '
+       git checkout -f master &&
+       echo master >add-differently &&
+       git add add-differently &&
+       git commit -m "add differently" &&
+       test_must_fail git merge fifth &&
+       git rerere forget add-differently 2>actual &&
+       test_i18ngrep "no remembered" actual
+'
+
 test_done
index 4cdebda6a5c9b893f46e99b5b565cc4b70efb2db..c317254b9a82befd3400d300f85ecfd661d1a948 100755 (executable)
@@ -80,6 +80,22 @@ test_expect_success 'change gets noticed' '
 
 '
 
+# Note that this is scheduled to change in Git 2.0, when
+# "git add -u" will become full-tree by default.
+test_expect_success 'non-limited update in subdir leaves root alone' '
+       (
+               cd dir1 &&
+               echo even more >>sub2 &&
+               git add -u
+       ) &&
+       cat >expect <<-\EOF &&
+       check
+       top
+       EOF
+       git diff-files --name-only >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success SYMLINKS 'replace a file with a symlink' '
 
        rm foo &&
index 12f1e4a63c33b2f394ea37db71e1cd4467cee8f5..d969f0ecd85a6907f219d141cad2c00c4b5a89f8 100755 (executable)
@@ -7,20 +7,18 @@ test_description='git branch assorted tests'
 
 . ./test-lib.sh
 
-test_expect_success \
-    'prepare a trivial repository' \
-    'echo Hello > A &&
-     git update-index --add A &&
-     git commit -m "Initial commit." &&
-     echo World >> A &&
-     git update-index --add A &&
-     git commit -m "Second commit." &&
-     HEAD=$(git rev-parse --verify HEAD)'
-
-test_expect_success \
-    'git branch --help should not have created a bogus branch' '
-     test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
-     test_path_is_missing .git/refs/heads/--help
+test_expect_success 'prepare a trivial repository' '
+       echo Hello >A &&
+       git update-index --add A &&
+       git commit -m "Initial commit." &&
+       echo World >>A &&
+       git update-index --add A &&
+       git commit -m "Second commit." &&
+       HEAD=$(git rev-parse --verify HEAD)'
+
+test_expect_success 'git branch --help should not have created a bogus branch' '
+       test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null &&
+       test_path_is_missing .git/refs/heads/--help
 '
 
 test_expect_success 'branch -h in broken repository' '
@@ -34,67 +32,67 @@ test_expect_success 'branch -h in broken repository' '
        test_i18ngrep "[Uu]sage" broken/usage
 '
 
-test_expect_success \
-    'git branch abc should create a branch' \
-    'git branch abc && test_path_is_file .git/refs/heads/abc'
+test_expect_success 'git branch abc should create a branch' '
+       git branch abc && test_path_is_file .git/refs/heads/abc
+'
 
-test_expect_success \
-    'git branch a/b/c should create a branch' \
-    'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c'
+test_expect_success 'git branch a/b/c should create a branch' '
+       git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
+'
 
-test_expect_success \
-    'git branch HEAD should fail' \
-    'test_must_fail git branch HEAD'
+test_expect_success 'git branch HEAD should fail' '
+       test_must_fail git branch HEAD
+'
 
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
 EOF
-test_expect_success \
-    'git branch -l d/e/f should create a branch and a log' \
-       'GIT_COMMITTER_DATE="2005-05-26 23:30" \
-     git branch -l d/e/f &&
-        test_path_is_file .git/refs/heads/d/e/f &&
-        test_path_is_file .git/logs/refs/heads/d/e/f &&
-        test_cmp expect .git/logs/refs/heads/d/e/f'
-
-test_expect_success \
-    'git branch -d d/e/f should delete a branch and a log' \
-       'git branch -d d/e/f &&
-        test_path_is_missing .git/refs/heads/d/e/f &&
-        test_path_is_missing .git/logs/refs/heads/d/e/f'
-
-test_expect_success \
-    'git branch j/k should work after branch j has been deleted' \
-       'git branch j &&
-        git branch -d j &&
-        git branch j/k'
-
-test_expect_success \
-    'git branch l should work after branch l/m has been deleted' \
-       'git branch l/m &&
-        git branch -d l/m &&
-        git branch l'
-
-test_expect_success \
-    'git branch -m dumps usage' \
-       'test_expect_code 128 git branch -m 2>err &&
-       test_i18ngrep "too many branches for a rename operation" err'
-
-test_expect_success \
-    'git branch -m m m/m should work' \
-       'git branch -l m &&
-        git branch -m m m/m &&
-       test_path_is_file .git/logs/refs/heads/m/m'
-
-test_expect_success \
-    'git branch -m n/n n should work' \
-       'git branch -l n/n &&
+test_expect_success 'git branch -l d/e/f should create a branch and a log' '
+       GIT_COMMITTER_DATE="2005-05-26 23:30" \
+       git branch -l d/e/f &&
+       test_path_is_file .git/refs/heads/d/e/f &&
+       test_path_is_file .git/logs/refs/heads/d/e/f &&
+       test_cmp expect .git/logs/refs/heads/d/e/f
+'
+
+test_expect_success 'git branch -d d/e/f should delete a branch and a log' '
+       git branch -d d/e/f &&
+       test_path_is_missing .git/refs/heads/d/e/f &&
+       test_path_is_missing .git/logs/refs/heads/d/e/f
+'
+
+test_expect_success 'git branch j/k should work after branch j has been deleted' '
+       git branch j &&
+       git branch -d j &&
+       git branch j/k
+'
+
+test_expect_success 'git branch l should work after branch l/m has been deleted' '
+       git branch l/m &&
+       git branch -d l/m &&
+       git branch l
+'
+
+test_expect_success 'git branch -m dumps usage' '
+       test_expect_code 128 git branch -m 2>err &&
+       test_i18ngrep "branch name required" err
+'
+
+test_expect_success 'git branch -m m m/m should work' '
+       git branch -l m &&
+       git branch -m m m/m &&
+       test_path_is_file .git/logs/refs/heads/m/m
+'
+
+test_expect_success 'git branch -m n/n n should work' '
+       git branch -l n/n &&
        git branch -m n/n n &&
-       test_path_is_file .git/logs/refs/heads/n'
+       test_path_is_file .git/logs/refs/heads/n
+'
 
 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
        git branch o/o &&
-        git branch o/p &&
+       git branch o/p &&
        test_must_fail git branch -m o/o o
 '
 
@@ -252,19 +250,20 @@ mv .git/config-saved .git/config
 
 git config branch.s/s.dummy Hello
 
-test_expect_success \
-    'git branch -m s/s s should work when s/t is deleted' \
-       'git branch -l s/s &&
+test_expect_success 'git branch -m s/s s should work when s/t is deleted' '
+       git branch -l s/s &&
        test_path_is_file .git/logs/refs/heads/s/s &&
-        git branch -l s/t &&
+       git branch -l s/t &&
        test_path_is_file .git/logs/refs/heads/s/t &&
-        git branch -d s/t &&
-        git branch -m s/s s &&
-       test_path_is_file .git/logs/refs/heads/s'
+       git branch -d s/t &&
+       git branch -m s/s s &&
+       test_path_is_file .git/logs/refs/heads/s
+'
 
-test_expect_success 'config information was renamed, too' \
-       "test $(git config branch.s.dummy) = Hello &&
-        test_must_fail git config branch.s/s/dummy"
+test_expect_success 'config information was renamed, too' '
+       test $(git config branch.s.dummy) = Hello &&
+       test_must_fail git config branch.s/s/dummy
+'
 
 test_expect_success 'deleting a symref' '
        git branch target &&
@@ -285,8 +284,7 @@ test_expect_success 'deleting a dangling symref' '
        test_i18ncmp expect actual
 '
 
-test_expect_success 'renaming a symref is not allowed' \
-'
+test_expect_success 'renaming a symref is not allowed' '
        git symbolic-ref refs/heads/master2 refs/heads/master &&
        test_must_fail git branch -m master2 master3 &&
        git symbolic-ref refs/heads/master2 &&
@@ -294,163 +292,191 @@ test_expect_success 'renaming a symref is not allowed' \
        test_path_is_missing .git/refs/heads/master3
 '
 
-test_expect_success SYMLINKS \
-    'git branch -m u v should fail when the reflog for u is a symlink' '
-     git branch -l u &&
-     mv .git/logs/refs/heads/u real-u &&
-     ln -s real-u .git/logs/refs/heads/u &&
-     test_must_fail git branch -m u v
-'
-
-test_expect_success 'test tracking setup via --track' \
-    'git config remote.local.url . &&
-     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/master || git fetch local) &&
-     git branch --track my1 local/master &&
-     test $(git config branch.my1.remote) = local &&
-     test $(git config branch.my1.merge) = refs/heads/master'
-
-test_expect_success 'test tracking setup (non-wildcard, matching)' \
-    'git config remote.local.url . &&
-     git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
-     (git show-ref -q refs/remotes/local/master || git fetch local) &&
-     git branch --track my4 local/master &&
-     test $(git config branch.my4.remote) = local &&
-     test $(git config branch.my4.merge) = refs/heads/master'
-
-test_expect_success 'test tracking setup (non-wildcard, not matching)' \
-    'git config remote.local.url . &&
-     git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
-     (git show-ref -q refs/remotes/local/master || git fetch local) &&
-     git branch --track my5 local/master &&
-     ! test "$(git config branch.my5.remote)" = local &&
-     ! test "$(git config branch.my5.merge)" = refs/heads/master'
-
-test_expect_success 'test tracking setup via config' \
-    'git config branch.autosetupmerge true &&
-     git config remote.local.url . &&
-     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/master || git fetch local) &&
-     git branch my3 local/master &&
-     test $(git config branch.my3.remote) = local &&
-     test $(git config branch.my3.merge) = refs/heads/master'
-
-test_expect_success 'test overriding tracking setup via --no-track' \
-    'git config branch.autosetupmerge true &&
-     git config remote.local.url . &&
-     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/master || git fetch local) &&
-     git branch --no-track my2 local/master &&
-     git config branch.autosetupmerge false &&
-     ! test "$(git config branch.my2.remote)" = local &&
-     ! test "$(git config branch.my2.merge)" = refs/heads/master'
-
-test_expect_success 'no tracking without .fetch entries' \
-    'git config branch.autosetupmerge true &&
-     git branch my6 s &&
-     git config branch.automsetupmerge false &&
-     test -z "$(git config branch.my6.remote)" &&
-     test -z "$(git config branch.my6.merge)"'
-
-test_expect_success 'test tracking setup via --track but deeper' \
-    'git config remote.local.url . &&
-     git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
-     (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
-     git branch --track my7 local/o/o &&
-     test "$(git config branch.my7.remote)" = local &&
-     test "$(git config branch.my7.merge)" = refs/heads/o/o'
-
-test_expect_success 'test deleting branch deletes branch config' \
-    'git branch -d my7 &&
-     test -z "$(git config branch.my7.remote)" &&
-     test -z "$(git config branch.my7.merge)"'
-
-test_expect_success 'test deleting branch without config' \
-    'git branch my7 s &&
-     sha1=$(git rev-parse my7 | cut -c 1-7) &&
-     echo "Deleted branch my7 (was $sha1)." >expect &&
-     git branch -d my7 >actual 2>&1 &&
-     test_i18ncmp expect actual'
-
-test_expect_success 'test --track without .fetch entries' \
-    'git branch --track my8 &&
-     test "$(git config branch.my8.remote)" &&
-     test "$(git config branch.my8.merge)"'
-
-test_expect_success \
-    'branch from non-branch HEAD w/autosetupmerge=always' \
-    'git config branch.autosetupmerge always &&
-     git branch my9 HEAD^ &&
-     git config branch.autosetupmerge false'
-
-test_expect_success \
-    'branch from non-branch HEAD w/--track causes failure' \
-    'test_must_fail git branch --track my10 HEAD^'
-
-test_expect_success \
-    'branch from tag w/--track causes failure' \
-    'git tag foobar &&
-     test_must_fail git branch --track my11 foobar'
-
-test_expect_success '--set-upstream-to fails on multiple branches' \
-    'test_must_fail git branch --set-upstream-to master a b c'
-
-test_expect_success '--set-upstream-to fails on detached HEAD' \
-    'git checkout HEAD^{} &&
-     test_must_fail git branch --set-upstream-to master &&
-     git checkout -'
-
-test_expect_success 'use --set-upstream-to modify HEAD' \
-    'test_config branch.master.remote foo &&
-     test_config branch.master.merge foo &&
-     git branch my12
-     git branch --set-upstream-to my12 &&
-     test "$(git config branch.master.remote)" = "." &&
-     test "$(git config branch.master.merge)" = "refs/heads/my12"'
-
-test_expect_success 'use --set-upstream-to modify a particular branch' \
-    'git branch my13
-     git branch --set-upstream-to master my13 &&
-     test "$(git config branch.my13.remote)" = "." &&
-     test "$(git config branch.my13.merge)" = "refs/heads/master"'
-
-test_expect_success '--unset-upstream should fail if given a non-existent branch' \
-    'test_must_fail git branch --unset-upstream i-dont-exist'
-
-test_expect_success 'test --unset-upstream on HEAD' \
-    'git branch my14
-     test_config branch.master.remote foo &&
-     test_config branch.master.merge foo &&
-     git branch --set-upstream-to my14 &&
-     git branch --unset-upstream &&
-     test_must_fail git config branch.master.remote &&
-     test_must_fail git config branch.master.merge &&
-     # fail for a branch without upstream set
-     test_must_fail git branch --unset-upstream
-'
-
-test_expect_success '--unset-upstream should fail on multiple branches' \
-    'test_must_fail git branch --unset-upstream a b c'
-
-test_expect_success '--unset-upstream should fail on detached HEAD' \
-    'git checkout HEAD^{} &&
-     test_must_fail git branch --unset-upstream &&
-     git checkout -
-'
-
-test_expect_success 'test --unset-upstream on a particular branch' \
-    'git branch my15
-     git branch --set-upstream-to master my14 &&
-     git branch --unset-upstream my14 &&
-     test_must_fail git config branch.my14.remote &&
-     test_must_fail git config branch.my14.merge'
-
-test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' \
-    'git update-ref refs/remotes/origin/master HEAD &&
-     git branch --set-upstream origin/master 2>actual &&
-     test_when_finished git update-ref -d refs/remotes/origin/master &&
-     test_when_finished git branch -d origin/master &&
-     cat >expected <<EOF &&
+test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' '
+       git branch -l u &&
+       mv .git/logs/refs/heads/u real-u &&
+       ln -s real-u .git/logs/refs/heads/u &&
+       test_must_fail git branch -m u v
+'
+
+test_expect_success 'test tracking setup via --track' '
+       git config remote.local.url . &&
+       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
+       git branch --track my1 local/master &&
+       test $(git config branch.my1.remote) = local &&
+       test $(git config branch.my1.merge) = refs/heads/master
+'
+
+test_expect_success 'test tracking setup (non-wildcard, matching)' '
+       git config remote.local.url . &&
+       git config remote.local.fetch refs/heads/master:refs/remotes/local/master &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
+       git branch --track my4 local/master &&
+       test $(git config branch.my4.remote) = local &&
+       test $(git config branch.my4.merge) = refs/heads/master
+'
+
+test_expect_success 'test tracking setup (non-wildcard, not matching)' '
+       git config remote.local.url . &&
+       git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
+       git branch --track my5 local/master &&
+       ! test "$(git config branch.my5.remote)" = local &&
+       ! test "$(git config branch.my5.merge)" = refs/heads/master
+'
+
+test_expect_success 'test tracking setup via config' '
+       git config branch.autosetupmerge true &&
+       git config remote.local.url . &&
+       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
+       git branch my3 local/master &&
+       test $(git config branch.my3.remote) = local &&
+       test $(git config branch.my3.merge) = refs/heads/master
+'
+
+test_expect_success 'test overriding tracking setup via --no-track' '
+       git config branch.autosetupmerge true &&
+       git config remote.local.url . &&
+       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+       (git show-ref -q refs/remotes/local/master || git fetch local) &&
+       git branch --no-track my2 local/master &&
+       git config branch.autosetupmerge false &&
+       ! test "$(git config branch.my2.remote)" = local &&
+       ! test "$(git config branch.my2.merge)" = refs/heads/master
+'
+
+test_expect_success 'no tracking without .fetch entries' '
+       git config branch.autosetupmerge true &&
+       git branch my6 s &&
+       git config branch.automsetupmerge false &&
+       test -z "$(git config branch.my6.remote)" &&
+       test -z "$(git config branch.my6.merge)"
+'
+
+test_expect_success 'test tracking setup via --track but deeper' '
+       git config remote.local.url . &&
+       git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+       (git show-ref -q refs/remotes/local/o/o || git fetch local) &&
+       git branch --track my7 local/o/o &&
+       test "$(git config branch.my7.remote)" = local &&
+       test "$(git config branch.my7.merge)" = refs/heads/o/o
+'
+
+test_expect_success 'test deleting branch deletes branch config' '
+       git branch -d my7 &&
+       test -z "$(git config branch.my7.remote)" &&
+       test -z "$(git config branch.my7.merge)"
+'
+
+test_expect_success 'test deleting branch without config' '
+       git branch my7 s &&
+       sha1=$(git rev-parse my7 | cut -c 1-7) &&
+       echo "Deleted branch my7 (was $sha1)." >expect &&
+       git branch -d my7 >actual 2>&1 &&
+       test_i18ncmp expect actual
+'
+
+test_expect_success 'test --track without .fetch entries' '
+       git branch --track my8 &&
+       test "$(git config branch.my8.remote)" &&
+       test "$(git config branch.my8.merge)"
+'
+
+test_expect_success 'branch from non-branch HEAD w/autosetupmerge=always' '
+       git config branch.autosetupmerge always &&
+       git branch my9 HEAD^ &&
+       git config branch.autosetupmerge false
+'
+
+test_expect_success 'branch from non-branch HEAD w/--track causes failure' '
+       test_must_fail git branch --track my10 HEAD^
+'
+
+test_expect_success 'branch from tag w/--track causes failure' '
+       git tag foobar &&
+       test_must_fail git branch --track my11 foobar
+'
+
+test_expect_success '--set-upstream-to fails on multiple branches' '
+       test_must_fail git branch --set-upstream-to master a b c
+'
+
+test_expect_success '--set-upstream-to fails on detached HEAD' '
+       git checkout HEAD^{} &&
+       test_must_fail git branch --set-upstream-to master &&
+       git checkout -
+'
+
+test_expect_success '--set-upstream-to fails on a missing dst branch' '
+       test_must_fail git branch --set-upstream-to master does-not-exist
+'
+
+test_expect_success '--set-upstream-to fails on a missing src branch' '
+       test_must_fail git branch --set-upstream-to does-not-exist master
+'
+
+test_expect_success '--set-upstream-to fails on a non-ref' '
+       test_must_fail git branch --set-upstream-to HEAD^{}
+'
+
+test_expect_success 'use --set-upstream-to modify HEAD' '
+       test_config branch.master.remote foo &&
+       test_config branch.master.merge foo &&
+       git branch my12
+       git branch --set-upstream-to my12 &&
+       test "$(git config branch.master.remote)" = "." &&
+       test "$(git config branch.master.merge)" = "refs/heads/my12"
+'
+
+test_expect_success 'use --set-upstream-to modify a particular branch' '
+       git branch my13
+       git branch --set-upstream-to master my13 &&
+       test "$(git config branch.my13.remote)" = "." &&
+       test "$(git config branch.my13.merge)" = "refs/heads/master"
+'
+
+test_expect_success '--unset-upstream should fail if given a non-existent branch' '
+       test_must_fail git branch --unset-upstream i-dont-exist
+'
+
+test_expect_success 'test --unset-upstream on HEAD' '
+       git branch my14
+       test_config branch.master.remote foo &&
+       test_config branch.master.merge foo &&
+       git branch --set-upstream-to my14 &&
+       git branch --unset-upstream &&
+       test_must_fail git config branch.master.remote &&
+       test_must_fail git config branch.master.merge &&
+       # fail for a branch without upstream set
+       test_must_fail git branch --unset-upstream
+'
+
+test_expect_success '--unset-upstream should fail on multiple branches' '
+       test_must_fail git branch --unset-upstream a b c
+'
+
+test_expect_success '--unset-upstream should fail on detached HEAD' '
+       git checkout HEAD^{} &&
+       test_must_fail git branch --unset-upstream &&
+       git checkout -
+'
+
+test_expect_success 'test --unset-upstream on a particular branch' '
+       git branch my15
+       git branch --set-upstream-to master my14 &&
+       git branch --unset-upstream my14 &&
+       test_must_fail git config branch.my14.remote &&
+       test_must_fail git config branch.my14.merge
+'
+
+test_expect_success '--set-upstream shows message when creating a new branch that exists as remote-tracking' '
+       git update-ref refs/remotes/origin/master HEAD &&
+       git branch --set-upstream origin/master 2>actual &&
+       test_when_finished git update-ref -d refs/remotes/origin/master &&
+       test_when_finished git branch -d origin/master &&
+       cat >expected <<EOF &&
 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 
 If you wanted to make '"'master'"' track '"'origin/master'"', do this:
@@ -458,38 +484,38 @@ If you wanted to make '"'master'"' track '"'origin/master'"', do this:
     git branch -d origin/master
     git branch --set-upstream-to origin/master
 EOF
-     test_cmp expected actual
+       test_cmp expected actual
 '
 
-test_expect_success '--set-upstream with two args only shows the deprecation message' \
-    'git branch --set-upstream master my13 2>actual &&
-     test_when_finished git branch --unset-upstream master &&
-     cat >expected <<EOF &&
+test_expect_success '--set-upstream with two args only shows the deprecation message' '
+       git branch --set-upstream master my13 2>actual &&
+       test_when_finished git branch --unset-upstream master &&
+       cat >expected <<EOF &&
 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 EOF
-     test_cmp expected actual
+       test_cmp expected actual
 '
 
-test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' \
-    'git branch --set-upstream my13 2>actual &&
-     test_when_finished git branch --unset-upstream my13 &&
-     cat >expected <<EOF &&
+test_expect_success '--set-upstream with one arg only shows the deprecation message if the branch existed' '
+       git branch --set-upstream my13 2>actual &&
+       test_when_finished git branch --unset-upstream my13 &&
+       cat >expected <<EOF &&
 The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
 EOF
-     test_cmp expected actual
+       test_cmp expected actual
 '
 
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
 $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000        branch: Created from master
 EOF
-test_expect_success \
-    'git checkout -b g/h/i -l should create a branch and a log' \
-       'GIT_COMMITTER_DATE="2005-05-26 23:30" \
-     git checkout -b g/h/i -l master &&
-        test_path_is_file .git/refs/heads/g/h/i &&
-        test_path_is_file .git/logs/refs/heads/g/h/i &&
-        test_cmp expect .git/logs/refs/heads/g/h/i'
+test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' '
+       GIT_COMMITTER_DATE="2005-05-26 23:30" \
+       git checkout -b g/h/i -l master &&
+       test_path_is_file .git/refs/heads/g/h/i &&
+       test_path_is_file .git/logs/refs/heads/g/h/i &&
+       test_cmp expect .git/logs/refs/heads/g/h/i
+'
 
 test_expect_success 'checkout -b makes reflog by default' '
        git checkout master &&
@@ -760,7 +786,7 @@ test_expect_success 'detect misconfigured autosetuprebase (bad value)' '
 
 test_expect_success 'detect misconfigured autosetuprebase (no value)' '
        git config --unset branch.autosetuprebase &&
-       echo "[branch] autosetuprebase" >> .git/config &&
+       echo "[branch] autosetuprebase" >>.git/config &&
        test_must_fail git branch &&
        git config --unset branch.autosetuprebase
 '
index 76fe7e0060c20507cb6eb317451b69a2a0c9146d..ba4f98e800f262242ef7925f82dc8d13272fe3ca 100755 (executable)
@@ -94,13 +94,13 @@ test_expect_success 'git branch -v pattern does not show branch summaries' '
        test_must_fail git branch -v branch*
 '
 
-cat >expect <<'EOF'
-* (no branch)
+test_expect_success 'git branch shows detached HEAD properly' '
+       cat >expect <<EOF &&
+* (detached from $(git rev-parse --short HEAD^0))
   branch-one
   branch-two
   master
 EOF
-test_expect_success 'git branch shows detached HEAD properly' '
        git checkout HEAD^0 &&
        git branch >actual &&
        test_i18ncmp expect actual
index 1de0ebda25c1034fc1b343a8f0e3da9c2c7f8c6e..f6cc10265700730999174347704a0df6989c7f1b 100755 (executable)
@@ -138,8 +138,7 @@ test_expect_success 'rebase a single mode change' '
 '
 
 test_expect_success 'rebase is not broken by diff.renames' '
-       git config diff.renames copies &&
-       test_when_finished "git config --unset diff.renames" &&
+       test_config diff.renames copies &&
        git checkout filemove &&
        GIT_TRACE=1 git rebase force-3way
 '
index 15dcbd42d367c3ef6b487e0f235ad201b6cf8413..a58406d12fc8dabf8f2e73e721d2f622a781cc9a 100755 (executable)
@@ -937,8 +937,7 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
 test_expect_success 'rebase -i respects core.commentchar' '
        git reset --hard &&
        git checkout E^0 &&
-       git config core.commentchar "\\" &&
-       test_when_finished "git config --unset core.commentchar" &&
+       test_config core.commentchar "\\" &&
        write_script remove-all-but-first.sh <<-\EOF &&
        sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
        mv "$1.tmp" "$1"
diff --git a/t/t3511-cherry-pick-x.sh b/t/t3511-cherry-pick-x.sh
new file mode 100755 (executable)
index 0000000..f977279
--- /dev/null
@@ -0,0 +1,219 @@
+#!/bin/sh
+
+test_description='Test cherry-pick -x and -s'
+
+. ./test-lib.sh
+
+pristine_detach () {
+       git cherry-pick --quit &&
+       git checkout -f "$1^0" &&
+       git read-tree -u --reset HEAD &&
+       git clean -d -f -f -q -x
+}
+
+mesg_one_line='base: commit message'
+
+mesg_no_footer="$mesg_one_line
+
+OneWordBodyThatsNotA-S-o-B"
+
+mesg_with_footer="$mesg_no_footer
+
+Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+Signed-off-by: A.U. Thor <author@example.com>
+Signed-off-by: B.U. Thor <buthor@example.com>"
+
+mesg_broken_footer="$mesg_no_footer
+
+The signed-off-by string should begin with the words Signed-off-by followed
+by a colon and space, and then the signers name and email address. e.g.
+Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+
+mesg_with_footer_sob="$mesg_with_footer
+Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
+
+mesg_with_cherry_footer="$mesg_with_footer_sob
+(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
+Tested-by: C.U. Thor <cuthor@example.com>"
+
+
+test_expect_success setup '
+       git config advice.detachedhead false &&
+       echo unrelated >unrelated &&
+       git add unrelated &&
+       test_commit initial foo a &&
+       test_commit "$mesg_one_line" foo b mesg-one-line &&
+       git reset --hard initial &&
+       test_commit "$mesg_no_footer" foo b mesg-no-footer &&
+       git reset --hard initial &&
+       test_commit "$mesg_broken_footer" foo b mesg-broken-footer &&
+       git reset --hard initial &&
+       test_commit "$mesg_with_footer" foo b mesg-with-footer &&
+       git reset --hard initial &&
+       test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
+       git reset --hard initial &&
+       test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
+       pristine_detach initial &&
+       test_commit conflicting unrelated
+'
+
+test_expect_success 'cherry-pick -x inserts blank line after one line subject' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-one-line^0` &&
+       git cherry-pick -x mesg-one-line &&
+       cat <<-EOF >expect &&
+               $mesg_one_line
+
+               (cherry picked from commit $sha1)
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -s inserts blank line after one line subject' '
+       pristine_detach initial &&
+       git cherry-pick -s mesg-one-line &&
+       cat <<-EOF >expect &&
+               $mesg_one_line
+
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -s inserts blank line after non-conforming footer' '
+       pristine_detach initial &&
+       git cherry-pick -s mesg-broken-footer &&
+       cat <<-EOF >expect &&
+               $mesg_broken_footer
+
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -x inserts blank line when conforming footer not found' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-no-footer^0` &&
+       git cherry-pick -x mesg-no-footer &&
+       cat <<-EOF >expect &&
+               $mesg_no_footer
+
+               (cherry picked from commit $sha1)
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -s inserts blank line when conforming footer not found' '
+       pristine_detach initial &&
+       git cherry-pick -s mesg-no-footer &&
+       cat <<-EOF >expect &&
+               $mesg_no_footer
+
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -x -s inserts blank line when conforming footer not found' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-no-footer^0` &&
+       git cherry-pick -x -s mesg-no-footer &&
+       cat <<-EOF >expect &&
+               $mesg_no_footer
+
+               (cherry picked from commit $sha1)
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -s adds sob when last sob doesnt match committer' '
+       pristine_detach initial &&
+       git cherry-pick -s mesg-with-footer &&
+       cat <<-EOF >expect &&
+               $mesg_with_footer
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -x -s adds sob when last sob doesnt match committer' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-with-footer^0` &&
+       git cherry-pick -x -s mesg-with-footer &&
+       cat <<-EOF >expect &&
+               $mesg_with_footer
+               (cherry picked from commit $sha1)
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -s refrains from adding duplicate trailing sob' '
+       pristine_detach initial &&
+       git cherry-pick -s mesg-with-footer-sob &&
+       cat <<-EOF >expect &&
+               $mesg_with_footer_sob
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -x -s adds sob even when trailing sob exists for committer' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-with-footer-sob^0` &&
+       git cherry-pick -x -s mesg-with-footer-sob &&
+       cat <<-EOF >expect &&
+               $mesg_with_footer_sob
+               (cherry picked from commit $sha1)
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -x treats "(cherry picked from..." line as part of footer' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-with-cherry-footer^0` &&
+       git cherry-pick -x mesg-with-cherry-footer &&
+       cat <<-EOF >expect &&
+               $mesg_with_cherry_footer
+               (cherry picked from commit $sha1)
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -s treats "(cherry picked from..." line as part of footer' '
+       pristine_detach initial &&
+       git cherry-pick -s mesg-with-cherry-footer &&
+       cat <<-EOF >expect &&
+               $mesg_with_cherry_footer
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as part of footer' '
+       pristine_detach initial &&
+       sha1=`git rev-parse mesg-with-cherry-footer^0` &&
+       git cherry-pick -x -s mesg-with-cherry-footer &&
+       cat <<-EOF >expect &&
+               $mesg_with_cherry_footer
+               (cherry picked from commit $sha1)
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expect actual
+'
+
+test_done
index 37bf5f13b07a632cb8e96e865a75b51f1b7844aa..0c44e9f5d04af8d038a1e78ed5fdf892ce4dd5b5 100755 (executable)
@@ -622,4 +622,69 @@ test_expect_success 'rm of a populated nested submodule with a nested .git direc
        rm -rf submod
 '
 
+test_expect_success 'rm of d/f when d has become a non-directory' '
+       rm -rf d &&
+       mkdir d &&
+       >d/f &&
+       git add d &&
+       rm -rf d &&
+       >d &&
+       git rm d/f &&
+       test_must_fail git rev-parse --verify :d/f &&
+       test_path_is_file d
+'
+
+test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
+       rm -rf d &&
+       mkdir d &&
+       >d/f &&
+       git add d &&
+       rm -rf d &&
+       ln -s nonexistent d &&
+       git rm d/f &&
+       test_must_fail git rev-parse --verify :d/f &&
+       test -h d &&
+       test_path_is_missing d
+'
+
+test_expect_success 'rm of file when it has become a directory' '
+       rm -rf d &&
+       >d &&
+       git add d &&
+       rm -f d &&
+       mkdir d &&
+       >d/f &&
+       test_must_fail git rm d &&
+       git rev-parse --verify :d &&
+       test_path_is_file d/f
+'
+
+test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
+       rm -rf d e &&
+       mkdir e &&
+       echo content >e/f &&
+       ln -s e d &&
+       git add -A e d &&
+       git commit -m "symlink d to e, e/f exists" &&
+       test_must_fail git rm d/f &&
+       git rev-parse --verify :d &&
+       git rev-parse --verify :e/f &&
+       test -h d &&
+       test_path_is_file e/f
+'
+
+test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
+       rm -rf d e &&
+       mkdir d &&
+       echo content >d/f &&
+       git add -A e d &&
+       git commit -m "d/f exists" &&
+       mv d e &&
+       ln -s e d &&
+       test_must_fail git rm d/f &&
+       git rev-parse --verify :d/f &&
+       test -h d &&
+       test_path_is_file e/f
+'
+
 test_done
index 098a6ae4a086ccfeb8c658a80773eb07c9d66441..9fab25cc96b079349a3ca3caffbd8d2bc322265c 100755 (executable)
@@ -319,7 +319,7 @@ test_expect_success PERL 'split hunk "add -p (edit)"' '
        # times to get out.
        #
        # 2. Correct version applies the (not)edited version, and asks
-       #    about the next hunk, against wich we say q and program
+       #    about the next hunk, against which we say q and program
        #    exits.
        for a in s e     q n q q
        do
index bb1fc47fe8aa6904555c153f90a6026c45bf3645..86ee0771077a9da0404a276873c81dd17600ceb4 100755 (executable)
@@ -742,21 +742,21 @@ test_expect_success 'format-patch --signature --cover-letter' '
        test 2 = $(grep "my sig" output | wc -l)
 '
 
-test_expect_success 'format.signature="" supresses signatures' '
+test_expect_success 'format.signature="" suppresses signatures' '
        git config format.signature "" &&
        git format-patch --stdout -1 >output &&
        check_patch output &&
        ! grep "^-- \$" output
 '
 
-test_expect_success 'format-patch --no-signature supresses signatures' '
+test_expect_success 'format-patch --no-signature suppresses signatures' '
        git config --unset-all format.signature &&
        git format-patch --stdout --no-signature -1 >output &&
        check_patch output &&
        ! grep "^-- \$" output
 '
 
-test_expect_success 'format-patch --signature="" supresses signatures' '
+test_expect_success 'format-patch --signature="" suppresses signatures' '
        git format-patch --stdout --signature="" -1 >output &&
        check_patch output &&
        ! grep "^-- \$" output
@@ -972,6 +972,268 @@ test_expect_success 'empty subject prefix does not have extra space' '
        test_cmp expect actual
 '
 
+append_signoff()
+{
+       C=$(git commit-tree HEAD^^{tree} -p HEAD) &&
+       git format-patch --stdout --signoff $C^..$C >append_signoff.patch &&
+       sed -n -e "1,/^---$/p" append_signoff.patch |
+               egrep -n "^Subject|Sign|^$"
+}
+
+test_expect_success 'signoff: commit with no body' '
+       append_signoff </dev/null >actual &&
+       cat <<\EOF | sed "s/EOL$//" >expected &&
+4:Subject: [PATCH] EOL
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: commit with only subject' '
+       echo subject | append_signoff >actual &&
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: commit with only subject that does not end with NL' '
+       printf subject | append_signoff >actual &&
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: no existing signoffs' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: no existing signoffs and no trailing NL' '
+       printf "subject\n\nbody" | append_signoff >actual &&
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: some random signoff' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Signed-off-by: my@house
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: my@house
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: misc conforming footer elements' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Signed-off-by: my@house
+(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
+Tested-by: Some One <someone@example.com>
+Bug: 1234
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: my@house
+15:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: some random signoff-alike' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+Fooled-by-me: my@house
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+11:
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: not really a signoff' '
+       append_signoff <<\EOF >actual &&
+subject
+
+I want to mention about Signed-off-by: here.
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:I want to mention about Signed-off-by: here.
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: not really a signoff (2)' '
+       append_signoff <<\EOF >actual &&
+subject
+
+My unfortunate
+Signed-off-by: example happens to be wrapped here.
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:Signed-off-by: example happens to be wrapped here.
+11:
+12:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: valid S-o-b paragraph in the middle' '
+       append_signoff <<\EOF >actual &&
+subject
+
+Signed-off-by: my@house
+Signed-off-by: your@house
+
+A lot of houses.
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: my@house
+10:Signed-off-by: your@house
+11:
+13:
+14:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: the same signoff at the end' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: the same signoff at the end, no trailing NL' '
+       printf "subject\n\nSigned-off-by: C O Mitter <committer@example.com>" |
+               append_signoff >actual &&
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+9:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: the same signoff NOT at the end' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Signed-off-by: C O Mitter <committer@example.com>
+Signed-off-by: my@house
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+11:Signed-off-by: C O Mitter <committer@example.com>
+12:Signed-off-by: my@house
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: detect garbage in non-conforming footer' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Tested-by: my@house
+Some Trash
+Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+13:Signed-off-by: C O Mitter <committer@example.com>
+14:
+15:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'signoff: footer begins with non-signoff without @ sign' '
+       append_signoff <<\EOF >actual &&
+subject
+
+body
+
+Reviewed-id: Noone
+Tested-by: my@house
+Change-id: Ideadbeef
+Signed-off-by: C O Mitter <committer@example.com>
+Bug: 1234
+EOF
+       cat >expected <<\EOF &&
+4:Subject: [PATCH] subject
+8:
+10:
+14:Signed-off-by: C O Mitter <committer@example.com>
+EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'format patch ignores color.ui' '
        test_unconfig color.ui &&
        git format-patch --stdout -1 >expect &&
index 40ab333a8a4849d620e1d41a75f611921f83055a..f2f55fc51ccd294194300d4bbf66307ac73f9ac6 100755 (executable)
@@ -230,7 +230,7 @@ test_expect_success '.gitattributes override config' '
 '
 
 test_expect_success 'setup: remove diff driver regex' '
-       test_might_fail git config --unset diff.testdriver.wordRegex
+       test_unconfig diff.testdriver.wordRegex
 '
 
 test_expect_success 'use configured regex' '
@@ -335,8 +335,7 @@ test_expect_success 'word-diff with diff.sbe' '
 
        c
        EOF
-       test_when_finished "git config --unset diff.suppress-blank-empty" &&
-       git config diff.suppress-blank-empty true &&
+       test_config diff.suppress-blank-empty true &&
        word_diff --word-diff=plain
 '
 
@@ -368,7 +367,7 @@ test_expect_success 'setup history with two files' '
 
 test_expect_success 'wordRegex for the first file does not apply to the second' '
        echo "*.tex diff=tex" >.gitattributes &&
-       git config diff.tex.wordRegex "[a-z]+|." &&
+       test_config diff.tex.wordRegex "[a-z]+|." &&
        cat >expect <<-\EOF &&
                diff --git a/a.tex b/a.tex
                --- a/a.tex
index 614425adac536d84e6835d9d707b86fe8f5f4d36..1261dbbdf5869b671e36cd7128bfde61fd67b8de 100755 (executable)
@@ -3,6 +3,7 @@
 test_description='combined diff'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/diff-lib.sh
 
 setup_helper () {
        one=$1 branch=$2 side=$3 &&
@@ -113,4 +114,243 @@ test_expect_success 'check --cc --raw with forty trees' '
        grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
 '
 
+test_expect_success 'setup combined ignore spaces' '
+       git checkout master &&
+       >test &&
+       git add test &&
+       git commit -m initial &&
+
+       tr -d Q <<-\EOF >test &&
+       always coalesce
+       eol space coalesce Q
+       space  change coalesce
+       all spa ces coalesce
+       eol spaces Q
+       space  change
+       all spa ces
+       EOF
+       git commit -m "test space change" -a &&
+
+       git checkout -b side HEAD^ &&
+       tr -d Q <<-\EOF >test &&
+       always coalesce
+       eol space coalesce
+       space change coalesce
+       all spaces coalesce
+       eol spaces
+       space change
+       all spaces
+       EOF
+       git commit -m "test other space changes" -a &&
+
+       test_must_fail git merge master &&
+       tr -d Q <<-\EOF >test &&
+       eol spaces Q
+       space  change
+       all spa ces
+       EOF
+       git commit -m merged -a
+'
+
+test_expect_success 'check combined output (no ignore space)' '
+       git show >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       --always coalesce
+       - eol space coalesce
+       - space change coalesce
+       - all spaces coalesce
+       - eol spaces
+       - space change
+       - all spaces
+        -eol space coalesce Q
+        -space  change coalesce
+        -all spa ces coalesce
+       + eol spaces Q
+       + space  change
+       + all spa ces
+       EOF
+       compare_diff_patch expected actual
+'
+
+test_expect_success 'check combined output (ignore space at eol)' '
+       git show --ignore-space-at-eol >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       --always coalesce
+       --eol space coalesce
+       - space change coalesce
+       - all spaces coalesce
+        -space  change coalesce
+        -all spa ces coalesce
+         eol spaces Q
+       - space change
+       - all spaces
+       + space  change
+       + all spa ces
+       EOF
+       compare_diff_patch expected actual
+'
+
+test_expect_success 'check combined output (ignore space change)' '
+       git show -b >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       --always coalesce
+       --eol space coalesce
+       --space change coalesce
+       - all spaces coalesce
+        -all spa ces coalesce
+         eol spaces Q
+         space  change
+       - all spaces
+       + all spa ces
+       EOF
+       compare_diff_patch expected actual
+'
+
+test_expect_success 'check combined output (ignore all spaces)' '
+       git show -w >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       --always coalesce
+       --eol space coalesce
+       --space change coalesce
+       --all spaces coalesce
+         eol spaces Q
+         space  change
+         all spa ces
+       EOF
+       compare_diff_patch expected actual
+'
+
+test_expect_success 'combine diff coalesce simple' '
+       >test &&
+       git add test &&
+       git commit -m initial &&
+       test_seq 4 >test &&
+       git commit -a -m empty1 &&
+       git branch side1 &&
+       git checkout HEAD^ &&
+       test_seq 5 >test &&
+       git commit -a -m empty2 &&
+       test_must_fail git merge side1 &&
+       >test &&
+       git commit -a -m merge &&
+       git show >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       --1
+       --2
+       --3
+       --4
+       - 5
+       EOF
+       compare_diff_patch expected actual
+'
+
+test_expect_success 'combine diff coalesce tricky' '
+       >test &&
+       git add test &&
+       git commit -m initial --allow-empty &&
+       cat <<-\EOF >test &&
+       3
+       1
+       2
+       3
+       4
+       EOF
+       git commit -a -m empty1 &&
+       git branch -f side1 &&
+       git checkout HEAD^ &&
+       cat <<-\EOF >test &&
+       1
+       3
+       5
+       4
+       EOF
+       git commit -a -m empty2 &&
+       git branch -f side2 &&
+       test_must_fail git merge side1 &&
+       >test &&
+       git commit -a -m merge &&
+       git show >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+        -3
+       --1
+        -2
+       --3
+       - 5
+       --4
+       EOF
+       compare_diff_patch expected actual &&
+       git checkout -f side1 &&
+       test_must_fail git merge side2 &&
+       >test &&
+       git commit -a -m merge &&
+       git show >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       - 3
+       --1
+       - 2
+       --3
+        -5
+       --4
+       EOF
+       compare_diff_patch expected actual
+'
+
+test_expect_failure 'combine diff coalesce three parents' '
+       >test &&
+       git add test &&
+       git commit -m initial --allow-empty &&
+       cat <<-\EOF >test &&
+       3
+       1
+       2
+       3
+       4
+       EOF
+       git commit -a -m empty1 &&
+       git checkout -B side1 &&
+       git checkout HEAD^ &&
+       cat <<-\EOF >test &&
+       1
+       3
+       7
+       5
+       4
+       EOF
+       git commit -a -m empty2 &&
+       git branch -f side2 &&
+       git checkout HEAD^ &&
+       cat <<-\EOF >test &&
+       3
+       1
+       6
+       5
+       4
+       EOF
+       git commit -a -m empty3 &&
+       >test &&
+       git add test &&
+       TREE=$(git write-tree) &&
+       COMMIT=$(git commit-tree -p HEAD -p side1 -p side2 -m merge $TREE) &&
+       git show $COMMIT >actual.tmp &&
+       sed -e "1,/^@@@/d" < actual.tmp >actual &&
+       tr -d Q <<-\EOF >expected &&
+       -- 3
+       ---1
+       -  6
+        - 2
+        --3
+         -7
+       - -5
+       ---4
+       EOF
+       compare_diff_patch expected actual
+'
+
 test_done
index 6f6ee88b28bc5417035b45d87aaf4a9c974ab6c5..5d0c5983381b4072d915de0f8d75053b19172d66 100755 (executable)
@@ -47,7 +47,7 @@ test_fix () {
        # find touched lines
        $DIFF file target | sed -n -e "s/^> //p" >fixed
 
-       # the changed lines are all expeced to change
+       # the changed lines are all expected to change
        fixed_cnt=$(wc -l <fixed)
        case "$1" in
        '') expect_cnt=$fixed_cnt ;;
@@ -486,4 +486,30 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol unset' '
        test_cmp one expect
 '
 
+test_expect_success 'whitespace=fix to expand' '
+       qz_to_tab_space >preimage <<-\EOF &&
+       QQa
+       QQb
+       QQc
+       ZZZZZZZZZZZZZZZZd
+       QQe
+       QQf
+       QQg
+       EOF
+       qz_to_tab_space >patch <<-\EOF &&
+       diff --git a/preimage b/preimage
+       --- a/preimage
+       +++ b/preimage
+       @@ -1,7 +1,6 @@
+        QQa
+        QQb
+        QQc
+       -QQd
+        QQe
+        QQf
+        QQg
+       EOF
+       git -c core.whitespace=tab-in-indent apply --whitespace=fix patch
+'
+
 test_done
index cdafd7e7c1e6c73a97c36a60f77810badff603f2..12f6b027acbccae3fe524906970ff139ddccfed0 100755 (executable)
@@ -17,7 +17,7 @@ test_expect_success 'setup: messages' '
        vero eos et accusam et justo duo dolores et ea rebum.
 
        EOF
-       q_to_tab <<-\EOF >>msg &&
+       qz_to_tab_space <<-\EOF >>msg &&
        QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
        Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
        Qat vero eros et accumsan et iusto odio dignissim qui blandit
index fa686b887d6b49ab8e6d30893501744645f72a91..9243a979933997286bb6004bd7b224bad1bbc5cc 100755 (executable)
@@ -419,8 +419,6 @@ test_expect_success 'log --graph with merge' '
 '
 
 test_expect_success 'log.decorate configuration' '
-       test_might_fail git config --unset-all log.decorate &&
-
        git log --oneline >expect.none &&
        git log --oneline --decorate >expect.short &&
        git log --oneline --decorate=full >expect.full &&
@@ -429,8 +427,7 @@ test_expect_success 'log.decorate configuration' '
        git log --oneline >actual &&
        test_cmp expect.short actual &&
 
-       git config --unset-all log.decorate &&
-       git config log.decorate true &&
+       test_config log.decorate true &&
        git log --oneline >actual &&
        test_cmp expect.short actual &&
        git log --oneline --decorate=full >actual &&
@@ -438,8 +435,7 @@ test_expect_success 'log.decorate configuration' '
        git log --oneline --decorate=no >actual &&
        test_cmp expect.none actual &&
 
-       git config --unset-all log.decorate &&
-       git config log.decorate no &&
+       test_config log.decorate no &&
        git log --oneline >actual &&
        test_cmp expect.none actual &&
        git log --oneline --decorate >actual &&
@@ -447,8 +443,7 @@ test_expect_success 'log.decorate configuration' '
        git log --oneline --decorate=full >actual &&
        test_cmp expect.full actual &&
 
-       git config --unset-all log.decorate &&
-       git config log.decorate 1 &&
+       test_config log.decorate 1 &&
        git log --oneline >actual &&
        test_cmp expect.short actual &&
        git log --oneline --decorate=full >actual &&
@@ -456,8 +451,7 @@ test_expect_success 'log.decorate configuration' '
        git log --oneline --decorate=no >actual &&
        test_cmp expect.none actual &&
 
-       git config --unset-all log.decorate &&
-       git config log.decorate short &&
+       test_config log.decorate short &&
        git log --oneline >actual &&
        test_cmp expect.short actual &&
        git log --oneline --no-decorate >actual &&
@@ -465,8 +459,7 @@ test_expect_success 'log.decorate configuration' '
        git log --oneline --decorate=full >actual &&
        test_cmp expect.full actual &&
 
-       git config --unset-all log.decorate &&
-       git config log.decorate full &&
+       test_config log.decorate full &&
        git log --oneline >actual &&
        test_cmp expect.full actual &&
        git log --oneline --no-decorate >actual &&
@@ -474,16 +467,15 @@ test_expect_success 'log.decorate configuration' '
        git log --oneline --decorate >actual &&
        test_cmp expect.short actual
 
-       git config --unset-all log.decorate &&
+       test_unconfig log.decorate &&
        git log --pretty=raw >expect.raw &&
-       git config log.decorate full &&
+       test_config log.decorate full &&
        git log --pretty=raw >actual &&
        test_cmp expect.raw actual
 
 '
 
 test_expect_success 'reflog is expected format' '
-       test_might_fail git config --remove-section log &&
        git log -g --abbrev-commit --pretty=oneline >expect &&
        git reflog >actual &&
        test_cmp expect actual
@@ -496,10 +488,6 @@ test_expect_success 'whatchanged is expected format' '
 '
 
 test_expect_success 'log.abbrevCommit configuration' '
-       test_when_finished "git config --unset log.abbrevCommit" &&
-
-       test_might_fail git config --unset log.abbrevCommit &&
-
        git log --abbrev-commit >expect.log.abbrev &&
        git log --no-abbrev-commit >expect.log.full &&
        git log --pretty=raw >expect.log.raw &&
@@ -508,7 +496,7 @@ test_expect_success 'log.abbrevCommit configuration' '
        git whatchanged --abbrev-commit >expect.whatchanged.abbrev &&
        git whatchanged --no-abbrev-commit >expect.whatchanged.full &&
 
-       git config log.abbrevCommit true &&
+       test_config log.abbrevCommit true &&
 
        git log >actual &&
        test_cmp expect.log.abbrev actual &&
index eed727341dca4cd16a2558644506573885baccd9..38fb80f643534a2bd724e13ef271f90167ac11a3 100755 (executable)
@@ -80,6 +80,20 @@ test_expect_success 'log -G -i (match)' '
        test_cmp expect actual
 '
 
+test_expect_success 'log -G --textconv (missing textconv tool)' '
+       echo "* diff=test" >.gitattributes &&
+       test_must_fail git -c diff.test.textconv=missing log -Gfoo &&
+       rm .gitattributes
+'
+
+test_expect_success 'log -G --no-textconv (missing textconv tool)' '
+       echo "* diff=test" >.gitattributes &&
+       git -c diff.test.textconv=missing log -Gfoo --no-textconv >actual &&
+       >expect &&
+       test_cmp expect actual &&
+       rm .gitattributes
+'
+
 test_expect_success 'log -S (nomatch)' '
        git log -Spicked --format=%H >actual &&
        >expect &&
@@ -116,4 +130,18 @@ test_expect_success 'log -S -i (nomatch)' '
        test_cmp expect actual
 '
 
+test_expect_success 'log -S --textconv (missing textconv tool)' '
+       echo "* diff=test" >.gitattributes &&
+       test_must_fail git -c diff.test.textconv=missing log -Sfoo &&
+       rm .gitattributes
+'
+
+test_expect_success 'log -S --no-textconv (missing textconv tool)' '
+       echo "* diff=test" >.gitattributes &&
+       git -c diff.test.textconv=missing log -Sfoo --no-textconv >actual &&
+       >expect &&
+       test_cmp expect actual &&
+       rm .gitattributes
+'
+
 test_done
index 0c847fb45482b67266dc6eb9ec62b8cc7b5a9d76..6667d159ab0950f10a3271f1cb81a63953214f17 100755 (executable)
@@ -27,6 +27,25 @@ test_expect_success 'setup' '
        echo ignored-only-if-dir/ export-ignore >>.git/info/attributes &&
        git add ignored-only-if-dir &&
 
+       mkdir -p ignored-without-slash &&
+       echo "ignored without slash" >ignored-without-slash/foo &&
+       git add ignored-without-slash/foo &&
+       echo "ignored-without-slash export-ignore" >>.git/info/attributes &&
+
+       mkdir -p wildcard-without-slash &&
+       echo "ignored without slash" >wildcard-without-slash/foo &&
+       git add wildcard-without-slash/foo &&
+       echo "wild*-without-slash export-ignore" >>.git/info/attributes &&
+
+       mkdir -p deep/and/slashless &&
+       echo "ignored without slash" >deep/and/slashless/foo &&
+       git add deep/and/slashless/foo &&
+       echo "deep/and/slashless export-ignore" >>.git/info/attributes &&
+
+       mkdir -p deep/with/wildcard &&
+       echo "ignored without slash" >deep/with/wildcard/foo &&
+       git add deep/with/wildcard/foo &&
+       echo "deep/*t*/wildcard export-ignore" >>.git/info/attributes &&
 
        mkdir -p one-level-lower/two-levels-lower/ignored-only-if-dir &&
        echo ignored by ignored dir >one-level-lower/two-levels-lower/ignored-only-if-dir/ignored-by-ignored-dir &&
@@ -49,6 +68,14 @@ test_expect_exists   archive/not-ignored-dir/ignored-only-if-dir
 test_expect_exists     archive/not-ignored-dir/
 test_expect_missing    archive/ignored-only-if-dir/
 test_expect_missing    archive/ignored-ony-if-dir/ignored-by-ignored-dir
+test_expect_missing    archive/ignored-without-slash/ &&
+test_expect_missing    archive/ignored-without-slash/foo &&
+test_expect_missing    archive/wildcard-without-slash/
+test_expect_missing    archive/wildcard-without-slash/foo &&
+test_expect_missing    archive/deep/and/slashless/ &&
+test_expect_missing    archive/deep/and/slashless/foo &&
+test_expect_missing    archive/deep/with/wildcard/ &&
+test_expect_missing    archive/deep/with/wildcard/foo &&
 test_expect_exists     archive/one-level-lower/
 test_expect_missing    archive/one-level-lower/two-levels-lower/ignored-only-if-dir/
 test_expect_missing    archive/one-level-lower/two-levels-lower/ignored-ony-if-dir/ignored-by-ignored-dir
index d645328609c9ec63782a0b9f80c31a73ef745802..e4bb3a14570780b41ce4ebea9e47870d4cbcb127 100755 (executable)
@@ -195,4 +195,30 @@ test_expect_success 'gc: prune old objects after local clone' '
        )
 '
 
+test_expect_success 'garbage report in count-objects -v' '
+       : >.git/objects/pack/foo &&
+       : >.git/objects/pack/foo.bar &&
+       : >.git/objects/pack/foo.keep &&
+       : >.git/objects/pack/foo.pack &&
+       : >.git/objects/pack/fake.bar &&
+       : >.git/objects/pack/fake.keep &&
+       : >.git/objects/pack/fake.pack &&
+       : >.git/objects/pack/fake.idx &&
+       : >.git/objects/pack/fake2.keep &&
+       : >.git/objects/pack/fake3.idx &&
+       git count-objects -v 2>stderr &&
+       grep "index file .git/objects/pack/fake.idx is too small" stderr &&
+       grep "^warning:" stderr | sort >actual &&
+       cat >expected <<\EOF &&
+warning: garbage found: .git/objects/pack/fake.bar
+warning: garbage found: .git/objects/pack/foo
+warning: garbage found: .git/objects/pack/foo.bar
+warning: no corresponding .idx nor .pack: .git/objects/pack/fake2.keep
+warning: no corresponding .idx: .git/objects/pack/foo.keep
+warning: no corresponding .idx: .git/objects/pack/foo.pack
+warning: no corresponding .pack: .git/objects/pack/fake3.idx
+EOF
+       test_cmp expected actual
+'
+
 test_done
index 60de2d6ede958e713aebe85d73ee65ddbc10201d..f30c03885cda050f0bc704428ffa8a66932ff3fd 100755 (executable)
@@ -4,10 +4,6 @@ test_description='test automatic tag following'
 
 . ./test-lib.sh
 
-if ! test_have_prereq NOT_MINGW; then
-       say "GIT_DEBUG_SEND_PACK not supported - skipping tests"
-fi
-
 # End state of the repository:
 #
 #         T - tag1          S - tag2
@@ -17,7 +13,7 @@ fi
 #     \   C - origin/cat    \
 #      origin/master         master
 
-test_expect_success NOT_MINGW setup '
+test_expect_success setup '
        test_tick &&
        echo ichi >file &&
        git add file &&
@@ -39,28 +35,35 @@ test_expect_success NOT_MINGW setup '
 '
 
 U=UPLOAD_LOG
+UPATH="$(pwd)/$U"
 
-test_expect_success NOT_MINGW 'setup expect' '
+test_expect_success 'setup expect' '
 cat - <<EOF >expect
-#S
 want $A
-#E
 EOF
 '
 
-test_expect_success NOT_MINGW 'fetch A (new commit : 1 connection)' '
+get_needs () {
+       test -s "$1" &&
+       perl -alne '
+               next unless $F[1] eq "upload-pack<";
+               last if $F[2] eq "0000";
+               print $F[2], " ", $F[3];
+       ' "$1"
+}
+
+test_expect_success 'fetch A (new commit : 1 connection)' '
        rm -f $U &&
        (
                cd cloned &&
-               GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
+               GIT_TRACE_PACKET=$UPATH git fetch &&
                test $A = $(git rev-parse --verify origin/master)
        ) &&
-       test -s $U &&
-       cut -d" " -f1,2 $U >actual &&
+       get_needs $U >actual &&
        test_cmp expect actual
 '
 
-test_expect_success NOT_MINGW "create tag T on A, create C on branch cat" '
+test_expect_success "create tag T on A, create C on branch cat" '
        git tag -a -m tag1 tag1 $A &&
        T=$(git rev-parse --verify tag1) &&
 
@@ -72,30 +75,27 @@ test_expect_success NOT_MINGW "create tag T on A, create C on branch cat" '
        git checkout master
 '
 
-test_expect_success NOT_MINGW 'setup expect' '
+test_expect_success 'setup expect' '
 cat - <<EOF >expect
-#S
 want $C
 want $T
-#E
 EOF
 '
 
-test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' '
+test_expect_success 'fetch C, T (new branch, tag : 1 connection)' '
        rm -f $U &&
        (
                cd cloned &&
-               GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
+               GIT_TRACE_PACKET=$UPATH git fetch &&
                test $C = $(git rev-parse --verify origin/cat) &&
                test $T = $(git rev-parse --verify tag1) &&
                test $A = $(git rev-parse --verify tag1^0)
        ) &&
-       test -s $U &&
-       cut -d" " -f1,2 $U >actual &&
+       get_needs $U >actual &&
        test_cmp expect actual
 '
 
-test_expect_success NOT_MINGW "create commits O, B, tag S on B" '
+test_expect_success "create commits O, B, tag S on B" '
        test_tick &&
        echo O >file &&
        git add file &&
@@ -111,39 +111,34 @@ test_expect_success NOT_MINGW "create commits O, B, tag S on B" '
        S=$(git rev-parse --verify tag2)
 '
 
-test_expect_success NOT_MINGW 'setup expect' '
+test_expect_success 'setup expect' '
 cat - <<EOF >expect
-#S
 want $B
 want $S
-#E
 EOF
 '
 
-test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' '
+test_expect_success 'fetch B, S (commit and tag : 1 connection)' '
        rm -f $U &&
        (
                cd cloned &&
-               GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
+               GIT_TRACE_PACKET=$UPATH git fetch &&
                test $B = $(git rev-parse --verify origin/master) &&
                test $B = $(git rev-parse --verify tag2^0) &&
                test $S = $(git rev-parse --verify tag2)
        ) &&
-       test -s $U &&
-       cut -d" " -f1,2 $U >actual &&
+       get_needs $U >actual &&
        test_cmp expect actual
 '
 
-test_expect_success NOT_MINGW 'setup expect' '
+test_expect_success 'setup expect' '
 cat - <<EOF >expect
-#S
 want $B
 want $S
-#E
 EOF
 '
 
-test_expect_success NOT_MINGW 'new clone fetch master and tags' '
+test_expect_success 'new clone fetch master and tags' '
        git branch -D cat
        rm -f $U
        (
@@ -151,15 +146,14 @@ test_expect_success NOT_MINGW 'new clone fetch master and tags' '
                cd clone2 &&
                git init &&
                git remote add origin .. &&
-               GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U &&
+               GIT_TRACE_PACKET=$UPATH git fetch &&
                test $B = $(git rev-parse --verify origin/master) &&
                test $S = $(git rev-parse --verify tag2) &&
                test $B = $(git rev-parse --verify tag2^0) &&
                test $T = $(git rev-parse --verify tag1) &&
                test $A = $(git rev-parse --verify tag1^0)
        ) &&
-       test -s $U &&
-       cut -d" " -f1,2 $U >actual &&
+       get_needs $U >actual &&
        test_cmp expect actual
 '
 
index c31e5c1c525eea5a9f4677b03c5d7314d70c6136..838e71dafea8388cbe18c82b26f58f074f56abbd 100755 (executable)
@@ -1,16 +1,28 @@
 #!/bin/sh
 
-test_description='fetching and pushing, with or without wildcard'
+test_description='Basic fetch/push functionality.
+
+This test checks the following functionality:
+
+* command-line syntax
+* refspecs
+* fast-forward detection, and overriding it
+* configuration
+* hooks
+* --porcelain output format
+* hiderefs
+'
 
 . ./test-lib.sh
 
 D=`pwd`
 
 mk_empty () {
-       rm -fr testrepo &&
-       mkdir testrepo &&
+       repo_name="$1"
+       rm -fr "$repo_name" &&
+       mkdir "$repo_name" &&
        (
-               cd testrepo &&
+               cd "$repo_name" &&
                git init &&
                git config receive.denyCurrentBranch warn &&
                mv .git/hooks .git/hooks-disabled
@@ -18,32 +30,33 @@ mk_empty () {
 }
 
 mk_test () {
-       mk_empty &&
+       repo_name="$1"
+       shift
+
+       mk_empty "$repo_name" &&
        (
                for ref in "$@"
                do
-                       git push testrepo $the_first_commit:refs/$ref || {
-                               echo "Oops, push refs/$ref failure"
-                               exit 1
-                       }
+                       git push "$repo_name" $the_first_commit:refs/$ref ||
+                       exit
                done &&
-               cd testrepo &&
+               cd "$repo_name" &&
                for ref in "$@"
                do
-                       r=$(git show-ref -s --verify refs/$ref) &&
-                       test "z$r" = "z$the_first_commit" || {
-                               echo "Oops, refs/$ref is wrong"
-                               exit 1
-                       }
+                       echo "$the_first_commit" >expect &&
+                       git show-ref -s --verify refs/$ref >actual &&
+                       test_cmp expect actual ||
+                       exit
                done &&
                git fsck --full
        )
 }
 
 mk_test_with_hooks() {
+       repo_name=$1
        mk_test "$@" &&
        (
-               cd testrepo &&
+               cd "$repo_name" &&
                mkdir .git/hooks &&
                cd .git/hooks &&
 
@@ -75,22 +88,23 @@ mk_test_with_hooks() {
 }
 
 mk_child() {
-       rm -rf "$1" &&
-       git clone testrepo "$1"
+       rm -rf "$2" &&
+       git clone "$1" "$2"
 }
 
 check_push_result () {
+       repo_name="$1"
+       shift
+
        (
-               cd testrepo &&
-               it="$1" &&
-               shift
+               cd "$repo_name" &&
+               echo "$1" >expect &&
+               shift &&
                for ref in "$@"
                do
-                       r=$(git show-ref -s --verify refs/$ref) &&
-                       test "z$r" = "z$it" || {
-                               echo "Oops, refs/$ref is wrong"
-                               exit 1
-                       }
+                       git show-ref -s --verify refs/$ref >actual &&
+                       test_cmp expect actual ||
+                       exit
                done &&
                git fsck --full
        )
@@ -113,35 +127,33 @@ test_expect_success setup '
 '
 
 test_expect_success 'fetch without wildcard' '
-       mk_empty &&
+       mk_empty testrepo &&
        (
                cd testrepo &&
                git fetch .. refs/heads/master:refs/remotes/origin/master &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'fetch with wildcard' '
-       mk_empty &&
+       mk_empty testrepo &&
        (
                cd testrepo &&
                git config remote.up.url .. &&
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'fetch with insteadOf' '
-       mk_empty &&
+       mk_empty testrepo &&
        (
                TRASH=$(pwd)/ &&
                cd testrepo &&
@@ -150,15 +162,14 @@ test_expect_success 'fetch with insteadOf' '
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
-       mk_empty &&
+       mk_empty testrepo &&
        (
                TRASH=$(pwd)/ &&
                cd testrepo &&
@@ -167,321 +178,310 @@ test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push without wildcard' '
-       mk_empty &&
+       mk_empty testrepo &&
 
        git push testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push with wildcard' '
-       mk_empty &&
+       mk_empty testrepo &&
 
        git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push with insteadOf' '
-       mk_empty &&
+       mk_empty testrepo &&
        TRASH="$(pwd)/" &&
-       git config "url.$TRASH.insteadOf" trash/ &&
+       test_config "url.$TRASH.insteadOf" trash/ &&
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push with pushInsteadOf' '
-       mk_empty &&
+       mk_empty testrepo &&
        TRASH="$(pwd)/" &&
-       git config "url.$TRASH.pushInsteadOf" trash/ &&
+       test_config "url.$TRASH.pushInsteadOf" trash/ &&
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
-       mk_empty &&
-       TRASH="$(pwd)/" &&
-       git config "url.trash2/.pushInsteadOf" trash/ &&
-       git config remote.r.url trash/wrong &&
-       git config remote.r.pushurl "$TRASH/testrepo" &&
+       mk_empty testrepo &&
+       test_config "url.trash2/.pushInsteadOf" testrepo/ &&
+       test_config "url.trash3/.pusnInsteadOf" trash/wrong &&
+       test_config remote.r.url trash/wrong &&
+       test_config remote.r.pushurl "testrepo/" &&
        git push r refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push with matching heads' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git push testrepo &&
-       check_push_result $the_commit heads/master
+       check_push_result testrepo $the_commit heads/master
 
 '
 
 test_expect_success 'push with matching heads on the command line' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git push testrepo : &&
-       check_push_result $the_commit heads/master
+       check_push_result testrepo $the_commit heads/master
 
 '
 
 test_expect_success 'failed (non-fast-forward) push with matching heads' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git push testrepo : &&
        git commit --amend -massaged &&
        test_must_fail git push testrepo &&
-       check_push_result $the_commit heads/master &&
+       check_push_result testrepo $the_commit heads/master &&
        git reset --hard $the_commit
 
 '
 
 test_expect_success 'push --force with matching heads' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git push testrepo : &&
        git commit --amend -massaged &&
        git push --force testrepo &&
-       ! check_push_result $the_commit heads/master &&
+       ! check_push_result testrepo $the_commit heads/master &&
        git reset --hard $the_commit
 
 '
 
 test_expect_success 'push with matching heads and forced update' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git push testrepo : &&
        git commit --amend -massaged &&
        git push testrepo +: &&
-       ! check_push_result $the_commit heads/master &&
+       ! check_push_result testrepo $the_commit heads/master &&
        git reset --hard $the_commit
 
 '
 
 test_expect_success 'push with no ambiguity (1)' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git push testrepo master:master &&
-       check_push_result $the_commit heads/master
+       check_push_result testrepo $the_commit heads/master
 
 '
 
 test_expect_success 'push with no ambiguity (2)' '
 
-       mk_test remotes/origin/master &&
+       mk_test testrepo remotes/origin/master &&
        git push testrepo master:origin/master &&
-       check_push_result $the_commit remotes/origin/master
+       check_push_result testrepo $the_commit remotes/origin/master
 
 '
 
 test_expect_success 'push with colon-less refspec, no ambiguity' '
 
-       mk_test heads/master heads/t/master &&
+       mk_test testrepo heads/master heads/t/master &&
        git branch -f t/master master &&
        git push testrepo master &&
-       check_push_result $the_commit heads/master &&
-       check_push_result $the_first_commit heads/t/master
+       check_push_result testrepo $the_commit heads/master &&
+       check_push_result testrepo $the_first_commit heads/t/master
 
 '
 
 test_expect_success 'push with weak ambiguity (1)' '
 
-       mk_test heads/master remotes/origin/master &&
+       mk_test testrepo heads/master remotes/origin/master &&
        git push testrepo master:master &&
-       check_push_result $the_commit heads/master &&
-       check_push_result $the_first_commit remotes/origin/master
+       check_push_result testrepo $the_commit heads/master &&
+       check_push_result testrepo $the_first_commit remotes/origin/master
 
 '
 
 test_expect_success 'push with weak ambiguity (2)' '
 
-       mk_test heads/master remotes/origin/master remotes/another/master &&
+       mk_test testrepo heads/master remotes/origin/master remotes/another/master &&
        git push testrepo master:master &&
-       check_push_result $the_commit heads/master &&
-       check_push_result $the_first_commit remotes/origin/master remotes/another/master
+       check_push_result testrepo $the_commit heads/master &&
+       check_push_result testrepo $the_first_commit remotes/origin/master remotes/another/master
 
 '
 
 test_expect_success 'push with ambiguity' '
 
-       mk_test heads/frotz tags/frotz &&
-       if git push testrepo master:frotz
-       then
-               echo "Oops, should have failed"
-               false
-       else
-               check_push_result $the_first_commit heads/frotz tags/frotz
-       fi
+       mk_test testrepo heads/frotz tags/frotz &&
+       test_must_fail git push testrepo master:frotz &&
+       check_push_result testrepo $the_first_commit heads/frotz tags/frotz
 
 '
 
 test_expect_success 'push with colon-less refspec (1)' '
 
-       mk_test heads/frotz tags/frotz &&
+       mk_test testrepo heads/frotz tags/frotz &&
        git branch -f frotz master &&
        git push testrepo frotz &&
-       check_push_result $the_commit heads/frotz &&
-       check_push_result $the_first_commit tags/frotz
+       check_push_result testrepo $the_commit heads/frotz &&
+       check_push_result testrepo $the_first_commit tags/frotz
 
 '
 
 test_expect_success 'push with colon-less refspec (2)' '
 
-       mk_test heads/frotz tags/frotz &&
+       mk_test testrepo heads/frotz tags/frotz &&
        if git show-ref --verify -q refs/heads/frotz
        then
                git branch -D frotz
        fi &&
        git tag -f frotz &&
        git push -f testrepo frotz &&
-       check_push_result $the_commit tags/frotz &&
-       check_push_result $the_first_commit heads/frotz
+       check_push_result testrepo $the_commit tags/frotz &&
+       check_push_result testrepo $the_first_commit heads/frotz
 
 '
 
 test_expect_success 'push with colon-less refspec (3)' '
 
-       mk_test &&
+       mk_test testrepo &&
        if git show-ref --verify -q refs/tags/frotz
        then
                git tag -d frotz
        fi &&
        git branch -f frotz master &&
        git push testrepo frotz &&
-       check_push_result $the_commit heads/frotz &&
+       check_push_result testrepo $the_commit heads/frotz &&
        test 1 = $( cd testrepo && git show-ref | wc -l )
 '
 
 test_expect_success 'push with colon-less refspec (4)' '
 
-       mk_test &&
+       mk_test testrepo &&
        if git show-ref --verify -q refs/heads/frotz
        then
                git branch -D frotz
        fi &&
        git tag -f frotz &&
        git push testrepo frotz &&
-       check_push_result $the_commit tags/frotz &&
+       check_push_result testrepo $the_commit tags/frotz &&
        test 1 = $( cd testrepo && git show-ref | wc -l )
 
 '
 
 test_expect_success 'push head with non-existent, incomplete dest' '
 
-       mk_test &&
+       mk_test testrepo &&
        git push testrepo master:branch &&
-       check_push_result $the_commit heads/branch
+       check_push_result testrepo $the_commit heads/branch
 
 '
 
 test_expect_success 'push tag with non-existent, incomplete dest' '
 
-       mk_test &&
+       mk_test testrepo &&
        git tag -f v1.0 &&
        git push testrepo v1.0:tag &&
-       check_push_result $the_commit tags/tag
+       check_push_result testrepo $the_commit tags/tag
 
 '
 
 test_expect_success 'push sha1 with non-existent, incomplete dest' '
 
-       mk_test &&
+       mk_test testrepo &&
        test_must_fail git push testrepo `git rev-parse master`:foo
 
 '
 
 test_expect_success 'push ref expression with non-existent, incomplete dest' '
 
-       mk_test &&
+       mk_test testrepo &&
        test_must_fail git push testrepo master^:branch
 
 '
 
 test_expect_success 'push with HEAD' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git checkout master &&
        git push testrepo HEAD &&
-       check_push_result $the_commit heads/master
+       check_push_result testrepo $the_commit heads/master
 
 '
 
 test_expect_success 'push with HEAD nonexisting at remote' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git checkout -b local master &&
        git push testrepo HEAD &&
-       check_push_result $the_commit heads/local
+       check_push_result testrepo $the_commit heads/local
 '
 
 test_expect_success 'push with +HEAD' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git checkout master &&
        git branch -D local &&
        git checkout -b local &&
        git push testrepo master local &&
-       check_push_result $the_commit heads/master &&
-       check_push_result $the_commit heads/local &&
+       check_push_result testrepo $the_commit heads/master &&
+       check_push_result testrepo $the_commit heads/local &&
 
        # Without force rewinding should fail
        git reset --hard HEAD^ &&
        test_must_fail git push testrepo HEAD &&
-       check_push_result $the_commit heads/local &&
+       check_push_result testrepo $the_commit heads/local &&
 
        # With force rewinding should succeed
        git push testrepo +HEAD &&
-       check_push_result $the_first_commit heads/local
+       check_push_result testrepo $the_first_commit heads/local
 
 '
 
 test_expect_success 'push HEAD with non-existent, incomplete dest' '
 
-       mk_test &&
+       mk_test testrepo &&
        git checkout master &&
        git push testrepo HEAD:branch &&
-       check_push_result $the_commit heads/branch
+       check_push_result testrepo $the_commit heads/branch
 
 '
 
 test_expect_success 'push with config remote.*.push = HEAD' '
 
-       mk_test heads/local &&
+       mk_test testrepo heads/local &&
        git checkout master &&
        git branch -f local $the_commit &&
        (
@@ -489,46 +489,66 @@ test_expect_success 'push with config remote.*.push = HEAD' '
                git checkout local &&
                git reset --hard $the_first_commit
        ) &&
-       git config remote.there.url testrepo &&
-       git config remote.there.push HEAD &&
-       git config branch.master.remote there &&
+       test_config remote.there.url testrepo &&
+       test_config remote.there.push HEAD &&
+       test_config branch.master.remote there &&
        git push &&
-       check_push_result $the_commit heads/master &&
-       check_push_result $the_first_commit heads/local
+       check_push_result testrepo $the_commit heads/master &&
+       check_push_result testrepo $the_first_commit heads/local
 '
 
-# clean up the cruft left with the previous one
-git config --remove-section remote.there
-git config --remove-section branch.master
+test_expect_success 'push with remote.pushdefault' '
+       mk_test up_repo heads/master &&
+       mk_test down_repo heads/master &&
+       test_config remote.up.url up_repo &&
+       test_config remote.down.url down_repo &&
+       test_config branch.master.remote up &&
+       test_config remote.pushdefault down &&
+       git push &&
+       check_push_result up_repo $the_first_commit heads/master &&
+       check_push_result down_repo $the_commit heads/master
+'
 
 test_expect_success 'push with config remote.*.pushurl' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git checkout master &&
-       git config remote.there.url test2repo &&
-       git config remote.there.pushurl testrepo &&
+       test_config remote.there.url test2repo &&
+       test_config remote.there.pushurl testrepo &&
        git push there &&
-       check_push_result $the_commit heads/master
+       check_push_result testrepo $the_commit heads/master
+'
+
+test_expect_success 'push with config branch.*.pushremote' '
+       mk_test up_repo heads/master &&
+       mk_test side_repo heads/master &&
+       mk_test down_repo heads/master &&
+       test_config remote.up.url up_repo &&
+       test_config remote.pushdefault side_repo &&
+       test_config remote.down.url down_repo &&
+       test_config branch.master.remote up &&
+       test_config branch.master.pushremote down &&
+       git push &&
+       check_push_result up_repo $the_first_commit heads/master &&
+       check_push_result side_repo $the_first_commit heads/master &&
+       check_push_result down_repo $the_commit heads/master
 '
 
-# clean up the cruft left with the previous one
-git config --remove-section remote.there
-
 test_expect_success 'push with dry-run' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        (
                cd testrepo &&
                old_commit=$(git show-ref -s --verify refs/heads/master)
        ) &&
        git push --dry-run testrepo &&
-       check_push_result $old_commit heads/master
+       check_push_result testrepo $old_commit heads/master
 '
 
 test_expect_success 'push updates local refs' '
 
-       mk_test heads/master &&
-       mk_child child &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child &&
        (
                cd child &&
                git pull .. master &&
@@ -541,9 +561,9 @@ test_expect_success 'push updates local refs' '
 
 test_expect_success 'push updates up-to-date local refs' '
 
-       mk_test heads/master &&
-       mk_child child1 &&
-       mk_child child2 &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child1 &&
+       mk_child testrepo child2 &&
        (cd child1 && git pull .. master && git push) &&
        (
                cd child2 &&
@@ -557,8 +577,8 @@ test_expect_success 'push updates up-to-date local refs' '
 
 test_expect_success 'push preserves up-to-date packed refs' '
 
-       mk_test heads/master &&
-       mk_child child &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child &&
        (
                cd child &&
                git push &&
@@ -569,8 +589,8 @@ test_expect_success 'push preserves up-to-date packed refs' '
 
 test_expect_success 'push does not update local refs on failure' '
 
-       mk_test heads/master &&
-       mk_child child &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child &&
        mkdir testrepo/.git/hooks &&
        echo "#!/no/frobnication/today" >testrepo/.git/hooks/pre-receive &&
        chmod +x testrepo/.git/hooks/pre-receive &&
@@ -586,7 +606,7 @@ test_expect_success 'push does not update local refs on failure' '
 
 test_expect_success 'allow deleting an invalid remote ref' '
 
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        rm -f testrepo/.git/objects/??/* &&
        git push testrepo :refs/heads/master &&
        (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
@@ -594,7 +614,7 @@ test_expect_success 'allow deleting an invalid remote ref' '
 '
 
 test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' '
-       mk_test_with_hooks heads/master heads/next &&
+       mk_test_with_hooks testrepo heads/master heads/next &&
        orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
        newmaster=$(git show-ref -s --verify refs/heads/master) &&
        orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
@@ -630,7 +650,7 @@ test_expect_success 'pushing valid refs triggers post-receive and post-update ho
 '
 
 test_expect_success 'deleting dangling ref triggers hooks with correct args' '
-       mk_test_with_hooks heads/master &&
+       mk_test_with_hooks testrepo heads/master &&
        rm -f testrepo/.git/objects/??/* &&
        git push testrepo :refs/heads/master &&
        (
@@ -659,7 +679,7 @@ test_expect_success 'deleting dangling ref triggers hooks with correct args' '
 '
 
 test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' '
-       mk_test_with_hooks heads/master &&
+       mk_test_with_hooks testrepo heads/master &&
        orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
        newmaster=$(git show-ref -s --verify refs/heads/master) &&
        git push testrepo master :refs/heads/nonexistent &&
@@ -691,7 +711,7 @@ test_expect_success 'deletion of a non-existent ref is not fed to post-receive a
 '
 
 test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' '
-       mk_test_with_hooks heads/master &&
+       mk_test_with_hooks testrepo heads/master &&
        git push testrepo :refs/heads/nonexistent &&
        (
                cd testrepo/.git &&
@@ -711,7 +731,7 @@ test_expect_success 'deletion of a non-existent ref alone does trigger post-rece
 '
 
 test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' '
-       mk_test_with_hooks heads/master heads/next heads/pu &&
+       mk_test_with_hooks testrepo heads/master heads/next heads/pu &&
        orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) &&
        newmaster=$(git show-ref -s --verify refs/heads/master) &&
        orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) &&
@@ -757,14 +777,14 @@ test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks w
 '
 
 test_expect_success 'allow deleting a ref using --delete' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        (cd testrepo && git config receive.denyDeleteCurrent warn) &&
        git push testrepo --delete master &&
        (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
 '
 
 test_expect_success 'allow deleting a tag using --delete' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        git tag -a -m dummy_message deltag heads/master &&
        git push testrepo --tags &&
        (cd testrepo && git rev-parse --verify -q refs/tags/deltag) &&
@@ -773,17 +793,17 @@ test_expect_success 'allow deleting a tag using --delete' '
 '
 
 test_expect_success 'push --delete without args aborts' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        test_must_fail git push testrepo --delete
 '
 
 test_expect_success 'push --delete refuses src:dest refspecs' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        test_must_fail git push testrepo --delete master:foo
 '
 
 test_expect_success 'warn on push to HEAD of non-bare repository' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        (
                cd testrepo &&
                git checkout master &&
@@ -794,7 +814,7 @@ test_expect_success 'warn on push to HEAD of non-bare repository' '
 '
 
 test_expect_success 'deny push to HEAD of non-bare repository' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        (
                cd testrepo &&
                git checkout master &&
@@ -804,7 +824,7 @@ test_expect_success 'deny push to HEAD of non-bare repository' '
 '
 
 test_expect_success 'allow push to HEAD of bare repository (bare)' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        (
                cd testrepo &&
                git checkout master &&
@@ -816,7 +836,7 @@ test_expect_success 'allow push to HEAD of bare repository (bare)' '
 '
 
 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
-       mk_test heads/master &&
+       mk_test testrepo heads/master &&
        (
                cd testrepo &&
                git checkout master &&
@@ -827,63 +847,63 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
 '
 
 test_expect_success 'fetch with branches' '
-       mk_empty &&
+       mk_empty testrepo &&
        git branch second $the_first_commit &&
        git checkout second &&
        echo ".." > testrepo/.git/branches/branch1 &&
        (
                cd testrepo &&
                git fetch branch1 &&
-               r=$(git show-ref -s --verify refs/heads/branch1) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_commit commit        refs/heads/branch1" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
 '
 
 test_expect_success 'fetch with branches containing #' '
-       mk_empty &&
+       mk_empty testrepo &&
        echo "..#second" > testrepo/.git/branches/branch2 &&
        (
                cd testrepo &&
                git fetch branch2 &&
-               r=$(git show-ref -s --verify refs/heads/branch2) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/branch2" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
 '
 
 test_expect_success 'push with branches' '
-       mk_empty &&
+       mk_empty testrepo &&
        git checkout second &&
        echo "testrepo" > .git/branches/branch1 &&
        git push branch1 &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/heads/master) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/master" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        )
 '
 
 test_expect_success 'push with branches containing #' '
-       mk_empty &&
+       mk_empty testrepo &&
        echo "testrepo#branch3" > .git/branches/branch2 &&
        git push branch2 &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/heads/branch3) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/branch3" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
 '
 
 test_expect_success 'push into aliased refs (consistent)' '
-       mk_test heads/master &&
-       mk_child child1 &&
-       mk_child child2 &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child1 &&
+       mk_child testrepo child2 &&
        (
                cd child1 &&
                git branch foo &&
@@ -903,9 +923,9 @@ test_expect_success 'push into aliased refs (consistent)' '
 '
 
 test_expect_success 'push into aliased refs (inconsistent)' '
-       mk_test heads/master &&
-       mk_child child1 &&
-       mk_child child2 &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child1 &&
+       mk_child testrepo child2 &&
        (
                cd child1 &&
                git branch foo &&
@@ -930,9 +950,9 @@ test_expect_success 'push into aliased refs (inconsistent)' '
 '
 
 test_expect_success 'push requires --force to update lightweight tag' '
-       mk_test heads/master &&
-       mk_child child1 &&
-       mk_child child2 &&
+       mk_test testrepo heads/master &&
+       mk_child testrepo child1 &&
+       mk_child testrepo child2 &&
        (
                cd child1 &&
                git tag Tag &&
@@ -951,28 +971,28 @@ test_expect_success 'push requires --force to update lightweight tag' '
 '
 
 test_expect_success 'push --porcelain' '
-       mk_empty &&
+       mk_empty testrepo &&
        echo >.git/foo  "To testrepo" &&
        echo >>.git/foo "*      refs/heads/master:refs/remotes/origin/master    [new branch]"  &&
        echo >>.git/foo "Done" &&
        git push >.git/bar --porcelain  testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        ) &&
        test_cmp .git/foo .git/bar
 '
 
 test_expect_success 'push --porcelain bad url' '
-       mk_empty &&
+       mk_empty testrepo &&
        test_must_fail git push >.git/bar --porcelain asdfasdfasd refs/heads/master:refs/remotes/origin/master &&
        test_must_fail grep -q Done .git/bar
 '
 
 test_expect_success 'push --porcelain rejected' '
-       mk_empty &&
+       mk_empty testrepo &&
        git push testrepo refs/heads/master:refs/remotes/origin/master &&
        (cd testrepo &&
                git reset --hard origin/master^
@@ -986,7 +1006,7 @@ test_expect_success 'push --porcelain rejected' '
 '
 
 test_expect_success 'push --porcelain --dry-run rejected' '
-       mk_empty &&
+       mk_empty testrepo &&
        git push testrepo refs/heads/master:refs/remotes/origin/master &&
        (cd testrepo &&
                git reset --hard origin/master
@@ -1001,25 +1021,25 @@ test_expect_success 'push --porcelain --dry-run rejected' '
 '
 
 test_expect_success 'push --prune' '
-       mk_test heads/master heads/second heads/foo heads/bar &&
+       mk_test testrepo heads/master heads/second heads/foo heads/bar &&
        git push --prune testrepo &&
-       check_push_result $the_commit heads/master &&
-       check_push_result $the_first_commit heads/second &&
-       ! check_push_result $the_first_commit heads/foo heads/bar
+       check_push_result testrepo $the_commit heads/master &&
+       check_push_result testrepo $the_first_commit heads/second &&
+       ! check_push_result testrepo $the_first_commit heads/foo heads/bar
 '
 
 test_expect_success 'push --prune refspec' '
-       mk_test tmp/master tmp/second tmp/foo tmp/bar &&
+       mk_test testrepo tmp/master tmp/second tmp/foo tmp/bar &&
        git push --prune testrepo "refs/heads/*:refs/tmp/*" &&
-       check_push_result $the_commit tmp/master &&
-       check_push_result $the_first_commit tmp/second &&
-       ! check_push_result $the_first_commit tmp/foo tmp/bar
+       check_push_result testrepo $the_commit tmp/master &&
+       check_push_result testrepo $the_first_commit tmp/second &&
+       ! check_push_result testrepo $the_first_commit tmp/foo tmp/bar
 '
 
 for configsection in transfer receive
 do
        test_expect_success "push to update a ref hidden by $configsection.hiderefs" '
-               mk_test heads/master hidden/one hidden/two hidden/three &&
+               mk_test testrepo heads/master hidden/one hidden/two hidden/three &&
                (
                        cd testrepo &&
                        git config $configsection.hiderefs refs/hidden
 
                # push to unhidden ref succeeds normally
                git push testrepo master:refs/heads/master &&
-               check_push_result $the_commit heads/master &&
+               check_push_result testrepo $the_commit heads/master &&
 
                # push to update a hidden ref should fail
                test_must_fail git push testrepo master:refs/hidden/one &&
-               check_push_result $the_first_commit hidden/one &&
+               check_push_result testrepo $the_first_commit hidden/one &&
 
                # push to delete a hidden ref should fail
                test_must_fail git push testrepo :refs/hidden/two &&
-               check_push_result $the_first_commit hidden/two &&
+               check_push_result testrepo $the_first_commit hidden/two &&
 
                # idempotent push to update a hidden ref should fail
                test_must_fail git push testrepo $the_first_commit:refs/hidden/three &&
-               check_push_result $the_first_commit hidden/three
+               check_push_result testrepo $the_first_commit hidden/three
        '
 done
 
+test_expect_success 'fetch exact SHA1' '
+       mk_test testrepo heads/master hidden/one &&
+       git push testrepo master:refs/hidden/one &&
+       (
+               cd testrepo &&
+               git config transfer.hiderefs refs/hidden
+       ) &&
+       check_push_result testrepo $the_commit hidden/one &&
+
+       mk_child testrepo child &&
+       (
+               cd child &&
+
+               # make sure $the_commit does not exist here
+               git repack -a -d &&
+               git prune &&
+               test_must_fail git cat-file -t $the_commit &&
+
+               # fetching the hidden object should fail by default
+               test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
+               test_must_fail git rev-parse --verify refs/heads/copy &&
+
+               # the server side can allow it to succeed
+               (
+                       cd ../testrepo &&
+                       git config uploadpack.allowtipsha1inwant true
+               ) &&
+
+               git fetch -v ../testrepo $the_commit:refs/heads/copy &&
+               result=$(git rev-parse --verify refs/heads/copy) &&
+               test "$the_commit" = "$result"
+       )
+'
+
+test_expect_success 'fetch follows tags by default' '
+       mk_test testrepo heads/master &&
+       rm -fr src dst &&
+       git init src &&
+       (
+               cd src &&
+               git pull ../testrepo master &&
+               git tag -m "annotated" tag &&
+               git for-each-ref >tmp1 &&
+               (
+                       cat tmp1
+                       sed -n "s|refs/heads/master$|refs/remotes/origin/master|p" tmp1
+               ) |
+               sort -k 3 >../expect
+       ) &&
+       git init dst &&
+       (
+               cd dst &&
+               git remote add origin ../src &&
+               git config branch.master.remote origin &&
+               git config branch.master.merge refs/heads/master &&
+               git pull &&
+               git for-each-ref >../actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success 'push does not follow tags by default' '
+       mk_test testrepo heads/master &&
+       rm -fr src dst &&
+       git init src &&
+       git init --bare dst &&
+       (
+               cd src &&
+               git pull ../testrepo master &&
+               git tag -m "annotated" tag &&
+               git checkout -b another &&
+               git commit --allow-empty -m "future commit" &&
+               git tag -m "future" future &&
+               git checkout master &&
+               git for-each-ref refs/heads/master >../expect &&
+               git push ../dst master
+       ) &&
+       (
+               cd dst &&
+               git for-each-ref >../actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success 'push --follow-tag only pushes relevant tags' '
+       mk_test testrepo heads/master &&
+       rm -fr src dst &&
+       git init src &&
+       git init --bare dst &&
+       (
+               cd src &&
+               git pull ../testrepo master &&
+               git tag -m "annotated" tag &&
+               git checkout -b another &&
+               git commit --allow-empty -m "future commit" &&
+               git tag -m "future" future &&
+               git checkout master &&
+               git for-each-ref refs/heads/master refs/tags/tag >../expect
+               git push --follow-tag ../dst master
+       ) &&
+       (
+               cd dst &&
+               git for-each-ref >../actual
+       ) &&
+       test_cmp expect actual
+'
+
 test_done
index 35304b41e9ce6222f7d713e3d310e47241d8e6e0..6af6c63350383e049082e61d3c8133af79d5a749 100755 (executable)
@@ -96,8 +96,7 @@ test_expect_success '--rebase' '
 '
 test_expect_success 'pull.rebase' '
        git reset --hard before-rebase &&
-       git config --bool pull.rebase true &&
-       test_when_finished "git config --unset pull.rebase" &&
+       test_config pull.rebase true &&
        git pull . copy &&
        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
        test new = $(git show HEAD:file2)
@@ -105,8 +104,7 @@ test_expect_success 'pull.rebase' '
 
 test_expect_success 'branch.to-rebase.rebase' '
        git reset --hard before-rebase &&
-       git config --bool branch.to-rebase.rebase true &&
-       test_when_finished "git config --unset branch.to-rebase.rebase" &&
+       test_config branch.to-rebase.rebase true &&
        git pull . copy &&
        test $(git rev-parse HEAD^) = $(git rev-parse copy) &&
        test new = $(git show HEAD:file2)
@@ -114,10 +112,8 @@ test_expect_success 'branch.to-rebase.rebase' '
 
 test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
        git reset --hard before-rebase &&
-       git config --bool pull.rebase true &&
-       test_when_finished "git config --unset pull.rebase" &&
-       git config --bool branch.to-rebase.rebase false &&
-       test_when_finished "git config --unset branch.to-rebase.rebase" &&
+       test_config pull.rebase true &&
+       test_config branch.to-rebase.rebase false &&
        git pull . copy &&
        test $(git rev-parse HEAD^) != $(git rev-parse copy) &&
        test new = $(git show HEAD:file2)
@@ -171,9 +167,9 @@ test_expect_success 'pull --rebase dies early with dirty working directory' '
        git update-ref refs/remotes/me/copy copy^ &&
        COPY=$(git rev-parse --verify me/copy) &&
        git rebase --onto $COPY copy &&
-       git config branch.to-rebase.remote me &&
-       git config branch.to-rebase.merge refs/heads/copy &&
-       git config branch.to-rebase.rebase true &&
+       test_config branch.to-rebase.remote me &&
+       test_config branch.to-rebase.merge refs/heads/copy &&
+       test_config branch.to-rebase.rebase true &&
        echo dirty >> file &&
        git add file &&
        test_must_fail git pull &&
index 1b06691bb41586b3bc564841b720ce710f927a1c..aa31abe32b3abc1b43d8111f6503313aa8237455 100755 (executable)
@@ -19,6 +19,17 @@ test_expect_success 'git pull -q' '
        test ! -s out)
 '
 
+test_expect_success 'git pull -q --rebase' '
+       mkdir clonedqrb &&
+       (cd clonedqrb && git init &&
+       git pull -q --rebase "../parent" >out 2>err &&
+       test ! -s err &&
+       test ! -s out &&
+       git pull -q --rebase "../parent" >out 2>err &&
+       test ! -s err &&
+       test ! -s out)
+'
+
 test_expect_success 'git pull' '
        mkdir cloned &&
        (cd cloned && git init &&
@@ -27,6 +38,14 @@ test_expect_success 'git pull' '
        test ! -s out)
 '
 
+test_expect_success 'git pull --rebase' '
+       mkdir clonedrb &&
+       (cd clonedrb && git init &&
+       git pull --rebase "../parent" >out 2>err &&
+       test -s err &&
+       test ! -s out)
+'
+
 test_expect_success 'git pull -v' '
        mkdir clonedv &&
        (cd clonedv && git init &&
@@ -35,6 +54,14 @@ test_expect_success 'git pull -v' '
        test ! -s out)
 '
 
+test_expect_success 'git pull -v --rebase' '
+       mkdir clonedvrb &&
+       (cd clonedvrb && git init &&
+       git pull -v --rebase "../parent" >out 2>err &&
+       test -s err &&
+       test ! -s out)
+'
+
 test_expect_success 'git pull -v -q' '
        mkdir clonedvq &&
        (cd clonedvq && git init &&
index 4b4b4a604f3075dec1056b31da5cccc0c4ed5a9a..4086f02bc129b3628c724c7037fe60509fbef46c 100755 (executable)
@@ -181,8 +181,7 @@ test_expect_success 'push (chunked)' '
        git checkout master &&
        test_commit commit path3 &&
        HEAD=$(git rev-parse --verify HEAD) &&
-       git config http.postbuffer 4 &&
-       test_when_finished "git config --unset http.postbuffer" &&
+       test_config http.postbuffer 4 &&
        git push -v -v origin $BRANCH 2>err &&
        grep "POST git-receive-pack (chunked)" err &&
        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
index c47d450cc3731cb471aa8485178f517bb0d6cbf5..60f1552adef417b8d37ca4215be1e66627c37258 100755 (executable)
@@ -54,11 +54,14 @@ cd "$base_dir"
 
 rm -f "$U.D"
 
-test_expect_success 'cloning with reference (no -l -s)' \
-'GIT_DEBUG_SEND_PACK=3 git clone --reference B "file://$(pwd)/A" D 3>"$U.D"'
+test_expect_success 'cloning with reference (no -l -s)' '
+       GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
+'
 
-test_expect_success 'fetched no objects' \
-'! grep "^want" "$U.D"'
+test_expect_success 'fetched no objects' '
+       test -s "$U.D" &&
+       ! grep " want" "$U.D"
+'
 
 cd "$base_dir"
 
@@ -173,12 +176,13 @@ test_expect_success 'fetch with incomplete alternates' '
        (
                cd K &&
                git remote add J "file://$base_dir/J" &&
-               GIT_DEBUG_SEND_PACK=3 git fetch J 3>"$U.K"
+               GIT_TRACE_PACKET=$U.K git fetch J
        ) &&
        master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
-       ! grep "^want $master_object" "$U.K" &&
+       test -s "$U.K" &&
+       ! grep " want $master_object" "$U.K" &&
        tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
-       ! grep "^want $tag_object" "$U.K"
+       ! grep " want $tag_object" "$U.K"
 '
 
 test_done
index aa045295dec5af9dedc25495668d4afd6022d2cd..8956c21617410863660bff0bc22ec8e81903e81a 100755 (executable)
@@ -58,13 +58,7 @@ test_expect_success 'creating too deep nesting' \
 git clone -l -s D E &&
 git clone -l -s E F &&
 git clone -l -s F G &&
-git clone -l -s G H'
-
-test_expect_success 'invalidity of deepest repository' \
-'cd H && {
-       test_valid_repo
-       test $? -ne 0
-}'
+test_must_fail git clone --bare -l -s G H'
 
 cd "$base_dir"
 
index 839ad97b791c6aa757d0b82eea7fc16369ad4586..dd6dc844e787549ab7622fb4fbec4f89b52e22ab 100755 (executable)
@@ -56,19 +56,37 @@ test_expect_success setup '
 
        echo "Final change" >file &&
        test_tick && git commit -a -m "Final change" &&
-       note I
+       note I &&
+
+       git symbolic-ref HEAD refs/heads/unrelated &&
+       git rm -f "*" &&
+       echo "Unrelated branch" >side &&
+       git add side &&
+       test_tick && git commit -m "Side root" &&
+       note J &&
+
+       git checkout master &&
+       test_tick && git merge -m "Coolest" unrelated &&
+       note K &&
+
+       echo "Immaterial" >elif &&
+       git add elif &&
+       test_tick && git commit -m "Last" &&
+       note L
 '
 
 FMT='tformat:%P        %H | %s'
 
-check_result () {
+check_outcome () {
+       outcome=$1
+       shift
        for c in $1
        do
                echo "$c"
        done >expect &&
        shift &&
        param="$*" &&
-       test_expect_success "log $param" '
+       test_expect_$outcome "log $param" '
                git log --pretty="$FMT" --parents $param |
                unnote >actual &&
                sed -e "s/^.*   \([^ ]*\) .*/\1/" >check <actual &&
@@ -79,11 +97,15 @@ check_result () {
        '
 }
 
-check_result 'I H G F E D C B A' --full-history
-check_result 'I H E C B A' --full-history -- file
-check_result 'I H E C B A' --full-history --topo-order -- file
-check_result 'I H E C B A' --full-history --date-order -- file
-check_result 'I E C B A' --simplify-merges -- file
+check_result () {
+       check_outcome success "$@"
+}
+
+check_result 'L K J I H G F E D C B A' --full-history
+check_result 'K I H E C B A' --full-history -- file
+check_result 'K I H E C B A' --full-history --topo-order -- file
+check_result 'K I H E C B A' --full-history --date-order -- file
+check_outcome failure 'I E C B A' --simplify-merges -- file
 check_result 'I B A' -- file
 check_result 'I B A' --topo-order -- file
 check_result 'H' --first-parent -- another-file
index 3e0e15fb3e0b92ab7e95789d27db34d9a1fa423c..8bf53de3ef6bc7cc5de14b70e93ffe42b9b3f094 100755 (executable)
@@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if
        cp .git/BISECT_START saved &&
        test_must_fail git bisect start $HASH4 foo -- &&
        git branch > branch.output &&
-       test_i18ngrep "* (no branch)" branch.output > /dev/null &&
+       test_i18ngrep "* (no branch, bisect started on other)" branch.output > /dev/null &&
        test_cmp saved .git/BISECT_START
 '
 test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
@@ -190,7 +190,7 @@ test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
 # but $HASH2 is bad,
 # so we should find $HASH2 as the first bad commit
-test_expect_success 'bisect skip: successfull result' '
+test_expect_success 'bisect skip: successful result' '
        git bisect reset &&
        git bisect start $HASH4 $HASH1 &&
        git bisect skip &&
index 992c2a04674d474a8875da955935512ec99f335a..f73eceabfbcd0a763b8908a8d829894a5e36055b 100755 (executable)
@@ -112,8 +112,8 @@ test_expect_success '[merge] summary/log configuration' '
          Common #1
        EOF
 
-       git config merge.log true &&
-       test_might_fail git config --unset-all merge.summary &&
+       test_config merge.log true &&
+       test_unconfig merge.summary &&
 
        git checkout master &&
        test_tick &&
@@ -121,8 +121,8 @@ test_expect_success '[merge] summary/log configuration' '
 
        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary true &&
+       test_unconfig merge.log &&
+       test_config merge.summary true &&
 
        git checkout master &&
        test_tick &&
@@ -134,11 +134,6 @@ test_expect_success '[merge] summary/log configuration' '
        test_cmp expected actual2
 '
 
-test_expect_success 'setup: clear [merge] configuration' '
-       test_might_fail git config --unset-all merge.log &&
-       test_might_fail git config --unset-all merge.summary
-'
-
 test_expect_success 'setup FETCH_HEAD' '
        git checkout master &&
        test_tick &&
@@ -248,14 +243,14 @@ test_expect_success 'fmt-merge-msg -m' '
          Common #1
        EOF
 
-       test_might_fail git config --unset merge.log &&
-       test_might_fail git config --unset merge.summary &&
+       test_unconfig merge.log &&
+       test_unconfig merge.summary &&
        git checkout master &&
        git fetch "$(pwd)" left &&
        git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
        git fmt-merge-msg --log -m "Sync with left" \
                                        <.git/FETCH_HEAD >actual.log &&
-       git config merge.log true &&
+       test_config merge.log true &&
        git fmt-merge-msg -m "Sync with left" \
                                        <.git/FETCH_HEAD >actual.log-config &&
        git fmt-merge-msg --no-log -m "Sync with left" \
@@ -290,29 +285,29 @@ test_expect_success 'setup: expected shortlog for two branches' '
 '
 
 test_expect_success 'shortlog for two branches' '
-       git config merge.log true &&
-       test_might_fail git config --unset-all merge.summary &&
+       test_config merge.log true &&
+       test_unconfig merge.summary &&
        git checkout master &&
        test_tick &&
        git fetch . left right &&
        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary true &&
+       test_unconfig merge.log &&
+       test_config merge.summary true &&
        git checkout master &&
        test_tick &&
        git fetch . left right &&
        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 
-       git config merge.log yes &&
-       test_might_fail git config --unset-all merge.summary &&
+       test_config merge.log yes &&
+       test_unconfig merge.summary &&
        git checkout master &&
        test_tick &&
        git fetch . left right &&
        git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
        git checkout master &&
        test_tick &&
        git fetch . left right &&
@@ -325,8 +320,8 @@ test_expect_success 'shortlog for two branches' '
 '
 
 test_expect_success 'merge-msg -F' '
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
        git checkout master &&
        test_tick &&
        git fetch . left right &&
@@ -335,8 +330,8 @@ test_expect_success 'merge-msg -F' '
 '
 
 test_expect_success 'merge-msg -F in subdirectory' '
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
        git checkout master &&
        test_tick &&
        git fetch . left right &&
@@ -350,8 +345,8 @@ test_expect_success 'merge-msg -F in subdirectory' '
 '
 
 test_expect_success 'merge-msg with nothing to merge' '
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
 
        >empty &&
 
@@ -376,8 +371,8 @@ test_expect_success 'merge-msg tag' '
          Common #1
        EOF
 
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
 
        git checkout master &&
        test_tick &&
@@ -406,8 +401,8 @@ test_expect_success 'merge-msg two tags' '
          Common #1
        EOF
 
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
 
        git checkout master &&
        test_tick &&
@@ -436,8 +431,8 @@ test_expect_success 'merge-msg tag and branch' '
          Common #1
        EOF
 
-       test_might_fail git config --unset-all merge.log &&
-       git config merge.summary yes &&
+       test_unconfig merge.log &&
+       test_config merge.summary yes &&
 
        git checkout master &&
        test_tick &&
@@ -464,6 +459,8 @@ test_expect_success 'merge-msg lots of commits' '
                echo "  ..."
        } >expected &&
 
+       test_config merge.summary yes &&
+
        git checkout master &&
        test_tick &&
        git fetch . long &&
@@ -472,4 +469,43 @@ test_expect_success 'merge-msg lots of commits' '
        test_cmp expected actual
 '
 
+test_expect_success 'merge-msg with "merging" an annotated tag' '
+       test_config merge.log true &&
+
+       git checkout master^0 &&
+       git commit --allow-empty -m "One step ahead" &&
+       git tag -a -m "An annotated one" annote HEAD &&
+
+       git checkout master &&
+       git fetch . annote &&
+
+       git fmt-merge-msg <.git/FETCH_HEAD >actual &&
+       {
+               cat <<-\EOF
+               Merge tag '\''annote'\''
+
+               An annotated one
+
+               * tag '\''annote'\'':
+                 One step ahead
+               EOF
+       } >expected &&
+       test_cmp expected actual &&
+
+       test_when_finished "git reset --hard" &&
+       annote=$(git rev-parse annote) &&
+       git merge --no-commit $annote &&
+       {
+               cat <<-EOF
+               Merge tag '\''$annote'\''
+
+               An annotated one
+
+               * tag '\''$annote'\'':
+                 One step ahead
+               EOF
+       } >expected &&
+       test_cmp expected .git/MERGE_MSG
+'
+
 test_done
index 1e7a209efa715bc52d14d7f653ecfc13ffb5301f..9496736a89eb6b0b1ece64052cd2726c516c952b 100755 (executable)
@@ -64,6 +64,20 @@ test_expect_success 'correct GIT_DIR while using -d' '
        grep drepo "$TRASHDIR/backup-refs"
 '
 
+test_expect_success 'tree-filter works with -d' '
+       git init drepo-tree &&
+       (
+               cd drepo-tree &&
+               test_commit one &&
+               git filter-branch -d "$TRASHDIR/dfoo" \
+                       --tree-filter "echo changed >one.t" &&
+               echo changed >expect &&
+               git cat-file blob HEAD:one.t >actual &&
+               test_cmp expect actual &&
+               test_cmp one.t actual
+       )
+'
+
 test_expect_success 'Fail if commit filter fails' '
        test_must_fail git filter-branch -f --commit-filter "exit 1" HEAD
 '
index 2683cba7e3f0ba7fbb7ea1752a39a6068fc91718..ff265353a375d02bb578fed29ea00f07dc08a6fc 100755 (executable)
@@ -757,4 +757,115 @@ test_expect_success 'submodule add with an existing name fails unless forced' '
        )
 '
 
+test_expect_success 'set up a second submodule' '
+       git submodule add ./init2 example2 &&
+       git commit -m "submodule example2 added"
+'
+
+test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
+       git config submodule.example.foo bar &&
+       git config submodule.example2.frotz nitfol &&
+       git submodule deinit init &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test -n "$(git config --get-regexp "submodule\.example2\.")" &&
+       test -f example2/.git &&
+       rmdir init
+'
+
+test_expect_success 'submodule deinit . deinits all initialized submodules' '
+       git submodule update --init &&
+       git config submodule.example.foo bar &&
+       git config submodule.example2.frotz nitfol &&
+       test_must_fail git submodule deinit &&
+       git submodule deinit . >actual &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test -z "$(git config --get-regexp "submodule\.example2\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       test_i18ngrep "Cleared directory .example2" actual &&
+       rmdir init example2
+'
+
+test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
+       git submodule update --init &&
+       rm -rf init example2/* example2/.git &&
+       git submodule deinit init example2 >actual &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test -z "$(git config --get-regexp "submodule\.example2\.")" &&
+       test_i18ngrep ! "Cleared directory .init" actual &&
+       test_i18ngrep "Cleared directory .example2" actual &&
+       rmdir init
+'
+
+test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
+       git submodule update --init &&
+       echo X >>init/s &&
+       test_must_fail git submodule deinit init &&
+       test -n "$(git config --get-regexp "submodule\.example\.")" &&
+       test -f example2/.git &&
+       git submodule deinit -f init >actual &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       rmdir init
+'
+
+test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
+       git submodule update --init &&
+       echo X >>init/untracked &&
+       test_must_fail git submodule deinit init &&
+       test -n "$(git config --get-regexp "submodule\.example\.")" &&
+       test -f example2/.git &&
+       git submodule deinit -f init >actual &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       rmdir init
+'
+
+test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
+       git submodule update --init &&
+       (
+               cd init &&
+               git checkout HEAD^
+       ) &&
+       test_must_fail git submodule deinit init &&
+       test -n "$(git config --get-regexp "submodule\.example\.")" &&
+       test -f example2/.git &&
+       git submodule deinit -f init >actual &&
+       test -z "$(git config --get-regexp "submodule\.example\.")" &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       rmdir init
+'
+
+test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
+       git submodule update --init &&
+       git submodule deinit init >actual &&
+       test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       git submodule deinit init >actual &&
+       test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       git submodule deinit . >actual &&
+       test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       git submodule deinit . >actual &&
+       test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
+       test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
+       test_i18ngrep "Cleared directory .init" actual &&
+       rmdir init example2
+'
+
+test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
+       git submodule update --init &&
+       (
+               cd init &&
+               rm .git &&
+               cp -R ../.git/modules/example .git &&
+               GIT_WORK_TREE=. git config --unset core.worktree
+       ) &&
+       test_must_fail git submodule deinit init &&
+       test_must_fail git submodule deinit -f init &&
+       test -d init/.git &&
+       test -n "$(git config --get-regexp "submodule\.example\.")"
+'
+
 test_done
index 1a3d20bdc36c63c5261090d76858d43bd7f64113..2a0cfaac329c6c0974f205c81c45a0304a04897d 100755 (executable)
@@ -665,8 +665,10 @@ test_expect_success 'submodule add properly re-creates deeper level submodules'
 
 test_expect_success 'submodule update properly revives a moved submodule' '
        (cd super &&
+        H=$(git rev-parse --short HEAD) &&
         git commit -am "pre move" &&
-        git status >expect&&
+        H2=$(git rev-parse --short HEAD) &&
+        git status | sed "s/$H/XXX/" >expect &&
         H=$(cd submodule2; git rev-parse HEAD) &&
         git rm --cached submodule2 &&
         rm -rf submodule2 &&
@@ -675,7 +677,7 @@ test_expect_success 'submodule update properly revives a moved submodule' '
         git config -f .gitmodules submodule.submodule2.path "moved/sub module"
         git commit -am "post move" &&
         git submodule update &&
-        git status >actual &&
+        git status | sed "s/$H2/XXX/" >actual &&
         test_cmp expect actual
        )
 '
index 1c908f4d3966cb9a2769465652981bef831f312d..436b7b606e3eab09a0dd8c1b67ab90e43c24dffc 100755 (executable)
@@ -36,8 +36,7 @@ test_expect_success 'nonexistent template file should return error' '
 '
 
 test_expect_success 'nonexistent template file in config should return error' '
-       git config commit.template "$PWD"/notexist &&
-       test_when_finished "git config --unset commit.template" &&
+       test_config commit.template "$PWD"/notexist &&
        (
                GIT_EDITOR="echo hello >\"\$1\"" &&
                export GIT_EDITOR &&
@@ -93,14 +92,13 @@ test_expect_success '-t option should be short for --template' '
 
 test_expect_success 'config-specified template should commit' '
        echo "new template" > "$TEMPLATE" &&
-       git config commit.template "$TEMPLATE" &&
+       test_config commit.template "$TEMPLATE" &&
        echo "more content" >> foo &&
        git add foo &&
        (
                test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
                git commit
        ) &&
-       git config --unset commit.template &&
        commit_msg_is "new templatecommit message"
 '
 
index 292bc082b2ecc74c652a740b55b888568a0b8eb2..a4938b1e4549d5082362ec3f5513ffe91f210d39 100755 (executable)
@@ -171,10 +171,9 @@ test_expect_success 'verbose' '
 
 test_expect_success 'verbose respects diff config' '
 
-       git config color.diff always &&
+       test_config color.diff always &&
        git status -v >actual &&
-       grep "\[1mdiff --git" actual &&
-       git config --unset color.diff
+       grep "\[1mdiff --git" actual
 '
 
 mesg_with_comment_and_newlines='
@@ -263,32 +262,40 @@ test_expect_success 'cleanup commit message (fail on invalid cleanup mode config
 test_expect_success 'cleanup commit message (no config and no option uses default)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git commit --no-status &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git commit --no-status
+       ) &&
        commit_msg_is "commit message"
 '
 
 test_expect_success 'cleanup commit message (option overrides default)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git commit --cleanup=whitespace --no-status &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git commit --cleanup=whitespace --no-status
+       ) &&
        commit_msg_is "commit message # comment"
 '
 
 test_expect_success 'cleanup commit message (config overrides default)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git -c commit.cleanup=whitespace commit --no-status &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git -c commit.cleanup=whitespace commit --no-status
+       ) &&
        commit_msg_is "commit message # comment"
 '
 
 test_expect_success 'cleanup commit message (option overrides config)' '
        echo content >>file &&
        git add file &&
-       test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
-       git -c commit.cleanup=whitespace commit --cleanup=default &&
+       (
+         test_set_editor "$TEST_DIRECTORY"/t7500/add-content-and-comment &&
+         git -c commit.cleanup=whitespace commit --cleanup=default
+       ) &&
        commit_msg_is "commit message"
 '
 
@@ -417,6 +424,18 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo
 
 '
 
+test_expect_success 'commit -s places sob on third line after two empty lines' '
+       git commit -s --allow-empty --allow-empty-message &&
+       cat <<-EOF >expect &&
+
+
+       Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+
+       EOF
+       sed -e "/^#/d" -e "s/^:.*//" .git/COMMIT_EDITMSG >actual &&
+       test_cmp expect actual
+'
+
 write_script .git/FAKE_EDITOR <<\EOF
 mv "$1" "$1.orig"
 (
@@ -427,16 +446,6 @@ EOF
 
 echo '## Custom template' >template
 
-clear_config () {
-       (
-               git config --unset-all "$1"
-               case $? in
-               0|5)    exit 0 ;;
-               *)      exit 1 ;;
-               esac
-       )
-}
-
 try_commit () {
        git reset --hard &&
        echo >>negative &&
@@ -452,67 +461,57 @@ try_commit () {
 try_commit_status_combo () {
 
        test_expect_success 'commit' '
-               clear_config commit.status &&
                try_commit "" &&
                test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit' '
-               clear_config commit.status &&
                try_commit "" &&
                test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit --status' '
-               clear_config commit.status &&
                try_commit --status &&
                test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit --no-status' '
-               clear_config commit.status &&
                try_commit --no-status &&
                test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit with commit.status = yes' '
-               clear_config commit.status &&
-               git config commit.status yes &&
+               test_config commit.status yes &&
                try_commit "" &&
                test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit with commit.status = no' '
-               clear_config commit.status &&
-               git config commit.status no &&
+               test_config commit.status no &&
                try_commit "" &&
                test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit --status with commit.status = yes' '
-               clear_config commit.status &&
-               git config commit.status yes &&
+               test_config commit.status yes &&
                try_commit --status &&
                test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit --no-status with commit.status = yes' '
-               clear_config commit.status &&
-               git config commit.status yes &&
+               test_config commit.status yes &&
                try_commit --no-status &&
                test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit --status with commit.status = no' '
-               clear_config commit.status &&
-               git config commit.status no &&
+               test_config commit.status no &&
                try_commit --status &&
                test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
        test_expect_success 'commit --no-status with commit.status = no' '
-               clear_config commit.status &&
-               git config commit.status no &&
+               test_config commit.status no &&
                try_commit --no-status &&
                test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
@@ -526,8 +525,7 @@ use_template="-t template"
 try_commit_status_combo
 
 test_expect_success 'commit --status with custom comment character' '
-       test_when_finished "git config --unset core.commentchar" &&
-       git config core.commentchar ";" &&
+       test_config core.commentchar ";" &&
        try_commit --status &&
        test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG
 '
index aecb4d1e5fdc1e966aad07ee1f1e7af834388bb2..e2ffdacc267c22e369247791e24338a20badf94d 100755 (executable)
@@ -131,8 +131,7 @@ cat >expect <<\EOF
 EOF
 
 test_expect_success 'status (advice.statusHints false)' '
-       test_when_finished "git config --unset advice.statusHints" &&
-       git config advice.statusHints false &&
+       test_config advice.statusHints false &&
        git status >output &&
        test_i18ncmp expect output
 
@@ -332,8 +331,7 @@ test_expect_success 'status -uno' '
 '
 
 test_expect_success 'status (status.showUntrackedFiles no)' '
-       git config status.showuntrackedfiles no
-       test_when_finished "git config --unset status.showuntrackedfiles" &&
+       test_config status.showuntrackedfiles no &&
        git status >output &&
        test_i18ncmp expect output
 '
@@ -348,12 +346,11 @@ cat >expect <<EOF
 #
 # Untracked files not listed
 EOF
-git config advice.statusHints false
 test_expect_success 'status -uno (advice.statusHints false)' '
+       test_config advice.statusHints false &&
        git status -uno >output &&
        test_i18ncmp expect output
 '
-git config --unset advice.statusHints
 
 cat >expect << EOF
  M dir1/modified
@@ -400,8 +397,7 @@ test_expect_success 'status -unormal' '
 '
 
 test_expect_success 'status (status.showUntrackedFiles normal)' '
-       git config status.showuntrackedfiles normal
-       test_when_finished "git config --unset status.showuntrackedfiles" &&
+       test_config status.showuntrackedfiles normal
        git status >output &&
        test_i18ncmp expect output
 '
@@ -459,8 +455,7 @@ test_expect_success 'status -uall' '
 '
 
 test_expect_success 'status (status.showUntrackedFiles all)' '
-       git config status.showuntrackedfiles all
-       test_when_finished "git config --unset status.showuntrackedfiles" &&
+       test_config status.showuntrackedfiles all
        git status >output &&
        test_i18ncmp expect output
 '
@@ -485,10 +480,9 @@ test_expect_success 'status -s -uall' '
        test_cmp expect output
 '
 test_expect_success 'status -s (status.showUntrackedFiles all)' '
-       git config status.showuntrackedfiles all
+       test_config status.showuntrackedfiles all &&
        git status -s >output &&
        rm -rf dir3 &&
-       git config --unset status.showuntrackedfiles &&
        test_cmp expect output
 '
 
@@ -588,15 +582,13 @@ cat >expect <<\EOF
 EOF
 
 test_expect_success 'status with color.ui' '
-       git config color.ui always &&
-       test_when_finished "git config --unset color.ui" &&
+       test_config color.ui always &&
        git status | test_decode_color >output &&
        test_i18ncmp expect output
 '
 
 test_expect_success 'status with color.status' '
-       git config color.status always &&
-       test_when_finished "git config --unset color.status" &&
+       test_config color.status always &&
        git status | test_decode_color >output &&
        test_i18ncmp expect output
 '
@@ -720,8 +712,7 @@ EOF
 
 test_expect_success 'status without relative paths' '
 
-       git config status.relativePaths false &&
-       test_when_finished "git config --unset status.relativePaths" &&
+       test_config status.relativePaths false &&
        (cd dir1 && git status) >output &&
        test_i18ncmp expect output
 
@@ -740,8 +731,7 @@ EOF
 
 test_expect_success 'status -s without relative paths' '
 
-       git config status.relativePaths false &&
-       test_when_finished "git config --unset status.relativePaths" &&
+       test_config status.relativePaths false &&
        (cd dir1 && git status -s) >output &&
        test_cmp expect output
 
@@ -1038,15 +1028,14 @@ test_expect_success '--ignore-submodules=untracked suppresses submodules with un
 '
 
 test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
-       git config diff.ignoreSubmodules dirty &&
+       test_config diff.ignoreSubmodules dirty &&
        git status >output &&
        test_i18ncmp expect output &&
        git config --add -f .gitmodules submodule.subname.ignore untracked &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git status >output &&
        test_i18ncmp expect output &&
-       git config -f .gitmodules  --remove-section submodule.subname &&
-       git config --unset diff.ignoreSubmodules
+       git config -f .gitmodules  --remove-section submodule.subname
 '
 
 test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
@@ -1066,15 +1055,14 @@ test_expect_success '--ignore-submodules=dirty suppresses submodules with untrac
 '
 
 test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
-       git config diff.ignoreSubmodules dirty &&
+       test_config diff.ignoreSubmodules dirty &&
        git status >output &&
        ! test -s actual &&
        git config --add -f .gitmodules submodule.subname.ignore dirty &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git status >output &&
        test_i18ncmp expect output &&
-       git config -f .gitmodules  --remove-section submodule.subname &&
-       git config --unset diff.ignoreSubmodules
+       git config -f .gitmodules  --remove-section submodule.subname
 '
 
 test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
@@ -1291,15 +1279,13 @@ cat > expect << EOF
 EOF
 
 test_expect_success "status (core.commentchar with submodule summary)" '
-       test_when_finished "git config --unset core.commentchar" &&
-       git config core.commentchar ";" &&
+       test_config core.commentchar ";" &&
        git status >output &&
        test_i18ncmp expect output
 '
 
 test_expect_success "status (core.commentchar with two chars with submodule summary)" '
-       test_when_finished "git config --unset core.commentchar" &&
-       git config core.commentchar ";;" &&
+       test_config core.commentchar ";;" &&
        git status >output &&
        test_i18ncmp expect output
 '
index 9d4610629d725c22b9de5187abf71b2b8544292d..bf08d4e098f1bdc3adc5ec3df37b90d90b0e5c8f 100755 (executable)
@@ -77,7 +77,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
        ONTO=$(git rev-parse --short HEAD^^) &&
        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached at $ONTO
        # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
        #   (fix conflicts and then run "git rebase --continue")
        #   (use "git rebase --skip" to skip this patch)
@@ -104,7 +104,7 @@ test_expect_success 'status when rebase in progress before rebase --continue' '
        echo three >main.txt &&
        git add main.txt &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached at $ONTO
        # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
        #   (all conflicts fixed: run "git rebase --continue")
        #
@@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
        ONTO=$(git rev-parse --short rebase_i_conflicts) &&
        test_must_fail git rebase -i rebase_i_conflicts &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached at $ONTO
        # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
        #   (fix conflicts and then run "git rebase --continue")
        #   (use "git rebase --skip" to skip this patch)
@@ -162,7 +162,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
        test_must_fail git rebase -i rebase_i_conflicts &&
        git add main.txt &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached at $ONTO
        # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
        #   (all conflicts fixed: run "git rebase --continue")
        #
@@ -188,9 +188,10 @@ test_expect_success 'status when rebasing -i in edit mode' '
        export FAKE_LINES &&
        test_when_finished "git rebase --abort" &&
        ONTO=$(git rev-parse --short HEAD~2) &&
+       TGT=$(git rev-parse --short two_rebase_i) &&
        git rebase -i HEAD~2 &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $TGT
        # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -215,8 +216,9 @@ test_expect_success 'status when splitting a commit' '
        ONTO=$(git rev-parse --short HEAD~3) &&
        git rebase -i HEAD~3 &&
        git reset HEAD^ &&
+       TGT=$(git rev-parse --short HEAD) &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached at $TGT
        # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@ -244,10 +246,11 @@ test_expect_success 'status after editing the last commit with --amend during a
        export FAKE_LINES &&
        test_when_finished "git rebase --abort" &&
        ONTO=$(git rev-parse --short HEAD~3) &&
+       TGT=$(git rev-parse --short three_amend) &&
        git rebase -i HEAD~3 &&
        git commit --amend -m "foo" &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $TGT
        # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -277,7 +280,7 @@ test_expect_success 'status: (continue first edit) second edit' '
        git rebase -i HEAD~3 &&
        git rebase --continue &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -299,7 +302,7 @@ test_expect_success 'status: (continue first edit) second edit and split' '
        git rebase --continue &&
        git reset HEAD^ &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@ -326,7 +329,7 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
        git rebase --continue &&
        git commit --amend -m "foo" &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -348,7 +351,7 @@ test_expect_success 'status: (amend first edit) second edit' '
        git commit --amend -m "a" &&
        git rebase --continue &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -371,7 +374,7 @@ test_expect_success 'status: (amend first edit) second edit and split' '
        git rebase --continue &&
        git reset HEAD^ &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@ -399,7 +402,7 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
        git rebase --continue &&
        git commit --amend -m "d" &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -423,7 +426,7 @@ test_expect_success 'status: (split first edit) second edit' '
        git commit -m "e" &&
        git rebase --continue &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -448,7 +451,7 @@ test_expect_success 'status: (split first edit) second edit and split' '
        git rebase --continue &&
        git reset HEAD^ &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (Once your working directory is clean, run "git rebase --continue")
        #
@@ -478,7 +481,7 @@ test_expect_success 'status: (split first edit) second edit and amend' '
        git rebase --continue &&
        git commit --amend -m "h" &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached from $ONTO
        # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
        #   (use "git commit --amend" to amend the current commit)
        #   (use "git rebase --continue" once you are satisfied with your changes)
@@ -573,9 +576,10 @@ test_expect_success 'status when bisecting' '
        git bisect start &&
        git bisect bad &&
        git bisect good one_bisect &&
-       cat >expected <<-\EOF &&
-       # Not currently on any branch.
-       # You are currently bisecting branch '\''bisect'\''.
+       TGT=$(git rev-parse --short two_bisect) &&
+       cat >expected <<-EOF &&
+       # HEAD detached at $TGT
+       # You are currently bisecting, started from branch '\''bisect'\''.
        #   (use "git bisect reset" to get back to the original branch)
        #
        nothing to commit (use -u to show untracked files)
@@ -597,7 +601,7 @@ test_expect_success 'status when rebase conflicts with statushints disabled' '
        ONTO=$(git rev-parse --short HEAD^^) &&
        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
        cat >expected <<-EOF &&
-       # Not currently on any branch.
+       # HEAD detached at $ONTO
        # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
        #
        # Unmerged paths:
@@ -663,5 +667,73 @@ test_expect_success 'status when cherry-picking after resolving conflicts' '
        test_i18ncmp expected actual
 '
 
+test_expect_success 'status showing detached from a tag' '
+       test_commit atag tagging &&
+       git checkout atag &&
+       cat >expected <<-\EOF
+       # HEAD detached at atag
+       nothing to commit (use -u to show untracked files)
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+test_expect_success 'status while reverting commit (conflicts)' '
+       git checkout master &&
+       echo before >to-revert.txt &&
+       test_commit before to-revert.txt &&
+       echo old >to-revert.txt &&
+       test_commit old to-revert.txt &&
+       echo new >to-revert.txt &&
+       test_commit new to-revert.txt &&
+       TO_REVERT=$(git rev-parse --short HEAD^) &&
+       test_must_fail git revert $TO_REVERT &&
+       cat >expected <<-EOF
+       # On branch master
+       # You are currently reverting commit $TO_REVERT.
+       #   (fix conflicts and run "git revert --continue")
+       #   (use "git revert --abort" to cancel the revert operation)
+       #
+       # Unmerged paths:
+       #   (use "git reset HEAD <file>..." to unstage)
+       #   (use "git add <file>..." to mark resolution)
+       #
+       #       both modified:      to-revert.txt
+       #
+       no changes added to commit (use "git add" and/or "git commit -a")
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+test_expect_success 'status while reverting commit (conflicts resolved)' '
+       echo reverted >to-revert.txt &&
+       git add to-revert.txt &&
+       cat >expected <<-EOF
+       # On branch master
+       # You are currently reverting commit $TO_REVERT.
+       #   (all conflicts fixed: run "git revert --continue")
+       #   (use "git revert --abort" to cancel the revert operation)
+       #
+       # Changes to be committed:
+       #   (use "git reset HEAD <file>..." to unstage)
+       #
+       #       modified:   to-revert.txt
+       #
+       # Untracked files not listed (use -u option to show untracked files)
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+test_expect_success 'status after reverting commit' '
+       git revert --continue &&
+       cat >expected <<-\EOF
+       # On branch master
+       nothing to commit (use -u to show untracked files)
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
 
 test_done
index 5e19598fe72787e17d521980a3edfacb1dfa2024..2f70433568e3134b09d7e1eb10cc5c8995c1a106 100755 (executable)
@@ -56,7 +56,8 @@ create_merge_msgs () {
                echo &&
                git log --no-merges ^HEAD c2 c3
        } >squash.1-5-9 &&
-       echo >msg.nolog &&
+       : >msg.nologff &&
+       echo >msg.nolognoff &&
        {
                echo "* tag 'c3':" &&
                echo "  commit 3" &&
@@ -244,8 +245,7 @@ test_expect_success 'merges with --ff-only' '
 test_expect_success 'merges with merge.ff=only' '
        git reset --hard c1 &&
        test_tick &&
-       test_when_finished "git config --unset merge.ff" &&
-       git config merge.ff only &&
+       test_config merge.ff "only" &&
        test_must_fail git merge c2 &&
        test_must_fail git merge c3 &&
        test_must_fail git merge c2 c3 &&
@@ -336,7 +336,7 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c2 (no-commit in config)' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "--no-commit" &&
+       test_config branch.master.mergeoptions "--no-commit" &&
        git merge c2 &&
        verify_merge file result.1-5 &&
        verify_head $c1 &&
@@ -346,12 +346,11 @@ test_expect_success 'merge c1 with c2 (no-commit in config)' '
 test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c2 (log in config)' '
-       git config branch.master.mergeoptions "" &&
        git reset --hard c1 &&
        git merge --log c2 &&
        git show -s --pretty=tformat:%s%n%b >expect &&
 
-       git config branch.master.mergeoptions --log &&
+       test_config branch.master.mergeoptions "--log" &&
        git reset --hard c1 &&
        git merge c2 &&
        git show -s --pretty=tformat:%s%n%b >actual &&
@@ -360,17 +359,12 @@ test_expect_success 'merge c1 with c2 (log in config)' '
 '
 
 test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
-       test_when_finished "git config --remove-section branch.master" &&
-       test_when_finished "git config --remove-section merge" &&
-       test_might_fail git config --remove-section branch.master &&
-       test_might_fail git config --remove-section merge &&
-
        git reset --hard c1 &&
        git merge c2 &&
        git show -s --pretty=tformat:%s%n%b >expect &&
 
-       git config branch.master.mergeoptions "--no-log" &&
-       git config merge.log true &&
+       test_config branch.master.mergeoptions "--no-log" &&
+       test_config merge.log "true" &&
        git reset --hard c1 &&
        git merge c2 &&
        git show -s --pretty=tformat:%s%n%b >actual &&
@@ -380,7 +374,7 @@ test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
 
 test_expect_success 'merge c1 with c2 (squash in config)' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "--squash" &&
+       test_config branch.master.mergeoptions "--squash" &&
        git merge c2 &&
        verify_merge file result.1-5 &&
        verify_head $c1 &&
@@ -392,7 +386,7 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'override config option -n with --summary' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "-n" &&
+       test_config branch.master.mergeoptions "-n" &&
        test_tick &&
        git merge --summary c2 >diffstat.txt &&
        verify_merge file result.1-5 msg.1-5 &&
@@ -406,7 +400,7 @@ test_expect_success 'override config option -n with --summary' '
 
 test_expect_success 'override config option -n with --stat' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "-n" &&
+       test_config branch.master.mergeoptions "-n" &&
        test_tick &&
        git merge --stat c2 >diffstat.txt &&
        verify_merge file result.1-5 msg.1-5 &&
@@ -422,7 +416,7 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'override config option --stat' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "--stat" &&
+       test_config branch.master.mergeoptions "--stat" &&
        test_tick &&
        git merge -n c2 >diffstat.txt &&
        verify_merge file result.1-5 msg.1-5 &&
@@ -438,7 +432,7 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c2 (override --no-commit)' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "--no-commit" &&
+       test_config branch.master.mergeoptions "--no-commit" &&
        test_tick &&
        git merge --commit c2 &&
        verify_merge file result.1-5 msg.1-5 &&
@@ -449,7 +443,7 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c2 (override --squash)' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "--squash" &&
+       test_config branch.master.mergeoptions "--squash" &&
        test_tick &&
        git merge --no-squash c2 &&
        verify_merge file result.1-5 msg.1-5 &&
@@ -460,7 +454,6 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c0 with c1 (no-ff)' '
        git reset --hard c0 &&
-       git config branch.master.mergeoptions "" &&
        test_tick &&
        git merge --no-ff c1 &&
        verify_merge file result.1 &&
@@ -471,10 +464,9 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c0 with c1 (merge.ff=false)' '
        git reset --hard c0 &&
-       git config merge.ff false &&
+       test_config merge.ff "false" &&
        test_tick &&
        git merge c1 &&
-       git config --remove-section merge &&
        verify_merge file result.1 &&
        verify_parents $c0 $c1
 '
@@ -482,22 +474,19 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
        git reset --hard c0 &&
-       git config branch.master.mergeoptions --ff &&
-       git config merge.ff false &&
+       test_config branch.master.mergeoptions "--ff" &&
+       test_config merge.ff "false" &&
        test_tick &&
        git merge c1 &&
-       git config --remove-section "branch.master" &&
-       git config --remove-section "merge" &&
        verify_merge file result.1 &&
        verify_parents "$c0"
 '
 
 test_expect_success 'tolerate unknown values for merge.ff' '
        git reset --hard c0 &&
-       git config merge.ff something-new &&
+       test_config merge.ff "something-new" &&
        test_tick &&
        git merge c1 2>message &&
-       git config --remove-section "merge" &&
        verify_head "$c1" &&
        test_cmp empty message
 '
@@ -515,7 +504,7 @@ test_expect_success 'combining --ff-only and --no-ff is refused' '
 
 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
        git reset --hard c0 &&
-       git config branch.master.mergeoptions "--no-ff" &&
+       test_config branch.master.mergeoptions "--no-ff" &&
        git merge --ff c1 &&
        verify_merge file result.1 &&
        verify_head $c1
@@ -525,14 +514,20 @@ test_expect_success 'merge log message' '
        git reset --hard c0 &&
        git merge --no-log c2 &&
        git show -s --pretty=format:%b HEAD >msg.act &&
-       test_cmp msg.nolog msg.act &&
+       test_cmp msg.nologff msg.act &&
+
+       git reset --hard c0 &&
+       test_config branch.master.mergeoptions "--no-ff" &&
+       git merge --no-log c2 &&
+       git show -s --pretty=format:%b HEAD >msg.act &&
+       test_cmp msg.nolognoff msg.act &&
 
        git merge --log c3 &&
        git show -s --pretty=format:%b HEAD >msg.act &&
        test_cmp msg.log msg.act &&
 
        git reset --hard HEAD^ &&
-       git config merge.log yes &&
+       test_config merge.log "yes" &&
        git merge c3 &&
        git show -s --pretty=format:%b HEAD >msg.act &&
        test_cmp msg.log msg.act
@@ -542,7 +537,6 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "" &&
        test_tick &&
        git merge c0 c2 c0 c1 &&
        verify_merge file result.1-5 &&
@@ -553,7 +547,6 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "" &&
        test_tick &&
        git merge c0 c2 c0 c1 &&
        verify_merge file result.1-5 &&
@@ -564,7 +557,6 @@ test_debug 'git log --graph --decorate --oneline --all'
 
 test_expect_success 'merge c1 with c1 and c2' '
        git reset --hard c1 &&
-       git config branch.master.mergeoptions "" &&
        test_tick &&
        git merge c1 c2 &&
        verify_merge file result.1-5 &&
index b44b29395049308b30e61b00a55e2eb39f4355a1..25dac798894f6a3cb4b62c8b9ba944bfc1d82d9f 100755 (executable)
@@ -109,7 +109,7 @@ test_expect_success 'setup conflicted merge' '
 '
 
 # First do the merge with resolve and recursive then verify that
-# recusive is choosen.
+# recusive is chosen.
 
 test_expect_success 'merge picks up the best result' '
        git config --unset-all pull.twohead &&
index bc38737b2a5ebd9b7ba20fcb92ac87c48b9496c8..d526b1d96a2e98bc304f4d36eaaa60858080e63d 100755 (executable)
@@ -237,7 +237,7 @@ test_expect_success 'mergetool takes partial path' '
     git submodule update -N &&
     test_must_fail git merge master &&
 
-    #shouldnt need these lines
+    #should not need these lines
     #( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
     #( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
     #( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
diff --git a/t/t7612-merge-verify-signatures.sh b/t/t7612-merge-verify-signatures.sh
new file mode 100755 (executable)
index 0000000..21a0bf8
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+test_description='merge signature verification tests'
+. ./test-lib.sh
+. "$TEST_DIRECTORY/lib-gpg.sh"
+
+test_expect_success GPG 'create signed commits' '
+       echo 1 >file && git add file &&
+       test_tick && git commit -m initial &&
+       git tag initial &&
+
+       git checkout -b side-signed &&
+       echo 3 >elif && git add elif &&
+       test_tick && git commit -S -m "signed on side" &&
+       git checkout initial &&
+
+       git checkout -b side-unsigned &&
+       echo 3 >foo && git add foo &&
+       test_tick && git commit -m "unsigned on side" &&
+       git checkout initial &&
+
+       git checkout -b side-bad &&
+       echo 3 >bar && git add bar &&
+       test_tick && git commit -S -m "bad on side" &&
+       git cat-file commit side-bad >raw &&
+       sed -e "s/bad/forged bad/" raw >forged &&
+       git hash-object -w -t commit forged >forged.commit &&
+       git checkout initial &&
+
+       git checkout -b side-untrusted &&
+       echo 3 >baz && git add baz &&
+       test_tick && git commit -SB7227189 -m "untrusted on side"
+
+       git checkout master
+'
+
+test_expect_success GPG 'merge unsigned commit with verification' '
+       test_must_fail git merge --ff-only --verify-signatures side-unsigned 2>mergeerror &&
+       test_i18ngrep "does not have a GPG signature" mergeerror
+'
+
+test_expect_success GPG 'merge commit with bad signature with verification' '
+       test_must_fail git merge --ff-only --verify-signatures $(cat forged.commit) 2>mergeerror &&
+       test_i18ngrep "has a bad GPG signature" mergeerror
+'
+
+test_expect_success GPG 'merge commit with untrusted signature with verification' '
+       test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
+       test_i18ngrep "has an untrusted GPG signature" mergeerror
+'
+
+test_expect_success GPG 'merge signed commit with verification' '
+       git merge --verbose --ff-only --verify-signatures side-signed >mergeoutput &&
+       test_i18ngrep "has a good GPG signature" mergeoutput
+'
+
+test_expect_success GPG 'merge commit with bad signature without verification' '
+       git merge $(cat forged.commit)
+'
+
+test_done
index eb1d3f85b59b2e74231f0285fc4e90d95d0658fa..a6bd99eaf51943a899aa5e5801479b0a84b6b692 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# Copyright (c) 2009, 2010 David Aguilar
+# Copyright (c) 2009, 2010, 2012, 2013 David Aguilar
 #
 
 test_description='git-difftool
@@ -10,47 +10,19 @@ Testing basic diff tool invocation
 
 . ./test-lib.sh
 
-remove_config_vars()
+difftool_test_setup ()
 {
-       # Unset all config variables used by git-difftool
-       git config --unset diff.tool
-       git config --unset diff.guitool
-       git config --unset difftool.test-tool.cmd
-       git config --unset difftool.prompt
-       git config --unset merge.tool
-       git config --unset mergetool.test-tool.cmd
-       git config --unset mergetool.prompt
-       return 0
+       test_config diff.tool test-tool &&
+       test_config difftool.test-tool.cmd 'cat "$LOCAL"' &&
+       test_config difftool.bogus-tool.cmd false
 }
 
-restore_test_defaults()
-{
-       # Restores the test defaults used by several tests
-       remove_config_vars
-       unset GIT_DIFF_TOOL
-       unset GIT_DIFFTOOL_PROMPT
-       unset GIT_DIFFTOOL_NO_PROMPT
-       git config diff.tool test-tool &&
-       git config difftool.test-tool.cmd 'cat $LOCAL'
-       git config difftool.bogus-tool.cmd false
-}
-
-prompt_given()
+prompt_given ()
 {
        prompt="$1"
        test "$prompt" = "Launch 'test-tool' [Y/n]: branch"
 }
 
-stdin_contains()
-{
-       grep >/dev/null "$1"
-}
-
-stdin_doesnot_contain()
-{
-       ! stdin_contains "$1"
-}
-
 # Create a file on master and change it on branch
 test_expect_success PERL 'setup' '
        echo master >file &&
@@ -65,249 +37,237 @@ test_expect_success PERL 'setup' '
 
 # Configure a custom difftool.<tool>.cmd and use it
 test_expect_success PERL 'custom commands' '
-       restore_test_defaults &&
-       git config difftool.test-tool.cmd "cat \$REMOTE" &&
+       difftool_test_setup &&
+       test_config difftool.test-tool.cmd "cat \"\$REMOTE\"" &&
+       echo master >expect &&
+       git difftool --no-prompt branch >actual &&
+       test_cmp expect actual &&
 
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "master" &&
-
-       restore_test_defaults &&
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "branch"
+       test_config difftool.test-tool.cmd "cat \"\$LOCAL\"" &&
+       echo branch >expect &&
+       git difftool --no-prompt branch >actual &&
+       test_cmp expect actual
 '
 
-# Ensures that a custom difftool.<tool>.cmd overrides built-ins
-test_expect_success PERL 'custom commands override built-ins' '
-       restore_test_defaults &&
-       git config difftool.defaults.cmd "cat \$REMOTE" &&
-
-       diff=$(git difftool --tool defaults --no-prompt branch) &&
-       test "$diff" = "master" &&
-
-       git config --unset difftool.defaults.cmd
+test_expect_success PERL 'custom tool commands override built-ins' '
+       test_config difftool.vimdiff.cmd "cat \"\$REMOTE\"" &&
+       echo master >expect &&
+       git difftool --tool vimdiff --no-prompt branch >actual &&
+       test_cmp expect actual
 '
 
-# Ensures that git-difftool ignores bogus --tool values
 test_expect_success PERL 'difftool ignores bad --tool values' '
-       diff=$(git difftool --no-prompt --tool=bad-tool branch)
-       test "$?" = 1 &&
-       test "$diff" = ""
+       : >expect &&
+       test_expect_code 1 \
+               git difftool --no-prompt --tool=bad-tool branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool forwards arguments to diff' '
+       difftool_test_setup &&
        >for-diff &&
        git add for-diff &&
        echo changes>for-diff &&
        git add for-diff &&
-       diff=$(git difftool --cached --no-prompt -- for-diff) &&
-       test "$diff" = "" &&
+       : >expect &&
+       git difftool --cached --no-prompt -- for-diff >actual &&
+       test_cmp expect actual &&
        git reset -- for-diff &&
        rm for-diff
 '
 
 test_expect_success PERL 'difftool honors --gui' '
-       git config merge.tool bogus-tool &&
-       git config diff.tool bogus-tool &&
-       git config diff.guitool test-tool &&
+       difftool_test_setup &&
+       test_config merge.tool bogus-tool &&
+       test_config diff.tool bogus-tool &&
+       test_config diff.guitool test-tool &&
 
-       diff=$(git difftool --no-prompt --gui branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       echo branch >expect &&
+       git difftool --no-prompt --gui branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool --gui last setting wins' '
-       git config diff.guitool bogus-tool &&
-       git difftool --no-prompt --gui --no-gui &&
-
-       git config merge.tool bogus-tool &&
-       git config diff.tool bogus-tool &&
-       git config diff.guitool test-tool &&
-       diff=$(git difftool --no-prompt --no-gui --gui branch) &&
-       test "$diff" = "branch" &&
+       difftool_test_setup &&
+       : >expect &&
+       git difftool --no-prompt --gui --no-gui >actual &&
+       test_cmp expect actual &&
 
-       restore_test_defaults
+       test_config merge.tool bogus-tool &&
+       test_config diff.tool bogus-tool &&
+       test_config diff.guitool test-tool &&
+       echo branch >expect &&
+       git difftool --no-prompt --no-gui --gui branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool --gui works without configured diff.guitool' '
-       git config diff.tool test-tool &&
-
-       diff=$(git difftool --no-prompt --gui branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       echo branch >expect &&
+       git difftool --no-prompt --gui branch >actual &&
+       test_cmp expect actual
 '
 
 # Specify the diff tool using $GIT_DIFF_TOOL
 test_expect_success PERL 'GIT_DIFF_TOOL variable' '
-       test_might_fail git config --unset diff.tool &&
-       GIT_DIFF_TOOL=test-tool &&
-       export GIT_DIFF_TOOL &&
-
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       git config --unset diff.tool &&
+       echo branch >expect &&
+       GIT_DIFF_TOOL=test-tool git difftool --no-prompt branch >actual &&
+       test_cmp expect actual
 '
 
 # Test the $GIT_*_TOOL variables and ensure
 # that $GIT_DIFF_TOOL always wins unless --tool is specified
 test_expect_success PERL 'GIT_DIFF_TOOL overrides' '
-       git config diff.tool bogus-tool &&
-       git config merge.tool bogus-tool &&
+       difftool_test_setup &&
+       test_config diff.tool bogus-tool &&
+       test_config merge.tool bogus-tool &&
 
-       GIT_DIFF_TOOL=test-tool &&
-       export GIT_DIFF_TOOL &&
+       echo branch >expect &&
+       GIT_DIFF_TOOL=test-tool git difftool --no-prompt branch >actual &&
+       test_cmp expect actual &&
 
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "branch" &&
-
-       GIT_DIFF_TOOL=bogus-tool &&
-       export GIT_DIFF_TOOL &&
-
-       diff=$(git difftool --no-prompt --tool=test-tool branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       test_config diff.tool bogus-tool &&
+       test_config merge.tool bogus-tool &&
+       GIT_DIFF_TOOL=bogus-tool \
+               git difftool --no-prompt --tool=test-tool branch >actual &&
+       test_cmp expect actual
 '
 
 # Test that we don't have to pass --no-prompt to difftool
 # when $GIT_DIFFTOOL_NO_PROMPT is true
 test_expect_success PERL 'GIT_DIFFTOOL_NO_PROMPT variable' '
-       GIT_DIFFTOOL_NO_PROMPT=true &&
-       export GIT_DIFFTOOL_NO_PROMPT &&
-
-       diff=$(git difftool branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       echo branch >expect &&
+       GIT_DIFFTOOL_NO_PROMPT=true git difftool branch >actual &&
+       test_cmp expect actual
 '
 
 # git-difftool supports the difftool.prompt variable.
 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
 test_expect_success PERL 'GIT_DIFFTOOL_PROMPT variable' '
-       git config difftool.prompt false &&
-       GIT_DIFFTOOL_PROMPT=true &&
-       export GIT_DIFFTOOL_PROMPT &&
-
-       prompt=$(echo | git difftool branch | tail -1) &&
-       prompt_given "$prompt" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       test_config difftool.prompt false &&
+       echo >input &&
+       GIT_DIFFTOOL_PROMPT=true git difftool branch <input >output &&
+       prompt=$(tail -1 <output) &&
+       prompt_given "$prompt"
 '
 
 # Test that we don't have to pass --no-prompt when difftool.prompt is false
 test_expect_success PERL 'difftool.prompt config variable is false' '
-       git config difftool.prompt false &&
-
-       diff=$(git difftool branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       test_config difftool.prompt false &&
+       echo branch >expect &&
+       git difftool branch >actual &&
+       test_cmp expect actual
 '
 
 # Test that we don't have to pass --no-prompt when mergetool.prompt is false
 test_expect_success PERL 'difftool merge.prompt = false' '
+       difftool_test_setup &&
        test_might_fail git config --unset difftool.prompt &&
-       git config mergetool.prompt false &&
-
-       diff=$(git difftool branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       test_config mergetool.prompt false &&
+       echo branch >expect &&
+       git difftool branch >actual &&
+       test_cmp expect actual
 '
 
 # Test that the -y flag can override difftool.prompt = true
 test_expect_success PERL 'difftool.prompt can overridden with -y' '
-       git config difftool.prompt true &&
-
-       diff=$(git difftool -y branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       test_config difftool.prompt true &&
+       echo branch >expect &&
+       git difftool -y branch >actual &&
+       test_cmp expect actual
 '
 
 # Test that the --prompt flag can override difftool.prompt = false
 test_expect_success PERL 'difftool.prompt can overridden with --prompt' '
-       git config difftool.prompt false &&
-
-       prompt=$(echo | git difftool --prompt branch | tail -1) &&
-       prompt_given "$prompt" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       test_config difftool.prompt false &&
+       echo >input &&
+       git difftool --prompt branch <input >output &&
+       prompt=$(tail -1 <output) &&
+       prompt_given "$prompt"
 '
 
 # Test that the last flag passed on the command-line wins
 test_expect_success PERL 'difftool last flag wins' '
-       diff=$(git difftool --prompt --no-prompt branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults &&
-
-       prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
-       prompt_given "$prompt" &&
-
-       restore_test_defaults
+       difftool_test_setup &&
+       echo branch >expect &&
+       git difftool --prompt --no-prompt branch >actual &&
+       test_cmp expect actual &&
+       echo >input &&
+       git difftool --no-prompt --prompt branch <input >output &&
+       prompt=$(tail -1 <output) &&
+       prompt_given "$prompt"
 '
 
 # git-difftool falls back to git-mergetool config variables
 # so test that behavior here
 test_expect_success PERL 'difftool + mergetool config variables' '
-       remove_config_vars &&
-       git config merge.tool test-tool &&
-       git config mergetool.test-tool.cmd "cat \$LOCAL" &&
-
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "branch" &&
+       test_config merge.tool test-tool &&
+       test_config mergetool.test-tool.cmd "cat \$LOCAL" &&
+       echo branch >expect &&
+       git difftool --no-prompt branch >actual &&
+       test_cmp expect actual &&
 
        # set merge.tool to something bogus, diff.tool to test-tool
-       git config merge.tool bogus-tool &&
-       git config diff.tool test-tool &&
-
-       diff=$(git difftool --no-prompt branch) &&
-       test "$diff" = "branch" &&
-
-       restore_test_defaults
+       test_config merge.tool bogus-tool &&
+       test_config diff.tool test-tool &&
+       git difftool --no-prompt branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool.<tool>.path' '
-       git config difftool.tkdiff.path echo &&
-       diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
-       git config --unset difftool.tkdiff.path &&
-       lines=$(echo "$diff" | grep file | wc -l) &&
-       test "$lines" -eq 1 &&
-
-       restore_test_defaults
+       test_config difftool.tkdiff.path echo &&
+       git difftool --tool=tkdiff --no-prompt branch >output &&
+       lines=$(grep file output | wc -l) &&
+       test "$lines" -eq 1
 '
 
 test_expect_success PERL 'difftool --extcmd=cat' '
-       diff=$(git difftool --no-prompt --extcmd=cat branch) &&
-       test "$diff" = branch"$LF"master
+       echo branch >expect &&
+       echo master >>expect &&
+       git difftool --no-prompt --extcmd=cat branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool --extcmd cat' '
-       diff=$(git difftool --no-prompt --extcmd cat branch) &&
-       test "$diff" = branch"$LF"master
+       echo branch >expect &&
+       echo master >>expect &&
+       git difftool --no-prompt --extcmd=cat branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool -x cat' '
-       diff=$(git difftool --no-prompt -x cat branch) &&
-       test "$diff" = branch"$LF"master
+       echo branch >expect &&
+       echo master >>expect &&
+       git difftool --no-prompt -x cat branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool --extcmd echo arg1' '
-       diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) &&
-       test "$diff" = file
+       echo file >expect &&
+       git difftool --no-prompt \
+               --extcmd sh\ -c\ \"echo\ \$1\" branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool --extcmd cat arg1' '
-       diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) &&
-       test "$diff" = master
+       echo master >expect &&
+       git difftool --no-prompt \
+               --extcmd sh\ -c\ \"cat\ \$1\" branch >actual &&
+       test_cmp expect actual
 '
 
 test_expect_success PERL 'difftool --extcmd cat arg2' '
-       diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) &&
-       test "$diff" = branch
+       echo branch >expect &&
+       git difftool --no-prompt \
+               --extcmd sh\ -c\ \"cat\ \$2\" branch >actual &&
+       test_cmp expect actual
 '
 
 # Create a second file on master and a different version on branch
@@ -324,26 +284,26 @@ test_expect_success PERL 'setup with 2 files different' '
 '
 
 test_expect_success PERL 'say no to the first file' '
-       diff=$( (echo n; echo) | git difftool -x cat branch ) &&
-
-       echo "$diff" | stdin_contains m2 &&
-       echo "$diff" | stdin_contains br2 &&
-       echo "$diff" | stdin_doesnot_contain master &&
-       echo "$diff" | stdin_doesnot_contain branch
+       (echo n && echo) >input &&
+       git difftool -x cat branch <input >output &&
+       grep m2 output &&
+       grep br2 output &&
+       ! grep master output &&
+       ! grep branch output
 '
 
 test_expect_success PERL 'say no to the second file' '
-       diff=$( (echo; echo n) | git difftool -x cat branch ) &&
-
-       echo "$diff" | stdin_contains master &&
-       echo "$diff" | stdin_contains branch &&
-       echo "$diff" | stdin_doesnot_contain m2 &&
-       echo "$diff" | stdin_doesnot_contain br2
+       (echo && echo n) >input &&
+       git difftool -x cat branch <input >output &&
+       grep master output &&
+       grep branch output &&
+       ! grep m2 output &&
+       ! grep br2 output
 '
 
 test_expect_success PERL 'difftool --tool-help' '
-       tool_help=$(git difftool --tool-help) &&
-       echo "$tool_help" | stdin_contains tool
+       git difftool --tool-help >output &&
+       grep tool output
 '
 
 test_expect_success PERL 'setup change in subdirectory' '
@@ -354,34 +314,97 @@ test_expect_success PERL 'setup change in subdirectory' '
        git commit -m "added sub/sub" &&
        echo test >>file &&
        echo test >>sub/sub &&
-       git add . &&
+       git add file sub/sub &&
        git commit -m "modified both"
 '
 
-test_expect_success PERL 'difftool -d' '
-       diff=$(git difftool -d --extcmd ls branch) &&
-       echo "$diff" | stdin_contains sub &&
-       echo "$diff" | stdin_contains file
+run_dir_diff_test () {
+       test_expect_success PERL "$1 --no-symlinks" "
+               symlinks=--no-symlinks &&
+               $2
+       "
+       test_expect_success PERL,SYMLINKS "$1 --symlinks" "
+               symlinks=--symlinks &&
+               $2
+       "
+}
+
+run_dir_diff_test 'difftool -d' '
+       git difftool -d $symlinks --extcmd ls branch >output &&
+       grep sub output &&
+       grep file output
 '
 
-test_expect_success PERL 'difftool --dir-diff' '
-       diff=$(git difftool --dir-diff --extcmd ls branch) &&
-       echo "$diff" | stdin_contains sub &&
-       echo "$diff" | stdin_contains file
+run_dir_diff_test 'difftool --dir-diff' '
+       git difftool --dir-diff $symlinks --extcmd ls branch >output &&
+       grep sub output &&
+       grep file output
 '
 
-test_expect_success PERL 'difftool --dir-diff ignores --prompt' '
-       diff=$(git difftool --dir-diff --prompt --extcmd ls branch) &&
-       echo "$diff" | stdin_contains sub &&
-       echo "$diff" | stdin_contains file
+run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
+       git difftool --dir-diff $symlinks --prompt --extcmd ls branch >output &&
+       grep sub output &&
+       grep file output
 '
 
-test_expect_success PERL 'difftool --dir-diff from subdirectory' '
+run_dir_diff_test 'difftool --dir-diff from subdirectory' '
        (
                cd sub &&
-               diff=$(git difftool --dir-diff --extcmd ls branch) &&
-               echo "$diff" | stdin_contains sub &&
-               echo "$diff" | stdin_contains file
+               git difftool --dir-diff $symlinks --extcmd ls branch >output &&
+               grep sub output &&
+               grep file output
+       )
+'
+
+write_script .git/CHECK_SYMLINKS <<\EOF
+for f in file file2 sub/sub
+do
+       echo "$f"
+       readlink "$2/$f"
+done >actual
+EOF
+
+test_expect_success PERL,SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
+       cat >expect <<-EOF &&
+       file
+       $(pwd)/file
+       file2
+       $(pwd)/file2
+       sub/sub
+       $(pwd)/sub/sub
+       EOF
+       git difftool --dir-diff --symlink \
+               --extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
+       test_cmp actual expect
+'
+
+write_script modify-file <<\EOF
+echo "new content" >file
+EOF
+
+test_expect_success PERL 'difftool --no-symlinks does not overwrite working tree file ' '
+       echo "orig content" >file &&
+       git difftool --dir-diff --no-symlinks --extcmd "$(pwd)/modify-file" branch &&
+       echo "new content" >expect &&
+       test_cmp expect file
+'
+
+write_script modify-both-files <<\EOF
+echo "wt content" >file &&
+echo "tmp content" >"$2/file" &&
+echo "$2" >tmpdir
+EOF
+
+test_expect_success PERL 'difftool --no-symlinks detects conflict ' '
+       (
+               TMPDIR=$TRASH_DIRECTORY &&
+               export TMPDIR &&
+               echo "orig content" >file &&
+               test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$(pwd)/modify-both-files" branch &&
+               echo "wt content" >expect &&
+               test_cmp expect file &&
+               echo "tmp content" >expect &&
+               test_cmp expect "$(cat tmpdir)/file"
        )
 '
 
index 97d6f4c7de57c54adfd5fed6401dbd168b5f3064..ebd5c5db45c8816f39b2d8c60775f455ab9c48aa 100755 (executable)
@@ -101,7 +101,7 @@ test_expect_success $PREREQ \
 
 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
     clean_fake_sendmail &&
-     git send-email --envelope-sender="Patch Contributer <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
+     git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
 '
 
 test_expect_success $PREREQ 'setup expect' '
@@ -787,7 +787,7 @@ test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
        test $ret = "0"
 '
 
-test_expect_success $PREREQ 'confirm doesnt loop forever' '
+test_expect_success $PREREQ 'confirm does not loop forever' '
        CONFIRM=$(git config --get sendemail.confirm) &&
        git config sendemail.confirm auto &&
        GIT_SEND_EMAIL_NOTTY=1 &&
index b7eed2489fa169aa1c6e5c98f59a0349ba8118fa..6dafe7e99ab4bd0006ed4f7204062fca31750689 100755 (executable)
@@ -54,14 +54,6 @@ text_no_props () {
 
 >empty
 
-test_expect_success 'setup: have pipes?' '
-       rm -f frob &&
-       if mkfifo frob
-       then
-               test_set_prereq PIPE
-       fi
-'
-
 test_expect_success PIPE 'empty dump' '
        reinit_git &&
        echo "SVN-fs-dump-format-version: 2" >input &&
index 2fcf2694696fedb5e7e3d57c869f7dbbbf23dbec..ac6f3b6af25c67ae3a2c0748c34f99b4cd0d4b32 100755 (executable)
@@ -49,14 +49,6 @@ echo "$@"'
 
 >empty
 
-test_expect_success 'setup: have pipes?' '
-       rm -f frob &&
-       if mkfifo frob
-       then
-               test_set_prereq PIPE
-       fi
-'
-
 ###
 ### series A
 ###
index 90bb6050c13ece02199b6978e43e3c67de563c84..6783c14c1ad9af0f5aa3d16e13250e9a1a292b28 100755 (executable)
@@ -539,8 +539,7 @@ test_expect_success \
         test_when_finished "GIT_COMMITTER_NAME=\"C O Mitter\"" &&
         echo "ISO-8859-1" >> file &&
         git add file &&
-        git config i18n.commitencoding ISO-8859-1 &&
-        test_when_finished "git config --unset i18n.commitencoding" &&
+        test_config i18n.commitencoding ISO-8859-1 &&
         git commit -F "$TEST_DIRECTORY"/t3900/ISO8859-1.txt &&
         gitweb_run "p=.git;a=commit"'
 
index dc92e60cd6f09fa5e2610d491cf1c07d43c45dfd..11d2b5102cde384ad11540610a52f62c4732aa8c 100755 (executable)
@@ -42,6 +42,47 @@ test_expect_success 'P4CONFIG and relative dir clone' '
        )
 '
 
+# Common setup using .p4config to set P4CLIENT and P4PORT breaks
+# if clone destination is relative.  Make sure that chdir() expands
+# the relative path in --dest to absolute.
+test_expect_success 'p4 client root would be relative due to clone --dest' '
+       test_when_finished cleanup_git &&
+       (
+               echo P4PORT=$P4PORT >git/.p4config &&
+               P4CONFIG=.p4config &&
+               export P4CONFIG &&
+               unset P4PORT &&
+               git p4 clone --dest="git" //depot
+       )
+'
+
+# When the p4 client Root is a symlink, make sure chdir() does not use
+# getcwd() to convert it to a physical path.
+test_expect_success SYMLINKS 'p4 client root symlink should stay symbolic' '
+       physical="$TRASH_DIRECTORY/physical" &&
+       symbolic="$TRASH_DIRECTORY/symbolic" &&
+       test_when_finished "rm -rf \"$physical\"" &&
+       test_when_finished "rm \"$symbolic\"" &&
+       mkdir -p "$physical" &&
+       ln -s "$physical" "$symbolic" &&
+       test_when_finished cleanup_git &&
+       (
+               P4CLIENT=client-sym &&
+               p4 client -i <<-EOF &&
+               Client: $P4CLIENT
+               Description: $P4CLIENT
+               Root: $symbolic
+               LineEnd: unix
+               View: //depot/... //$P4CLIENT/...
+               EOF
+               git p4 clone --dest="$git" //depot &&
+               cd "$git" &&
+               test_commit file2 &&
+               git config git-p4.skipSubmitEdit true &&
+               git p4 submit
+       )
+'
+
 test_expect_success 'kill p4d' '
        kill_p4d
 '
index fa62d010f68e3ee97e6754687ad4d08564d3c96b..52510094add59b508e1581ffebfa555e7249561c 100644 (file)
@@ -91,6 +91,10 @@ q_to_tab () {
        tr Q '\011'
 }
 
+qz_to_tab_space () {
+       tr QZ '\011\040'
+}
+
 append_cr () {
        sed -e 's/$/Q/' | tr Q '\015'
 }
@@ -135,12 +139,12 @@ test_pause () {
        fi
 }
 
-# Call test_commit with the arguments "<message> [<file> [<contents>]]"
+# Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
 #
 # This will commit a file with the given contents and the given commit
-# message.  It will also add a tag with <message> as name.
+# message, and tag the resulting commit with the given tag name.
 #
-# Both <file> and <contents> default to <message>.
+# <file>, <contents>, and <tag> all default to <message>.
 
 test_commit () {
        notick= &&
@@ -168,7 +172,7 @@ test_commit () {
                test_tick
        fi &&
        git commit $signoff -m "$1" &&
-       git tag "$1"
+       git tag "${4:-$1}"
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
@@ -536,6 +540,9 @@ test_must_fail () {
        elif test $exit_code = 127; then
                echo >&2 "test_must_fail: command not found: $*"
                return 1
+       elif test $exit_code = 126; then
+               echo >&2 "test_must_fail: valgrind error: $*"
+               return 1
        fi
        return 0
 }
index 1f510252ad7cb7a5afae67731bc37fccf941b654..debd8b475186591ec1d1ef38848fef1a213889f4 100644 (file)
@@ -193,7 +193,11 @@ do
        --no-color)
                color=; shift ;;
        --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
-               valgrind=t; verbose=t; shift ;;
+               valgrind=memcheck
+               shift ;;
+       --valgrind=*)
+               valgrind=$(expr "z$1" : 'z[^=]*=\(.*\)')
+               shift ;;
        --tee)
                shift ;; # was handled already
        --root=*)
@@ -204,6 +208,8 @@ do
        esac
 done
 
+test -n "$valgrind" && verbose=t
+
 if test -n "$color"
 then
        say_color () {
@@ -530,6 +536,8 @@ then
        PATH=$GIT_VALGRIND/bin:$PATH
        GIT_EXEC_PATH=$GIT_VALGRIND/bin
        export GIT_VALGRIND
+       GIT_VALGRIND_MODE="$valgrind"
+       export GIT_VALGRIND_MODE
 elif test -n "$GIT_TEST_INSTALLED"
 then
        GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)  ||
@@ -727,6 +735,11 @@ test_i18ngrep () {
        fi
 }
 
+test_lazy_prereq PIPE '
+       # test whether the filesystem supports FIFOs
+       rm -f testfifo && mkfifo testfifo
+'
+
 test_lazy_prereq SYMLINKS '
        # test whether the filesystem supports symbolic links
        ln -s x y && test -h y
index 582b4dca9497363c7bfd6ae5ecc2c98d28d5ac0a..6b87c91b60cde4b19d6644227548f1ba6b226545 100755 (executable)
@@ -2,20 +2,27 @@
 
 base=$(basename "$0")
 
-TRACK_ORIGINS=
+TOOL_OPTIONS='--leak-check=no'
 
-VALGRIND_VERSION=$(valgrind --version)
-VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)')
-VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)')
-test 3 -gt "$VALGRIND_MAJOR" ||
-test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" ||
-TRACK_ORIGINS=--track-origins=yes
+case "$GIT_VALGRIND_MODE" in
+memcheck-fast)
+       ;;
+memcheck)
+       VALGRIND_VERSION=$(valgrind --version)
+       VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)')
+       VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)')
+       test 3 -gt "$VALGRIND_MAJOR" ||
+       test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" ||
+       TOOL_OPTIONS="$TOOL_OPTIONS --track-origins=yes"
+       ;;
+*)
+       TOOL_OPTIONS="--tool=$GIT_VALGRIND_MODE"
+esac
 
 exec valgrind -q --error-exitcode=126 \
-       --leak-check=no \
-       --suppressions="$GIT_VALGRIND/default.supp" \
        --gen-suppressions=all \
-       $TRACK_ORIGINS \
+       --suppressions="$GIT_VALGRIND/default.supp" \
+       $TOOL_OPTIONS \
        --log-fd=4 \
        --input-fd=4 \
        $GIT_VALGRIND_OPTIONS \
index 0f2d9a4a3d8ea732c7c61e3818bd0bbe417c76b0..120ec96b0dbd94e7be9ffc81d0fb87ccbd30a7df 100644 (file)
@@ -24,7 +24,7 @@ static int apply_delta(int argc, char *argv[])
                die_errno("cannot open preimage");
        if (buffer_init(&delta, argv[3]))
                die_errno("cannot open delta");
-       if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
+       if (svndiff0_apply(&delta, (off_t) strtoumax(argv[4], NULL, 0),
                                        &preimage_view, stdout))
                return 1;
        if (buffer_deinit(&preimage))
index cb3ef7d38e475480a5d81ce6077c4c87ea09a318..dcd8d97411dd15e01ba1480a44b2a998043b424a 100644 (file)
@@ -991,7 +991,7 @@ struct unidirectional_transfer {
        int src_is_sock;
        /* Is destination socket? */
        int dest_is_sock;
-       /* Transfer state (TRANSFERING/FLUSHING/FINISHED) */
+       /* Transfer state (TRANSFERRING/FLUSHING/FINISHED) */
        int state;
        /* Buffer. */
        char buf[BUFFERSIZE];
index e6f9346c762416b9c0e97f9023062f99e4542dbc..ba5d8afb1b04ba9d331c721fd9f730184fff2f23 100644 (file)
@@ -508,7 +508,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
        struct ref *refs;
 
        connect_setup(transport, for_push, 0);
-       get_remote_heads(data->fd[0], &refs,
+       get_remote_heads(data->fd[0], NULL, 0, &refs,
                         for_push ? REF_NORMAL : 0, &data->extra_have);
        data->got_remote_heads = 1;
 
@@ -519,11 +519,9 @@ static int fetch_refs_via_pack(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct git_transport_data *data = transport->data;
-       struct string_list sought = STRING_LIST_INIT_DUP;
        const struct ref *refs;
        char *dest = xstrdup(transport->url);
        struct fetch_pack_args args;
-       int i;
        struct ref *refs_tmp = NULL;
 
        memset(&args, 0, sizeof(args));
@@ -537,18 +535,16 @@ static int fetch_refs_via_pack(struct transport *transport,
        args.no_progress = !transport->progress;
        args.depth = data->options.depth;
 
-       for (i = 0; i < nr_heads; i++)
-               string_list_append(&sought, to_fetch[i]->name);
-
        if (!data->got_remote_heads) {
                connect_setup(transport, 0, 0);
-               get_remote_heads(data->fd[0], &refs_tmp, 0, NULL);
+               get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0, NULL);
                data->got_remote_heads = 1;
        }
 
        refs = fetch_pack(&args, data->fd, data->conn,
                          refs_tmp ? refs_tmp : transport->remote_refs,
-                         dest, &sought, &transport->pack_lockfile);
+                         dest, to_fetch, nr_heads,
+                         &transport->pack_lockfile);
        close(data->fd[0]);
        close(data->fd[1]);
        if (finish_connect(data->conn))
@@ -558,7 +554,6 @@ static int fetch_refs_via_pack(struct transport *transport,
 
        free_refs(refs_tmp);
 
-       string_list_clear(&sought, 0);
        free(dest);
        return (refs ? 0 : -1);
 }
@@ -800,7 +795,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
                struct ref *tmp_refs;
                connect_setup(transport, 1, 0);
 
-               get_remote_heads(data->fd[0], &tmp_refs, REF_NORMAL, NULL);
+               get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL);
                data->got_remote_heads = 1;
        }
 
@@ -1133,6 +1128,8 @@ int transport_push(struct transport *transport,
                        match_flags |= MATCH_REFS_MIRROR;
                if (flags & TRANSPORT_PUSH_PRUNE)
                        match_flags |= MATCH_REFS_PRUNE;
+               if (flags & TRANSPORT_PUSH_FOLLOW_TAGS)
+                       match_flags |= MATCH_REFS_FOLLOW_TAGS;
 
                if (match_push_refs(local_refs, &remote_refs,
                                    refspec_nr, refspec, match_flags)) {
index a3450e97c0d0d94778a4b635efdd53b724eb70c2..fcb1d25d96a750c171c4341a9c5f08992915fb6b 100644 (file)
@@ -74,7 +74,7 @@ struct transport {
                       const char *executable, int fd[2]);
 
        /** get_refs_list(), fetch(), and push_refs() can keep
-        * resources (such as a connection) reserved for futher
+        * resources (such as a connection) reserved for further
         * use. disconnect() releases these resources.
         **/
        int (*disconnect)(struct transport *connection);
@@ -105,6 +105,7 @@ struct transport {
 #define TRANSPORT_PUSH_PRUNE 128
 #define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND 256
 #define TRANSPORT_PUSH_NO_HOOK 512
+#define TRANSPORT_PUSH_FOLLOW_TAGS 1024
 
 #define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
 #define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
index 948cfffe13376742cc46276652048cd6f5edaa7c..bfa6279cc418278079bd95854adfe8d8301b6788 100644 (file)
@@ -26,6 +26,7 @@ static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<
 #define SHALLOW                (1u << 16)
 #define NOT_SHALLOW    (1u << 17)
 #define CLIENT_SHALLOW (1u << 18)
+#define HIDDEN_REF     (1u << 19)
 
 static unsigned long oldest_have;
 
@@ -33,6 +34,7 @@ static int multi_ack;
 static int no_done;
 static int use_thin_pack, use_ofs_delta, use_include_tag;
 static int no_progress, daemon_mode;
+static int allow_tip_sha1_in_want;
 static int shallow_nr;
 static struct object_array have_obj;
 static struct object_array want_obj;
@@ -42,7 +44,6 @@ static unsigned int timeout;
  * otherwise maximum packet size (up to 65520 bytes).
  */
 static int use_sideband;
-static int debug_fd;
 static int advertise_refs;
 static int stateless_rpc;
 
@@ -51,13 +52,6 @@ static void reset_timeout(void)
        alarm(timeout);
 }
 
-static int strip(char *line, int len)
-{
-       if (len && line[len-1] == '\n')
-               line[--len] = 0;
-       return len;
-}
-
 static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 {
        if (use_sideband)
@@ -70,7 +64,8 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
                xwrite(fd, data, sz);
                return sz;
        }
-       return safe_write(fd, data, sz);
+       write_or_die(fd, data, sz);
+       return sz;
 }
 
 static FILE *pack_pipe = NULL;
@@ -413,7 +408,6 @@ static int ok_to_give_up(void)
 
 static int get_common_commits(void)
 {
-       static char line[1000];
        unsigned char sha1[20];
        char last_hex[41];
        int got_common = 0;
@@ -423,10 +417,10 @@ static int get_common_commits(void)
        save_commit_buffer = 0;
 
        for (;;) {
-               int len = packet_read_line(0, line, sizeof(line));
+               char *line = packet_read_line(0, NULL);
                reset_timeout();
 
-               if (!len) {
+               if (!line) {
                        if (multi_ack == 2 && got_common
                            && !got_other && ok_to_give_up()) {
                                sent_ready = 1;
@@ -445,7 +439,6 @@ static int get_common_commits(void)
                        got_other = 0;
                        continue;
                }
-               strip(line, len);
                if (!prefixcmp(line, "have ")) {
                        switch (got_sha1(line+5, sha1)) {
                        case -1: /* they have what we do not */
@@ -485,6 +478,12 @@ static int get_common_commits(void)
        }
 }
 
+static int is_our_ref(struct object *o)
+{
+       return o->flags &
+               ((allow_tip_sha1_in_want ? HIDDEN_REF : 0) | OUR_REF);
+}
+
 static void check_non_tip(void)
 {
        static const char *argv[] = {
@@ -521,7 +520,7 @@ static void check_non_tip(void)
                o = get_indexed_object(--i);
                if (!o)
                        continue;
-               if (!(o->flags & OUR_REF))
+               if (!is_our_ref(o))
                        continue;
                memcpy(namebuf + 1, sha1_to_hex(o->sha1), 40);
                if (write_in_full(cmd.in, namebuf, 42) < 0)
@@ -530,7 +529,7 @@ static void check_non_tip(void)
        namebuf[40] = '\n';
        for (i = 0; i < want_obj.nr; i++) {
                o = want_obj.objects[i].item;
-               if (o->flags & OUR_REF)
+               if (is_our_ref(o))
                        continue;
                memcpy(namebuf, sha1_to_hex(o->sha1), 40);
                if (write_in_full(cmd.in, namebuf, 41) < 0)
@@ -564,7 +563,7 @@ static void check_non_tip(void)
        /* Pick one of them (we know there at least is one) */
        for (i = 0; i < want_obj.nr; i++) {
                o = want_obj.objects[i].item;
-               if (!(o->flags & OUR_REF))
+               if (!is_our_ref(o))
                        die("git upload-pack: not our ref %s",
                            sha1_to_hex(o->sha1));
        }
@@ -573,36 +572,33 @@ static void check_non_tip(void)
 static void receive_needs(void)
 {
        struct object_array shallows = OBJECT_ARRAY_INIT;
-       static char line[1000];
-       int len, depth = 0;
+       int depth = 0;
        int has_non_tip = 0;
 
        shallow_nr = 0;
-       if (debug_fd)
-               write_str_in_full(debug_fd, "#S\n");
        for (;;) {
                struct object *o;
                const char *features;
                unsigned char sha1_buf[20];
-               len = packet_read_line(0, line, sizeof(line));
+               char *line = packet_read_line(0, NULL);
                reset_timeout();
-               if (!len)
+               if (!line)
                        break;
-               if (debug_fd)
-                       write_in_full(debug_fd, line, len);
 
                if (!prefixcmp(line, "shallow ")) {
                        unsigned char sha1[20];
                        struct object *object;
-                       if (get_sha1(line + 8, sha1))
+                       if (get_sha1_hex(line + 8, sha1))
                                die("invalid shallow line: %s", line);
                        object = parse_object(sha1);
                        if (!object)
                                die("did not find object for %s", line);
                        if (object->type != OBJ_COMMIT)
                                die("invalid shallow object %s", sha1_to_hex(sha1));
-                       object->flags |= CLIENT_SHALLOW;
-                       add_object_array(object, NULL, &shallows);
+                       if (!(object->flags & CLIENT_SHALLOW)) {
+                               object->flags |= CLIENT_SHALLOW;
+                               add_object_array(object, NULL, &shallows);
+                       }
                        continue;
                }
                if (!prefixcmp(line, "deepen ")) {
@@ -644,13 +640,11 @@ static void receive_needs(void)
                            sha1_to_hex(sha1_buf));
                if (!(o->flags & WANTED)) {
                        o->flags |= WANTED;
-                       if (!(o->flags & OUR_REF))
+                       if (!is_our_ref(o))
                                has_non_tip = 1;
                        add_object_array(o, NULL, &want_obj);
                }
        }
-       if (debug_fd)
-               write_str_in_full(debug_fd, "#E\n");
 
        /*
         * We have sent all our refs already, and the other end
@@ -730,8 +724,10 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag
 {
        struct object *o = lookup_unknown_object(sha1);
 
-       if (ref_is_hidden(refname))
+       if (ref_is_hidden(refname)) {
+               o->flags |= HIDDEN_REF;
                return 1;
+       }
        if (!o)
                die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
        o->flags |= OUR_REF;
@@ -750,9 +746,10 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
                return 0;
 
        if (capabilities)
-               packet_write(1, "%s %s%c%s%s agent=%s\n",
+               packet_write(1, "%s %s%c%s%s%s agent=%s\n",
                             sha1_to_hex(sha1), refname_nons,
                             0, capabilities,
+                            allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "",
                             stateless_rpc ? " no-done" : "",
                             git_user_agent_sanitized());
        else
@@ -786,6 +783,8 @@ static void upload_pack(void)
 
 static int upload_pack_config(const char *var, const char *value, void *unused)
 {
+       if (!strcmp("uploadpack.allowtipsha1inwant", var))
+               allow_tip_sha1_in_want = git_config_bool(var, value);
        return parse_hide_refs_config(var, value, "uploadpack");
 }
 
@@ -841,8 +840,6 @@ int main(int argc, char **argv)
        if (is_repository_shallow())
                die("attempt to fetch/clone from a shallow repository");
        git_config(upload_pack_config, NULL);
-       if (getenv("GIT_DEBUG_SEND_PACK"))
-               debug_fd = atoi(getenv("GIT_DEBUG_SEND_PACK"));
        upload_pack();
        return 0;
 }
index 960f448cffd9ffd4e53763dfed3669bc374b8620..b50f99a9361926d2116c85e3e90a132fb9dab742 100644 (file)
@@ -1,5 +1,15 @@
 #include "cache.h"
 
+static void check_pipe(int err)
+{
+       if (err == EPIPE) {
+               signal(SIGPIPE, SIG_DFL);
+               raise(SIGPIPE);
+               /* Should never happen, but just in case... */
+               exit(141);
+       }
+}
+
 /*
  * Some cases use stdio, but want to flush after the write
  * to get error handling (and to get better interactive
@@ -34,8 +44,7 @@ void maybe_flush_or_die(FILE *f, const char *desc)
                        return;
        }
        if (fflush(f)) {
-               if (errno == EPIPE)
-                       exit(0);
+               check_pipe(errno);
                die_errno("write failure on '%s'", desc);
        }
 }
@@ -50,8 +59,7 @@ void fsync_or_die(int fd, const char *msg)
 void write_or_die(int fd, const void *buf, size_t count)
 {
        if (write_in_full(fd, buf, count) < 0) {
-               if (errno == EPIPE)
-                       exit(0);
+               check_pipe(errno);
                die_errno("write error");
        }
 }
@@ -59,8 +67,7 @@ void write_or_die(int fd, const void *buf, size_t count)
 int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
 {
        if (write_in_full(fd, buf, count) < 0) {
-               if (errno == EPIPE)
-                       exit(0);
+               check_pipe(errno);
                fprintf(stderr, "%s: write error (%s)\n",
                        msg, strerror(errno));
                return 0;
index 54f4391f9cc86d3d485ed80383cb142b1f25b1e7..ec5f27c5992e5fec5fb54384a04ffacf1745ce4a 100644 (file)
@@ -965,13 +965,32 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
        wt_status_print_trailer(s);
 }
 
+static void show_revert_in_progress(struct wt_status *s,
+                                       struct wt_status_state *state,
+                                       const char *color)
+{
+       status_printf_ln(s, color, _("You are currently reverting commit %s."),
+                        find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
+       if (advice_status_hints) {
+               if (has_unmerged(s))
+                       status_printf_ln(s, color,
+                               _("  (fix conflicts and run \"git revert --continue\")"));
+               else
+                       status_printf_ln(s, color,
+                               _("  (all conflicts fixed: run \"git revert --continue\")"));
+               status_printf_ln(s, color,
+                       _("  (use \"git revert --abort\" to cancel the revert operation)"));
+       }
+       wt_status_print_trailer(s);
+}
+
 static void show_bisect_in_progress(struct wt_status *s,
                                struct wt_status_state *state,
                                const char *color)
 {
        if (state->branch)
                status_printf_ln(s, color,
-                                _("You are currently bisecting branch '%s'."),
+                                _("You are currently bisecting, started from branch '%s'."),
                                 state->branch);
        else
                status_printf_ln(s, color,
@@ -985,96 +1004,172 @@ static void show_bisect_in_progress(struct wt_status *s,
 /*
  * Extract branch information from rebase/bisect
  */
-static void read_and_strip_branch(struct strbuf *sb,
-                                 const char **branch,
-                                 const char *path)
+static char *read_and_strip_branch(const char *path)
 {
+       struct strbuf sb = STRBUF_INIT;
        unsigned char sha1[20];
 
-       strbuf_reset(sb);
-       if (strbuf_read_file(sb, git_path("%s", path), 0) <= 0)
-               return;
+       if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0)
+               goto got_nothing;
 
-       while (sb->len && sb->buf[sb->len - 1] == '\n')
-               strbuf_setlen(sb, sb->len - 1);
-       if (!sb->len)
-               return;
-       if (!prefixcmp(sb->buf, "refs/heads/"))
-               *branch = sb->buf + strlen("refs/heads/");
-       else if (!prefixcmp(sb->buf, "refs/"))
-               *branch = sb->buf;
-       else if (!get_sha1_hex(sb->buf, sha1)) {
+       while (&sb.len && sb.buf[sb.len - 1] == '\n')
+               strbuf_setlen(&sb, sb.len - 1);
+       if (!sb.len)
+               goto got_nothing;
+       if (!prefixcmp(sb.buf, "refs/heads/"))
+               strbuf_remove(&sb,0, strlen("refs/heads/"));
+       else if (!prefixcmp(sb.buf, "refs/"))
+               ;
+       else if (!get_sha1_hex(sb.buf, sha1)) {
                const char *abbrev;
                abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
-               strbuf_reset(sb);
-               strbuf_addstr(sb, abbrev);
-               *branch = sb->buf;
-       } else if (!strcmp(sb->buf, "detached HEAD")) /* rebase */
-               ;
+               strbuf_reset(&sb);
+               strbuf_addstr(&sb, abbrev);
+       } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
+               goto got_nothing;
        else                    /* bisect */
-               *branch = sb->buf;
+               ;
+       return strbuf_detach(&sb, NULL);
+
+got_nothing:
+       strbuf_release(&sb);
+       return NULL;
 }
 
-static void wt_status_print_state(struct wt_status *s)
+struct grab_1st_switch_cbdata {
+       int found;
+       struct strbuf buf;
+       unsigned char nsha1[20];
+};
+
+static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
+                          const char *email, unsigned long timestamp, int tz,
+                          const char *message, void *cb_data)
 {
-       const char *state_color = color(WT_STATUS_HEADER, s);
-       struct strbuf branch = STRBUF_INIT;
-       struct strbuf onto = STRBUF_INIT;
-       struct wt_status_state state;
-       struct stat st;
+       struct grab_1st_switch_cbdata *cb = cb_data;
+       const char *target = NULL, *end;
 
-       memset(&state, 0, sizeof(state));
+       if (prefixcmp(message, "checkout: moving from "))
+               return 0;
+       message += strlen("checkout: moving from ");
+       target = strstr(message, " to ");
+       if (!target)
+               return 0;
+       target += strlen(" to ");
+       strbuf_reset(&cb->buf);
+       hashcpy(cb->nsha1, nsha1);
+       for (end = target; *end && *end != '\n'; end++)
+               ;
+       strbuf_add(&cb->buf, target, end - target);
+       cb->found = 1;
+       return 1;
+}
+
+static void wt_status_get_detached_from(struct wt_status_state *state)
+{
+       struct grab_1st_switch_cbdata cb;
+       struct commit *commit;
+       unsigned char sha1[20];
+       char *ref = NULL;
+
+       strbuf_init(&cb.buf, 0);
+       if (for_each_reflog_ent_reverse("HEAD", grab_1st_switch, &cb) <= 0) {
+               strbuf_release(&cb.buf);
+               return;
+       }
+
+       if (dwim_ref(cb.buf.buf, cb.buf.len, sha1, &ref) == 1 &&
+           /* sha1 is a commit? match without further lookup */
+           (!hashcmp(cb.nsha1, sha1) ||
+            /* perhaps sha1 is a tag, try to dereference to a commit */
+            ((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
+             !hashcmp(cb.nsha1, commit->object.sha1)))) {
+               int ofs;
+               if (!prefixcmp(ref, "refs/tags/"))
+                       ofs = strlen("refs/tags/");
+               else if (!prefixcmp(ref, "refs/remotes/"))
+                       ofs = strlen("refs/remotes/");
+               else
+                       ofs = 0;
+               state->detached_from = xstrdup(ref + ofs);
+       } else
+               state->detached_from =
+                       xstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV));
+       hashcpy(state->detached_sha1, cb.nsha1);
+
+       free(ref);
+       strbuf_release(&cb.buf);
+}
+
+void wt_status_get_state(struct wt_status_state *state,
+                        int get_detached_from)
+{
+       struct stat st;
+       unsigned char sha1[20];
 
        if (!stat(git_path("MERGE_HEAD"), &st)) {
-               state.merge_in_progress = 1;
+               state->merge_in_progress = 1;
        } else if (!stat(git_path("rebase-apply"), &st)) {
                if (!stat(git_path("rebase-apply/applying"), &st)) {
-                       state.am_in_progress = 1;
+                       state->am_in_progress = 1;
                        if (!stat(git_path("rebase-apply/patch"), &st) && !st.st_size)
-                               state.am_empty_patch = 1;
+                               state->am_empty_patch = 1;
                } else {
-                       state.rebase_in_progress = 1;
-                       read_and_strip_branch(&branch, &state.branch,
-                                             "rebase-apply/head-name");
-                       read_and_strip_branch(&onto, &state.onto,
-                                             "rebase-apply/onto");
+                       state->rebase_in_progress = 1;
+                       state->branch = read_and_strip_branch("rebase-apply/head-name");
+                       state->onto = read_and_strip_branch("rebase-apply/onto");
                }
        } else if (!stat(git_path("rebase-merge"), &st)) {
                if (!stat(git_path("rebase-merge/interactive"), &st))
-                       state.rebase_interactive_in_progress = 1;
+                       state->rebase_interactive_in_progress = 1;
                else
-                       state.rebase_in_progress = 1;
-               read_and_strip_branch(&branch, &state.branch,
-                                     "rebase-merge/head-name");
-               read_and_strip_branch(&onto, &state.onto,
-                                     "rebase-merge/onto");
+                       state->rebase_in_progress = 1;
+               state->branch = read_and_strip_branch("rebase-merge/head-name");
+               state->onto = read_and_strip_branch("rebase-merge/onto");
        } else if (!stat(git_path("CHERRY_PICK_HEAD"), &st)) {
-               state.cherry_pick_in_progress = 1;
+               state->cherry_pick_in_progress = 1;
        }
        if (!stat(git_path("BISECT_LOG"), &st)) {
-               state.bisect_in_progress = 1;
-               read_and_strip_branch(&branch, &state.branch,
-                                     "BISECT_START");
+               state->bisect_in_progress = 1;
+               state->branch = read_and_strip_branch("BISECT_START");
+       }
+       if (!stat(git_path("REVERT_HEAD"), &st) &&
+           !get_sha1("REVERT_HEAD", sha1)) {
+               state->revert_in_progress = 1;
+               hashcpy(state->revert_head_sha1, sha1);
        }
 
-       if (state.merge_in_progress)
-               show_merge_in_progress(s, &state, state_color);
-       else if (state.am_in_progress)
-               show_am_in_progress(s, &state, state_color);
-       else if (state.rebase_in_progress || state.rebase_interactive_in_progress)
-               show_rebase_in_progress(s, &state, state_color);
-       else if (state.cherry_pick_in_progress)
-               show_cherry_pick_in_progress(s, &state, state_color);
-       if (state.bisect_in_progress)
-               show_bisect_in_progress(s, &state, state_color);
-       strbuf_release(&branch);
-       strbuf_release(&onto);
+       if (get_detached_from)
+               wt_status_get_detached_from(state);
+}
+
+static void wt_status_print_state(struct wt_status *s,
+                                 struct wt_status_state *state)
+{
+       const char *state_color = color(WT_STATUS_HEADER, s);
+       if (state->merge_in_progress)
+               show_merge_in_progress(s, state, state_color);
+       else if (state->am_in_progress)
+               show_am_in_progress(s, state, state_color);
+       else if (state->rebase_in_progress || state->rebase_interactive_in_progress)
+               show_rebase_in_progress(s, state, state_color);
+       else if (state->cherry_pick_in_progress)
+               show_cherry_pick_in_progress(s, state, state_color);
+       else if (state->revert_in_progress)
+               show_revert_in_progress(s, state, state_color);
+       if (state->bisect_in_progress)
+               show_bisect_in_progress(s, state, state_color);
 }
 
 void wt_status_print(struct wt_status *s)
 {
        const char *branch_color = color(WT_STATUS_ONBRANCH, s);
        const char *branch_status_color = color(WT_STATUS_HEADER, s);
+       struct wt_status_state state;
+
+       memset(&state, 0, sizeof(state));
+       wt_status_get_state(&state,
+                           s->branch && !strcmp(s->branch, "HEAD"));
 
        if (s->branch) {
                const char *on_what = _("On branch ");
@@ -1082,9 +1177,19 @@ void wt_status_print(struct wt_status *s)
                if (!prefixcmp(branch_name, "refs/heads/"))
                        branch_name += 11;
                else if (!strcmp(branch_name, "HEAD")) {
-                       branch_name = "";
                        branch_status_color = color(WT_STATUS_NOBRANCH, s);
-                       on_what = _("Not currently on any branch.");
+                       if (state.detached_from) {
+                               unsigned char sha1[20];
+                               branch_name = state.detached_from;
+                               if (!get_sha1("HEAD", sha1) &&
+                                   !hashcmp(sha1, state.detached_sha1))
+                                       on_what = _("HEAD detached at ");
+                               else
+                                       on_what = _("HEAD detached from ");
+                       } else {
+                               branch_name = "";
+                               on_what = _("Not currently on any branch.");
+                       }
                }
                status_printf(s, color(WT_STATUS_HEADER, s), "");
                status_printf_more(s, branch_status_color, "%s", on_what);
@@ -1093,7 +1198,11 @@ void wt_status_print(struct wt_status *s)
                        wt_status_print_tracking(s);
        }
 
-       wt_status_print_state(s);
+       wt_status_print_state(s, &state);
+       free(state.branch);
+       free(state.onto);
+       free(state.detached_from);
+
        if (s->is_initial) {
                status_printf_ln(s, color(WT_STATUS_HEADER, s), "");
                status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit"));
@@ -1116,14 +1225,10 @@ void wt_status_print(struct wt_status *s)
                if (advice_status_u_option && 2000 < s->untracked_in_ms) {
                        status_printf_ln(s, GIT_COLOR_NORMAL, "");
                        status_printf_ln(s, GIT_COLOR_NORMAL,
-                                _("It took %.2f seconds to enumerate untracked files."
-                                  "  'status -uno'"),
-                                s->untracked_in_ms / 1000.0);
-                       status_printf_ln(s, GIT_COLOR_NORMAL,
-                                _("may speed it up, but you have to be careful not"
-                                  " to forget to add"));
-                       status_printf_ln(s, GIT_COLOR_NORMAL,
-                                _("new files yourself (see 'git help status')."));
+                                        _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n"
+                                          "may speed it up, but you have to be careful not to forget to add\n"
+                                          "new files yourself (see 'git help status')."),
+                                        s->untracked_in_ms / 1000.0);
                }
        } else if (s->commitable)
                status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"),
index 74208c06fd08b49041489c869d3c5f16804493da..4121bc208db2fbe5e4eb00af10056a9d8c0bab40 100644 (file)
@@ -80,13 +80,18 @@ struct wt_status_state {
        int rebase_interactive_in_progress;
        int cherry_pick_in_progress;
        int bisect_in_progress;
-       const char *branch;
-       const char *onto;
+       int revert_in_progress;
+       char *branch;
+       char *onto;
+       char *detached_from;
+       unsigned char detached_sha1[20];
+       unsigned char revert_head_sha1[20];
 };
 
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
+void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
 
 void wt_shortstatus_print(struct wt_status *s);
 void wt_porcelain_print(struct wt_status *s);
index 1b7012a119ad3ea7e2ebe0aad80891529d4936da..b2eb6db2c851aea7eb08b17d802155876bef211c 100644 (file)
@@ -490,7 +490,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
 
                /*
                 * Try to move back the possibly merged group of changes, to match
-                * the recorded postion in the other file.
+                * the recorded position in the other file.
                 */
                while (ixref < ix) {
                        rchg[--ixs] = 1;
index bf99787c3e4c791426311495dda9d4da81cbb571..73210cb6f3fb5d1cb90b1c5959a5a90e058ea1f2 100644 (file)
@@ -55,7 +55,7 @@ struct histindex {
        struct record {
                unsigned int ptr, cnt;
                struct record *next;
-       } **records, /* an ocurrence */
+       } **records, /* an occurrence */
          **line_map; /* map of line to record chain */
        chastore_t rcha;
        unsigned int *next_ptrs;
diff --git a/zlib.c b/zlib.c
index 2b2c0c780e3fca6217c688298053a01aad724505..bbaa0815ed55a425e458773a58a0eb9aca8453eb 100644 (file)
--- a/zlib.c
+++ b/zlib.c
@@ -168,13 +168,8 @@ void git_deflate_init(git_zstream *strm, int level)
            strm->z.msg ? strm->z.msg : "no message");
 }
 
-void git_deflate_init_gzip(git_zstream *strm, int level)
+static void do_git_deflate_init(git_zstream *strm, int level, int windowBits)
 {
-       /*
-        * Use default 15 bits, +16 is to generate gzip header/trailer
-        * instead of the zlib wrapper.
-        */
-       const int windowBits = 15 + 16;
        int status;
 
        zlib_pre_call(strm);
@@ -188,6 +183,24 @@ void git_deflate_init_gzip(git_zstream *strm, int level)
            strm->z.msg ? strm->z.msg : "no message");
 }
 
+void git_deflate_init_gzip(git_zstream *strm, int level)
+{
+       /*
+        * Use default 15 bits, +16 is to generate gzip header/trailer
+        * instead of the zlib wrapper.
+        */
+       return do_git_deflate_init(strm, level, 15 + 16);
+}
+
+void git_deflate_init_raw(git_zstream *strm, int level)
+{
+       /*
+        * Use default 15 bits, negate the value to get raw compressed
+        * data without zlib header and trailer.
+        */
+       return do_git_deflate_init(strm, level, -15);
+}
+
 int git_deflate_abort(git_zstream *strm)
 {
        int status;