Code

Merge branch 'sg/completion-updates'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 May 2011 23:47:00 +0000 (16:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 May 2011 23:47:00 +0000 (16:47 -0700)
* sg/completion-updates:
  Revert "completion: don't declare 'local words' to make zsh happy"
  git-completion: fix regression in zsh support
  completion: move private shopt shim for zsh to __git_ namespace
  completion: don't declare 'local words' to make zsh happy

177 files changed:
.gitignore
Documentation/RelNotes/1.7.5.1.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.5.2.txt [new file with mode: 0644]
Documentation/RelNotes/1.7.6.txt
Documentation/SubmittingPatches
Documentation/config.txt
Documentation/diff-config.txt
Documentation/diff-options.txt
Documentation/git-add.txt
Documentation/git-checkout.txt
Documentation/git-cherry-pick.txt
Documentation/git-fast-import.txt
Documentation/git-format-patch.txt
Documentation/git-fsck.txt
Documentation/git-imap-send.txt
Documentation/git-log.txt
Documentation/git-merge-base.txt
Documentation/git-notes.txt
Documentation/git-rebase.txt
Documentation/git-reset.txt
Documentation/git-send-email.txt
Documentation/git-stash.txt
Documentation/git-submodule.txt
Documentation/git-svn.txt
Documentation/git.txt
Documentation/merge-config.txt
Documentation/pretty-options.txt
Documentation/rev-list-options.txt
Makefile
archive.c
builtin/add.c
builtin/apply.c
builtin/blame.c
builtin/checkout.c
builtin/clone.c
builtin/commit.c
builtin/diff-tree.c
builtin/diff.c
builtin/grep.c
builtin/init-db.c
builtin/log.c
builtin/ls-files.c
builtin/ls-tree.c
builtin/merge-base.c
builtin/merge.c
builtin/notes.c
builtin/rerere.c
builtin/rev-list.c
builtin/send-pack.c
cache.h
contrib/completion/git-completion.bash
diff-lib.c
diff.c
diff.h
diffcore-rename.c
dir.c
dir.h
fast-import.c
git-add--interactive.perl
git-cvsimport.perl
git-merge-one-file.sh
git-mergetool--lib.sh
git-mergetool.sh
git-parse-remote.sh
git-pull.sh
git-rebase--am.sh [new file with mode: 0644]
git-rebase--interactive.sh [changed mode: 0755->0644]
git-rebase--merge.sh [new file with mode: 0644]
git-rebase.sh
git-send-email.perl
git-submodule.sh
git.c
gitweb/gitweb.perl
http-push.c
http-walker.c
http.c
http.h
list-objects.c
merge-recursive.c
notes.c
notes.h
pretty.c
remote-curl.c
rerere.c
rerere.h
revision.c
revision.h
run-command.c
setup.c
sha1_file.c
shell.c
strbuf.h
t/README
t/annotate-tests.sh
t/lib-httpd.sh
t/t0001-init.sh
t/t0061-run-command.sh
t/t1020-subdirectory.sh
t/t1200-tutorial.sh
t/t1400-update-ref.sh
t/t1501-worktree.sh
t/t1506-rev-parse-diagnosis.sh
t/t2011-checkout-invalid-head.sh
t/t2019-checkout-ambiguous-ref.sh
t/t2020-checkout-detach.sh
t/t2200-add-update.sh
t/t2201-add-update-typechange.sh
t/t2204-add-ignored.sh
t/t3030-merge-recursive.sh
t/t3102-ls-tree-wildcards.sh [new file with mode: 0755]
t/t3200-branch.sh
t/t3203-branch-output.sh
t/t3301-notes.sh
t/t3400-rebase.sh
t/t3403-rebase-skip.sh
t/t3407-rebase-abort.sh
t/t3409-rebase-preserve-merges.sh
t/t3418-rebase-continue.sh
t/t3501-revert-cherry-pick.sh
t/t3507-cherry-pick-conflict.sh
t/t3600-rm.sh
t/t3700-add.sh
t/t3701-add-interactive.sh
t/t4001-diff-rename.sh
t/t4002-diff-basic.sh
t/t4013-diff-various.sh
t/t4013/diff.diff_--dirstat-by-file_initial_rearrange [new file with mode: 0644]
t/t4013/diff.diff_--dirstat_initial_rearrange [new file with mode: 0644]
t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^
t/t4013/diff.log_--decorate=full_--all
t/t4013/diff.log_--decorate_--all
t/t4014-format-patch.sh
t/t4020-diff-external.sh
t/t4022-diff-rewrite.sh
t/t4027-diff-submodule.sh
t/t4046-diff-unmerged.sh [new file with mode: 0755]
t/t4047-diff-dirstat.sh [new file with mode: 0755]
t/t5400-send-pack.sh
t/t5526-fetch-submodules.sh
t/t5541-http-push.sh
t/t5601-clone.sh
t/t6007-rev-list-cherry-pick-file.sh
t/t6010-merge-base.sh
t/t6018-rev-list-glob.sh
t/t6022-merge-rename.sh
t/t6040-tracking-info.sh
t/t6060-merge-index.sh [new file with mode: 0755]
t/t6120-describe.sh
t/t7004-tag.sh
t/t7011-skip-worktree-reading.sh
t/t7012-skip-worktree-writing.sh
t/t7060-wtstatus.sh
t/t7102-reset.sh
t/t7110-reset-merge.sh
t/t7201-co.sh
t/t7406-submodule-update.sh
t/t7500-commit.sh
t/t7500/add-whitespaced-content [new file with mode: 0755]
t/t7501-commit.sh
t/t7502-commit.sh
t/t7506-status-submodule.sh
t/t7508-status.sh
t/t7600-merge.sh
t/t7607-merge-overwrite.sh
t/t7610-mergetool.sh
t/t7611-merge-abort.sh
t/t7811-grep-open.sh
t/t8002-blame.sh
t/t9500-gitweb-standalone-no-errors.sh
t/t9502-gitweb-standalone-parse-output.sh
t/test-lib.sh
test-run-command.c
tree-diff.c
tree-walk.c
tree.c
tree.h
xdiff-interface.c

index 2cf3ca5808b51be3921a0f25b5871f806ce447e1..711fce7e08beea95d1870047452131e3bf5278dd 100644 (file)
 /git-quiltimport
 /git-read-tree
 /git-rebase
+/git-rebase--am
 /git-rebase--interactive
+/git-rebase--merge
 /git-receive-pack
 /git-reflog
 /git-relink
diff --git a/Documentation/RelNotes/1.7.5.1.txt b/Documentation/RelNotes/1.7.5.1.txt
new file mode 100644 (file)
index 0000000..c6ebd76
--- /dev/null
@@ -0,0 +1,47 @@
+Git v1.7.5.1 Release Notes
+==========================
+
+Fixes since v1.7.5
+------------------
+
+ * When an object "$tree:$path" does not exist, if $path does exist in the
+   subtree of $tree that corresponds to the subdirectory the user is in,
+   git now suggests using "$tree:./$path" in addition to the advice to use
+   the full path from the root of the working tree.
+
+ * The "--date=relative" output format used to say "X years, 12 months"
+   when it should have said "X+1 years".
+
+ * The smart-HTTP transfer was broken in 1.7.5 when the client needs
+   to issue a small POST (which uses content-length) and then a large
+   POST (which uses chunked) back to back.
+
+ * "git clean" used to fail on an empty directory that is not readable,
+   even though rmdir(2) could remove such a directory.  Now we attempt it
+   as the last resort.
+
+ * The "--dirstat" option of "diff" family of commands used to totally
+   ignore a change that only rearranged lines within a file.  Such a
+   change now counts as at least a minimum but non zero change.
+
+ * The "--dirstat" option of "diff" family of commands used to use the
+   pathname in the original, instead of the pathname in the result,
+   when renames are involved.
+
+ * "git pack-object" did not take core.bigfilethreashold into account
+   (unlike fast-import); now it does.
+
+ * "git reflog" ignored options like "--format=.." on the command line.
+
+ * "git stash apply" used to refuse to work if there was any change in
+   the working tree, even when the change did not overlap with the change
+   the stash recorded.
+
+ * "git stash apply @{99999}" was not diagnosed as an error, even when you
+   did not have that many stash entries.
+
+ * An error message from "git send-email" to diagnose a broken SMTP
+   connection configuration lacked a space between "hello=<smtp-domain>"
+   and "port=<smtp-server-port>".
+
+And other minor fixes and documentation updates.
diff --git a/Documentation/RelNotes/1.7.5.2.txt b/Documentation/RelNotes/1.7.5.2.txt
new file mode 100644 (file)
index 0000000..951eb7c
--- /dev/null
@@ -0,0 +1,57 @@
+Git v1.7.5.2 Release Notes
+==========================
+
+The release notes to 1.7.5.1 forgot to mention:
+
+ * "git stash -p --no-keep-index" and "git stash --no-keep-index -p" now
+   mean the same thing.
+
+ * "git upload-pack" (hence "git push" over git native protocol) had a
+   subtle race condition that could lead to a deadlock.
+
+Fixes since v1.7.5.1
+--------------------
+
+ * "git add -p" did not work correctly when a hunk is split and then
+   one of them was given to the editor.
+
+ * "git add -u" did not resolve a conflict where our history deleted and
+   their history modified the same file, and the working tree resolved to
+   keep a file.
+
+ * "git cvsimport" did not know that CVSNT stores its password file in a
+   location different from the traditional CVS.
+
+ * "git diff-files" did not show the mode information from the working
+   tree side of an unmerged path correctly.
+
+ * "git diff -M --cached" used to use unmerged path as a possible rename
+   source candidate, which made no sense.
+
+ * The option name parser in "git fast-import" used prefix matches for
+   some options where it shouldn't, and accepted non-existent options,
+   e.g. "--relative-marksmith" or "--forceps".
+
+ * "git format-patch" did not quote RFC822 special characters in the
+   email address (e.g From: Junio C. Hamano <jch@example.com>, not
+   From: "Junio C. Hamano" <jch@example.com>).
+
+ * "git format-patch" when run with "--quiet" option used to produce a
+   nonsense result that consists of alternating empty output.
+
+ * In "git merge", per-branch branch.<name>.mergeoptions configuration
+   variables did not override the fallback default merge.<option>
+   configuration variables such as merge.ff, merge.log, etc.
+
+ * "git merge-one-file" did not honor GIT_WORK_TREE settings when
+   handling a "both sides added, differently" conflict.
+
+ * "git mergetool" did not handle conflicted submoudules gracefully.
+
+ * "git-p4" (in contrib) used a wrong base image while merge a file that
+   was added on both branches differently.
+
+ * "git rebase -i -p" failed to preserve the history when there is a
+   redundant merge created with the --no-ff option.
+
+And other minor fixes and documentation updates.
index 3e08bd917e5285c30cf1666dca88222f4062bd61..f644378d2155d767749d80b6bd702e67e70cafc0 100644 (file)
@@ -1,4 +1,4 @@
-Git v1.7.5 Release Notes (draft)
+Git v1.7.6 Release Notes (draft)
 ========================
 
 Updates since v1.7.5
@@ -6,36 +6,59 @@ Updates since v1.7.5
 
  * Various git-svn updates.
 
- * When an object "$tree:$path" does not exist, if $path does exist in the
-   subtree of $tree that corresponds to the subdirectory the user is in,
-   git now suggests using "$tree:./$path" in addition to the advice to use
-   the full path from the root of the working tree.
+ * Updates the way content tags are handled in gitweb.
+
+ * Clean-up of the C part of i18n (but not l10n---please wait)
+   continues.
+
+ * Processes spawned by "[alias] <name> = !process" in the configuration
+   can inspect GIT_PREFIX environment variable to learn where in the
+   working tree the original command was invoked.
 
  * "git blame" learned "--abbrev[=<n>]" option to control the minimum
    number of hexdigits shown for commit object names.
 
- * "git clean" used to fail on an empty directory that is not readable,
-   even though rmdir(2) could remove such a directory.  Now we attempt it
-   as the last resort.
+ * "git diff -C -C" used to disable the rename detection entirely when
+   there are too many copy candidate paths in the tree; now it falls
+   back to "-C" when doing so would keep the copy candidate paths
+   under the rename detection limit.
+
+ * "git diff" and its family of commands learned --dirstat=0 to show
+   directories that contribute less than 0.1% of changes.
+
+ * "git diff" and its family of commands learned --dirstat=lines mode to
+   assess damage to the directory based on number of lines in the patch
+   output, not based on the similarity numbers.
 
  * "git format-patch" learned "--quiet" option to suppress the output of
    the names of generated files.
 
+ * "git format-patch" quotes people's names when it has RFC822 special
+   characters in it, e.g. "Junio C. Hamano" <jch@example.com>.  Earlier
+   it was up to the user to do this when using its output.
+
+ * "git log" and friends learned a new "--notes" option to replace the
+   "--show-notes" option.  Unlike "--show-notes", "--notes=<ref>" does
+   not imply showing the default notes.
+
  * "git merge" learned "-" as a short-hand for "the previous branch", just
    like the way "git checkout -" works.
 
- * "git pack-object" now takes core.bigfilethreashold into account, just
-   like fast-imoprt does.
+ * "git rebase" that does not specify on top of which branch to rebase
+   the current branch now uses @{upstream} of the current branch.
 
- * "git reflog" allows options like "--format=.." to be given.
+ * "git rev-list --count" used with "--cherry-mark" counts the cherry-picked
+   commits separately, producing more a useful output.
 
- * "git stash apply" can now apply to a working tree with changes as long
-   as there is no overlapping change as the stash being applied.
+ * "git submodule update" learned "--force" option to get rid of local
+   changes in submodules and replace them with the up-to-date version.
 
- * "git stash apply @{99999}" now is diagnosed as an error, unless you
-   really have that many stash entries.
+ * Compressed tarball gitweb generates is made without the timestamp of
+   the tarball generation; snapshot from the same tree should result in
+   a same tarball.
 
-Also contains various documentation updates.
+Also contains various documentation updates and minor miscellaneous
+changes.
 
 
 Fixes since v1.7.5
@@ -44,36 +67,29 @@ Fixes since v1.7.5
 Unless otherwise noted, all the fixes in 1.7.5.X maintenance track are
 included in this release.
 
- * The "--date=relative" output format used to say "X years, 12 months"
-   when it should have said "X+1 years".
-   (merge mg/x-years-12-months later)
+ * "git add -p" did not work correctly when a hunk is split and then
+   one of them was given to the editor.
+   (merge jc/maint-add-p-overlapping-hunks later)
+
+ * "git add -u" did not resolve a conflict where our history deleted and
+   their history modified the same file, and the working tree resolved to
+   keep a file.
+   (merge jc/fix-add-u-unmerged later)
 
  * "git config" used to choke with an insanely long line.
    (merge ef/maint-strbuf-init later)
 
- * The "--dirstat" option of "diff" family of commands used to totally
-   ignore a change that only rearranged lines within a file.  Such a
-   change now counts as at least a minimum but non zero change.
-
- * The "--dirstat" option of "diff" family of commands used to use the
-   pathname in the original, instead of the pathname in the result,
-   when renames are involved.
-   (merge jh/dirstat for the above two later)
-
- * "git format-patch" when run with "--quiet" option used to produce a
-   nonsense result that consists of alternating empty output.
-   (merge early part of cn/format-patch-quiet later)
-
- * "git stash -p --no-keep-index" and "git stash --no-keep-index -p" now
-   mean the same thing.
-   (merge dm/stash-k-i-p later)
+ * In "git merge", per-branch branch.<name>.mergeoptions configuration
+   variables did not override the fallback default merge.<option>
+   configuration variables such as merge.ff, merge.log, etc.
+   (merge jc/maint-branch-mergeoptions later)
 
- * "git upload-pack" (hence "git push" over git native protocol) had a
-   subtle race condition that could lead to a deadlock.
-   (merge jk/maint-upload-pack-shallow later)
+ * "git send-pack" (hence "git push") over smalt-HTTP protocol could
+   deadlock when the client side pack-object died early.
+   (merge js/maint-send-pack-stateless-rpc-deadlock-fix later)
 
 ---
 exec >/var/tmp/1
 echo O=$(git describe master)
-O=v1.7.5
+O=v1.7.5.1-288-ge4ae6ef
 git shortlog --no-merges ^maint ^$O master
index c6a503291205f0b8047a213d1ebeb6a509ff6fa8..938eccf2a5ac9dd629be1bc6bb53a59723c99083 100644 (file)
@@ -344,50 +344,20 @@ MUA specific hints
 
 Some of patches I receive or pick up from the list share common
 patterns of breakage.  Please make sure your MUA is set up
-properly not to corrupt whitespaces.  Here are two common ones
-I have seen:
+properly not to corrupt whitespaces.
 
-* Empty context lines that do not have _any_ whitespace.
+See the DISCUSSION section of git-format-patch(1) for hints on
+checking your patch by mailing it to yourself and applying with
+git-am(1).
 
-* Non empty context lines that have one extra whitespace at the
-  beginning.
-
-One test you could do yourself if your MUA is set up correctly is:
-
-* Send the patch to yourself, exactly the way you would, except
-  To: and Cc: lines, which would not contain the list and
-  maintainer address.
-
-* Save that patch to a file in UNIX mailbox format.  Call it say
-  a.patch.
-
-* Try to apply to the tip of the "master" branch from the
-  git.git public repository:
-
-    $ git fetch http://kernel.org/pub/scm/git/git.git master:test-apply
-    $ git checkout test-apply
-    $ git reset --hard
-    $ git am a.patch
-
-If it does not apply correctly, there can be various reasons.
-
-* Your patch itself does not apply cleanly.  That is _bad_ but
-  does not have much to do with your MUA.  Please rebase the
-  patch appropriately.
-
-* Your MUA corrupted your patch; "am" would complain that
-  the patch does not apply.  Look at .git/rebase-apply/ subdirectory and
-  see what 'patch' file contains and check for the common
-  corruption patterns mentioned above.
-
-* While you are at it, check what are in 'info' and
-  'final-commit' files as well.  If what is in 'final-commit' is
-  not exactly what you would want to see in the commit log
-  message, it is very likely that your maintainer would end up
-  hand editing the log message when he applies your patch.
-  Things like "Hi, this is my first patch.\n", if you really
-  want to put in the patch e-mail, should come after the
-  three-dash line that signals the end of the commit message.
+While you are at it, check the resulting commit log message from
+a trial run of applying the patch.  If what is in the resulting
+commit is not exactly what you would want to see, it is very
+likely that your maintainer would end up hand editing the log
+message when he applies your patch.  Things like "Hi, this is my
+first patch.\n", if you really want to put in the patch e-mail,
+should come after the three-dash line that signals the end of the
+commit message.
 
 
 Pine
@@ -443,89 +413,10 @@ that or Gentoo did it.) So you need to set the
 it.
 
 
-Thunderbird
------------
-
-(A Large Angry SCM)
-
-By default, Thunderbird will both wrap emails as well as flag them as
-being 'format=flowed', both of which will make the resulting email unusable
-by git.
-
-Here are some hints on how to successfully submit patches inline using
-Thunderbird.
-
-There are two different approaches.  One approach is to configure
-Thunderbird to not mangle patches.  The second approach is to use
-an external editor to keep Thunderbird from mangling the patches.
-
-Approach #1 (configuration):
-
-This recipe is current as of Thunderbird 2.0.0.19.  Three steps:
-  1.  Configure your mail server composition as plain text
-      Edit...Account Settings...Composition & Addressing,
-        uncheck 'Compose Messages in HTML'.
-  2.  Configure your general composition window to not wrap
-      Edit..Preferences..Composition, wrap plain text messages at 0
-  3.  Disable the use of format=flowed
-      Edit..Preferences..Advanced..Config Editor.  Search for:
-        mailnews.send_plaintext_flowed
-      toggle it to make sure it is set to 'false'.
-
-After that is done, you should be able to compose email as you
-otherwise would (cut + paste, git-format-patch | git-imap-send, etc),
-and the patches should not be mangled.
-
-Approach #2 (external editor):
-
-This recipe appears to work with the current [*1*] Thunderbird from Suse.
-
-The following Thunderbird extensions are needed:
-       AboutConfig 0.5
-               http://aboutconfig.mozdev.org/
-       External Editor 0.7.2
-               http://globs.org/articles.php?lng=en&pg=8
-
-1) Prepare the patch as a text file using your method of choice.
-
-2) Before opening a compose window, use Edit->Account Settings to
-uncheck the "Compose messages in HTML format" setting in the
-"Composition & Addressing" panel of the account to be used to send the
-patch. [*2*]
-
-3) In the main Thunderbird window, _before_ you open the compose window
-for the patch, use Tools->about:config to set the following to the
-indicated values:
-       mailnews.send_plaintext_flowed  => false
-       mailnews.wraplength             => 0
-
-4) Open a compose window and click the external editor icon.
-
-5) In the external editor window, read in the patch file and exit the
-editor normally.
-
-6) Back in the compose window: Add whatever other text you wish to the
-message, complete the addressing and subject fields, and press send.
-
-7) Optionally, undo the about:config/account settings changes made in
-steps 2 & 3.
+Thunderbird, KMail, GMail
+-------------------------
 
-
-[Footnotes]
-*1* Version 1.0 (20041207) from the MozillaThunderbird-1.0-5 rpm of Suse
-9.3 professional updates.
-
-*2* It may be possible to do this with about:config and the following
-settings but I haven't tried, yet.
-       mail.html_compose                       => false
-       mail.identity.default.compose_html      => false
-       mail.identity.id?.compose_html          => false
-
-(Lukas Sandström)
-
-There is a script in contrib/thunderbird-patch-inline which can help
-you include patches with Thunderbird in an easy way. To use it, do the
-steps above and then use the script as the external editor.
+See the MUA-SPECIFIC HINTS section of git-format-patch(1).
 
 Gnus
 ----
@@ -540,71 +431,3 @@ characters (most notably in people's names), and also
 whitespaces (fatal in patches).  Running 'C-u g' to display the
 message in raw form before using '|' to run the pipe can work
 this problem around.
-
-
-KMail
------
-
-This should help you to submit patches inline using KMail.
-
-1) Prepare the patch as a text file.
-
-2) Click on New Mail.
-
-3) Go under "Options" in the Composer window and be sure that
-"Word wrap" is not set.
-
-4) Use Message -> Insert file... and insert the patch.
-
-5) Back in the compose window: add whatever other text you wish to the
-message, complete the addressing and subject fields, and press send.
-
-
-Gmail
------
-
-GMail does not appear to have any way to turn off line wrapping in the web
-interface, so this will mangle any emails that you send.  You can however
-use "git send-email" and send your patches through the GMail SMTP server, or
-use any IMAP email client to connect to the google IMAP server and forward
-the emails through that.
-
-To use "git send-email" and send your patches through the GMail SMTP server,
-edit ~/.gitconfig to specify your account settings:
-
-[sendemail]
-       smtpencryption = tls
-       smtpserver = smtp.gmail.com
-       smtpuser = user@gmail.com
-       smtppass = p4ssw0rd
-       smtpserverport = 587
-
-Once your commits are ready to be sent to the mailing list, run the
-following commands:
-
-  $ git format-patch --cover-letter -M origin/master -o outgoing/
-  $ edit outgoing/0000-*
-  $ git send-email outgoing/*
-
-To submit using the IMAP interface, first, edit your ~/.gitconfig to specify your
-account settings:
-
-[imap]
-       folder = "[Gmail]/Drafts"
-       host = imaps://imap.gmail.com
-       user = user@gmail.com
-       pass = p4ssw0rd
-       port = 993
-       sslverify = false
-
-You might need to instead use: folder = "[Google Mail]/Drafts" if you get an error
-that the "Folder doesn't exist".
-
-Once your commits are ready to be sent to the mailing list, run the
-following commands:
-
-  $ git format-patch --cover-letter -M --stdout origin/master | git imap-send
-
-Just make sure to disable line wrapping in the email client (GMail web
-interface will line wrap no matter what, so you need to use a real
-IMAP client).
index ce17805509801d812511418a026e4733c05a8968..285c7f73ca1b7a2a63b549a6cacec4cc77ad5ad7 100644 (file)
@@ -587,6 +587,8 @@ it will be treated as a shell command.  For example, defining
 "gitk --all --not ORIG_HEAD".  Note that shell commands will be
 executed from the top-level directory of a repository, which may
 not necessarily be the current directory.
+'GIT_PREFIX' is set as returned by running 'git rev-parse --show-prefix'
+from the original current directory. See linkgit:git-rev-parse[1].
 
 am.keepcr::
        If true, git-am will call git-mailsplit for patches in mbox format
@@ -641,7 +643,7 @@ branch.<name>.remote::
 
 branch.<name>.merge::
        Defines, together with branch.<name>.remote, the upstream branch
-       for the given branch. It tells 'git fetch'/'git pull' which
+       for the given branch. It tells 'git fetch'/'git pull'/'git rebase' which
        branch to merge and can also affect 'git push' (see push.default).
        When in branch <name>, it tells 'git fetch' the default
        refspec to be marked for merging in FETCH_HEAD. The value is
@@ -706,9 +708,16 @@ second is the background.  The position of the attribute, if any,
 doesn't matter.
 
 color.diff::
-       When set to `always`, always use colors in patch.
-       When false (or `never`), never.  When set to `true` or `auto`, use
-       colors only when the output is to the terminal. Defaults to false.
+       Whether to use ANSI escape sequences to add color to patches.
+       If this is set to `always`, linkgit:git-diff[1],
+       linkgit:git-log[1], and linkgit:git-show[1] will use color
+       for all patches.  If it is set to `true` or `auto`, those
+       commands will only use color when output is to the terminal.
+       Defaults to false.
++
+This does not affect linkgit:git-format-patch[1] nor the
+'git-diff-{asterisk}' plumbing commands.  Can be overridden on the
+command line with the `--color[=<when>]` option.
 
 color.diff.<slot>::
        Use customized color for diff colorization.  `<slot>` specifies
@@ -794,11 +803,15 @@ color.status.<slot>::
        color.branch.<slot>.
 
 color.ui::
-       When set to `always`, always use colors in all git commands which
-       are capable of colored output. When false (or `never`), never. When
-       set to `true` or `auto`, use colors only when the output is to the
-       terminal. When more specific variables of color.* are set, they always
-       take precedence over this setting. Defaults to false.
+       This variable determines the default value for variables such
+       as `color.diff` and `color.grep` that control the use of color
+       per command family. Its scope will expand as more commands learn
+       configuration to set a default for the `--color` option.  Set it
+       to `always` if you want all output not intended for machine
+       consumption to use color, to `true` or `auto` if you want such
+       output to use color when written to the terminal, or to `false` or
+       `never` if you prefer git commands not to use color unless enabled
+       explicitly with some other configuration or the `--color` option.
 
 commit.status::
        A boolean to enable/disable inclusion of status information in the
@@ -1296,8 +1309,9 @@ instaweb.port::
 interactive.singlekey::
        In interactive commands, allow the user to provide one-letter
        input with a single key (i.e., without hitting enter).
-       Currently this is used only by the `\--patch` mode of
-       linkgit:git-add[1].  Note that this setting is silently
+       Currently this is used by the `\--patch` mode of
+       linkgit:git-add[1], linkgit:git-reset[1], linkgit:git-stash[1] and
+       linkgit:git-checkout[1]. Note that this setting is silently
        ignored if portable keystroke input is not available.
 
 log.date::
index 2b1605f5c8f07b96f8e8c27a65717fca6046d613..1aed79e7dc451f02e1b15dd0644c89fee6071703 100644 (file)
@@ -8,6 +8,50 @@ diff.autorefreshindex::
        affects only 'git diff' Porcelain, and not lower level
        'diff' commands such as 'git diff-files'.
 
+diff.dirstat::
+       A comma separated list of `--dirstat` parameters specifying the
+       default behavior of the `--dirstat` option to linkgit:git-diff[1]`
+       and friends. The defaults can be overridden on the command line
+       (using `--dirstat=<param1,param2,...>`). The fallback defaults
+       (when not changed by `diff.dirstat`) are `changes,noncumulative,3`.
+       The following parameters are available:
++
+--
+`changes`;;
+       Compute the dirstat numbers by counting the lines that have been
+       removed from the source, or added to the destination. This ignores
+       the amount of pure code movements within a file.  In other words,
+       rearranging lines in a file is not counted as much as other changes.
+       This is the default behavior when no parameter is given.
+`lines`;;
+       Compute the dirstat numbers by doing the regular line-based diff
+       analysis, and summing the removed/added line counts. (For binary
+       files, count 64-byte chunks instead, since binary files have no
+       natural concept of lines). This is a more expensive `--dirstat`
+       behavior than the `changes` behavior, but it does count rearranged
+       lines within a file as much as other changes. The resulting output
+       is consistent with what you get from the other `--*stat` options.
+`files`;;
+       Compute the dirstat numbers by counting the number of files changed.
+       Each changed file counts equally in the dirstat analysis. This is
+       the computationally cheapest `--dirstat` behavior, since it does
+       not have to look at the file contents at all.
+`cumulative`;;
+       Count changes in a child directory for the parent directory as well.
+       Note that when using `cumulative`, the sum of the percentages
+       reported may exceed 100%. The default (non-cumulative) behavior can
+       be specified with the `noncumulative` parameter.
+<limit>;;
+       An integer parameter specifies a cut-off percent (3% by default).
+       Directories contributing less than this percentage of the changes
+       are not shown in the output.
+--
++
+Example: The following will count changed files, while ignoring
+directories with less than 10% of the total amount of changed files,
+and accumulating child directory counts in the parent directories:
+`files,10,cumulative`.
+
 diff.external::
        If this config variable is set, diff generation is not
        performed using the internal diff machinery, but using the
index c93124be79809e36d9a29fd69ce77cd7f22413e1..c7ed94635786789baca1de41d482cd6334d1181a 100644 (file)
@@ -66,15 +66,49 @@ endif::git-format-patch[]
        number of modified files, as well as number of added and deleted
        lines.
 
---dirstat[=<limit>]::
-       Output the distribution of relative amount of changes (number of lines added or
-       removed) for each sub-directory. Directories with changes below
-       a cut-off percent (3% by default) are not shown. The cut-off percent
-       can be set with `--dirstat=<limit>`. Changes in a child directory are not
-       counted for the parent directory, unless `--cumulative` is used.
-
---dirstat-by-file[=<limit>]::
-       Same as `--dirstat`, but counts changed files instead of lines.
+--dirstat[=<param1,param2,...>]::
+       Output the distribution of relative amount of changes for each
+       sub-directory. The behavior of `--dirstat` can be customized by
+       passing it a comma separated list of parameters.
+       The defaults are controlled by the `diff.dirstat` configuration
+       variable (see linkgit:git-config[1]).
+       The following parameters are available:
++
+--
+`changes`;;
+       Compute the dirstat numbers by counting the lines that have been
+       removed from the source, or added to the destination. This ignores
+       the amount of pure code movements within a file.  In other words,
+       rearranging lines in a file is not counted as much as other changes.
+       This is the default behavior when no parameter is given.
+`lines`;;
+       Compute the dirstat numbers by doing the regular line-based diff
+       analysis, and summing the removed/added line counts. (For binary
+       files, count 64-byte chunks instead, since binary files have no
+       natural concept of lines). This is a more expensive `--dirstat`
+       behavior than the `changes` behavior, but it does count rearranged
+       lines within a file as much as other changes. The resulting output
+       is consistent with what you get from the other `--*stat` options.
+`files`;;
+       Compute the dirstat numbers by counting the number of files changed.
+       Each changed file counts equally in the dirstat analysis. This is
+       the computationally cheapest `--dirstat` behavior, since it does
+       not have to look at the file contents at all.
+`cumulative`;;
+       Count changes in a child directory for the parent directory as well.
+       Note that when using `cumulative`, the sum of the percentages
+       reported may exceed 100%. The default (non-cumulative) behavior can
+       be specified with the `noncumulative` parameter.
+<limit>;;
+       An integer parameter specifies a cut-off percent (3% by default).
+       Directories contributing less than this percentage of the changes
+       are not shown in the output.
+--
++
+Example: The following will count changed files, while ignoring
+directories with less than 10% of the total amount of changed files,
+and accumulating child directory counts in the parent directories:
+`--dirstat=files,10,cumulative`.
 
 --summary::
        Output a condensed summary of extended header information
@@ -120,12 +154,19 @@ any of those replacements occurred.
 
 --color[=<when>]::
        Show colored diff.
-       The value must be always (the default), never, or auto.
+       The value must be `always` (the default for `<when>`), `never`, or `auto`.
+       The default value is `never`.
+ifdef::git-diff[]
+       It can be changed by the `color.ui` and `color.diff`
+       configuration settings.
+endif::git-diff[]
 
 --no-color::
-       Turn off colored diff, even when the configuration file
-       gives the default to color output.
-       Same as `--color=never`.
+       Turn off colored diff.
+ifdef::git-diff[]
+       This can be used to override configuration settings.
+endif::git-diff[]
+       It is the same as `--color=never`.
 
 --word-diff[=<mode>]::
        Show a word diff, using the <mode> to delimit changed words.
@@ -239,7 +280,7 @@ ifdef::git-log[]
        For following files across renames while traversing history, see
        `--follow`.
 endif::git-log[]
-       If `n` is specified, it is a is a threshold on the similarity
+       If `n` is specified, it is a threshold on the similarity
        index (i.e. amount of addition/deletions compared to the
        file's size). For example, `-M90%` means git should consider a
        delete/add pair to be a rename if more than 90% of the file
@@ -259,6 +300,19 @@ endif::git-log[]
        projects, so use it with caution.  Giving more than one
        `-C` option has the same effect.
 
+-D::
+--irreversible-delete::
+       Omit the preimage for deletes, i.e. print only the header but not
+       the diff between the preimage and `/dev/null`. The resulting patch
+       is not meant to be applied with `patch` nor `git apply`; this is
+       solely for people who want to just concentrate on reviewing the
+       text after the change. In addition, the output obviously lack
+       enough information to apply such a patch in reverse, even manually,
+       hence the name of the option.
++
+When used together with `-B`, omit also the preimage in the deletion part
+of a delete/create pair.
+
 -l<num>::
        The `-M` and `-C` options require O(n^2) processing time where n
        is the number of potential rename/copy targets.  This
index 7eebbefe7b6f665a8f6a5003eb37d7bcb3c196bd..9c1d3957223355e00eea917d4a7dff6d50343f32 100644 (file)
@@ -134,6 +134,8 @@ subdirectories.
        If some files could not be added because of errors indexing
        them, do not abort the operation, but continue adding the
        others. The command shall still exit with non-zero status.
+       The configuration variable `add.ignoreErrors` can be set to
+       true to make this the default behaviour.
 
 --ignore-missing::
        This option can only be used together with --dry-run. By using
@@ -272,7 +274,8 @@ patch::
   This lets you choose one path out of a 'status' like selection.
   After choosing the path, it presents the diff between the index
   and the working tree file and asks you if you want to stage
-  the change of each hunk.  You can say:
+  the change of each hunk.  You can select one of the following
+  options and type return:
 
        y - stage this hunk
        n - do not stage this hunk
@@ -291,6 +294,9 @@ patch::
 +
 After deciding the fate for all hunks, if there is any hunk
 that was chosen, the index is updated with the selected hunks.
++
+You can omit having to type return here, by setting the configuration
+variable `interactive.singlekey` to `true`.
 
 diff::
 
index 1063f69023f97357c747cf73f8a4bcc9d9a59c4b..c0a96e6c1eede3b511689f35e9130a26ea81e003 100644 (file)
@@ -12,7 +12,7 @@ SYNOPSIS
 'git checkout' [-q] [-f] [-m] [--detach] [<commit>]
 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
 'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
-'git checkout' --patch [<tree-ish>] [--] [<paths>...]
+'git checkout' [-p|--patch] [<tree-ish>] [--] [<paths>...]
 
 DESCRIPTION
 -----------
@@ -45,7 +45,7 @@ $ git checkout <branch>
 that is to say, the branch is not reset/created unless "git checkout" is
 successful.
 
-'git checkout' [--patch] [<tree-ish>] [--] <pathspec>...::
+'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
 
        When <paths> or `--patch` are given, 'git checkout' does *not*
        switch branches.  It updates the named paths in the working tree
@@ -183,7 +183,8 @@ the conflicted merge in the specified paths.
        working tree (and if a <tree-ish> was specified, the index).
 +
 This means that you can use `git checkout -p` to selectively discard
-edits from your current working tree.
+edits from your current working tree. See the ``Interactive Mode''
+section of linkgit:git-add[1] to learn how to operate the `\--patch` mode.
 
 <branch>::
        Branch to checkout; if it refers to a branch (i.e., a name that,
index 01db83039fc36aa4bc08eab730db48ec513ec583..9d8fe0d26145ae45f566d3e8d4253c396630b41f 100644 (file)
@@ -51,9 +51,10 @@ OPTIONS
        message prior to committing.
 
 -x::
-       When recording the commit, append to the original commit
-       message a note that indicates which commit this change
-       was cherry-picked from.  Append the note only for cherry
+       When recording the commit, append a line that says
+       "(cherry picked from commit ...)" to the original commit
+       message in order to indicate which commit this change was
+       cherry-picked from.  This is done only for cherry
        picks without conflicts.  Do not use this option if
        you are cherry-picking from your private branch because
        the information is useless to the recipient.  If on the
index 2c2ea12c5c4e19907674609c228997062d305983..249249aac7b2b9def824794b2bf71e2c7fe497ce 100644 (file)
@@ -83,7 +83,7 @@ OPTIONS
        skips the file if it does not exist.
 
 --relative-marks::
-       After specifying --relative-marks= the paths specified
+       After specifying --relative-marks the paths specified
        with --import-marks= and --export-marks= are relative
        to an internal directory in the current repository.
        In git-fast-import this means that the paths are relative
@@ -93,7 +93,7 @@ OPTIONS
 --no-relative-marks::
        Negates a previous --relative-marks. Allows for combining
        relative and non-relative marks by interweaving
-       --(no-)-relative-marks= with the --(import|export)-marks=
+       --(no-)-relative-marks with the --(import|export)-marks=
        options.
 
 --cat-blob-fd=<fd>::
index f4e959d662fab9ca36753be59d547cf206129da0..d13c9b23f7bce6379f638e5bf86b30c95abef30e 100644 (file)
@@ -232,6 +232,233 @@ attachments, and sign off patches with configuration variables.
 ------------
 
 
+DISCUSSION
+----------
+
+The patch produced by 'git format-patch' is in UNIX mailbox format,
+with a fixed "magic" time stamp to indicate that the file is output
+from format-patch rather than a real mailbox, like so:
+
+------------
+From 8f72bad1baf19a53459661343e21d6491c3908d3 Mon Sep 17 00:00:00 2001
+From: Tony Luck <tony.luck@intel.com>
+Date: Tue, 13 Jul 2010 11:42:54 -0700
+Subject: [PATCH] =?UTF-8?q?[IA64]=20Put=20ia64=20config=20files=20on=20the=20?=
+ =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20diet?=
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+arch/arm config files were slimmed down using a python script
+(See commit c2330e286f68f1c408b4aa6515ba49d57f05beae comment)
+
+Do the same for ia64 so we can have sleek & trim looking
+...
+------------
+
+Typically it will be placed in a MUA's drafts folder, edited to add
+timely commentary that should not go in the changelog after the three
+dashes, and then sent as a message whose body, in our example, starts
+with "arch/arm config files were...".  On the receiving end, readers
+can save interesting patches in a UNIX mailbox and apply them with
+linkgit:git-am[1].
+
+When a patch is part of an ongoing discussion, the patch generated by
+'git format-patch' can be tweaked to take advantage of the 'git am
+--scissors' feature.  After your response to the discussion comes a
+line that consists solely of "`-- >8 --`" (scissors and perforation),
+followed by the patch with unnecessary header fields removed:
+
+------------
+...
+> So we should do such-and-such.
+
+Makes sense to me.  How about this patch?
+
+-- >8 --
+Subject: [IA64] Put ia64 config files on the Uwe Kleine-König diet
+
+arch/arm config files were slimmed down using a python script
+...
+------------
+
+When sending a patch this way, most often you are sending your own
+patch, so in addition to the "`From $SHA1 $magic_timestamp`" marker you
+should omit `From:` and `Date:` lines from the patch file.  The patch
+title is likely to be different from the subject of the discussion the
+patch is in response to, so it is likely that you would want to keep
+the Subject: line, like the example above.
+
+Checking for patch corruption
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Many mailers if not set up properly will corrupt whitespace.  Here are
+two common types of corruption:
+
+* Empty context lines that do not have _any_ whitespace.
+
+* Non-empty context lines that have one extra whitespace at the
+  beginning.
+
+One way to test if your MUA is set up correctly is:
+
+* Send the patch to yourself, exactly the way you would, except
+  with To: and Cc: lines that do not contain the list and
+  maintainer address.
+
+* Save that patch to a file in UNIX mailbox format.  Call it a.patch,
+  say.
+
+* Apply it:
+
+    $ git fetch <project> master:test-apply
+    $ git checkout test-apply
+    $ git reset --hard
+    $ git am a.patch
+
+If it does not apply correctly, there can be various reasons.
+
+* The patch itself does not apply cleanly.  That is _bad_ but
+  does not have much to do with your MUA.  You might want to rebase
+  the patch with linkgit:git-rebase[1] before regenerating it in
+  this case.
+
+* The MUA corrupted your patch; "am" would complain that
+  the patch does not apply.  Look in the .git/rebase-apply/ subdirectory and
+  see what 'patch' file contains and check for the common
+  corruption patterns mentioned above.
+
+* While at it, check the 'info' and 'final-commit' files as well.
+  If what is in 'final-commit' is not exactly what you would want to
+  see in the commit log message, it is very likely that the
+  receiver would end up hand editing the log message when applying
+  your patch.  Things like "Hi, this is my first patch.\n" in the
+  patch e-mail should come after the three-dash line that signals
+  the end of the commit message.
+
+MUA-SPECIFIC HINTS
+------------------
+Here are some hints on how to successfully submit patches inline using
+various mailers.
+
+GMail
+~~~~~
+GMail does not have any way to turn off line wrapping in the web
+interface, so it will mangle any emails that you send.  You can however
+use "git send-email" and send your patches through the GMail SMTP server, or
+use any IMAP email client to connect to the google IMAP server and forward
+the emails through that.
+
+For hints on using 'git send-email' to send your patches through the
+GMail SMTP server, see the EXAMPLE section of linkgit:git-send-email[1].
+
+For hints on submission using the IMAP interface, see the EXAMPLE
+section of linkgit:git-imap-send[1].
+
+Thunderbird
+~~~~~~~~~~~
+By default, Thunderbird will both wrap emails as well as flag
+them as being 'format=flowed', both of which will make the
+resulting email unusable by git.
+
+There are three different approaches: use an add-on to turn off line wraps,
+configure Thunderbird to not mangle patches, or use
+an external editor to keep Thunderbird from mangling the patches.
+
+Approach #1 (add-on)
+^^^^^^^^^^^^^^^^^^^^
+
+Install the Toggle Word Wrap add-on that is available from
+https://addons.mozilla.org/thunderbird/addon/toggle-word-wrap/
+It adds a menu entry "Enable Word Wrap" in the composer's "Options" menu
+that you can tick off. Now you can compose the message as you otherwise do
+(cut + paste, 'git format-patch' | 'git imap-send', etc), but you have to
+insert line breaks manually in any text that you type.
+
+Approach #2 (configuration)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Three steps:
+
+1. Configure your mail server composition as plain text:
+   Edit...Account Settings...Composition & Addressing,
+   uncheck "Compose Messages in HTML".
+
+2. Configure your general composition window to not wrap.
++
+In Thunderbird 2:
+Edit..Preferences..Composition, wrap plain text messages at 0
++
+In Thunderbird 3:
+Edit..Preferences..Advanced..Config Editor.  Search for
+"mail.wrap_long_lines".
+Toggle it to make sure it is set to `false`.
+
+3. Disable the use of format=flowed:
+Edit..Preferences..Advanced..Config Editor.  Search for
+"mailnews.send_plaintext_flowed".
+Toggle it to make sure it is set to `false`.
+
+After that is done, you should be able to compose email as you
+otherwise would (cut + paste, 'git format-patch' | 'git imap-send', etc),
+and the patches will not be mangled.
+
+Approach #3 (external editor)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The following Thunderbird extensions are needed:
+AboutConfig from http://aboutconfig.mozdev.org/ and
+External Editor from http://globs.org/articles.php?lng=en&pg=8
+
+1. Prepare the patch as a text file using your method of choice.
+
+2. Before opening a compose window, use Edit->Account Settings to
+   uncheck the "Compose messages in HTML format" setting in the
+   "Composition & Addressing" panel of the account to be used to
+   send the patch.
+
+3. In the main Thunderbird window, 'before' you open the compose
+   window for the patch, use Tools->about:config to set the
+   following to the indicated values:
++
+----------
+       mailnews.send_plaintext_flowed  => false
+       mailnews.wraplength             => 0
+----------
+
+4. Open a compose window and click the external editor icon.
+
+5. In the external editor window, read in the patch file and exit
+   the editor normally.
+
+Side note: it may be possible to do step 2 with
+about:config and the following settings but no one's tried yet.
+
+----------
+       mail.html_compose                       => false
+       mail.identity.default.compose_html      => false
+       mail.identity.id?.compose_html          => false
+----------
+
+There is a script in contrib/thunderbird-patch-inline which can help
+you include patches with Thunderbird in an easy way. To use it, do the
+steps above and then use the script as the external editor.
+
+KMail
+~~~~~
+This should help you to submit patches inline using KMail.
+
+1. Prepare the patch as a text file.
+
+2. Click on New Mail.
+
+3. Go under "Options" in the Composer window and be sure that
+   "Word wrap" is not set.
+
+4. Use Message -> Insert file... and insert the patch.
+
+5. Back in the compose window: add whatever other text you wish to the
+   message, complete the addressing and subject fields, and press send.
+
+
 EXAMPLES
 --------
 
index c9ede794b03460ec2911b6ceddc781ab08fb8ded..a2a508dc2829b88e143ceb5c8e5edf0880263b2b 100644 (file)
@@ -26,7 +26,7 @@ index file, all SHA1 references in .git/refs/*, and all reflogs (unless
 --no-reflogs is given) as heads.
 
 --unreachable::
-       Print out objects that exist but that aren't readable from any
+       Print out objects that exist but that aren't reachable from any
        of the reference nodes.
 
 --root::
@@ -76,7 +76,7 @@ It tests SHA1 and general object sanity, and it does full tracking of
 the resulting reachability and everything else. It prints out any
 corruption it finds (missing or bad objects), and if you use the
 '--unreachable' flag it will also print out objects that exist but
-that aren't readable from any of the specified head nodes.
+that aren't reachable from any of the specified head nodes.
 
 So for example
 
index d3013d6a29f2696e05e3c77b0d6f0159d0a98a76..4e09708cc96fbf88b468141c0234095ee35fee3c 100644 (file)
@@ -111,6 +111,31 @@ Using direct mode with SSL:
 ..........................
 
 
+EXAMPLE
+-------
+To submit patches using GMail's IMAP interface, first, edit your ~/.gitconfig
+to specify your account settings:
+
+---------
+[imap]
+       folder = "[Gmail]/Drafts"
+       host = imaps://imap.gmail.com
+       user = user@gmail.com
+       port = 993
+       sslverify = false
+---------
+
+You might need to instead use: folder = "[Google Mail]/Drafts" if you get an error
+that the "Folder doesn't exist".
+
+Once the commits are ready to be sent, run the following command:
+
+  $ git format-patch --cover-letter -M --stdout origin/master | git imap-send
+
+Just make sure to disable line wrapping in the email client (GMail's web
+interface will wrap lines no matter what, so you need to use a real
+IMAP client).
+
 CAUTION
 -------
 It is still your responsibility to make sure that the email message
@@ -124,6 +149,10 @@ Thunderbird in particular is known to be problematic.  Thunderbird
 users may wish to visit this web page for more information:
   http://kb.mozillazine.org/Plain_text_e-mail_-_Thunderbird#Completely_plain_email
 
+SEE ALSO
+--------
+linkgit:git-format-patch[1], linkgit:git-send-email[1], mbox(5)
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index 2c84028838d566d424082efc71516f565b0ebbd2..de5c0d37a5c1c8c948aa01e276c3e198eb617be6 100644 (file)
@@ -178,9 +178,9 @@ May be an unabbreviated ref name or a glob and may be specified
 multiple times.  A warning will be issued for refs that do not exist,
 but a glob that does not match any refs is silently ignored.
 +
-This setting can be disabled by the `--no-standard-notes` option,
+This setting can be disabled by the `--no-notes` option,
 overridden by the 'GIT_NOTES_DISPLAY_REF' environment variable,
-and supplemented by the `--show-notes` option.
+and overridden by the `--notes=<ref>` option.
 
 GIT
 ---
index ba36ec04f4b9fa4733b6e0a4c7e41aa3e43327a0..b295bf83302de3fdac2833df756799a7aad6b404 100644 (file)
@@ -9,7 +9,8 @@ git-merge-base - Find as good common ancestors as possible for a merge
 SYNOPSIS
 --------
 [verse]
-'git merge-base' [-a|--all] [--octopus] <commit> <commit>...
+'git merge-base' [-a|--all] <commit> <commit>...
+'git merge-base' [-a|--all] --octopus <commit>...
 'git merge-base' --independent <commit>...
 
 DESCRIPTION
@@ -22,23 +23,21 @@ that does not have any better common ancestor is a 'best common
 ancestor', i.e. a 'merge base'.  Note that there can be more than one
 merge base for a pair of commits.
 
-Unless `--octopus` is given, among the two commits to compute the merge
-base from, one is specified by the first commit argument on the command
-line; the other commit is a (possibly hypothetical) commit that is a merge
-across all the remaining commits on the command line.  As the most common
-special case, specifying only two commits on the command line means
-computing the merge base between the given two commits.
+OPERATION MODE
+--------------
+
+As the most common special case, specifying only two commits on the
+command line means computing the merge base between the given two commits.
+
+More generally, among the two commits to compute the merge base from,
+one is specified by the first commit argument on the command line;
+the other commit is a (possibly hypothetical) commit that is a merge
+across all the remaining commits on the command line.
 
 As a consequence, the 'merge base' is not necessarily contained in each of the
 commit arguments if more than two commits are specified. This is different
 from linkgit:git-show-branch[1] when used with the `--merge-base` option.
 
-OPTIONS
--------
--a::
---all::
-       Output all merge bases for the commits, instead of just one.
-
 --octopus::
        Compute the best common ancestors of all supplied commits,
        in preparation for an n-way merge.  This mimics the behavior
@@ -51,6 +50,12 @@ OPTIONS
        from any other.  This mimics the behavior of 'git show-branch
        --independent'.
 
+OPTIONS
+-------
+-a::
+--all::
+       Output all merge bases for the commits, instead of just one.
+
 DISCUSSION
 ----------
 
@@ -89,6 +94,9 @@ and the result of `git merge-base A M` is '1'.  Commit '2' is also a
 common ancestor between 'A' and 'M', but '1' is a better common ancestor,
 because '2' is an ancestor of '1'.  Hence, '2' is not a merge base.
 
+The result of `git merge-base --octopus A B C` is '2', because '2' is
+the best common ancestor of all commits.
+
 When the history involves criss-cross merges, there can be more than one
 'best' common ancestor for two commits.  For example, with this topology:
 
index 296f314eae5af684e68965f4b04bd9acbd4c35a1..913ecd8c433b7ebaaf932dd5cf9b789dc06b7b95 100644 (file)
@@ -57,8 +57,11 @@ list::
 
 add::
        Add notes for a given object (defaults to HEAD). Abort if the
-       object already has notes (use `-f` to overwrite an
-       existing note).
+       object already has notes (use `-f` to overwrite existing notes).
+       However, if you're using `add` interactively (using an editor
+       to supply the notes contents), then - instead of aborting -
+       the existing notes will be opened in the editor (like the `edit`
+       subcommand).
 
 copy::
        Copy the notes for the first object onto the second object.
index 620d50e71f1a04f587079180ff2d987521d38786..9a075bc4d24d59c7b585e204e6feb50326c762f3 100644 (file)
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git rebase' [-i | --interactive] [options] [--onto <newbase>]
-       <upstream> [<branch>]
+       [<upstream>] [<branch>]
 'git rebase' [-i | --interactive] [options] --onto <newbase>
        --root [<branch>]
 
@@ -21,6 +21,12 @@ If <branch> is specified, 'git rebase' will perform an automatic
 `git checkout <branch>` before doing anything else.  Otherwise
 it remains on the current branch.
 
+If <upstream> is not specified, the upstream configured in
+branch.<name>.remote and branch.<name>.merge options will be used; see
+linkgit:git-config[1] for details.  If you are currently not on any
+branch or if the current branch does not have a configured upstream,
+the rebase will abort.
+
 All changes made by commits in the current branch but that are not
 in <upstream> are saved to a temporary area.  This is the same set
 of commits that would be shown by `git log <upstream>..HEAD` (or
@@ -217,7 +223,8 @@ leave out at most one of A and B, in which case it defaults to HEAD.
 
 <upstream>::
        Upstream branch to compare against.  May be any valid commit,
-       not just an existing branch name.
+       not just an existing branch name. Defaults to the configured
+       upstream for the current branch.
 
 <branch>::
        Working branch; defaults to HEAD.
index 8481f9db746b70c10a2f20a97a8ef4a68cb56d75..b2832fc7eb809af9865d83cdb20829354165f62e 100644 (file)
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'git reset' [-q] [<commit>] [--] <paths>...
-'git reset' --patch [<commit>] [--] [<paths>...]
+'git reset' [--patch|-p] [<commit>] [--] [<paths>...]
 'git reset' [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>]
 
 DESCRIPTION
@@ -39,8 +39,9 @@ working tree in one go.
        and <commit> (defaults to HEAD).  The chosen hunks are applied
        in reverse to the index.
 +
-This means that `git reset -p` is the opposite of `git add -p` (see
-linkgit:git-add[1]).
+This means that `git reset -p` is the opposite of `git add -p`, i.e.
+you can use it to selectively reset hunks. See the ``Interactive Mode''
+section of linkgit:git-add[1] to learn how to operate the `\--patch` mode.
 
 'git reset' [--<mode>] [<commit>]::
        This form resets the current branch head to <commit> and
index ee14f74fd3af8dd6cfd9e52002993355d63b97c8..5a168cfab2206cf67453bb5f1fd93dbe75bb4ef0 100644 (file)
@@ -348,10 +348,12 @@ sendemail.confirm::
        one of 'always', 'never', 'cc', 'compose', or 'auto'. See '--confirm'
        in the previous section for the meaning of these values.
 
+EXAMPLE
+-------
 Use gmail as the smtp server
-----------------------------
-
-Add the following section to the config file:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+To use 'git send-email' to send your patches through the GMail SMTP server,
+edit ~/.gitconfig to specify your account settings:
 
        [sendemail]
                smtpencryption = tls
@@ -359,9 +361,20 @@ Add the following section to the config file:
                smtpuser = yourname@gmail.com
                smtpserverport = 587
 
+Once your commits are ready to be sent to the mailing list, run the
+following commands:
+
+       $ git format-patch --cover-letter -M origin/master -o outgoing/
+       $ edit outgoing/0000-*
+       $ git send-email outgoing/*
+
 Note: the following perl modules are required
       Net::SMTP::SSL, MIME::Base64 and Authen::SASL
 
+SEE ALSO
+--------
+linkgit:git-format-patch[1], linkgit:git-imap-send[1], mbox(5)
+
 GIT
 ---
 Part of the linkgit:git[1] suite
index 79abc38e50a9a82243085383401b2d93468efaf3..15f051fa44e4b2e90da8383318c62695359772ce 100644 (file)
@@ -13,7 +13,7 @@ SYNOPSIS
 'git stash' drop [-q|--quiet] [<stash>]
 'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
 'git stash' branch <branchname> [<stash>]
-'git stash' [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] [<message>]]
+'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [<message>]]
 'git stash' clear
 'git stash' create
 
@@ -42,7 +42,7 @@ is also possible).
 OPTIONS
 -------
 
-save [--patch] [--[no-]keep-index] [-q|--quiet] [<message>]::
+save [-p|--patch] [--[no-]keep-index] [-q|--quiet] [<message>]::
 
        Save your local modifications to a new 'stash', and run `git reset
        --hard` to revert them.  The <message> part is optional and gives
@@ -54,12 +54,13 @@ save [--patch] [--[no-]keep-index] [-q|--quiet] [<message>]::
 If the `--keep-index` option is used, all changes already added to the
 index are left intact.
 +
-With `--patch`, you can interactively select hunks from in the diff
+With `--patch`, you can interactively select hunks from the diff
 between HEAD and the working tree to be stashed.  The stash entry is
 constructed such that its index state is the same as the index state
 of your repository, and its worktree contains only the changes you
 selected interactively.  The selected changes are then rolled back
-from your worktree.
+from your worktree. See the ``Interactive Mode'' section of
+linkgit:git-add[1] to learn how to operate the `\--patch` mode.
 +
 The `--patch` option implies `--keep-index`.  You can use
 `--no-keep-index` to override this.
index 1a16ff60448a72bebcba2daff7dbabc5feed8a4c..5e7a4130eeec48c27abf92b37834613692446723 100644 (file)
@@ -186,8 +186,10 @@ OPTIONS
 
 -f::
 --force::
-       This option is only valid for the add command.
-       Allow adding an otherwise ignored submodule path.
+       This option is only valid for add and update commands.
+       When running add, allow adding an otherwise ignored submodule path.
+       When running update, throw away local changes in submodules when
+       switching to a different commit.
 
 --cached::
        This option is only valid for status and summary commands.  These
index 71fc0ae8c56320e08f995620d902c53a8a398664..713e523034d5b95071e2285252c1796cd83c6fcd 100644 (file)
@@ -145,17 +145,6 @@ Skip "branches" and "tags" of first level directories;;
 ------------------------------------------------------------------------
 --
 
---use-log-author;;
-       When retrieving svn commits into git (as part of fetch, rebase, or
-       dcommit operations), look for the first From: or Signed-off-by: line
-       in the log message and use that as the author string.
---add-author-from;;
-       When committing to svn from git (as part of commit or dcommit
-       operations), if the existing log message doesn't already have a
-       From: or Signed-off-by: line, append a From: line based on the
-       git commit's author string.  If you use this, then --use-log-author
-       will retrieve a valid author string for all commits.
-
 'clone'::
        Runs 'init' and 'fetch'.  It will automatically create a
        directory based on the basename of the URL passed to it;
@@ -574,6 +563,17 @@ repository that will be fetched from.
 For 'branch' and 'tag', display the urls that will be used for copying when
 creating the branch or tag.
 
+--use-log-author::
+       When retrieving svn commits into git (as part of 'fetch', 'rebase', or
+       'dcommit' operations), look for the first `From:` or `Signed-off-by:` line
+       in the log message and use that as the author string.
+--add-author-from::
+       When committing to svn from git (as part of 'commit-diff', 'set-tree' or 'dcommit'
+       operations), if the existing log message doesn't already have a
+       `From:` or `Signed-off-by:` line, append a `From:` line based on the
+       git commit's author string.  If you use this, then `--use-log-author`
+       will retrieve a valid author string for all commits.
+
 
 ADVANCED OPTIONS
 ----------------
@@ -784,10 +784,9 @@ use `git svn rebase` to update your work branch instead of `git pull` or
 when committing into SVN, which can lead to merge commits reversing
 previous commits in SVN.
 
-DESIGN PHILOSOPHY
------------------
-Merge tracking in Subversion is lacking and doing branched development
-with Subversion can be cumbersome as a result.  While 'git svn' can track
+MERGE TRACKING
+--------------
+While 'git svn' can track
 copy history (including branches and tags) for repositories adopting a
 standard layout, it cannot yet represent merge history that happened
 inside git back upstream to SVN users.  Therefore it is advised that
@@ -797,16 +796,15 @@ compatibility with SVN (see the CAVEATS section below).
 CAVEATS
 -------
 
-For the sake of simplicity and interoperating with a less-capable system
-(SVN), it is recommended that all 'git svn' users clone, fetch and dcommit
+For the sake of simplicity and interoperating with Subversion,
+it is recommended that all 'git svn' users clone, fetch and dcommit
 directly from the SVN server, and avoid all 'git clone'/'pull'/'merge'/'push'
 operations between git repositories and branches.  The recommended
 method of exchanging code between git branches and users is
 'git format-patch' and 'git am', or just 'dcommit'ing to the SVN repository.
 
 Running 'git merge' or 'git pull' is NOT recommended on a branch you
-plan to 'dcommit' from.  Subversion does not represent merges in any
-reasonable or useful fashion; so users using Subversion cannot see any
+plan to 'dcommit' from because Subversion users cannot see any
 merges you've made.  Furthermore, if you merge or pull from a git branch
 that is a mirror of an SVN branch, 'dcommit' may commit to the wrong
 branch.
@@ -856,7 +854,7 @@ Renamed and copied directories are not detected by git and hence not
 tracked when committing to SVN.  I do not plan on adding support for
 this as it's quite difficult and time-consuming to get working for all
 the possible corner cases (git doesn't do it, either).  Committing
-renamed and copied files are fully supported if they're similar enough
+renamed and copied files is fully supported if they're similar enough
 for git to detect them.
 
 CONFIGURATION
index 9d5949229abac83b3e38b4f08565653f10492360..f1292fc6ce63be015a3c40e8fb04ebdb6acacf70 100644 (file)
@@ -9,7 +9,7 @@ git - the stupid content tracker
 SYNOPSIS
 --------
 [verse]
-'git' [--version] [--exec-path[=<path>]] [--html-path]
+'git' [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
     [-p|--paginate|--no-pager] [--no-replace-objects]
     [--bare] [--git-dir=<path>] [--work-tree=<path>]
     [-c <name>=<value>]
@@ -44,9 +44,10 @@ unreleased) version of git, that is available from 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v1.7.5/git.html[documentation for release 1.7.5]
+* link:v1.7.5.1/git.html[documentation for release 1.7.5.1]
 
 * release notes for
+  link:RelNotes/1.7.5.1.txt[1.7.5.1],
   link:RelNotes/1.7.5.txt[1.7.5].
 
 * link:v1.7.4.5/git.html[documentation for release 1.7.4.5]
@@ -287,8 +288,16 @@ help ...`.
        the current setting and then exit.
 
 --html-path::
-       Print the path to wherever your git HTML documentation is installed
-       and exit.
+       Print the path, without trailing slash, where git's HTML
+       documentation is installed and exit.
+
+--man-path::
+       Print the manpath (see `man(1)`) for the man pages for
+       this version of git and exit.
+
+--info-path::
+       Print the path where the Info files documenting this
+       version of git are installed and exit.
 
 -p::
 --paginate::
index 8920258baa515b048555be3448edea0403ce05be..861bd6f55352a12db6d1d680508e1d02a8e90d12 100644 (file)
@@ -16,6 +16,16 @@ merge.defaultToUpstream::
        to their corresponding remote tracking branches, and the tips of
        these tracking branches are merged.
 
+merge.ff::
+       By default, git does not create an extra merge commit when merging
+       a commit that is a descendant of the current commit. Instead, the
+       tip of the current branch is fast-forwarded. When set to `false`,
+       this variable tells git to create an extra merge commit in such
+       a case (equivalent to giving the `--no-ff` option from the command
+       line). When set to `only`, only such fast-forward merges are
+       allowed (equivalent to giving the `--ff-only` option from the
+       command line).
+
 merge.log::
        In addition to branch names, populate the log message with at
        most the specified number of one-line descriptions from the
index 50923e2ce9a5bdc3bcabb072a67921c6cf8171c1..d5c977262a818683ebd47d77d37a26c66737119f 100644 (file)
@@ -30,19 +30,34 @@ people using 80-column terminals.
        preferred by the user.  For non plumbing commands this
        defaults to UTF-8.
 
---no-notes::
---show-notes[=<ref>]::
+--notes[=<ref>]::
        Show the notes (see linkgit:git-notes[1]) that annotate the
        commit, when showing the commit log message.  This is the default
        for `git log`, `git show` and `git whatchanged` commands when
-       there is no `--pretty`, `--format` nor `--oneline` option is
-       given on the command line.
+       there is no `--pretty`, `--format` nor `--oneline` option given
+       on the command line.
++
+By default, the notes shown are from the notes refs listed in the
+'core.notesRef' and 'notes.displayRef' variables (or corresponding
+environment overrides). See linkgit:git-config[1] for more details.
++
+With an optional '<ref>' argument, show this notes ref instead of the
+default notes ref(s). The ref is taken to be in `refs/notes/` if it
+is not qualified.
 +
-With an optional argument, add this ref to the list of notes.  The ref
-is taken to be in `refs/notes/` if it is not qualified.
+Multiple --notes options can be combined to control which notes are
+being displayed. Examples: "--notes=foo" will show only notes from
+"refs/notes/foo"; "--notes=foo --notes" will show both notes from
+"refs/notes/foo" and from the default notes ref(s).
 
+--no-notes::
+       Do not show notes. This negates the above `--notes` option, by
+       resetting the list of notes refs from which notes are shown.
+       Options are parsed in the order given on the command line, so e.g.
+       "--notes --notes=foo --no-notes --notes=bar" will only show notes
+       from "refs/notes/bar".
+
+--show-notes[=<ref>]::
 --[no-]standard-notes::
-       Enable or disable populating the notes ref list from the
-       'core.notesRef' and 'notes.displayRef' variables (or
-       corresponding environment overrides).  Enabled by default.
-       See linkgit:git-config[1].
+       These options are deprecated. Use the above --notes/--no-notes
+       options instead.
index 73111bb0512476cb1d1786d65c416b7f4efd94cf..52bae31fcb7f741c34911d94a9253a2a546ee2c2 100644 (file)
@@ -730,7 +730,10 @@ ifdef::git-rev-list[]
        Print a number stating how many commits would have been
        listed, and suppress all other output.  When used together
        with '--left-right', instead print the counts for left and
-       right commits, separated by a tab.
+       right commits, separated by a tab. When used together with
+       '--cherry-mark', omit patch equivalent commits from these
+       counts and print the count for equivalent commits separated
+       by a tab.
 endif::git-rev-list[]
 
 
index c7c1530b896e837b0755f8ced2c5593ed2d5a02f..5379aaa2e000a8944b1b2a6dbfeac32904c6e7f2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -274,8 +274,7 @@ STRIP ?= strip
 #   mandir
 #   infodir
 #   htmldir
-#   ETC_GITCONFIG (but not sysconfdir)
-#   ETC_GITATTRIBUTES
+#   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.
@@ -291,15 +290,8 @@ sharedir = $(prefix)/share
 gitwebdir = $(sharedir)/gitweb
 template_dir = share/git-core/templates
 htmldir = share/doc/git-doc
-ifeq ($(prefix),/usr)
-sysconfdir = /etc
 ETC_GITCONFIG = $(sysconfdir)/gitconfig
 ETC_GITATTRIBUTES = $(sysconfdir)/gitattributes
-else
-sysconfdir = $(prefix)/etc
-ETC_GITCONFIG = etc/gitconfig
-ETC_GITATTRIBUTES = etc/gitattributes
-endif
 lib = lib
 # DESTDIR=
 pathsep = :
@@ -368,7 +360,6 @@ SCRIPT_SH += git-merge-resolve.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
-SCRIPT_SH += git-rebase--interactive.sh
 SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
@@ -378,6 +369,9 @@ SCRIPT_SH += git-web--browse.sh
 
 SCRIPT_LIB += git-mergetool--lib
 SCRIPT_LIB += git-parse-remote
+SCRIPT_LIB += git-rebase--am
+SCRIPT_LIB += git-rebase--interactive
+SCRIPT_LIB += git-rebase--merge
 SCRIPT_LIB += git-sh-setup
 
 SCRIPT_PERL += git-add--interactive.perl
@@ -1193,6 +1187,14 @@ endif
 -include config.mak.autogen
 -include config.mak
 
+ifndef sysconfdir
+ifeq ($(prefix),/usr)
+sysconfdir = /etc
+else
+sysconfdir = etc
+endif
+endif
+
 ifdef CHECK_HEADER_DEPENDENCIES
 COMPUTE_HEADER_DEPENDENCIES =
 USE_COMPUTED_HEADER_DEPENDENCIES =
@@ -1678,7 +1680,9 @@ strip: $(PROGRAMS) git$X
 
 git.o: common-cmds.h
 git.sp git.s git.o: EXTRA_CPPFLAGS = -DGIT_VERSION='"$(GIT_VERSION)"' \
-       '-DGIT_HTML_PATH="$(htmldir_SQ)"'
+       '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
+       '-DGIT_MAN_PATH="$(mandir_SQ)"' \
+       '-DGIT_INFO_PATH="$(infodir_SQ)"'
 
 git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
@@ -1749,33 +1753,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
 gitweb:
        $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) all
 
-ifdef JSMIN
-GITWEB_PROGRAMS += gitweb/static/gitweb.min.js
-GITWEB_JS = gitweb/static/gitweb.min.js
-else
-GITWEB_JS = gitweb/static/gitweb.js
-endif
-ifdef CSSMIN
-GITWEB_PROGRAMS += gitweb/static/gitweb.min.css
-GITWEB_CSS = gitweb/static/gitweb.min.css
-else
-GITWEB_CSS = gitweb/static/gitweb.css
-endif
-OTHER_PROGRAMS +=  gitweb/gitweb.cgi  $(GITWEB_PROGRAMS)
-gitweb/gitweb.cgi: gitweb/gitweb.perl $(GITWEB_PROGRAMS)
-       $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
-
-ifdef JSMIN
-gitweb/static/gitweb.min.js: gitweb/static/gitweb.js
-       $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
-endif # JSMIN
-ifdef CSSMIN
-gitweb/static/gitweb.min.css: gitweb/static/gitweb.css
-       $(QUIET_SUBDIR0)gitweb $(QUIET_SUBDIR1) $(patsubst gitweb/%,%,$@)
-endif # CSSMIN
-
-
-git-instaweb: git-instaweb.sh gitweb/gitweb.cgi gitweb/static/gitweb.css gitweb/static/gitweb.js
+git-instaweb: git-instaweb.sh gitweb
        $(QUIET_GEN)$(RM) $@ $@+ && \
        sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
            -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
index 1944ed4e4dc36addaf6a8b408703a7ff418bd26c..42f2d2fdc81a7c656e3ec006227b092addd13044 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -157,6 +157,7 @@ int write_archive_entries(struct archiver_args *args,
        struct archiver_context context;
        struct unpack_trees_options opts;
        struct tree_desc t;
+       struct pathspec pathspec;
        int err;
 
        if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -191,8 +192,10 @@ int write_archive_entries(struct archiver_args *args,
                git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
        }
 
-       err = read_tree_recursive(args->tree, "", 0, 0, args->pathspec,
+       init_pathspec(&pathspec, args->pathspec);
+       err = read_tree_recursive(args->tree, "", 0, 0, &pathspec,
                                  write_archive_entry, &context);
+       free_pathspec(&pathspec);
        if (err == READ_TREE_RECURSIVE)
                err = 0;
        return err;
@@ -221,11 +224,14 @@ static int reject_entry(const unsigned char *sha1, const char *base,
 
 static int path_exists(struct tree *tree, const char *path)
 {
-       const char *pathspec[] = { path, NULL };
-
-       if (read_tree_recursive(tree, "", 0, 0, pathspec, reject_entry, NULL))
-               return 1;
-       return 0;
+       const char *paths[] = { path, NULL };
+       struct pathspec pathspec;
+       int ret;
+
+       init_pathspec(&pathspec, paths);
+       ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
+       free_pathspec(&pathspec);
+       return ret != 0;
 }
 
 static void parse_pathspec_arg(const char **pathspec,
index d39a6ab930adf2e3cd716d3e9925350befed8947..e57abddf5297432d62bc20b8e3bde2e5eab474c4 100644 (file)
@@ -26,6 +26,27 @@ struct update_callback_data {
        int add_errors;
 };
 
+static int fix_unmerged_status(struct diff_filepair *p,
+                              struct update_callback_data *data)
+{
+       if (p->status != DIFF_STATUS_UNMERGED)
+               return p->status;
+       if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL) && !p->two->mode)
+               /*
+                * This is not an explicit add request, and the
+                * path is missing from the working tree (deleted)
+                */
+               return DIFF_STATUS_DELETED;
+       else
+               /*
+                * Either an explicit add request, or path exists
+                * in the working tree.  An attempt to explicitly
+                * add a path that does not exist in the working tree
+                * will be caught as an error by the caller immediately.
+                */
+               return DIFF_STATUS_MODIFIED;
+}
+
 static void update_callback(struct diff_queue_struct *q,
                            struct diff_options *opt, void *cbdata)
 {
@@ -35,30 +56,9 @@ static void update_callback(struct diff_queue_struct *q,
        for (i = 0; i < q->nr; i++) {
                struct diff_filepair *p = q->queue[i];
                const char *path = p->one->path;
-               switch (p->status) {
+               switch (fix_unmerged_status(p, data)) {
                default:
                        die(_("unexpected diff status %c"), p->status);
-               case DIFF_STATUS_UNMERGED:
-                       /*
-                        * ADD_CACHE_IGNORE_REMOVAL is unset if "git
-                        * add -u" is calling us, In such a case, a
-                        * missing work tree file needs to be removed
-                        * if there is an unmerged entry at stage #2,
-                        * but such a diff record is followed by
-                        * another with DIFF_STATUS_DELETED (and if
-                        * there is no stage #2, we won't see DELETED
-                        * nor MODIFIED).  We can simply continue
-                        * either way.
-                        */
-                       if (!(data->flags & ADD_CACHE_IGNORE_REMOVAL))
-                               continue;
-                       /*
-                        * Otherwise, it is "git add path" is asking
-                        * to explicitly add it; we fall through.  A
-                        * missing work tree file is an error and is
-                        * caught by add_file_to_index() in such a
-                        * case.
-                        */
                case DIFF_STATUS_MODIFIED:
                case DIFF_STATUS_TYPE_CHANGED:
                        if (add_file_to_index(&the_index, path, data->flags)) {
@@ -91,6 +91,7 @@ int add_files_to_cache(const char *prefix, const char **pathspec, int flags)
        data.flags = flags;
        data.add_errors = 0;
        rev.diffopt.format_callback_data = &data;
+       rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
        run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
        return !!data.add_errors;
 }
@@ -330,8 +331,8 @@ static struct option builtin_add_options[] = {
 
 static int add_config(const char *var, const char *value, void *cb)
 {
-       if (!strcasecmp(var, "add.ignoreerrors") ||
-           !strcasecmp(var, "add.ignore-errors")) {
+       if (!strcmp(var, "add.ignoreerrors") ||
+           !strcmp(var, "add.ignore-errors")) {
                ignore_add_errors = git_config_bool(var, value);
                return 0;
        }
index 36e150768ba88e427e6257900d7ec4c67c8303c1..530d4bb7e76da8e402f78ab7f981a080d25d6e78 100644 (file)
@@ -43,6 +43,7 @@ static int apply = 1;
 static int apply_in_reverse;
 static int apply_with_reject;
 static int apply_verbosely;
+static int allow_overlap;
 static int no_add;
 static const char *fake_ancestor;
 static int line_termination = '\n';
@@ -2430,9 +2431,9 @@ static void update_image(struct image *img,
        memcpy(img->line + applied_pos,
               postimage->line,
               postimage->nr * sizeof(*img->line));
-       for (i = 0; i < postimage->nr; i++)
-               img->line[applied_pos + i].flag |= LINE_PATCHED;
-
+       if (!allow_overlap)
+               for (i = 0; i < postimage->nr; i++)
+                       img->line[applied_pos + i].flag |= LINE_PATCHED;
        img->nr = nr;
 }
 
@@ -3889,6 +3890,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
                        "don't expect at least one line of context"),
                OPT_BOOLEAN(0, "reject", &apply_with_reject,
                        "leave the rejected hunks in corresponding *.rej files"),
+               OPT_BOOLEAN(0, "allow-overlap", &allow_overlap,
+                       "allow overlapping hunks"),
                OPT__VERBOSE(&apply_verbosely, "be verbose"),
                OPT_BIT(0, "inaccurate-eof", &options,
                        "tolerate incorrectly detected missing new-line at the end of file",
index 463978817871b534dcdfb3c5c630ccd731d9733a..4242e4b513101a09b0f027188095ba3032802d3b 100644 (file)
@@ -1378,7 +1378,7 @@ static void get_ac_line(const char *inbuf, const char *what,
        timepos = tmp;
 
        *tmp = 0;
-       while (person < tmp && *tmp != ' ')
+       while (person < tmp && !(*tmp == ' ' && tmp[1] == '<'))
                tmp--;
        if (tmp <= person)
                return;
index eece5d6ac0f48ae76dc76c0f2ebda633cc0ded58..4761769512a8abcdd5652a93d39be18154e251dd 100644 (file)
@@ -79,7 +79,10 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
 
 static int read_tree_some(struct tree *tree, const char **pathspec)
 {
-       read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
+       struct pathspec ps;
+       init_pathspec(&ps, pathspec);
+       read_tree_recursive(tree, "", 0, 0, &ps, update_some, NULL);
+       free_pathspec(&ps);
 
        /* update the index with the given tree's info
         * for all args, expanding wildcards, and exit
@@ -648,18 +651,30 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
                if (more == 1)
                        describe_one_orphan(&sb, last);
                else
-                       strbuf_addf(&sb, " ... and %d more.\n", more);
+                       strbuf_addf(&sb, _(" ... and %d more.\n"), more);
        }
 
        fprintf(stderr,
-               "Warning: you are leaving %d commit%s behind, "
+               Q_(
+               /* The singular version */
+               "Warning: you are leaving %d commit behind, "
+               "not connected to\n"
+               "any of your branches:\n\n"
+               "%s\n"
+               "If you want to keep it by creating a new branch, "
+               "this may be a good time\nto do so with:\n\n"
+               " git branch new_branch_name %s\n\n",
+               /* The plural version */
+               "Warning: you are leaving %d commits behind, "
                "not connected to\n"
                "any of your branches:\n\n"
                "%s\n"
                "If you want to keep them by creating a new branch, "
                "this may be a good time\nto do so with:\n\n"
                " git branch new_branch_name %s\n\n",
-               lost, ((1 < lost) ? "s" : ""),
+               /* Give ngettext() the count */
+               lost),
+               lost,
                sb.buf,
                sha1_to_hex(commit->object.sha1));
        strbuf_release(&sb);
@@ -961,9 +976,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                die (_("--patch is incompatible with all other options"));
 
        if (opts.force_detach && (opts.new_branch || opts.new_orphan_branch))
-               die("--detach cannot be used with -b/-B/--orphan");
+               die(_("--detach cannot be used with -b/-B/--orphan"));
        if (opts.force_detach && 0 < opts.track)
-               die("--detach cannot be used with -t");
+               die(_("--detach cannot be used with -t"));
 
        /* --track without -b should DWIM */
        if (0 < opts.track && !opts.new_branch) {
@@ -1043,7 +1058,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                }
 
                if (opts.force_detach)
-                       die("git checkout: --detach does not take a path argument");
+                       die(_("git checkout: --detach does not take a path argument"));
 
                if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge)
                        die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\nchecking out of the index."));
index 4144bcf5ca320057b5ef1f5dac9c2df19aba250b..49c838fd3ff24ecc7821fbcf8f312d76967c168d 100644 (file)
@@ -417,7 +417,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (path)
                repo = xstrdup(absolute_path(repo_name));
        else if (!strchr(repo_name, ':'))
-               die("repository '%s' does not exist", repo_name);
+               die(_("repository '%s' does not exist"), repo_name);
        else
                repo = repo_name;
        is_local = path && !is_bundle;
index 67757e999fba514b62767d3351031e9eb6ef8c10..411d5e41531adabe679df2d1381dbf923c5e925b 100644 (file)
@@ -615,6 +615,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        const char *hook_arg1 = NULL;
        const char *hook_arg2 = NULL;
        int ident_shown = 0;
+       int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
 
        if (!no_verify && run_hook(index_file, "pre-commit", NULL))
                return 0;
@@ -681,6 +682,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                if (strbuf_read_file(&sb, template_file, 0) < 0)
                        die_errno(_("could not read '%s'"), template_file);
                hook_arg1 = "template";
+               clean_message_contents = 0;
        }
 
        /*
@@ -708,7 +710,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (s->fp == NULL)
                die_errno(_("could not open '%s'"), git_path(commit_editmsg));
 
-       if (cleanup_mode != CLEANUP_NONE)
+       if (clean_message_contents)
                stripspace(&sb, 0);
 
        if (signoff) {
index 0d2a3e9fa2023cc673f1f6d9e17d3deeca1c7e9d..be6417d166abf428d379a70b9d67f894da4641d1 100644 (file)
@@ -163,6 +163,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
        }
 
        if (read_stdin) {
+               int saved_nrl = 0;
+               int saved_dcctc = 0;
+
                if (opt->diffopt.detect_rename)
                        opt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |
                                               DIFF_SETUP_USE_CACHE);
@@ -173,9 +176,16 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                                fputs(line, stdout);
                                fflush(stdout);
                        }
-                       else
+                       else {
                                diff_tree_stdin(line);
+                               if (saved_nrl < opt->diffopt.needed_rename_limit)
+                                       saved_nrl = opt->diffopt.needed_rename_limit;
+                               if (opt->diffopt.degraded_cc_to_c)
+                                       saved_dcctc = 1;
+                       }
                }
+               opt->diffopt.degraded_cc_to_c = saved_dcctc;
+               opt->diffopt.needed_rename_limit = saved_nrl;
        }
 
        return diff_result_code(&opt->diffopt, 0);
index 717fa1a3414e18cbdd4c6eb1e0785761687688d7..14bd14fce0fa6b9c9b047142d23d4a2237b57a36 100644 (file)
@@ -202,7 +202,6 @@ static void refresh_index_quietly(void)
 
 static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
 {
-       int result;
        unsigned int options = 0;
 
        while (1 < argc && argv[1][0] == '-') {
@@ -236,8 +235,7 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
                perror("read_cache_preload");
                return -1;
        }
-       result = run_diff_files(revs, options);
-       return diff_result_code(&revs->diffopt, result);
+       return run_diff_files(revs, options);
 }
 
 int cmd_diff(int argc, const char **argv, const char *prefix)
index 10a1f65310f28f2014bab3f3295205abf6dc59ad..3ee2ec51def59695813ee14f104d142a62d530b6 100644 (file)
@@ -533,18 +533,18 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
 static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                     struct tree_desc *tree, struct strbuf *base, int tn_len)
 {
-       int hit = 0, matched = 0;
+       int hit = 0, match = 0;
        struct name_entry entry;
        int old_baselen = base->len;
 
        while (tree_entry(tree, &entry)) {
                int te_len = tree_entry_len(entry.path, entry.sha1);
 
-               if (matched != 2) {
-                       matched = tree_entry_interesting(&entry, base, tn_len, pathspec);
-                       if (matched == -1)
-                               break; /* no more matches */
-                       if (!matched)
+               if (match != 2) {
+                       match = tree_entry_interesting(&entry, base, tn_len, pathspec);
+                       if (match < 0)
+                               break;
+                       if (match == 0)
                                continue;
                }
 
index b7370d9bb8f235f1cf39b1ffa768498ca1e88654..ba13a54793d46de2410db14e6f387674e3b27c82 100644 (file)
@@ -319,10 +319,10 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
                struct stat st;
 
                if (!exist_ok && !stat(git_dir, &st))
-                       die("%s already exists", git_dir);
+                       die(_("%s already exists"), git_dir);
 
                if (!exist_ok && !stat(real_git_dir, &st))
-                       die("%s already exists", real_git_dir);
+                       die(_("%s already exists"), real_git_dir);
 
                /*
                 * make sure symlinks are resolved because we'll be
@@ -351,15 +351,15 @@ static void separate_git_dir(const char *git_dir)
                else if (S_ISDIR(st.st_mode))
                        src = git_link;
                else
-                       die("unable to handle file type %d", st.st_mode);
+                       die(_("unable to handle file type %d"), st.st_mode);
 
                if (rename(src, git_dir))
-                       die_errno("unable to move %s to %s", src, git_dir);
+                       die_errno(_("unable to move %s to %s"), src, git_dir);
        }
 
        fp = fopen(git_link, "w");
        if (!fp)
-               die("Could not create git link %s", git_link);
+               die(_("Could not create git link %s"), git_link);
        fprintf(fp, "gitdir: %s\n", git_dir);
        fclose(fp);
 }
index c6dce9b8950410b08e13c11aa940404a7fcd2b78..f6219909a787ae355a43e39974140a36848ab1d6 100644 (file)
@@ -25,12 +25,15 @@ static const char *default_date_mode = NULL;
 
 static int default_show_root = 1;
 static int decoration_style;
+static int decoration_given;
 static const char *fmt_patch_subject_prefix = "PATCH";
 static const char *fmt_pretty;
 
-static const char * const builtin_log_usage =
+static const char * const builtin_log_usage[] = {
        "git log [<options>] [<since>..<until>] [[--] <path>...]\n"
-       "   or: git show [options] <object>...";
+       "   or: git show [options] <object>...",
+       NULL
+};
 
 static int parse_decoration_style(const char *var, const char *value)
 {
@@ -49,6 +52,23 @@ static int parse_decoration_style(const char *var, const char *value)
        return -1;
 }
 
+static int decorate_callback(const struct option *opt, const char *arg, int unset)
+{
+       if (unset)
+               decoration_style = 0;
+       else if (arg)
+               decoration_style = parse_decoration_style("command line", arg);
+       else
+               decoration_style = DECORATE_SHORT_REFS;
+
+       if (decoration_style < 0)
+               die("invalid --decorate option: %s", arg);
+
+       decoration_given = 1;
+
+       return 0;
+}
+
 static void cmd_log_init_defaults(struct rev_info *rev)
 {
        rev->abbrev = DEFAULT_ABBREV;
@@ -68,17 +88,28 @@ static void cmd_log_init_defaults(struct rev_info *rev)
 static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
                         struct rev_info *rev, struct setup_revision_opt *opt)
 {
-       int i;
-       int decoration_given = 0;
        struct userformat_want w;
-       /*
-        * Check for -h before setup_revisions(), or "git log -h" will
-        * fail when run without a git directory.
-        */
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage(builtin_log_usage);
+       int quiet = 0, source = 0;
+
+       const struct option builtin_log_options[] = {
+               OPT_BOOLEAN(0, "quiet", &quiet, "supress diff output"),
+               OPT_BOOLEAN(0, "source", &source, "show source"),
+               { OPTION_CALLBACK, 0, "decorate", NULL, NULL, "decorate options",
+                 PARSE_OPT_OPTARG, decorate_callback},
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix,
+                            builtin_log_options, builtin_log_usage,
+                            PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
+                            PARSE_OPT_KEEP_DASHDASH);
+
        argc = setup_revisions(argc, argv, rev, opt);
 
+       /* Any arguments at this point are not recognized */
+       if (argc > 1)
+               die("unrecognized argument: %s", argv[1]);
+
        memset(&w, 0, sizeof(w));
        userformat_find_requirements(NULL, &w);
 
@@ -94,26 +125,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
                if (rev->diffopt.pathspec.nr != 1)
                        usage("git logs can only follow renames on one pathname at a time");
        }
-       for (i = 1; i < argc; i++) {
-               const char *arg = argv[i];
-               if (!strcmp(arg, "--decorate")) {
-                       decoration_style = DECORATE_SHORT_REFS;
-                       decoration_given = 1;
-               } else if (!prefixcmp(arg, "--decorate=")) {
-                       const char *v = skip_prefix(arg, "--decorate=");
-                       decoration_style = parse_decoration_style(arg, v);
-                       if (decoration_style < 0)
-                               die(_("invalid --decorate option: %s"), arg);
-                       decoration_given = 1;
-               } else if (!strcmp(arg, "--no-decorate")) {
-                       decoration_style = 0;
-               } else if (!strcmp(arg, "--source")) {
-                       rev->show_source = 1;
-               } else if (!strcmp(arg, "-h")) {
-                       usage(builtin_log_usage);
-               } else
-                       die(_("unrecognized argument: %s"), arg);
-       }
+
+       if (source)
+               rev->show_source = 1;
 
        /*
         * defeat log.decorate configuration interacting with --pretty=raw
@@ -256,6 +270,8 @@ static void finish_early_output(struct rev_info *rev)
 static int cmd_log_walk(struct rev_info *rev)
 {
        struct commit *commit;
+       int saved_nrl = 0;
+       int saved_dcctc = 0;
 
        if (rev->early_output)
                setup_early_output(rev);
@@ -286,7 +302,14 @@ static int cmd_log_walk(struct rev_info *rev)
                }
                free_commit_list(commit->parents);
                commit->parents = NULL;
+               if (saved_nrl < rev->diffopt.needed_rename_limit)
+                       saved_nrl = rev->diffopt.needed_rename_limit;
+               if (rev->diffopt.degraded_cc_to_c)
+                       saved_dcctc = 1;
        }
+       rev->diffopt.degraded_cc_to_c = saved_dcctc;
+       rev->diffopt.needed_rename_limit = saved_nrl;
+
        if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
            DIFF_OPT_TST(&rev->diffopt, CHECK_FAILED)) {
                return 02;
@@ -405,6 +428,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
        struct object_array_entry *objects;
        struct setup_revision_opt opt;
+       struct pathspec match_all;
        int i, count, ret = 0;
 
        git_config(git_log_config, NULL);
@@ -412,6 +436,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        if (diff_use_color_default == -1)
                diff_use_color_default = git_use_color_default;
 
+       init_pathspec(&match_all, NULL);
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.always_show_header = 1;
@@ -458,7 +483,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                                        diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
                                        name,
                                        diff_get_color_opt(&rev.diffopt, DIFF_RESET));
-                       read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
+                       read_tree_recursive((struct tree *)o, "", 0, 0, &match_all,
                                        show_tree_object, NULL);
                        rev.shown_one = 1;
                        break;
index fb2d5f4b1fb0ce9ef2fb0c4099b5fea6d07b6838..15701233e29b240cfa1abdb56bd489306e74c677 100644 (file)
@@ -338,7 +338,7 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
 {
        struct tree *tree;
        unsigned char sha1[20];
-       const char **match;
+       struct pathspec pathspec;
        struct cache_entry *last_stage0 = NULL;
        int i;
 
@@ -360,10 +360,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)
                static const char *(matchbuf[2]);
                matchbuf[0] = prefix;
                matchbuf[1] = NULL;
-               match = matchbuf;
+               init_pathspec(&pathspec, matchbuf);
+               pathspec.items[0].use_wildcard = 0;
        } else
-               match = NULL;
-       if (read_tree(tree, 1, match))
+               init_pathspec(&pathspec, NULL);
+       if (read_tree(tree, 1, &pathspec))
                die("unable to read tree entries %s", tree_name);
 
        for (i = 0; i < active_nr; i++) {
index f73e6bd9626a0e929a513fed1fd1227c28732ec7..f08c5b0c942eec58b85ab41e5e5fb1ec216df683 100644 (file)
@@ -19,7 +19,7 @@ static int line_termination = '\n';
 #define LS_SHOW_SIZE 16
 static int abbrev;
 static int ls_options;
-static const char **pathspec;
+static struct pathspec pathspec;
 static int chomp_prefix;
 static const char *ls_tree_prefix;
 
@@ -35,7 +35,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
        if (ls_options & LS_RECURSIVE)
                return 1;
 
-       s = pathspec;
+       s = pathspec.raw;
        if (!s)
                return 0;
 
@@ -120,7 +120,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
 {
        unsigned char sha1[20];
        struct tree *tree;
-       int full_tree = 0;
+       int i, full_tree = 0;
        const struct option ls_tree_options[] = {
                OPT_BIT('d', NULL, &ls_options, "only show trees",
                        LS_TREE_ONLY),
@@ -166,11 +166,14 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
        if (get_sha1(argv[0], sha1))
                die("Not a valid object name %s", argv[0]);
 
-       pathspec = get_pathspec(prefix, argv + 1);
+       init_pathspec(&pathspec, get_pathspec(prefix, argv + 1));
+       for (i = 0; i < pathspec.nr; i++)
+               pathspec.items[i].use_wildcard = 0;
+       pathspec.has_wildcard = 0;
        tree = parse_tree_indirect(sha1);
        if (!tree)
                die("not a tree object");
-       read_tree_recursive(tree, "", 0, 0, pathspec, show_tree, NULL);
+       read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
 
        return 0;
 }
index 96dd160731ce29b18be646893057929bab97cb8a..4f30f1b0c8b14e78e272ec54a86584d66501f754 100644 (file)
@@ -23,7 +23,8 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 }
 
 static const char * const merge_base_usage[] = {
-       "git merge-base [-a|--all] [--octopus] <commit> <commit>...",
+       "git merge-base [-a|--all] <commit> <commit>...",
+       "git merge-base [-a|--all] --octopus <commit>...",
        "git merge-base --independent <commit>...",
        NULL
 };
index 0bdd19a13784590c107108443f449d37fd7509d8..7eebb71491047b2df6231df500e5fc28db1881b4 100644 (file)
@@ -56,6 +56,7 @@ static size_t use_strategies_nr, use_strategies_alloc;
 static const char **xopts;
 static size_t xopts_nr, xopts_alloc;
 static const char *branch;
+static char *branch_mergeoptions;
 static int option_renormalize;
 static int verbosity;
 static int allow_rerere_auto;
@@ -503,26 +504,34 @@ cleanup:
        strbuf_release(&bname);
 }
 
+static void parse_branch_merge_options(char *bmo)
+{
+       const char **argv;
+       int argc;
+
+       if (!bmo)
+               return;
+       argc = split_cmdline(bmo, &argv);
+       if (argc < 0)
+               die(_("Bad branch.%s.mergeoptions string: %s"), branch,
+                   split_cmdline_strerror(argc));
+       argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
+       memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
+       argc++;
+       argv[0] = "branch.*.mergeoptions";
+       parse_options(argc, argv, NULL, builtin_merge_options,
+                     builtin_merge_usage, 0);
+       free(argv);
+}
+
 static int git_merge_config(const char *k, const char *v, void *cb)
 {
        if (branch && !prefixcmp(k, "branch.") &&
                !prefixcmp(k + 7, branch) &&
                !strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
-               const char **argv;
-               int argc;
-               char *buf;
-
-               buf = xstrdup(v);
-               argc = split_cmdline(buf, &argv);
-               if (argc < 0)
-                       die(_("Bad branch.%s.mergeoptions string: %s"), branch,
-                           split_cmdline_strerror(argc));
-               argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
-               memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
-               argc++;
-               parse_options(argc, argv, NULL, builtin_merge_options,
-                             builtin_merge_usage, 0);
-               free(buf);
+               free(branch_mergeoptions);
+               branch_mergeoptions = xstrdup(v);
+               return 0;
        }
 
        if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
@@ -541,6 +550,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)
                if (is_bool && shortlog_len)
                        shortlog_len = DEFAULT_MERGE_LOG_LEN;
                return 0;
+       } else if (!strcmp(k, "merge.ff")) {
+               int boolval = git_config_maybe_bool(k, v);
+               if (0 <= boolval) {
+                       allow_fast_forward = boolval;
+               } else if (v && !strcmp(v, "only")) {
+                       allow_fast_forward = 1;
+                       fast_forward_only = 1;
+               } /* do not barf on values from future versions of git */
+               return 0;
        } else if (!strcmp(k, "merge.defaulttoupstream")) {
                default_to_upstream = git_config_bool(k, v);
                return 0;
@@ -822,7 +840,7 @@ static void read_merge_msg(void)
 {
        strbuf_reset(&merge_msg);
        if (strbuf_read_file(&merge_msg, git_path("MERGE_MSG"), 0) < 0)
-               die_errno("Could not read from '%s'", git_path("MERGE_MSG"));
+               die_errno(_("Could not read from '%s'"), git_path("MERGE_MSG"));
 }
 
 static void run_prepare_commit_msg(void)
@@ -962,16 +980,16 @@ static int setup_with_upstream(const char ***argv)
        const char **args;
 
        if (!branch)
-               die("No current branch.");
+               die(_("No current branch."));
        if (!branch->remote)
-               die("No remote for the current branch.");
+               die(_("No remote for the current branch."));
        if (!branch->merge_nr)
-               die("No default upstream defined for the current branch.");
+               die(_("No default upstream defined for the current branch."));
 
        args = xcalloc(branch->merge_nr + 1, sizeof(char *));
        for (i = 0; i < branch->merge_nr; i++) {
                if (!branch->merge[i]->dst)
-                       die("No remote tracking branch for %s from %s",
+                       die(_("No remote tracking branch for %s from %s"),
                            branch->merge[i]->src, branch->remote_name);
                args[i] = branch->merge[i]->dst;
        }
@@ -1010,6 +1028,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (diff_use_color_default == -1)
                diff_use_color_default = git_use_color_default;
 
+       if (branch_mergeoptions)
+               parse_branch_merge_options(branch_mergeoptions);
        argc = parse_options(argc, argv, prefix, builtin_merge_options,
                        builtin_merge_usage, 0);
 
@@ -1043,10 +1063,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        }
        if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
                if (advice_resolve_conflict)
-                       die("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
-                           "Please, commit your changes before you can merge.");
+                       die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
+                           "Please, commit your changes before you can merge."));
                else
-                       die("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).");
+                       die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
        }
        resolve_undo_clear();
 
index d6dcfcb0149ab6dc45f4a71e21cf77d13b494e18..1fb1f734397668280b444e63dc8d3c129d41e3b9 100644 (file)
@@ -100,16 +100,6 @@ struct msg_arg {
        struct strbuf buf;
 };
 
-static void expand_notes_ref(struct strbuf *sb)
-{
-       if (!prefixcmp(sb->buf, "refs/notes/"))
-               return; /* we're happy */
-       else if (!prefixcmp(sb->buf, "notes/"))
-               strbuf_insert(sb, 0, "refs/", 5);
-       else
-               strbuf_insert(sb, 0, "refs/notes/", 11);
-}
-
 static int list_each_note(const unsigned char *object_sha1,
                const unsigned char *note_sha1, char *note_path,
                void *cb_data)
@@ -529,6 +519,8 @@ static int list(int argc, const char **argv, const char *prefix)
        return retval;
 }
 
+static int append_edit(int argc, const char **argv, const char *prefix);
+
 static int add(int argc, const char **argv, const char *prefix)
 {
        int retval = 0, force = 0;
@@ -556,14 +548,14 @@ static int add(int argc, const char **argv, const char *prefix)
        };
 
        argc = parse_options(argc, argv, prefix, options, git_notes_add_usage,
-                            0);
+                            PARSE_OPT_KEEP_ARGV0);
 
-       if (1 < argc) {
+       if (2 < argc) {
                error(_("too many parameters"));
                usage_with_options(git_notes_add_usage, options);
        }
 
-       object_ref = argc ? argv[0] : "HEAD";
+       object_ref = argc > 1 ? argv[1] : "HEAD";
 
        if (get_sha1(object_ref, object))
                die(_("Failed to resolve '%s' as a valid ref."), object_ref);
@@ -573,6 +565,18 @@ static int add(int argc, const char **argv, const char *prefix)
 
        if (note) {
                if (!force) {
+                       if (!msg.given) {
+                               /*
+                                * Redirect to "edit" subcommand.
+                                *
+                                * We only end up here if none of -m/-F/-c/-C
+                                * or -f are given. The original args are
+                                * therefore still in argv[0-1].
+                                */
+                               argv[0] = "edit";
+                               free_notes(t);
+                               return append_edit(argc, argv, prefix);
+                       }
                        retval = error(_("Cannot add notes. Found existing notes "
                                       "for object %s. Use '-f' to overwrite "
                                       "existing notes"), sha1_to_hex(object));
index 82358855d1da90b75f94c3d424a5da5c0f97960e..08213c7c0bc6fa5d649a38520dc87222019babe2 100644 (file)
@@ -12,74 +12,6 @@ static const char * const rerere_usage[] = {
        NULL,
 };
 
-/* these values are days */
-static int cutoff_noresolve = 15;
-static int cutoff_resolve = 60;
-
-static time_t rerere_created_at(const char *name)
-{
-       struct stat st;
-       return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
-}
-
-static time_t rerere_last_used_at(const char *name)
-{
-       struct stat st;
-       return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
-}
-
-static void unlink_rr_item(const char *name)
-{
-       unlink(rerere_path(name, "thisimage"));
-       unlink(rerere_path(name, "preimage"));
-       unlink(rerere_path(name, "postimage"));
-       rmdir(git_path("rr-cache/%s", name));
-}
-
-static int git_rerere_gc_config(const char *var, const char *value, void *cb)
-{
-       if (!strcmp(var, "gc.rerereresolved"))
-               cutoff_resolve = git_config_int(var, value);
-       else if (!strcmp(var, "gc.rerereunresolved"))
-               cutoff_noresolve = git_config_int(var, value);
-       else
-               return git_default_config(var, value, cb);
-       return 0;
-}
-
-static void garbage_collect(struct string_list *rr)
-{
-       struct string_list to_remove = STRING_LIST_INIT_DUP;
-       DIR *dir;
-       struct dirent *e;
-       int i, cutoff;
-       time_t now = time(NULL), then;
-
-       git_config(git_rerere_gc_config, NULL);
-       dir = opendir(git_path("rr-cache"));
-       if (!dir)
-               die_errno("unable to open rr-cache directory");
-       while ((e = readdir(dir))) {
-               if (is_dot_or_dotdot(e->d_name))
-                       continue;
-
-               then = rerere_last_used_at(e->d_name);
-               if (then) {
-                       cutoff = cutoff_resolve;
-               } else {
-                       then = rerere_created_at(e->d_name);
-                       if (!then)
-                               continue;
-                       cutoff = cutoff_noresolve;
-               }
-               if (then < now - cutoff * 86400)
-                       string_list_append(&to_remove, e->d_name);
-       }
-       for (i = 0; i < to_remove.nr; i++)
-               unlink_rr_item(to_remove.items[i].string);
-       string_list_clear(&to_remove, 0);
-}
-
 static int outf(void *dummy, mmbuffer_t *ptr, int nbuf)
 {
        int i;
@@ -148,14 +80,9 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
                return 0;
 
        if (!strcmp(argv[0], "clear")) {
-               for (i = 0; i < merge_rr.nr; i++) {
-                       const char *name = (const char *)merge_rr.items[i].util;
-                       if (!has_rerere_resolution(name))
-                               unlink_rr_item(name);
-               }
-               unlink_or_warn(git_path("MERGE_RR"));
+               rerere_clear(&merge_rr);
        } else if (!strcmp(argv[0], "gc"))
-               garbage_collect(&merge_rr);
+               rerere_gc(&merge_rr);
        else if (!strcmp(argv[0], "status"))
                for (i = 0; i < merge_rr.nr; i++)
                        printf("%s\n", merge_rr.items[i].string);
index 9bfb94201f298f5902c6da13b12f4ca539bb86ed..4be66998f6bcb998df094d0c434dfab6bbdcc8c7 100644 (file)
@@ -55,7 +55,9 @@ static void show_commit(struct commit *commit, void *data)
        graph_show_commit(revs->graph);
 
        if (revs->count) {
-               if (commit->object.flags & SYMMETRIC_LEFT)
+               if (commit->object.flags & PATCHSAME)
+                       revs->count_same++;
+               else if (commit->object.flags & SYMMETRIC_LEFT)
                        revs->count_left++;
                else
                        revs->count_right++;
@@ -406,8 +408,12 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                             &info);
 
        if (revs.count) {
-               if (revs.left_right)
+               if (revs.left_right && revs.cherry_mark)
+                       printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same);
+               else if (revs.left_right)
                        printf("%d\t%d\n", revs.count_left, revs.count_right);
+               else if (revs.cherry_mark)
+                       printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same);
                else
                        printf("%d\n", revs.count_left + revs.count_right);
        }
index 8b0911c0d2ac5a60f8a3c7a43e7960617ded9d7a..4ac2ca984ff36588c68274f10f131ef88023d622 100644 (file)
@@ -229,6 +229,9 @@ static void print_helper_status(struct ref *ref)
 static int sideband_demux(int in, int out, void *data)
 {
        int *fd = data;
+#ifdef NO_PTHREADS
+       close(fd[1]);
+#endif
        int ret = recv_sideband("send-pack", fd[0], out);
        close(out);
        return ret;
@@ -339,6 +342,8 @@ int send_pack(struct send_pack_args *args,
                if (pack_objects(out, remote_refs, extra_have, args) < 0) {
                        for (ref = remote_refs; ref; ref = ref->next)
                                ref->status = REF_STATUS_NONE;
+                       if (args->stateless_rpc)
+                               close(out);
                        if (use_sideband)
                                finish_async(&demux);
                        return -1;
diff --git a/cache.h b/cache.h
index 28899b7b7881474eed4a6f3b6fda8db79d5cbc9c..2b341166241c7be98fb1012871266ebb910e1226 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -511,7 +511,7 @@ struct pathspec {
        struct pathspec_item {
                const char *match;
                int len;
-               unsigned int has_wildcard:1;
+               unsigned int use_wildcard:1;
        } *items;
 };
 
@@ -676,14 +676,24 @@ extern char *sha1_pack_name(const unsigned char *sha1);
 extern char *sha1_pack_index_name(const unsigned char *sha1);
 extern const char *find_unique_abbrev(const unsigned char *sha1, int);
 extern const unsigned char null_sha1[20];
-static inline int is_null_sha1(const unsigned char *sha1)
+
+static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
 {
-       return !memcmp(sha1, null_sha1, 20);
+       int i;
+
+       for (i = 0; i < 20; i++, sha1++, sha2++) {
+               if (*sha1 != *sha2)
+                       return *sha1 - *sha2;
+       }
+
+       return 0;
 }
-static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
+
+static inline int is_null_sha1(const unsigned char *sha1)
 {
-       return memcmp(sha1, sha2, 20);
+       return !hashcmp(sha1, null_sha1);
 }
+
 static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
 {
        memcpy(sha_dst, sha_src, 20);
index d6ddf81d694abd0ec5c16c20e9a90acfbcb753f2..bb8d7d0878994eb3d53163c330de44d8c0d48b3f 100755 (executable)
@@ -1534,7 +1534,7 @@ __git_log_common_options="
 __git_log_gitk_options="
        --dense --sparse --full-history
        --simplify-merges --simplify-by-decoration
-       --left-right
+       --left-right --notes --no-notes
 "
 # Options that go well for log and shortlog (not gitk)
 __git_log_shortlog_options="
index 2870de400ed533d83c77269ee1654af212c6510c..3b5f2242a597ff1b44a3af6be72cb14e6e0d5455 100644 (file)
@@ -112,6 +112,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
                if (ce_stage(ce)) {
                        struct combine_diff_path *dpath;
+                       struct diff_filepair *pair;
+                       unsigned int wt_mode = 0;
                        int num_compare_stages = 0;
                        size_t path_len;
 
@@ -130,7 +132,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
                        changed = check_removed(ce, &st);
                        if (!changed)
-                               dpath->mode = ce_mode_from_stat(ce, st.st_mode);
+                               wt_mode = ce_mode_from_stat(ce, st.st_mode);
                        else {
                                if (changed < 0) {
                                        perror(ce->name);
@@ -138,7 +140,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                                }
                                if (silent_on_removed)
                                        continue;
+                               wt_mode = 0;
                        }
+                       dpath->mode = wt_mode;
 
                        while (i < entries) {
                                struct cache_entry *nce = active_cache[i];
@@ -184,7 +188,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                         * Show the diff for the 'ce' if we found the one
                         * from the desired stage.
                         */
-                       diff_unmerge(&revs->diffopt, ce->name, 0, null_sha1);
+                       pair = diff_unmerge(&revs->diffopt, ce->name);
+                       if (wt_mode)
+                               pair->two->mode = wt_mode;
                        if (ce_stage(ce) != diff_unmerged_stage)
                                continue;
                }
@@ -373,8 +379,9 @@ static void do_oneway_diff(struct unpack_trees_options *o,
        match_missing = !revs->ignore_merges;
 
        if (cached && idx && ce_stage(idx)) {
-               diff_unmerge(&revs->diffopt, idx->name, idx->ce_mode,
-                            idx->sha1);
+               struct diff_filepair *pair;
+               pair = diff_unmerge(&revs->diffopt, idx->name);
+               fill_filespec(pair->one, idx->sha1, idx->ce_mode);
                return;
        }
 
diff --git a/diff.c b/diff.c
index 9fa841010cc21bebc464926b15232b2aace0f5ba..ba5f7aa2173a7494b56395bfd88ab6228b5ed1fe 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -31,6 +31,7 @@ static const char *external_diff_cmd_cfg;
 int diff_auto_refresh_index = 1;
 static int diff_mnemonic_prefix;
 static int diff_no_prefix;
+static int diff_dirstat_permille_default = 30;
 static struct diff_options default_diff_options;
 
 static char diff_colors[][COLOR_MAXLEN] = {
@@ -66,6 +67,58 @@ static int parse_diff_color_slot(const char *var, int ofs)
        return -1;
 }
 
+static int parse_dirstat_params(struct diff_options *options, const char *params,
+                               struct strbuf *errmsg)
+{
+       const char *p = params;
+       int p_len, ret = 0;
+
+       while (*p) {
+               p_len = strchrnul(p, ',') - p;
+               if (!memcmp(p, "changes", p_len)) {
+                       DIFF_OPT_CLR(options, DIRSTAT_BY_LINE);
+                       DIFF_OPT_CLR(options, DIRSTAT_BY_FILE);
+               } else if (!memcmp(p, "lines", p_len)) {
+                       DIFF_OPT_SET(options, DIRSTAT_BY_LINE);
+                       DIFF_OPT_CLR(options, DIRSTAT_BY_FILE);
+               } else if (!memcmp(p, "files", p_len)) {
+                       DIFF_OPT_CLR(options, DIRSTAT_BY_LINE);
+                       DIFF_OPT_SET(options, DIRSTAT_BY_FILE);
+               } else if (!memcmp(p, "noncumulative", p_len)) {
+                       DIFF_OPT_CLR(options, DIRSTAT_CUMULATIVE);
+               } else if (!memcmp(p, "cumulative", p_len)) {
+                       DIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);
+               } else if (isdigit(*p)) {
+                       char *end;
+                       int permille = strtoul(p, &end, 10) * 10;
+                       if (*end == '.' && isdigit(*++end)) {
+                               /* only use first digit */
+                               permille += *end - '0';
+                               /* .. and ignore any further digits */
+                               while (isdigit(*++end))
+                                       ; /* nothing */
+                       }
+                       if (end - p == p_len)
+                               options->dirstat_permille = permille;
+                       else {
+                               strbuf_addf(errmsg, _("  Failed to parse dirstat cut-off percentage '%.*s'\n"),
+                                           p_len, p);
+                               ret++;
+                       }
+               } else {
+                       strbuf_addf(errmsg, _("  Unknown dirstat parameter '%.*s'\n"),
+                                   p_len, p);
+                       ret++;
+               }
+
+               p += p_len;
+
+               if (*p)
+                       p++; /* more parameters, swallow separator */
+       }
+       return ret;
+}
+
 static int git_config_rename(const char *var, const char *value)
 {
        if (!value)
@@ -145,6 +198,17 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (!strcmp(var, "diff.dirstat")) {
+               struct strbuf errmsg = STRBUF_INIT;
+               default_diff_options.dirstat_permille = diff_dirstat_permille_default;
+               if (parse_dirstat_params(&default_diff_options, value, &errmsg))
+                       warning(_("Found errors in 'diff.dirstat' config variable:\n%s"),
+                               errmsg.buf);
+               strbuf_release(&errmsg);
+               diff_dirstat_permille_default = default_diff_options.dirstat_permille;
+               return 0;
+       }
+
        if (!prefixcmp(var, "submodule."))
                return parse_submodule_config_option(var, value);
 
@@ -581,11 +645,14 @@ static void emit_rewrite_diff(const char *name_a,
                line_prefix, metainfo, a_name.buf, name_a_tab, reset,
                line_prefix, metainfo, b_name.buf, name_b_tab, reset,
                line_prefix, fraginfo);
-       print_line_count(o->file, lc_a);
+       if (!o->irreversible_delete)
+               print_line_count(o->file, lc_a);
+       else
+               fprintf(o->file, "?,?");
        fprintf(o->file, " +");
        print_line_count(o->file, lc_b);
        fprintf(o->file, " @@%s\n", reset);
-       if (lc_a)
+       if (lc_a && !o->irreversible_delete)
                emit_rewrite_lines(&ecbdata, '-', data_one, size_one);
        if (lc_b)
                emit_rewrite_lines(&ecbdata, '+', data_two, size_two);
@@ -1452,7 +1519,7 @@ struct dirstat_file {
 
 struct dirstat_dir {
        struct dirstat_file *files;
-       int alloc, nr, percent, cumulative;
+       int alloc, nr, permille, cumulative;
 };
 
 static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
@@ -1499,12 +1566,11 @@ static long gather_dirstat(struct diff_options *opt, struct dirstat_dir *dir,
         *    under this directory (sources == 1).
         */
        if (baselen && sources != 1) {
-               int permille = this_dir * 1000 / changed;
-               if (permille) {
-                       int percent = permille / 10;
-                       if (percent >= dir->percent) {
+               if (this_dir) {
+                       int permille = this_dir * 1000 / changed;
+                       if (permille >= dir->permille) {
                                fprintf(opt->file, "%s%4d.%01d%% %.*s\n", line_prefix,
-                                       percent, permille % 10, baselen, base);
+                                       permille / 10, permille % 10, baselen, base);
                                if (!dir->cumulative)
                                        return 0;
                        }
@@ -1530,7 +1596,7 @@ static void show_dirstat(struct diff_options *options)
        dir.files = NULL;
        dir.alloc = 0;
        dir.nr = 0;
-       dir.percent = options->dirstat_percent;
+       dir.permille = options->dirstat_permille;
        dir.cumulative = DIFF_OPT_TST(options, DIRSTAT_CUMULATIVE);
 
        changed = 0;
@@ -1538,8 +1604,36 @@ static void show_dirstat(struct diff_options *options)
                struct diff_filepair *p = q->queue[i];
                const char *name;
                unsigned long copied, added, damage;
+               int content_changed;
+
+               name = p->two->path ? p->two->path : p->one->path;
+
+               if (p->one->sha1_valid && p->two->sha1_valid)
+                       content_changed = hashcmp(p->one->sha1, p->two->sha1);
+               else
+                       content_changed = 1;
+
+               if (!content_changed) {
+                       /*
+                        * The SHA1 has not changed, so pre-/post-content is
+                        * identical. We can therefore skip looking at the
+                        * file contents altogether.
+                        */
+                       damage = 0;
+                       goto found_damage;
+               }
 
-               name = p->one->path ? p->one->path : p->two->path;
+               if (DIFF_OPT_TST(options, DIRSTAT_BY_FILE)) {
+                       /*
+                        * In --dirstat-by-file mode, we don't really need to
+                        * look at the actual file contents at all.
+                        * The fact that the SHA1 changed is enough for us to
+                        * add this file to the list of results
+                        * (with each file contributing equal damage).
+                        */
+                       damage = 1;
+                       goto found_damage;
+               }
 
                if (DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
                        diff_populate_filespec(p->one, 0);
@@ -1563,14 +1657,18 @@ static void show_dirstat(struct diff_options *options)
                /*
                 * Original minus copied is the removed material,
                 * added is the new material.  They are both damages
-                * made to the preimage. In --dirstat-by-file mode, count
-                * damaged files, not damaged lines. This is done by
-                * counting only a single damaged line per file.
+                * made to the preimage.
+                * If the resulting damage is zero, we know that
+                * diffcore_count_changes() considers the two entries to
+                * be identical, but since content_changed is true, we
+                * know that there must have been _some_ kind of change,
+                * so we force all entries to have damage > 0.
                 */
                damage = (p->one->size - copied) + added;
-               if (DIFF_OPT_TST(options, DIRSTAT_BY_FILE) && damage > 0)
+               if (!damage)
                        damage = 1;
 
+found_damage:
                ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
                dir.files[dir.nr].name = name;
                dir.files[dir.nr].changed = damage;
@@ -1587,6 +1685,50 @@ static void show_dirstat(struct diff_options *options)
        gather_dirstat(options, &dir, changed, "", 0);
 }
 
+static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *options)
+{
+       int i;
+       unsigned long changed;
+       struct dirstat_dir dir;
+
+       if (data->nr == 0)
+               return;
+
+       dir.files = NULL;
+       dir.alloc = 0;
+       dir.nr = 0;
+       dir.permille = options->dirstat_permille;
+       dir.cumulative = DIFF_OPT_TST(options, DIRSTAT_CUMULATIVE);
+
+       changed = 0;
+       for (i = 0; i < data->nr; i++) {
+               struct diffstat_file *file = data->files[i];
+               unsigned long damage = file->added + file->deleted;
+               if (file->is_binary)
+                       /*
+                        * binary files counts bytes, not lines. Must find some
+                        * way to normalize binary bytes vs. textual lines.
+                        * The following heuristic assumes that there are 64
+                        * bytes per "line".
+                        * This is stupid and ugly, but very cheap...
+                        */
+                       damage = (damage + 63) / 64;
+               ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
+               dir.files[dir.nr].name = file->name;
+               dir.files[dir.nr].changed = damage;
+               changed += damage;
+               dir.nr++;
+       }
+
+       /* This can happen even with many files, if everything was renames */
+       if (!changed)
+               return;
+
+       /* Show all directories with more than x% of the changes */
+       qsort(dir.files, dir.nr, sizeof(dir.files[0]), dirstat_compare);
+       gather_dirstat(options, &dir, changed, "", 0);
+}
+
 static void free_diffstat_info(struct diffstat_t *diffstat)
 {
        int i;
@@ -1949,7 +2091,11 @@ static void builtin_diff(const char *name_a,
                }
        }
 
-       if (!DIFF_OPT_TST(o, TEXT) &&
+       if (o->irreversible_delete && lbl[1][0] == '/') {
+               fprintf(o->file, "%s", header.buf);
+               strbuf_reset(&header);
+               goto free_ab_and_return;
+       } else if (!DIFF_OPT_TST(o, TEXT) &&
            ( (!textconv_one && diff_filespec_is_binary(one)) ||
              (!textconv_two && diff_filespec_is_binary(two)) )) {
                if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
@@ -1969,8 +2115,7 @@ static void builtin_diff(const char *name_a,
                        fprintf(o->file, "%sBinary files %s and %s differ\n",
                                line_prefix, lbl[0], lbl[1]);
                o->found_changes = 1;
-       }
-       else {
+       } else {
                /* Crazy xdl interfaces.. */
                const char *diffopts = getenv("GIT_DIFF_OPTS");
                xpparam_t xpp;
@@ -2853,7 +2998,7 @@ void diff_setup(struct diff_options *options)
        options->line_termination = '\n';
        options->break_opt = -1;
        options->rename_limit = -1;
-       options->dirstat_percent = 3;
+       options->dirstat_permille = diff_dirstat_permille_default;
        options->context = 3;
 
        options->change = diff_change;
@@ -3111,6 +3256,21 @@ static int stat_opt(struct diff_options *options, const char **av)
        return argcount;
 }
 
+static int parse_dirstat_opt(struct diff_options *options, const char *params)
+{
+       struct strbuf errmsg = STRBUF_INIT;
+       if (parse_dirstat_params(options, params, &errmsg))
+               die(_("Failed to parse --dirstat/-X option parameter:\n%s"),
+                   errmsg.buf);
+       strbuf_release(&errmsg);
+       /*
+        * The caller knows a dirstat-related option is given from the command
+        * line; allow it to say "return this_function();"
+        */
+       options->output_format |= DIFF_FORMAT_DIRSTAT;
+       return 1;
+}
+
 int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 {
        const char *arg = av[0];
@@ -3130,15 +3290,19 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->output_format |= DIFF_FORMAT_NUMSTAT;
        else if (!strcmp(arg, "--shortstat"))
                options->output_format |= DIFF_FORMAT_SHORTSTAT;
-       else if (opt_arg(arg, 'X', "dirstat", &options->dirstat_percent))
-               options->output_format |= DIFF_FORMAT_DIRSTAT;
-       else if (!strcmp(arg, "--cumulative")) {
-               options->output_format |= DIFF_FORMAT_DIRSTAT;
-               DIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);
-       } else if (opt_arg(arg, 0, "dirstat-by-file",
-                          &options->dirstat_percent)) {
-               options->output_format |= DIFF_FORMAT_DIRSTAT;
-               DIFF_OPT_SET(options, DIRSTAT_BY_FILE);
+       else if (!strcmp(arg, "-X") || !strcmp(arg, "--dirstat"))
+               return parse_dirstat_opt(options, "");
+       else if (!prefixcmp(arg, "-X"))
+               return parse_dirstat_opt(options, arg + 2);
+       else if (!prefixcmp(arg, "--dirstat="))
+               return parse_dirstat_opt(options, arg + 10);
+       else if (!strcmp(arg, "--cumulative"))
+               return parse_dirstat_opt(options, "cumulative");
+       else if (!strcmp(arg, "--dirstat-by-file"))
+               return parse_dirstat_opt(options, "files");
+       else if (!prefixcmp(arg, "--dirstat-by-file=")) {
+               parse_dirstat_opt(options, "files");
+               return parse_dirstat_opt(options, arg + 18);
        }
        else if (!strcmp(arg, "--check"))
                options->output_format |= DIFF_FORMAT_CHECKDIFF;
@@ -3168,6 +3332,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                        return error("invalid argument to -M: %s", arg+2);
                options->detect_rename = DIFF_DETECT_RENAME;
        }
+       else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
+               options->irreversible_delete = 1;
+       }
        else if (!prefixcmp(arg, "-C") || !prefixcmp(arg, "--find-copies=") ||
                 !strcmp(arg, "--find-copies")) {
                if (options->detect_rename == DIFF_DETECT_COPY)
@@ -3955,11 +4122,34 @@ static int is_summary_empty(const struct diff_queue_struct *q)
        return 1;
 }
 
+static const char rename_limit_warning[] =
+"inexact rename detection was skipped due to too many files.";
+
+static const char degrade_cc_to_c_warning[] =
+"only found copies from modified paths due to too many files.";
+
+static const char rename_limit_advice[] =
+"you may want to set your %s variable to at least "
+"%d and retry the command.";
+
+void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc)
+{
+       if (degraded_cc)
+               warning(degrade_cc_to_c_warning);
+       else if (needed)
+               warning(rename_limit_warning);
+       else
+               return;
+       if (0 < needed && needed < 32767)
+               warning(rename_limit_advice, varname, needed);
+}
+
 void diff_flush(struct diff_options *options)
 {
        struct diff_queue_struct *q = &diff_queued_diff;
        int i, output_format = options->output_format;
        int separator = 0;
+       int dirstat_by_line = 0;
 
        /*
         * Order: raw, stat, summary, patch
@@ -3980,7 +4170,11 @@ void diff_flush(struct diff_options *options)
                separator++;
        }
 
-       if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT)) {
+       if (output_format & DIFF_FORMAT_DIRSTAT && DIFF_OPT_TST(options, DIRSTAT_BY_LINE))
+               dirstat_by_line = 1;
+
+       if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT) ||
+           dirstat_by_line) {
                struct diffstat_t diffstat;
 
                memset(&diffstat, 0, sizeof(struct diffstat_t));
@@ -3995,10 +4189,12 @@ void diff_flush(struct diff_options *options)
                        show_stats(&diffstat, options);
                if (output_format & DIFF_FORMAT_SHORTSTAT)
                        show_shortstats(&diffstat, options);
+               if (output_format & DIFF_FORMAT_DIRSTAT)
+                       show_dirstat_by_line(&diffstat, options);
                free_diffstat_info(&diffstat);
                separator++;
        }
-       if (output_format & DIFF_FORMAT_DIRSTAT)
+       if ((output_format & DIFF_FORMAT_DIRSTAT) && !dirstat_by_line)
                show_dirstat(options);
 
        if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
@@ -4236,6 +4432,10 @@ void diffcore_std(struct diff_options *options)
 int diff_result_code(struct diff_options *opt, int status)
 {
        int result = 0;
+
+       diff_warn_rename_limit("diff.renamelimit",
+                              opt->needed_rename_limit,
+                              opt->degraded_cc_to_c);
        if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
            !(opt->output_format & DIFF_FORMAT_CHECKDIFF))
                return status;
@@ -4349,20 +4549,20 @@ void diff_change(struct diff_options *options,
                DIFF_OPT_SET(options, HAS_CHANGES);
 }
 
-void diff_unmerge(struct diff_options *options,
-                 const char *path,
-                 unsigned mode, const unsigned char *sha1)
+struct diff_filepair *diff_unmerge(struct diff_options *options, const char *path)
 {
+       struct diff_filepair *pair;
        struct diff_filespec *one, *two;
 
        if (options->prefix &&
            strncmp(path, options->prefix, options->prefix_length))
-               return;
+               return NULL;
 
        one = alloc_filespec(path);
        two = alloc_filespec(path);
-       fill_filespec(one, sha1, mode);
-       diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
+       pair = diff_queue(&diff_queued_diff, one, two);
+       pair->is_unmerged = 1;
+       return pair;
 }
 
 static char *run_textconv(const char *pgm, struct diff_filespec *spec,
diff --git a/diff.h b/diff.h
index 007a0554d4b252e83e98f5578758d51ec0c6e120..adb40ba273ffec74010a36e98a538fcc204919f1 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -78,6 +78,7 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
 #define DIFF_OPT_IGNORE_UNTRACKED_IN_SUBMODULES (1 << 25)
 #define DIFF_OPT_IGNORE_DIRTY_SUBMODULES (1 << 26)
 #define DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG (1 << 27)
+#define DIFF_OPT_DIRSTAT_BY_LINE     (1 << 28)
 
 #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)
 #define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)
@@ -104,6 +105,7 @@ struct diff_options {
        int interhunkcontext;
        int break_opt;
        int detect_rename;
+       int irreversible_delete;
        int skip_stat_unmatch;
        int line_termination;
        int output_format;
@@ -111,8 +113,9 @@ struct diff_options {
        int rename_score;
        int rename_limit;
        int needed_rename_limit;
+       int degraded_cc_to_c;
        int show_rename_progress;
-       int dirstat_percent;
+       int dirstat_permille;
        int setup;
        int abbrev;
        const char *prefix;
@@ -208,10 +211,7 @@ extern void diff_change(struct diff_options *,
                        const char *fullpath,
                        unsigned dirty_submodule1, unsigned dirty_submodule2);
 
-extern void diff_unmerge(struct diff_options *,
-                        const char *path,
-                        unsigned mode,
-                        const unsigned char *sha1);
+extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
 
 #define DIFF_SETUP_REVERSE             1
 #define DIFF_SETUP_USE_CACHE           2
@@ -273,6 +273,7 @@ extern void diffcore_fix_diff_index(struct diff_options *);
 
 extern int diff_queue_is_empty(void);
 extern void diff_flush(struct diff_options*);
+extern void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
 
 /* diff-raw status letters */
 #define DIFF_STATUS_ADDED              'A'
index d40e40a3ac9c919475d6157464fa906e37b0dd80..f639601c762ebbd12374fa739d1d63efaf265e2a 100644 (file)
@@ -55,22 +55,23 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
 
 /* Table of rename/copy src files */
 static struct diff_rename_src {
-       struct diff_filespec *one;
+       struct diff_filepair *p;
        unsigned short score; /* to remember the break score */
 } *rename_src;
 static int rename_src_nr, rename_src_alloc;
 
-static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
-                                                  unsigned short score)
+static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
 {
        int first, last;
+       struct diff_filespec *one = p->one;
+       unsigned short score = p->score;
 
        first = 0;
        last = rename_src_nr;
        while (last > first) {
                int next = (last + first) >> 1;
                struct diff_rename_src *src = &(rename_src[next]);
-               int cmp = strcmp(one->path, src->one->path);
+               int cmp = strcmp(one->path, src->p->one->path);
                if (!cmp)
                        return src;
                if (cmp < 0) {
@@ -90,7 +91,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
        if (first < rename_src_nr)
                memmove(rename_src + first + 1, rename_src + first,
                        (rename_src_nr - first - 1) * sizeof(*rename_src));
-       rename_src[first].one = one;
+       rename_src[first].p = p;
        rename_src[first].score = score;
        return &(rename_src[first]);
 }
@@ -205,7 +206,7 @@ static void record_rename_pair(int dst_index, int src_index, int score)
        if (rename_dst[dst_index].pair)
                die("internal error: dst already matched.");
 
-       src = rename_src[src_index].one;
+       src = rename_src[src_index].p->one;
        src->rename_used++;
        src->count++;
 
@@ -389,7 +390,7 @@ static int find_exact_renames(struct diff_options *options)
 
        init_hash(&file_table);
        for (i = 0; i < rename_src_nr; i++)
-               insert_file_table(&file_table, -1, i, rename_src[i].one);
+               insert_file_table(&file_table, -1, i, rename_src[i].p->one);
 
        for (i = 0; i < rename_dst_nr; i++)
                insert_file_table(&file_table, 1, i, rename_dst[i].two);
@@ -419,6 +420,55 @@ static void record_if_better(struct diff_score m[], struct diff_score *o)
                m[worst] = *o;
 }
 
+/*
+ * Returns:
+ * 0 if we are under the limit;
+ * 1 if we need to disable inexact rename detection;
+ * 2 if we would be under the limit if we were given -C instead of -C -C.
+ */
+static int too_many_rename_candidates(int num_create,
+                                     struct diff_options *options)
+{
+       int rename_limit = options->rename_limit;
+       int num_src = rename_src_nr;
+       int i;
+
+       options->needed_rename_limit = 0;
+
+       /*
+        * This basically does a test for the rename matrix not
+        * growing larger than a "rename_limit" square matrix, ie:
+        *
+        *    num_create * num_src > rename_limit * rename_limit
+        *
+        * but handles the potential overflow case specially (and we
+        * assume at least 32-bit integers)
+        */
+       if (rename_limit <= 0 || rename_limit > 32767)
+               rename_limit = 32767;
+       if ((num_create <= rename_limit || num_src <= rename_limit) &&
+           (num_create * num_src <= rename_limit * rename_limit))
+               return 0;
+
+       options->needed_rename_limit =
+               num_src > num_create ? num_src : num_create;
+
+       /* Are we running under -C -C? */
+       if (!DIFF_OPT_TST(options, FIND_COPIES_HARDER))
+               return 1;
+
+       /* Would we bust the limit if we were running under -C? */
+       for (num_src = i = 0; i < rename_src_nr; i++) {
+               if (diff_unmodified_pair(rename_src[i].p))
+                       continue;
+               num_src++;
+       }
+       if ((num_create <= rename_limit || num_src <= rename_limit) &&
+           (num_create * num_src <= rename_limit * rename_limit))
+               return 2;
+       return 1;
+}
+
 static int find_renames(struct diff_score *mx, int dst_cnt, int minimum_score, int copies)
 {
        int count = 0, i;
@@ -432,7 +482,7 @@ static int find_renames(struct diff_score *mx, int dst_cnt, int minimum_score, i
                dst = &rename_dst[mx[i].dst];
                if (dst->pair)
                        continue; /* already done, either exact or fuzzy. */
-               if (!copies && rename_src[mx[i].src].one->rename_used)
+               if (!copies && rename_src[mx[i].src].p->one->rename_used)
                        continue;
                record_rename_pair(mx[i].dst, mx[i].src, mx[i].score);
                count++;
@@ -444,12 +494,11 @@ void diffcore_rename(struct diff_options *options)
 {
        int detect_rename = options->detect_rename;
        int minimum_score = options->rename_score;
-       int rename_limit = options->rename_limit;
        struct diff_queue_struct *q = &diff_queued_diff;
        struct diff_queue_struct outq;
        struct diff_score *mx;
-       int i, j, rename_count;
-       int num_create, num_src, dst_cnt;
+       int i, j, rename_count, skip_unmodified = 0;
+       int num_create, dst_cnt;
        struct progress *progress = NULL;
 
        if (!minimum_score)
@@ -466,7 +515,7 @@ void diffcore_rename(struct diff_options *options)
                        else
                                locate_rename_dst(p->two, 1);
                }
-               else if (!DIFF_FILE_VALID(p->two)) {
+               else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
                        /*
                         * If the source is a broken "delete", and
                         * they did not really want to get broken,
@@ -476,7 +525,7 @@ void diffcore_rename(struct diff_options *options)
                         */
                        if (p->broken_pair && !p->score)
                                p->one->rename_used++;
-                       register_rename_src(p->one, p->score);
+                       register_rename_src(p);
                }
                else if (detect_rename == DIFF_DETECT_COPY) {
                        /*
@@ -484,7 +533,7 @@ void diffcore_rename(struct diff_options *options)
                         * one, to indicate ourselves as a user.
                         */
                        p->one->rename_used++;
-                       register_rename_src(p->one, p->score);
+                       register_rename_src(p);
                }
        }
        if (rename_dst_nr == 0 || rename_src_nr == 0)
@@ -505,29 +554,20 @@ void diffcore_rename(struct diff_options *options)
         * files still remain as options for rename/copies!)
         */
        num_create = (rename_dst_nr - rename_count);
-       num_src = rename_src_nr;
 
        /* All done? */
        if (!num_create)
                goto cleanup;
 
-       /*
-        * This basically does a test for the rename matrix not
-        * growing larger than a "rename_limit" square matrix, ie:
-        *
-        *    num_create * num_src > rename_limit * rename_limit
-        *
-        * but handles the potential overflow case specially (and we
-        * assume at least 32-bit integers)
-        */
-       options->needed_rename_limit = 0;
-       if (rename_limit <= 0 || rename_limit > 32767)
-               rename_limit = 32767;
-       if ((num_create > rename_limit && num_src > rename_limit) ||
-           (num_create * num_src > rename_limit * rename_limit)) {
-               options->needed_rename_limit =
-                       num_src > num_create ? num_src : num_create;
+       switch (too_many_rename_candidates(num_create, options)) {
+       case 1:
                goto cleanup;
+       case 2:
+               options->degraded_cc_to_c = 1;
+               skip_unmodified = 1;
+               break;
+       default:
+               break;
        }
 
        if (options->show_rename_progress) {
@@ -549,8 +589,13 @@ void diffcore_rename(struct diff_options *options)
                        m[j].dst = -1;
 
                for (j = 0; j < rename_src_nr; j++) {
-                       struct diff_filespec *one = rename_src[j].one;
+                       struct diff_filespec *one = rename_src[j].p->one;
                        struct diff_score this_src;
+
+                       if (skip_unmodified &&
+                           diff_unmodified_pair(rename_src[j].p))
+                               continue;
+
                        this_src.score = estimate_similarity(one, two,
                                                             minimum_score);
                        this_src.name_score = basename_same(one, two);
@@ -586,7 +631,10 @@ void diffcore_rename(struct diff_options *options)
                struct diff_filepair *p = q->queue[i];
                struct diff_filepair *pair_to_free = NULL;
 
-               if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
+               if (DIFF_PAIR_UNMERGED(p)) {
+                       diff_q(&outq, p);
+               }
+               else if (!DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
                        /*
                         * Creation
                         *
diff --git a/dir.c b/dir.c
index 532bcb65b523223b66efd3f4e458f62fcbe0d6a5..08281d2ef74ea7790913e71f08d00299a1825765 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -230,7 +230,7 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
                        return MATCHED_RECURSIVELY;
        }
 
-       if (item->has_wildcard && !fnmatch(match, name, 0))
+       if (item->use_wildcard && !fnmatch(match, name, 0))
                return MATCHED_FNMATCH;
 
        return 0;
@@ -1105,57 +1105,45 @@ int file_exists(const char *f)
 }
 
 /*
- * get_relative_cwd() gets the prefix of the current working directory
- * relative to 'dir'.  If we are not inside 'dir', it returns NULL.
- *
- * As a convenience, it also returns NULL if 'dir' is already NULL.  The
- * reason for this behaviour is that it is natural for functions returning
- * directory names to return NULL to say "this directory does not exist"
- * or "this directory is invalid".  These cases are usually handled the
- * same as if the cwd is not inside 'dir' at all, so get_relative_cwd()
- * returns NULL for both of them.
- *
- * Most notably, get_relative_cwd(buffer, size, get_git_work_tree())
- * unifies the handling of "outside work tree" with "no work tree at all".
+ * Given two normalized paths (a trailing slash is ok), if subdir is
+ * outside dir, return -1.  Otherwise return the offset in subdir that
+ * can be used as relative path to dir.
  */
-char *get_relative_cwd(char *buffer, int size, const char *dir)
+int dir_inside_of(const char *subdir, const char *dir)
 {
-       char *cwd = buffer;
-
-       if (!dir)
-               return NULL;
-       if (!getcwd(buffer, size))
-               die_errno("can't find the current directory");
+       int offset = 0;
 
-       if (!is_absolute_path(dir))
-               dir = real_path(dir);
+       assert(dir && subdir && *dir && *subdir);
 
-       while (*dir && *dir == *cwd) {
+       while (*dir && *subdir && *dir == *subdir) {
                dir++;
-               cwd++;
-       }
-       if (*dir)
-               return NULL;
-       switch (*cwd) {
-       case '\0':
-               return cwd;
-       case '/':
-               return cwd + 1;
-       default:
-               /*
-                * dir can end with a path separator when it's root
-                * directory. Return proper prefix in that case.
-                */
-               if (dir[-1] == '/')
-                       return cwd;
-               return NULL;
+               subdir++;
+               offset++;
        }
+
+       /* hel[p]/me vs hel[l]/yeah */
+       if (*dir && *subdir)
+               return -1;
+
+       if (!*subdir)
+               return !*dir ? offset : -1; /* same dir */
+
+       /* foo/[b]ar vs foo/[] */
+       if (is_dir_sep(dir[-1]))
+               return is_dir_sep(subdir[-1]) ? offset : -1;
+
+       /* foo[/]bar vs foo[] */
+       return is_dir_sep(*subdir) ? offset + 1 : -1;
 }
 
 int is_inside_dir(const char *dir)
 {
-       char buffer[PATH_MAX];
-       return get_relative_cwd(buffer, sizeof(buffer), dir) != NULL;
+       char cwd[PATH_MAX];
+       if (!dir)
+               return 0;
+       if (!getcwd(cwd, sizeof(cwd)))
+               die_errno("can't find the current directory");
+       return dir_inside_of(cwd, dir) >= 0;
 }
 
 int is_empty_dir(const char *path)
@@ -1286,8 +1274,8 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
 
                item->match = path;
                item->len = strlen(path);
-               item->has_wildcard = !no_wildcard(path);
-               if (item->has_wildcard)
+               item->use_wildcard = !no_wildcard(path);
+               if (item->use_wildcard)
                        pathspec->has_wildcard = 1;
        }
 
diff --git a/dir.h b/dir.h
index aa511da77b0ec54cbdbd3786faad0c1285df7182..433b5b4cd4c51e9b7557d3056570ed46b7ceba92 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -85,8 +85,8 @@ extern void add_exclude(const char *string, const char *base,
 extern void free_excludes(struct exclude_list *el);
 extern int file_exists(const char *);
 
-extern char *get_relative_cwd(char *buffer, int size, const char *dir);
 extern int is_inside_dir(const char *dir);
+extern int dir_inside_of(const char *subdir, const char *dir);
 
 static inline int is_dot_or_dotdot(const char *name)
 {
index 3e4e655bb989076e4bb6311fa4fe41320c344194..78d978684da2e2b79340c138e1b6300100df1221 100644 (file)
@@ -3135,11 +3135,11 @@ static int parse_one_feature(const char *feature, int from_stream)
                option_export_marks(feature + 13);
        } else if (!strcmp(feature, "cat-blob")) {
                ; /* Don't die - this feature is supported */
-       } else if (!prefixcmp(feature, "relative-marks")) {
+       } else if (!strcmp(feature, "relative-marks")) {
                relative_marks_paths = 1;
-       } else if (!prefixcmp(feature, "no-relative-marks")) {
+       } else if (!strcmp(feature, "no-relative-marks")) {
                relative_marks_paths = 0;
-       } else if (!prefixcmp(feature, "force")) {
+       } else if (!strcmp(feature, "force")) {
                force_update = 1;
        } else if (!strcmp(feature, "notes") || !strcmp(feature, "ls")) {
                ; /* do nothing; we have the feature */
index a329c5a1f8c3b63ee6976a8e0e3903a11783324b..4f08fe704bbaff64613ab07630a71da8bf8bbca0 100755 (executable)
@@ -705,7 +705,7 @@ sub add_untracked_cmd {
 sub run_git_apply {
        my $cmd = shift;
        my $fh;
-       open $fh, '| git ' . $cmd;
+       open $fh, '| git ' . $cmd . " --recount --allow-overlap";
        print $fh @_;
        return close $fh;
 }
@@ -1050,7 +1050,7 @@ EOF
 
 sub diff_applies {
        my $fh;
-       return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --recount --check',
+       return run_git_apply($patch_mode_flavour{APPLY_CHECK} . ' --check',
                             map { @{$_->{TEXT}} } @_);
 }
 
@@ -1139,7 +1139,7 @@ EOF
 
 sub apply_patch {
        my $cmd = shift;
-       my $ret = run_git_apply $cmd . ' --recount', @_;
+       my $ret = run_git_apply $cmd, @_;
        if (!$ret) {
                print STDERR @_;
        }
@@ -1148,17 +1148,17 @@ sub apply_patch {
 
 sub apply_patch_for_checkout_commit {
        my $reverse = shift;
-       my $applies_index = run_git_apply 'apply '.$reverse.' --cached --recount --check', @_;
-       my $applies_worktree = run_git_apply 'apply '.$reverse.' --recount --check', @_;
+       my $applies_index = run_git_apply 'apply '.$reverse.' --cached --check', @_;
+       my $applies_worktree = run_git_apply 'apply '.$reverse.' --check', @_;
 
        if ($applies_worktree && $applies_index) {
-               run_git_apply 'apply '.$reverse.' --cached --recount', @_;
-               run_git_apply 'apply '.$reverse.' --recount', @_;
+               run_git_apply 'apply '.$reverse.' --cached', @_;
+               run_git_apply 'apply '.$reverse, @_;
                return 1;
        } elsif (!$applies_index) {
                print colored $error_color, "The selected hunks do not apply to the index!\n";
                if (prompt_yesno "Apply them to the worktree anyway? ") {
-                       return run_git_apply 'apply '.$reverse.' --recount', @_;
+                       return run_git_apply 'apply '.$reverse, @_;
                } else {
                        print colored $error_color, "Nothing was applied.\n";
                        return 0;
@@ -1366,14 +1366,13 @@ sub patch_update_file {
                                next;
                        }
                        elsif ($line =~ /^q/i) {
-                               while ($ix < $num) {
-                                       if (!defined $hunk[$ix]{USE}) {
-                                               $hunk[$ix]{USE} = 0;
+                               for ($i = 0; $i < $num; $i++) {
+                                       if (!defined $hunk[$i]{USE}) {
+                                               $hunk[$i]{USE} = 0;
                                        }
-                                       $ix++;
                                }
                                $quit = 1;
-                               next;
+                               last;
                        }
                        elsif ($line =~ m|^/(.*)|) {
                                my $regex = $1;
index bbf327f3e891cacdd14c0b18b51702ce14b2b6df..8d41610bcf260545bcc5b6a8c30b43d427c70491 100755 (executable)
@@ -227,6 +227,31 @@ sub new {
        return $self;
 }
 
+sub find_password_entry {
+       my ($cvspass, @cvsroot) = @_;
+       my ($file, $delim) = @$cvspass;
+       my $pass;
+       local ($_);
+
+       if (open(my $fh, $file)) {
+               # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
+               CVSPASSFILE:
+               while (<$fh>) {
+                       chomp;
+                       s/^\/\d+\s+//;
+                       my ($w, $p) = split($delim,$_,2);
+                       for my $cvsroot (@cvsroot) {
+                               if ($w eq $cvsroot) {
+                                       $pass = $p;
+                                       last CVSPASSFILE;
+                               }
+                       }
+               }
+               close($fh);
+       }
+       return $pass;
+}
+
 sub conn {
        my $self = shift;
        my $repo = $self->{'fullrep'};
@@ -259,19 +284,23 @@ sub conn {
                if ($pass) {
                        $pass = $self->_scramble($pass);
                } else {
-                       open(H,$ENV{'HOME'}."/.cvspass") and do {
-                               # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
-                               while (<H>) {
-                                       chomp;
-                                       s/^\/\d+\s+//;
-                                       my ($w,$p) = split(/\s/,$_,2);
-                                       if ($w eq $rr or $w eq $rr2) {
-                                               $pass = $p;
-                                               last;
-                                       }
+                       my @cvspass = ([$ENV{'HOME'}."/.cvspass", qr/\s/],
+                                      [$ENV{'HOME'}."/.cvs/cvspass", qr/=/]);
+                       my @loc = ();
+                       foreach my $cvspass (@cvspass) {
+                               my $p = find_password_entry($cvspass, $rr, $rr2);
+                               if ($p) {
+                                       push @loc, $cvspass->[0];
+                                       $pass = $p;
                                }
-                       };
-                       $pass = "A" unless $pass;
+                       }
+
+                       if (1 < @loc) {
+                               die("Multiple cvs password files have ".
+                                   "entries for CVSROOT $opt_d: @loc");
+                       } elsif (!$pass) {
+                               $pass = "A";
+                       }
                }
 
                my ($s, $rep);
index b86402afa5d079df8d1cf6eebb15e5727cc8a5de..7aeb96952f668baef2fd18383806e13a20415f19 100755 (executable)
@@ -22,6 +22,11 @@ LONG_USAGE="Usage: git merge-one-file $USAGE
 
 Blob ids and modes should be empty for missing files."
 
+SUBDIRECTORY_OK=Yes
+. git-sh-setup
+cd_to_toplevel
+require_work_tree
+
 if ! test "$#" -eq 7
 then
        echo "$LONG_USAGE"
@@ -132,7 +137,7 @@ case "${1:-.}${2:-.}${3:-.}" in
 
        # Create the working tree file, using "our tree" version from the
        # index, and then store the result of the merge.
-       git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4"
+       git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4" || exit 1
        rm -f -- "$orig" "$src1" "$src2"
 
        if [ "$6" != "$7" ]; then
index fb3f52ba2507b4fb78db150b5c183f24bd2c57c1..4db9212331259664732f031438b7b87b7a10244f 100644 (file)
@@ -258,12 +258,9 @@ run_merge_tool () {
                ;;
        p4merge)
                if merge_mode; then
-                   touch "$BACKUP"
-                       if $base_present; then
-                               "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
-                       else
-                               "$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
-                       fi
+                       touch "$BACKUP"
+                       $base_present || >"$BASE"
+                       "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
                        check_unchanged
                else
                        "$merge_tool_path" "$LOCAL" "$REMOTE"
index bacbda2bb75854235b912903c7e45fc94d38e719..3aab5aae844b963fc4178675a56da20e02488dfd 100755 (executable)
@@ -21,6 +21,10 @@ is_symlink () {
     test "$1" = 120000
 }
 
+is_submodule () {
+    test "$1" = 160000
+}
+
 local_present () {
     test -n "$local_mode"
 }
@@ -35,7 +39,8 @@ base_present () {
 
 cleanup_temp_files () {
     if test "$1" = --save-backup ; then
-       mv -- "$BACKUP" "$MERGED.orig"
+       rm -rf -- "$MERGED.orig"
+       test -e "$BACKUP" && mv -- "$BACKUP" "$MERGED.orig"
        rm -f -- "$LOCAL" "$REMOTE" "$BASE"
     else
        rm -f -- "$LOCAL" "$REMOTE" "$BASE" "$BACKUP"
@@ -52,11 +57,13 @@ describe_file () {
        echo "deleted"
     elif is_symlink "$mode" ; then
        echo "a symbolic link -> '$(cat "$file")'"
+    elif is_submodule "$mode" ; then
+       echo "submodule commit $file"
     else
        if base_present; then
-           echo "modified"
+           echo "modified file"
        else
-           echo "created"
+           echo "created file"
        fi
     fi
 }
@@ -112,6 +119,67 @@ resolve_deleted_merge () {
        done
 }
 
+resolve_submodule_merge () {
+    while true; do
+       printf "Use (l)ocal or (r)emote, or (a)bort? "
+       read ans
+       case "$ans" in
+           [lL]*)
+               if ! local_present; then
+                   if test -n "$(git ls-tree HEAD -- "$MERGED")"; then
+                       # Local isn't present, but it's a subdirectory
+                       git ls-tree --full-name -r HEAD -- "$MERGED" | git update-index --index-info || exit $?
+                   else
+                       test -e "$MERGED" && mv -- "$MERGED" "$BACKUP"
+                       git update-index --force-remove "$MERGED"
+                       cleanup_temp_files --save-backup
+                   fi
+               elif is_submodule "$local_mode"; then
+                   stage_submodule "$MERGED" "$local_sha1"
+               else
+                   git checkout-index -f --stage=2 -- "$MERGED"
+                   git add -- "$MERGED"
+               fi
+               return 0
+               ;;
+           [rR]*)
+               if ! remote_present; then
+                   if test -n "$(git ls-tree MERGE_HEAD -- "$MERGED")"; then
+                       # Remote isn't present, but it's a subdirectory
+                       git ls-tree --full-name -r MERGE_HEAD -- "$MERGED" | git update-index --index-info || exit $?
+                   else
+                       test -e "$MERGED" && mv -- "$MERGED" "$BACKUP"
+                       git update-index --force-remove "$MERGED"
+                   fi
+               elif is_submodule "$remote_mode"; then
+                   ! is_submodule "$local_mode" && test -e "$MERGED" && mv -- "$MERGED" "$BACKUP"
+                   stage_submodule "$MERGED" "$remote_sha1"
+               else
+                   test -e "$MERGED" && mv -- "$MERGED" "$BACKUP"
+                   git checkout-index -f --stage=3 -- "$MERGED"
+                   git add -- "$MERGED"
+               fi
+               cleanup_temp_files --save-backup
+               return 0
+               ;;
+           [aA]*)
+               return 1
+               ;;
+           esac
+       done
+}
+
+stage_submodule () {
+    path="$1"
+    submodule_sha1="$2"
+    mkdir -p "$path" || die "fatal: unable to create directory for module at $path"
+    # Find $path relative to work tree
+    work_tree_root=$(cd_to_toplevel && pwd)
+    work_rel_path=$(cd "$path" && GIT_WORK_TREE="${work_tree_root}" git rev-parse --show-prefix)
+    test -n "$work_rel_path" || die "fatal: unable to get path of module $path relative to work tree"
+    git update-index --add --replace --cacheinfo 160000 "$submodule_sha1" "${work_rel_path%/}" || die
+}
+
 checkout_staged_file () {
     tmpfile=$(expr "$(git checkout-index --temp --stage="$1" "$2")" : '\([^    ]*\)    ')
 
@@ -139,13 +207,23 @@ merge_file () {
     REMOTE="./$MERGED.REMOTE.$ext"
     BASE="./$MERGED.BASE.$ext"
 
-    mv -- "$MERGED" "$BACKUP"
-    cp -- "$BACKUP" "$MERGED"
-
     base_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==1) print $1;}')
     local_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}')
     remote_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}')
 
+    if is_submodule "$local_mode" || is_submodule "$remote_mode"; then
+       echo "Submodule merge conflict for '$MERGED':"
+       local_sha1=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $2;}')
+       remote_sha1=$(git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $2;}')
+       describe_file "$local_mode" "local" "$local_sha1"
+       describe_file "$remote_mode" "remote" "$remote_sha1"
+       resolve_submodule_merge
+       return
+    fi
+
+    mv -- "$MERGED" "$BACKUP"
+    cp -- "$BACKUP" "$MERGED"
+
     base_present   && checkout_staged_file 1 "$MERGED" "$BASE"
     local_present  && checkout_staged_file 2 "$MERGED" "$LOCAL"
     remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE"
index ea093d251d98af6a3d4df19e900d56df34d51572..b24119d69c092e3bd345cff1b6bafd48f5fd1e1b 100644 (file)
@@ -50,3 +50,41 @@ get_remote_merge_branch () {
            esac
        esac
 }
+
+error_on_missing_default_upstream () {
+       cmd="$1"
+       op_type="$2"
+       op_prep="$3"
+       example="$4"
+       branch_name=$(git symbolic-ref -q HEAD)
+       if test -z "$branch_name"
+       then
+               echo "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which branch you want to $op_type $op_prep on the command
+line and try again (e.g. '$example').
+See git-${cmd}(1) for details."
+       else
+               echo "You asked me to $cmd without telling me which branch you
+want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
+your configuration file does not tell me, either. Please
+specify which branch you want to use on the command line and
+try again (e.g. '$example').
+See git-${cmd}(1) for details.
+
+If you often $op_type $op_prep the same branch, you may want to
+use something like the following in your configuration file:
+    [branch \"${branch_name#refs/heads/}\"]
+    remote = <nickname>
+    merge = <remote-ref>"
+               test rebase = "$op_type" &&
+               echo "    rebase = true"
+               echo "
+    [remote \"<nickname>\"]
+    url = <url>
+    fetch = <refspec>
+
+See git-config(1) for details."
+       fi
+       exit 1
+}
index 4e9e0e49ecf2532ac8af1bfd46033e68c6f1042d..fb9e2df9312e96ecf8ad5ab2bde4b74b979fe02e 100755 (executable)
@@ -168,34 +168,10 @@ error_on_no_merge_candidates () {
                echo "You asked to pull from the remote '$1', but did not specify"
                echo "a branch. Because this is not the default configured remote"
                echo "for your current branch, you must specify a branch on the command line."
-       elif [ -z "$curr_branch" ]; then
-               echo "You are not currently on a branch, so I cannot use any"
-               echo "'branch.<branchname>.merge' in your configuration file."
-               echo "Please specify which remote branch you want to use on the command"
-               echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-               echo "See git-pull(1) for details."
-       elif [ -z "$upstream" ]; then
-               echo "You asked me to pull without telling me which branch you"
-               echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
-               echo "your configuration file does not tell me, either. Please"
-               echo "specify which branch you want to use on the command line and"
-               echo "try again (e.g. 'git pull <repository> <refspec>')."
-               echo "See git-pull(1) for details."
-               echo
-               echo "If you often $op_type $op_prep the same branch, you may want to"
-               echo "use something like the following in your configuration file:"
-               echo
-               echo "    [branch \"${curr_branch}\"]"
-               echo "    remote = <nickname>"
-               echo "    merge = <remote-ref>"
-               test rebase = "$op_type" &&
-                       echo "    rebase = true"
-               echo
-               echo "    [remote \"<nickname>\"]"
-               echo "    url = <url>"
-               echo "    fetch = <refspec>"
-               echo
-               echo "See git-config(1) for details."
+       elif [ -z "$curr_branch" -o -z "$upstream" ]; then
+               . git-parse-remote
+               error_on_missing_default_upstream "pull" $op_type $op_prep \
+                       "git pull <repository> <refspec>"
        else
                echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
                echo "from the remote, but no such ref was fetched."
diff --git a/git-rebase--am.sh b/git-rebase--am.sh
new file mode 100644 (file)
index 0000000..c815a24
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+case "$action" in
+continue)
+       git am --resolved --resolvemsg="$resolvemsg" &&
+       move_to_original_branch
+       exit
+       ;;
+skip)
+       git am --skip --resolvemsg="$resolvemsg" &&
+       move_to_original_branch
+       exit
+       ;;
+esac
+
+test -n "$rebase_root" && root_flag=--root
+
+git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+       --src-prefix=a/ --dst-prefix=b/ \
+       --no-renames $root_flag "$revisions" |
+git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" &&
+move_to_original_branch
+ret=$?
+test 0 != $ret -a -d "$state_dir" && write_basic_state
+exit $ret
old mode 100755 (executable)
new mode 100644 (file)
index 5873ba4..41ba96a
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
 
-OPTIONS_KEEPDASHDASH=
-OPTIONS_SPEC="\
-git-rebase [-i] [options] [--] <upstream> [<branch>]
-git-rebase [-i] (--continue | --abort | --skip)
---
- Available options are
-v,verbose          display a diffstat of what changed upstream
-onto=              rebase onto given branch instead of upstream
-p,preserve-merges  try to recreate merges instead of ignoring them
-s,strategy=        use the given merge strategy
-no-ff              cherry-pick all commits, even if unchanged
-m,merge            always used (no-op)
-i,interactive      always used (no-op)
- Actions:
-continue           continue rebasing process
-abort              abort rebasing process and restore original branch
-skip               skip current patch and continue rebasing process
-no-verify          override pre-rebase hook from stopping the operation
-verify             allow pre-rebase hook to run
-root               rebase all reachable commmits up to the root(s)
-autosquash         move commits that begin with squash!/fixup! under -i
-"
-
 . git-sh-setup
-require_work_tree
-
-DOTEST="$GIT_DIR/rebase-merge"
 
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
 # the lines are processed, they are removed from the front of this
-# file and written to the tail of $DONE.
-TODO="$DOTEST"/git-rebase-todo
+# file and written to the tail of $done.
+todo="$state_dir"/git-rebase-todo
 
 # The rebase command lines that have already been processed.  A line
 # is moved here when it is first handled, before any associated user
 # actions.
-DONE="$DOTEST"/done
+done="$state_dir"/done
 
 # The commit message that is planned to be used for any changes that
 # need to be committed following a user interaction.
-MSG="$DOTEST"/message
+msg="$state_dir"/message
 
 # The file into which is accumulated the suggested commit message for
 # squash/fixup commands.  When the first of a series of squash/fixups
@@ -61,34 +35,34 @@ MSG="$DOTEST"/message
 # is appended to the file as it is processed.
 #
 # The first line of the file is of the form
-#     # This is a combination of $COUNT commits.
-# where $COUNT is the number of commits whose messages have been
+#     # This is a combination of $count commits.
+# where $count is the number of commits whose messages have been
 # written to the file so far (including the initial "pick" commit).
 # Each time that a commit message is processed, this line is read and
 # updated.  It is deleted just before the combined commit is made.
-SQUASH_MSG="$DOTEST"/message-squash
+squash_msg="$state_dir"/message-squash
 
 # If the current series of squash/fixups has not yet included a squash
 # command, then this file exists and holds the commit message of the
 # original "pick" commit.  (If the series ends without a "squash"
 # command, then this can be used as the commit message of the combined
 # commit without opening the editor.)
-FIXUP_MSG="$DOTEST"/message-fixup
+fixup_msg="$state_dir"/message-fixup
 
-# $REWRITTEN is the name of a directory containing files for each
-# commit that is reachable by at least one merge base of $HEAD and
-# $UPSTREAM. They are not necessarily rewritten, but their children
+# $rewritten is the name of a directory containing files for each
+# commit that is reachable by at least one merge base of $head and
+# $upstream. They are not necessarily rewritten, but their children
 # might be.  This ensures that commits on merged, but otherwise
 # unrelated side branches are left alone. (Think "X" in the man page's
 # example.)
-REWRITTEN="$DOTEST"/rewritten
+rewritten="$state_dir"/rewritten
 
-DROPPED="$DOTEST"/dropped
+dropped="$state_dir"/dropped
 
 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
 # GIT_AUTHOR_DATE that will be used for the commit that is currently
 # being rebased.
-AUTHOR_SCRIPT="$DOTEST"/author-script
+author_script="$state_dir"/author-script
 
 # When an "edit" rebase command is being processed, the SHA1 of the
 # commit to be edited is recorded in this file.  When "git rebase
@@ -96,69 +70,31 @@ AUTHOR_SCRIPT="$DOTEST"/author-script
 # will be amended to the HEAD commit, but only provided the HEAD
 # commit is still the commit to be edited.  When any other rebase
 # command is processed, this file is deleted.
-AMEND="$DOTEST"/amend
+amend="$state_dir"/amend
 
 # For the post-rewrite hook, we make a list of rewritten commits and
 # their new sha1s.  The rewritten-pending list keeps the sha1s of
 # commits that have been processed, but not committed yet,
 # e.g. because they are waiting for a 'squash' command.
-REWRITTEN_LIST="$DOTEST"/rewritten-list
-REWRITTEN_PENDING="$DOTEST"/rewritten-pending
-
-PRESERVE_MERGES=
-STRATEGY=
-ONTO=
-VERBOSE=
-OK_TO_SKIP_PRE_REBASE=
-REBASE_ROOT=
-AUTOSQUASH=
-test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
-NEVER_FF=
-
-GIT_CHERRY_PICK_HELP="\
-hint: after resolving the conflicts, mark the corrected paths
-hint: with 'git add <paths>' and run 'git rebase --continue'"
+rewritten_list="$state_dir"/rewritten-list
+rewritten_pending="$state_dir"/rewritten-pending
+
+GIT_CHERRY_PICK_HELP="$resolvemsg"
 export GIT_CHERRY_PICK_HELP
 
 warn () {
        printf '%s\n' "$*" >&2
 }
 
-output () {
-       case "$VERBOSE" in
-       '')
-               output=$("$@" 2>&1 )
-               status=$?
-               test $status != 0 && printf "%s\n" "$output"
-               return $status
-               ;;
-       *)
-               "$@"
-               ;;
-       esac
-}
-
 # Output the commit message for the specified commit.
 commit_message () {
        git cat-file commit "$1" | sed "1,/^$/d"
 }
 
-run_pre_rebase_hook () {
-       if test -z "$OK_TO_SKIP_PRE_REBASE" &&
-          test -x "$GIT_DIR/hooks/pre-rebase"
-       then
-               "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
-                       echo >&2 "The pre-rebase hook refused to rebase."
-                       exit 1
-               }
-       fi
-}
-
-
-ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"
+orig_reflog_action="$GIT_REFLOG_ACTION"
 
 comment_for_reflog () {
-       case "$ORIG_REFLOG_ACTION" in
+       case "$orig_reflog_action" in
        ''|rebase*)
                GIT_REFLOG_ACTION="rebase -i ($1)"
                export GIT_REFLOG_ACTION
@@ -168,16 +104,16 @@ comment_for_reflog () {
 
 last_count=
 mark_action_done () {
-       sed -e 1q < "$TODO" >> "$DONE"
-       sed -e 1d < "$TODO" >> "$TODO".new
-       mv -f "$TODO".new "$TODO"
-       count=$(sane_grep -c '^[^#]' < "$DONE")
-       total=$(($count+$(sane_grep -c '^[^#]' < "$TODO")))
-       if test "$last_count" != "$count"
+       sed -e 1q < "$todo" >> "$done"
+       sed -e 1d < "$todo" >> "$todo".new
+       mv -f "$todo".new "$todo"
+       new_count=$(sane_grep -c '^[^#]' < "$done")
+       total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
+       if test "$last_count" != "$new_count"
        then
-               last_count=$count
-               printf "Rebasing (%d/%d)\r" $count $total
-               test -z "$VERBOSE" || echo
+               last_count=$new_count
+               printf "Rebasing (%d/%d)\r" $new_count $total
+               test -z "$verbose" || echo
        fi
 }
 
@@ -193,22 +129,22 @@ make_patch () {
        *)
                echo "Root commit"
                ;;
-       esac > "$DOTEST"/patch
-       test -f "$MSG" ||
-               commit_message "$1" > "$MSG"
-       test -f "$AUTHOR_SCRIPT" ||
-               get_author_ident_from_commit "$1" > "$AUTHOR_SCRIPT"
+       esac > "$state_dir"/patch
+       test -f "$msg" ||
+               commit_message "$1" > "$msg"
+       test -f "$author_script" ||
+               get_author_ident_from_commit "$1" > "$author_script"
 }
 
 die_with_patch () {
-       echo "$1" > "$DOTEST"/stopped-sha
+       echo "$1" > "$state_dir"/stopped-sha
        make_patch "$1"
        git rerere
        die "$2"
 }
 
 die_abort () {
-       rm -rf "$DOTEST"
+       rm -rf "$state_dir"
        die "$1"
 }
 
@@ -228,15 +164,10 @@ do_with_author () {
 pick_one () {
        ff=--ff
        case "$1" in -n) sha1=$2; ff= ;; *) sha1=$1 ;; esac
-       case "$NEVER_FF" in '') ;; ?*) ff= ;; esac
+       case "$force_rebase" in '') ;; ?*) ff= ;; esac
        output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
-       test -d "$REWRITTEN" &&
+       test -d "$rewritten" &&
                pick_one_preserving_merges "$@" && return
-       if test -n "$REBASE_ROOT"
-       then
-               output git cherry-pick "$@"
-               return
-       fi
        output git cherry-pick $ff "$@"
 }
 
@@ -253,20 +184,20 @@ pick_one_preserving_merges () {
        esac
        sha1=$(git rev-parse $sha1)
 
-       if test -f "$DOTEST"/current-commit
+       if test -f "$state_dir"/current-commit
        then
                if test "$fast_forward" = t
                then
                        while read current_commit
                        do
-                               git rev-parse HEAD > "$REWRITTEN"/$current_commit
-                       done <"$DOTEST"/current-commit
-                       rm "$DOTEST"/current-commit ||
+                               git rev-parse HEAD > "$rewritten"/$current_commit
+                       done <"$state_dir"/current-commit
+                       rm "$state_dir"/current-commit ||
                        die "Cannot write current commit's replacement sha1"
                fi
        fi
 
-       echo $sha1 >> "$DOTEST"/current-commit
+       echo $sha1 >> "$state_dir"/current-commit
 
        # rewrite parents; if none were rewritten, we can fast-forward.
        new_parents=
@@ -280,9 +211,9 @@ pick_one_preserving_merges () {
                p=$(expr "$pend" : ' \([^ ]*\)')
                pend="${pend# $p}"
 
-               if test -f "$REWRITTEN"/$p
+               if test -f "$rewritten"/$p
                then
-                       new_p=$(cat "$REWRITTEN"/$p)
+                       new_p=$(cat "$rewritten"/$p)
 
                        # If the todo reordered commits, and our parent is marked for
                        # rewriting, but hasn't been gotten to yet, assume the user meant to
@@ -301,10 +232,10 @@ pick_one_preserving_merges () {
                                ;;
                        esac
                else
-                       if test -f "$DROPPED"/$p
+                       if test -f "$dropped"/$p
                        then
                                fast_forward=f
-                               replacement="$(cat "$DROPPED"/$p)"
+                               replacement="$(cat "$dropped"/$p)"
                                test -z "$replacement" && replacement=root
                                pend=" $replacement$pend"
                        else
@@ -333,18 +264,19 @@ pick_one_preserving_merges () {
                        test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
 
                        # redo merge
-                       author_script=$(get_author_ident_from_commit $sha1)
-                       eval "$author_script"
-                       msg="$(commit_message $sha1)"
+                       author_script_content=$(get_author_ident_from_commit $sha1)
+                       eval "$author_script_content"
+                       msg_content="$(commit_message $sha1)"
                        # No point in merging the first parent, that's HEAD
                        new_parents=${new_parents# $first_parent}
                        if ! do_with_author output \
-                               git merge $STRATEGY -m "$msg" $new_parents
+                               git merge --no-ff ${strategy:+-s $strategy} -m \
+                                       "$msg_content" $new_parents
                        then
-                               printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
+                               printf "%s\n" "$msg_content" > "$GIT_DIR"/MERGE_MSG
                                die_with_patch $sha1 "Error redoing merge $sha1"
                        fi
-                       echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST"
+                       echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
                        ;;
                *)
                        output git cherry-pick "$@" ||
@@ -365,46 +297,46 @@ nth_string () {
 }
 
 update_squash_messages () {
-       if test -f "$SQUASH_MSG"; then
-               mv "$SQUASH_MSG" "$SQUASH_MSG".bak || exit
-               COUNT=$(($(sed -n \
+       if test -f "$squash_msg"; then
+               mv "$squash_msg" "$squash_msg".bak || exit
+               count=$(($(sed -n \
                        -e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
-                       -e "q" < "$SQUASH_MSG".bak)+1))
+                       -e "q" < "$squash_msg".bak)+1))
                {
-                       echo "# This is a combination of $COUNT commits."
+                       echo "# This is a combination of $count commits."
                        sed -e 1d -e '2,/^./{
                                /^$/d
-                       }' <"$SQUASH_MSG".bak
-               } >"$SQUASH_MSG"
+                       }' <"$squash_msg".bak
+               } >"$squash_msg"
        else
-               commit_message HEAD > "$FIXUP_MSG" || die "Cannot write $FIXUP_MSG"
-               COUNT=2
+               commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
+               count=2
                {
                        echo "# This is a combination of 2 commits."
                        echo "# The first commit's message is:"
                        echo
-                       cat "$FIXUP_MSG"
-               } >"$SQUASH_MSG"
+                       cat "$fixup_msg"
+               } >"$squash_msg"
        fi
        case $1 in
        squash)
-               rm -f "$FIXUP_MSG"
+               rm -f "$fixup_msg"
                echo
-               echo "# This is the $(nth_string $COUNT) commit message:"
+               echo "# This is the $(nth_string $count) commit message:"
                echo
                commit_message $2
                ;;
        fixup)
                echo
-               echo "# The $(nth_string $COUNT) commit message will be skipped:"
+               echo "# The $(nth_string $count) commit message will be skipped:"
                echo
                commit_message $2 | sed -e 's/^/#       /'
                ;;
-       esac >>"$SQUASH_MSG"
+       esac >>"$squash_msg"
 }
 
 peek_next_command () {
-       sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$TODO"
+       sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
 }
 
 # A squash/fixup has failed.  Prepare the long version of the squash
@@ -414,24 +346,24 @@ peek_next_command () {
 # messages, effectively causing the combined commit to be used as the
 # new basis for any further squash/fixups.  Args: sha1 rest
 die_failed_squash() {
-       mv "$SQUASH_MSG" "$MSG" || exit
-       rm -f "$FIXUP_MSG"
-       cp "$MSG" "$GIT_DIR"/MERGE_MSG || exit
+       mv "$squash_msg" "$msg" || exit
+       rm -f "$fixup_msg"
+       cp "$msg" "$GIT_DIR"/MERGE_MSG || exit
        warn
        warn "Could not apply $1... $2"
        die_with_patch $1 ""
 }
 
 flush_rewritten_pending() {
-       test -s "$REWRITTEN_PENDING" || return
+       test -s "$rewritten_pending" || return
        newsha1="$(git rev-parse HEAD^0)"
-       sed "s/$/ $newsha1/" < "$REWRITTEN_PENDING" >> "$REWRITTEN_LIST"
-       rm -f "$REWRITTEN_PENDING"
+       sed "s/$/ $newsha1/" < "$rewritten_pending" >> "$rewritten_list"
+       rm -f "$rewritten_pending"
 }
 
 record_in_rewritten() {
        oldsha1="$(git rev-parse $1)"
-       echo "$oldsha1" >> "$REWRITTEN_PENDING"
+       echo "$oldsha1" >> "$rewritten_pending"
 
        case "$(peek_next_command)" in
        squash|s|fixup|f)
@@ -443,8 +375,8 @@ record_in_rewritten() {
 }
 
 do_next () {
-       rm -f "$MSG" "$AUTHOR_SCRIPT" "$AMEND" || exit
-       read -r command sha1 rest < "$TODO"
+       rm -f "$msg" "$author_script" "$amend" || exit
+       read -r command sha1 rest < "$todo"
        case "$command" in
        '#'*|''|noop)
                mark_action_done
@@ -472,9 +404,9 @@ do_next () {
                mark_action_done
                pick_one $sha1 ||
                        die_with_patch $sha1 "Could not apply $sha1... $rest"
-               echo "$sha1" > "$DOTEST"/stopped-sha
+               echo "$sha1" > "$state_dir"/stopped-sha
                make_patch $sha1
-               git rev-parse --verify HEAD > "$AMEND"
+               git rev-parse --verify HEAD > "$amend"
                warn "Stopped at $sha1... $rest"
                warn "You can amend the commit now, with"
                warn
@@ -497,47 +429,47 @@ do_next () {
                esac
                comment_for_reflog $squash_style
 
-               test -f "$DONE" && has_action "$DONE" ||
+               test -f "$done" && has_action "$done" ||
                        die "Cannot '$squash_style' without a previous commit"
 
                mark_action_done
                update_squash_messages $squash_style $sha1
-               author_script=$(get_author_ident_from_commit HEAD)
-               echo "$author_script" > "$AUTHOR_SCRIPT"
-               eval "$author_script"
+               author_script_content=$(get_author_ident_from_commit HEAD)
+               echo "$author_script_content" > "$author_script"
+               eval "$author_script_content"
                output git reset --soft HEAD^
                pick_one -n $sha1 || die_failed_squash $sha1 "$rest"
                case "$(peek_next_command)" in
                squash|s|fixup|f)
                        # This is an intermediate commit; its message will only be
                        # used in case of trouble.  So use the long version:
-                       do_with_author output git commit --no-verify -F "$SQUASH_MSG" ||
+                       do_with_author output git commit --no-verify -F "$squash_msg" ||
                                die_failed_squash $sha1 "$rest"
                        ;;
                *)
                        # This is the final command of this squash/fixup group
-                       if test -f "$FIXUP_MSG"
+                       if test -f "$fixup_msg"
                        then
-                               do_with_author git commit --no-verify -F "$FIXUP_MSG" ||
+                               do_with_author git commit --no-verify -F "$fixup_msg" ||
                                        die_failed_squash $sha1 "$rest"
                        else
-                               cp "$SQUASH_MSG" "$GIT_DIR"/SQUASH_MSG || exit
+                               cp "$squash_msg" "$GIT_DIR"/SQUASH_MSG || exit
                                rm -f "$GIT_DIR"/MERGE_MSG
                                do_with_author git commit --no-verify -e ||
                                        die_failed_squash $sha1 "$rest"
                        fi
-                       rm -f "$SQUASH_MSG" "$FIXUP_MSG"
+                       rm -f "$squash_msg" "$fixup_msg"
                        ;;
                esac
                record_in_rewritten $sha1
                ;;
        x|"exec")
-               read -r command rest < "$TODO"
+               read -r command rest < "$todo"
                mark_action_done
                printf 'Executing: %s\n' "$rest"
                # "exec" command doesn't take a sha1 in the todo-list.
                # => can't just use $sha1 here.
-               git rev-parse --verify HEAD > "$DOTEST"/stopped-sha
+               git rev-parse --verify HEAD > "$state_dir"/stopped-sha
                ${SHELL:-@SHELL_PATH@} -c "$rest" # Actual execution
                status=$?
                if test "$status" -ne 0
@@ -563,42 +495,40 @@ do_next () {
                warn "Unknown command: $command $sha1 $rest"
                if git rev-parse --verify -q "$sha1" >/dev/null
                then
-                       die_with_patch $sha1 "Please fix this in the file $TODO."
+                       die_with_patch $sha1 "Please fix this in the file $todo."
                else
-                       die "Please fix this in the file $TODO."
+                       die "Please fix this in the file $todo."
                fi
                ;;
        esac
-       test -s "$TODO" && return
+       test -s "$todo" && return
 
        comment_for_reflog finish &&
-       HEADNAME=$(cat "$DOTEST"/head-name) &&
-       OLDHEAD=$(cat "$DOTEST"/head) &&
-       SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) &&
-       NEWHEAD=$(git rev-parse HEAD) &&
-       case $HEADNAME in
+       shortonto=$(git rev-parse --short $onto) &&
+       newhead=$(git rev-parse HEAD) &&
+       case $head_name in
        refs/*)
-               message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO" &&
-               git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
-               git symbolic-ref HEAD $HEADNAME
+               message="$GIT_REFLOG_ACTION: $head_name onto $shortonto" &&
+               git update-ref -m "$message" $head_name $newhead $orig_head &&
+               git symbolic-ref HEAD $head_name
                ;;
        esac && {
-               test ! -f "$DOTEST"/verbose ||
-                       git diff-tree --stat $(cat "$DOTEST"/head)..HEAD
+               test ! -f "$state_dir"/verbose ||
+                       git diff-tree --stat $orig_head..HEAD
        } &&
        {
-               test -s "$REWRITTEN_LIST" &&
-               git notes copy --for-rewrite=rebase < "$REWRITTEN_LIST" ||
+               test -s "$rewritten_list" &&
+               git notes copy --for-rewrite=rebase < "$rewritten_list" ||
                true # we don't care if this copying failed
        } &&
        if test -x "$GIT_DIR"/hooks/post-rewrite &&
-               test -s "$REWRITTEN_LIST"; then
-               "$GIT_DIR"/hooks/post-rewrite rebase < "$REWRITTEN_LIST"
+               test -s "$rewritten_list"; then
+               "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
                true # we don't care if this hook failed
        fi &&
-       rm -rf "$DOTEST" &&
+       rm -rf "$state_dir" &&
        git gc --auto &&
-       warn "Successfully rebased and updated $HEADNAME."
+       warn "Successfully rebased and updated $head_name."
 
        exit
 }
@@ -618,11 +548,11 @@ skip_unnecessary_picks () {
                # fd=3 means we skip the command
                case "$fd,$command" in
                3,pick|3,p)
-                       # pick a commit whose parent is current $ONTO -> skip
+                       # pick a commit whose parent is current $onto -> skip
                        sha1=${rest%% *}
                        case "$(git rev-parse --verify --quiet "$sha1"^)" in
-                       "$ONTO"*)
-                               ONTO=$sha1
+                       "$onto"*)
+                               onto=$sha1
                                ;;
                        *)
                                fd=1
@@ -637,32 +567,16 @@ skip_unnecessary_picks () {
                        ;;
                esac
                printf '%s\n' "$command${rest:+ }$rest" >&$fd
-       done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
-       mv -f "$TODO".new "$TODO" &&
+       done <"$todo" >"$todo.new" 3>>"$done" &&
+       mv -f "$todo".new "$todo" &&
        case "$(peek_next_command)" in
        squash|s|fixup|f)
-               record_in_rewritten "$ONTO"
+               record_in_rewritten "$onto"
                ;;
        esac ||
        die "Could not skip unnecessary pick commands"
 }
 
-# check if no other options are set
-is_standalone () {
-       test $# -eq 2 -a "$2" = '--' &&
-       test -z "$ONTO" &&
-       test -z "$PRESERVE_MERGES" &&
-       test -z "$STRATEGY" &&
-       test -z "$VERBOSE"
-}
-
-get_saved_options () {
-       test -d "$REWRITTEN" && PRESERVE_MERGES=t
-       test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
-       test -f "$DOTEST"/verbose && VERBOSE=t
-       test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
-}
-
 # Rearrange the todo list that has both "pick sha1 msg" and
 # "pick sha1 fixup!/squash! msg" appears in it so that the latter
 # comes immediately after the former, and change "pick" to
@@ -699,7 +613,7 @@ rearrange_squash () {
                esac
                printf '%s\n' "$pick $sha1 $message"
                used="$used$sha1 "
-               while read -r squash action msg
+               while read -r squash action msg_content
                do
                        case " $used" in
                        *" $squash "*) continue ;;
@@ -709,13 +623,13 @@ rearrange_squash () {
                        +*)
                                action="${action#+}"
                                # full sha1 prefix test
-                               case "$msg" in "$sha1"*) emit=1;; esac ;;
+                               case "$msg_content" in "$sha1"*) emit=1;; esac ;;
                        *)
                                # message prefix test
-                               case "$message" in "$msg"*) emit=1;; esac ;;
+                               case "$message" in "$msg_content"*) emit=1;; esac ;;
                        esac
                        if test $emit = 1; then
-                               printf '%s\n' "$action $squash $action! $msg"
+                               printf '%s\n' "$action $squash $action! $msg_content"
                                used="$used$squash "
                        fi
                done <"$1.sq"
@@ -724,296 +638,159 @@ rearrange_squash () {
        rm -f "$1.sq" "$1.rearranged"
 }
 
-LF='
-'
-parse_onto () {
-       case "$1" in
-       *...*)
-               if      left=${1%...*} right=${1#*...} &&
-                       onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
-               then
-                       case "$onto" in
-                       ?*"$LF"?* | '')
-                               exit 1 ;;
-                       esac
-                       echo "$onto"
-                       exit 0
-               fi
-       esac
-       git rev-parse --verify "$1^0"
-}
-
-while test $# != 0
-do
-       case "$1" in
-       --no-verify)
-               OK_TO_SKIP_PRE_REBASE=yes
-               ;;
-       --verify)
-               OK_TO_SKIP_PRE_REBASE=
-               ;;
-       --continue)
-               is_standalone "$@" || usage
-               get_saved_options
-               comment_for_reflog continue
-
-               test -d "$DOTEST" || die "No interactive rebase running"
-
-               # Sanity check
-               git rev-parse --verify HEAD >/dev/null ||
-                       die "Cannot read HEAD"
-               git update-index --ignore-submodules --refresh &&
-                       git diff-files --quiet --ignore-submodules ||
-                       die "Working tree is dirty"
-
-               # do we have anything to commit?
-               if git diff-index --cached --quiet --ignore-submodules HEAD --
+case "$action" in
+continue)
+       # do we have anything to commit?
+       if git diff-index --cached --quiet --ignore-submodules HEAD --
+       then
+               : Nothing to commit -- skip this
+       else
+               . "$author_script" ||
+                       die "Cannot find the author identity"
+               current_head=
+               if test -f "$amend"
                then
-                       : Nothing to commit -- skip this
-               else
-                       . "$AUTHOR_SCRIPT" ||
-                               die "Cannot find the author identity"
-                       amend=
-                       if test -f "$AMEND"
-                       then
-                               amend=$(git rev-parse --verify HEAD)
-                               test "$amend" = $(cat "$AMEND") ||
-                               die "\
+                       current_head=$(git rev-parse --verify HEAD)
+                       test "$current_head" = $(cat "$amend") ||
+                       die "\
 You have uncommitted changes in your working tree. Please, commit them
 first and then run 'git rebase --continue' again."
-                               git reset --soft HEAD^ ||
-                               die "Cannot rewind the HEAD"
-                       fi
-                       do_with_author git commit --no-verify -F "$MSG" -e || {
-                               test -n "$amend" && git reset --soft $amend
-                               die "Could not commit staged changes."
-                       }
+                       git reset --soft HEAD^ ||
+                       die "Cannot rewind the HEAD"
                fi
+               do_with_author git commit --no-verify -F "$msg" -e || {
+                       test -n "$current_head" && git reset --soft $current_head
+                       die "Could not commit staged changes."
+               }
+       fi
 
-               record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
-
-               require_clean_work_tree "rebase"
-               do_rest
-               ;;
-       --abort)
-               is_standalone "$@" || usage
-               get_saved_options
-               comment_for_reflog abort
-
-               git rerere clear
-               test -d "$DOTEST" || die "No interactive rebase running"
-
-               HEADNAME=$(cat "$DOTEST"/head-name)
-               HEAD=$(cat "$DOTEST"/head)
-               case $HEADNAME in
-               refs/*)
-                       git symbolic-ref HEAD $HEADNAME
-                       ;;
-               esac &&
-               output git reset --hard $HEAD &&
-               rm -rf "$DOTEST"
-               exit
-               ;;
-       --skip)
-               is_standalone "$@" || usage
-               get_saved_options
-               comment_for_reflog skip
-
-               git rerere clear
-               test -d "$DOTEST" || die "No interactive rebase running"
-
-               output git reset --hard && do_rest
-               ;;
-       -s)
-               case "$#,$1" in
-               *,*=*)
-                       STRATEGY="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
-               1,*)
-                       usage ;;
-               *)
-                       STRATEGY="-s $2"
-                       shift ;;
-               esac
-               ;;
-       -m)
-               # we use merge anyway
-               ;;
-       -v)
-               VERBOSE=t
-               ;;
-       -p)
-               PRESERVE_MERGES=t
-               ;;
-       -i)
-               # yeah, we know
-               ;;
-       --no-ff)
-               NEVER_FF=t
-               ;;
-       --root)
-               REBASE_ROOT=t
-               ;;
-       --autosquash)
-               AUTOSQUASH=t
-               ;;
-       --no-autosquash)
-               AUTOSQUASH=
-               ;;
-       --onto)
-               shift
-               ONTO=$(parse_onto "$1") ||
-                       die "Does not point to a valid commit: $1"
-               ;;
-       --)
-               shift
-               test -z "$REBASE_ROOT" -a $# -ge 1 -a $# -le 2 ||
-               test ! -z "$REBASE_ROOT" -a $# -le 1 || usage
-               test -d "$DOTEST" &&
-                       die "Interactive rebase already started"
-
-               git var GIT_COMMITTER_IDENT >/dev/null ||
-                       die "You need to set your committer info first"
+       record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
 
-               if test -z "$REBASE_ROOT"
-               then
-                       UPSTREAM_ARG="$1"
-                       UPSTREAM=$(git rev-parse --verify "$1") || die "Invalid base"
-                       test -z "$ONTO" && ONTO=$UPSTREAM
-                       shift
-               else
-                       UPSTREAM=
-                       UPSTREAM_ARG=--root
-                       test -z "$ONTO" &&
-                               die "You must specify --onto when using --root"
-               fi
-               run_pre_rebase_hook "$UPSTREAM_ARG" "$@"
+       require_clean_work_tree "rebase"
+       do_rest
+       ;;
+skip)
+       git rerere clear
 
-               comment_for_reflog start
+       do_rest
+       ;;
+esac
 
-               require_clean_work_tree "rebase" "Please commit or stash them."
+git var GIT_COMMITTER_IDENT >/dev/null ||
+       die "You need to set your committer info first"
 
-               if test ! -z "$1"
-               then
-                       output git checkout "$1" -- ||
-                               die "Could not checkout $1"
-               fi
+comment_for_reflog start
 
-               HEAD=$(git rev-parse --verify HEAD) || die "No HEAD?"
-               mkdir "$DOTEST" || die "Could not create temporary $DOTEST"
+if test ! -z "$switch_to"
+then
+       output git checkout "$switch_to" -- ||
+               die "Could not checkout $switch_to"
+fi
 
-               : > "$DOTEST"/interactive || die "Could not mark as interactive"
-               git symbolic-ref HEAD > "$DOTEST"/head-name 2> /dev/null ||
-                       echo "detached HEAD" > "$DOTEST"/head-name
+orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
+mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
-               echo $HEAD > "$DOTEST"/head
-               case "$REBASE_ROOT" in
-               '')
-                       rm -f "$DOTEST"/rebase-root ;;
-               *)
-                       : >"$DOTEST"/rebase-root ;;
-               esac
-               echo $ONTO > "$DOTEST"/onto
-               test -z "$STRATEGY" || echo "$STRATEGY" > "$DOTEST"/strategy
-               test t = "$VERBOSE" && : > "$DOTEST"/verbose
-               if test t = "$PRESERVE_MERGES"
-               then
-                       if test -z "$REBASE_ROOT"
-                       then
-                               mkdir "$REWRITTEN" &&
-                               for c in $(git merge-base --all $HEAD $UPSTREAM)
-                               do
-                                       echo $ONTO > "$REWRITTEN"/$c ||
-                                               die "Could not init rewritten commits"
-                               done
-                       else
-                               mkdir "$REWRITTEN" &&
-                               echo $ONTO > "$REWRITTEN"/root ||
-                                       die "Could not init rewritten commits"
-                       fi
-                       # No cherry-pick because our first pass is to determine
-                       # parents to rewrite and skipping dropped commits would
-                       # prematurely end our probe
-                       MERGES_OPTION=
-                       first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
-               else
-                       MERGES_OPTION="--no-merges --cherry-pick"
-               fi
-
-               SHORTHEAD=$(git rev-parse --short $HEAD)
-               SHORTONTO=$(git rev-parse --short $ONTO)
-               if test -z "$REBASE_ROOT"
-                       # this is now equivalent to ! -z "$UPSTREAM"
-               then
-                       SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
-                       REVISIONS=$UPSTREAM...$HEAD
-                       SHORTREVISIONS=$SHORTUPSTREAM..$SHORTHEAD
-               else
-                       REVISIONS=$ONTO...$HEAD
-                       SHORTREVISIONS=$SHORTHEAD
-               fi
-               git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
-                       --abbrev=7 --reverse --left-right --topo-order \
-                       $REVISIONS | \
-                       sed -n "s/^>//p" |
-               while read -r shortsha1 rest
+: > "$state_dir"/interactive || die "Could not mark as interactive"
+write_basic_state
+if test t = "$preserve_merges"
+then
+       if test -z "$rebase_root"
+       then
+               mkdir "$rewritten" &&
+               for c in $(git merge-base --all $orig_head $upstream)
                do
-                       if test t != "$PRESERVE_MERGES"
-                       then
-                               printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
-                       else
-                               sha1=$(git rev-parse $shortsha1)
-                               if test -z "$REBASE_ROOT"
-                               then
-                                       preserve=t
-                                       for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
-                                       do
-                                               if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
-                                               then
-                                                       preserve=f
-                                               fi
-                                       done
-                               else
-                                       preserve=f
-                               fi
-                               if test f = "$preserve"
-                               then
-                                       touch "$REWRITTEN"/$sha1
-                                       printf '%s\n' "pick $shortsha1 $rest" >> "$TODO"
-                               fi
-                       fi
+                       echo $onto > "$rewritten"/$c ||
+                               die "Could not init rewritten commits"
                done
-
-               # Watch for commits that been dropped by --cherry-pick
-               if test t = "$PRESERVE_MERGES"
+       else
+               mkdir "$rewritten" &&
+               echo $onto > "$rewritten"/root ||
+                       die "Could not init rewritten commits"
+       fi
+       # No cherry-pick because our first pass is to determine
+       # parents to rewrite and skipping dropped commits would
+       # prematurely end our probe
+       merges_option=
+       first_after_upstream="$(git rev-list --reverse --first-parent $upstream..$orig_head | head -n 1)"
+else
+       merges_option="--no-merges --cherry-pick"
+fi
+
+shorthead=$(git rev-parse --short $orig_head)
+shortonto=$(git rev-parse --short $onto)
+if test -z "$rebase_root"
+       # this is now equivalent to ! -z "$upstream"
+then
+       shortupstream=$(git rev-parse --short $upstream)
+       revisions=$upstream...$orig_head
+       shortrevisions=$shortupstream..$shorthead
+else
+       revisions=$onto...$orig_head
+       shortrevisions=$shorthead
+fi
+git rev-list $merges_option --pretty=oneline --abbrev-commit \
+       --abbrev=7 --reverse --left-right --topo-order \
+       $revisions | \
+       sed -n "s/^>//p" |
+while read -r shortsha1 rest
+do
+       if test t != "$preserve_merges"
+       then
+               printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
+       else
+               sha1=$(git rev-parse $shortsha1)
+               if test -z "$rebase_root"
                then
-                       mkdir "$DROPPED"
-                       # Save all non-cherry-picked changes
-                       git rev-list $REVISIONS --left-right --cherry-pick | \
-                               sed -n "s/^>//p" > "$DOTEST"/not-cherry-picks
-                       # Now all commits and note which ones are missing in
-                       # not-cherry-picks and hence being dropped
-                       git rev-list $REVISIONS |
-                       while read rev
+                       preserve=t
+                       for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
                        do
-                               if test -f "$REWRITTEN"/$rev -a "$(sane_grep "$rev" "$DOTEST"/not-cherry-picks)" = ""
+                               if test -f "$rewritten"/$p -a \( $p != $onto -o $sha1 = $first_after_upstream \)
                                then
-                                       # Use -f2 because if rev-list is telling us this commit is
-                                       # not worthwhile, we don't want to track its multiple heads,
-                                       # just the history of its first-parent for others that will
-                                       # be rebasing on top of it
-                                       git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$DROPPED"/$rev
-                                       short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
-                                       sane_grep -v "^[a-z][a-z]* $short" <"$TODO" > "${TODO}2" ; mv "${TODO}2" "$TODO"
-                                       rm "$REWRITTEN"/$rev
+                                       preserve=f
                                fi
                        done
+               else
+                       preserve=f
+               fi
+               if test f = "$preserve"
+               then
+                       touch "$rewritten"/$sha1
+                       printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
                fi
+       fi
+done
 
-               test -s "$TODO" || echo noop >> "$TODO"
-               test -n "$AUTOSQUASH" && rearrange_squash "$TODO"
-               cat >> "$TODO" << EOF
+# Watch for commits that been dropped by --cherry-pick
+if test t = "$preserve_merges"
+then
+       mkdir "$dropped"
+       # Save all non-cherry-picked changes
+       git rev-list $revisions --left-right --cherry-pick | \
+               sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
+       # Now all commits and note which ones are missing in
+       # not-cherry-picks and hence being dropped
+       git rev-list $revisions |
+       while read rev
+       do
+               if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = ""
+               then
+                       # Use -f2 because if rev-list is telling us this commit is
+                       # not worthwhile, we don't want to track its multiple heads,
+                       # just the history of its first-parent for others that will
+                       # be rebasing on top of it
+                       git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
+                       short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
+                       sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
+                       rm "$rewritten"/$rev
+               fi
+       done
+fi
+
+test -s "$todo" || echo noop >> "$todo"
+test -n "$autosquash" && rearrange_squash "$todo"
+cat >> "$todo" << EOF
 
-# Rebase $SHORTREVISIONS onto $SHORTONTO
+# Rebase $shortrevisions onto $shortonto
 #
 # Commands:
 #  p, pick = use commit
@@ -1028,22 +805,18 @@ first and then run 'git rebase --continue' again."
 #
 EOF
 
-               has_action "$TODO" ||
-                       die_abort "Nothing to do"
+has_action "$todo" ||
+       die_abort "Nothing to do"
 
-               cp "$TODO" "$TODO".backup
-               git_editor "$TODO" ||
-                       die_abort "Could not execute editor"
+cp "$todo" "$todo".backup
+git_editor "$todo" ||
+       die_abort "Could not execute editor"
 
-               has_action "$TODO" ||
-                       die_abort "Nothing to do"
+has_action "$todo" ||
+       die_abort "Nothing to do"
 
-               test -d "$REWRITTEN" || test -n "$NEVER_FF" || skip_unnecessary_picks
+test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
 
-               output git checkout $ONTO || die_abort "could not detach HEAD"
-               git update-ref ORIG_HEAD $HEAD
-               do_rest
-               ;;
-       esac
-       shift
-done
+output git checkout $onto || die_abort "could not detach HEAD"
+git update-ref ORIG_HEAD $orig_head
+do_rest
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
new file mode 100644 (file)
index 0000000..26afc75
--- /dev/null
@@ -0,0 +1,151 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Junio C Hamano.
+#
+
+. git-sh-setup
+
+prec=4
+
+read_state () {
+       onto_name=$(cat "$state_dir"/onto_name) &&
+       end=$(cat "$state_dir"/end) &&
+       msgnum=$(cat "$state_dir"/msgnum)
+}
+
+continue_merge () {
+       test -d "$state_dir" || die "$state_dir directory does not exist"
+
+       unmerged=$(git ls-files -u)
+       if test -n "$unmerged"
+       then
+               echo "You still have unmerged paths in your index"
+               echo "did you forget to use git add?"
+               die "$resolvemsg"
+       fi
+
+       cmt=`cat "$state_dir/current"`
+       if ! git diff-index --quiet --ignore-submodules HEAD --
+       then
+               if ! git commit --no-verify -C "$cmt"
+               then
+                       echo "Commit failed, please do not call \"git commit\""
+                       echo "directly, but instead do one of the following: "
+                       die "$resolvemsg"
+               fi
+               if test -z "$GIT_QUIET"
+               then
+                       printf "Committed: %0${prec}d " $msgnum
+               fi
+               echo "$cmt $(git rev-parse HEAD^0)" >> "$state_dir/rewritten"
+       else
+               if test -z "$GIT_QUIET"
+               then
+                       printf "Already applied: %0${prec}d " $msgnum
+               fi
+       fi
+       test -z "$GIT_QUIET" &&
+       GIT_PAGER='' git log --format=%s -1 "$cmt"
+
+       # onto the next patch:
+       msgnum=$(($msgnum + 1))
+       echo "$msgnum" >"$state_dir/msgnum"
+}
+
+call_merge () {
+       cmt="$(cat "$state_dir/cmt.$1")"
+       echo "$cmt" > "$state_dir/current"
+       hd=$(git rev-parse --verify HEAD)
+       cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
+       msgnum=$(cat "$state_dir/msgnum")
+       eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
+       eval GITHEAD_$hd='$onto_name'
+       export GITHEAD_$cmt GITHEAD_$hd
+       if test -n "$GIT_QUIET"
+       then
+               GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
+       fi
+       test -z "$strategy" && strategy=recursive
+       eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
+       rv=$?
+       case "$rv" in
+       0)
+               unset GITHEAD_$cmt GITHEAD_$hd
+               return
+               ;;
+       1)
+               git rerere $allow_rerere_autoupdate
+               die "$resolvemsg"
+               ;;
+       2)
+               echo "Strategy: $strategy failed, try another" 1>&2
+               die "$resolvemsg"
+               ;;
+       *)
+               die "Unknown exit code ($rv) from command:" \
+                       "git-merge-$strategy $cmt^ -- HEAD $cmt"
+               ;;
+       esac
+}
+
+finish_rb_merge () {
+       move_to_original_branch
+       git notes copy --for-rewrite=rebase < "$state_dir"/rewritten
+       if test -x "$GIT_DIR"/hooks/post-rewrite &&
+               test -s "$state_dir"/rewritten; then
+               "$GIT_DIR"/hooks/post-rewrite rebase < "$state_dir"/rewritten
+       fi
+       rm -r "$state_dir"
+       say All done.
+}
+
+case "$action" in
+continue)
+       read_state
+       continue_merge
+       while test "$msgnum" -le "$end"
+       do
+               call_merge "$msgnum"
+               continue_merge
+       done
+       finish_rb_merge
+       exit
+       ;;
+skip)
+       read_state
+       git rerere clear
+       msgnum=$(($msgnum + 1))
+       while test "$msgnum" -le "$end"
+       do
+               call_merge "$msgnum"
+               continue_merge
+       done
+       finish_rb_merge
+       exit
+       ;;
+esac
+
+mkdir -p "$state_dir"
+echo "$onto_name" > "$state_dir/onto_name"
+write_basic_state
+
+msgnum=0
+for cmt in `git rev-list --reverse --no-merges "$revisions"`
+do
+       msgnum=$(($msgnum + 1))
+       echo "$cmt" > "$state_dir/cmt.$msgnum"
+done
+
+echo 1 >"$state_dir/msgnum"
+echo $msgnum >"$state_dir/end"
+
+end=$msgnum
+msgnum=1
+
+while test "$msgnum" -le "$end"
+do
+       call_merge "$msgnum"
+       continue_merge
+done
+
+finish_rb_merge
index cbb0ea90ed410d5af68ce814b7fd93a90829f3ee..7a54bfc6182a567860af023cb7720680d1806c72 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]'
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
 LONG_USAGE='git-rebase replaces <branch> with a new branch of the
 same name.  When the --onto option is provided the new branch starts
 out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
@@ -28,7 +28,39 @@ Example:       git-rebase master~1 topic
 '
 
 SUBDIRECTORY_OK=Yes
-OPTIONS_SPEC=
+OPTIONS_KEEPDASHDASH=
+OPTIONS_SPEC="\
+git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
+git rebase [-i] [options] --onto <newbase> --root [<branch>]
+git-rebase [-i] --continue | --abort | --skip
+--
+ Available options are
+v,verbose!         display a diffstat of what changed upstream
+q,quiet!           be quiet. implies --no-stat
+onto=!             rebase onto given branch instead of upstream
+p,preserve-merges! try to recreate merges instead of ignoring them
+s,strategy=!       use the given merge strategy
+no-ff!             cherry-pick all commits, even if unchanged
+m,merge!           use merging strategies to rebase
+i,interactive!     let the user edit the list of commits to rebase
+f,force-rebase!    force rebase even if branch is up to date
+X,strategy-option=! pass the argument through to the merge strategy
+stat!              display a diffstat of what changed upstream
+n,no-stat!         do not show diffstat of what changed upstream
+verify             allow pre-rebase hook to run
+rerere-autoupdate  allow rerere to update index with resolved conflicts
+root!              rebase all reachable commits up to the root(s)
+autosquash         move commits that begin with squash!/fixup! under -i
+committer-date-is-author-date! passed to 'git am'
+ignore-date!       passed to 'git am'
+whitespace=!       passed to 'git apply'
+ignore-whitespace! passed to 'git apply'
+C=!                passed to 'git apply'
+ Actions:
+continue!          continue rebasing process
+abort!             abort rebasing process and restore original branch
+skip!              skip current patch and continue rebasing process
+"
 . git-sh-setup
 set_reflog_action rebase
 require_work_tree
@@ -36,18 +68,18 @@ cd_to_toplevel
 
 LF='
 '
-OK_TO_SKIP_PRE_REBASE=
-RESOLVEMSG="
+ok_to_skip_pre_rebase=
+resolvemsg="
 When you have resolved this problem run \"git rebase --continue\".
 If you would prefer to skip this patch, instead run \"git rebase --skip\".
 To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
-unset newbase
-strategy=recursive
+unset onto
+strategy=
 strategy_opts=
 do_merge=
-dotest="$GIT_DIR"/rebase-merge
-prec=4
+merge_dir="$GIT_DIR"/rebase-merge
+apply_dir="$GIT_DIR"/rebase-apply
 verbose=
 diffstat=
 test "$(git config --bool rebase.stat)" = true && diffstat=t
@@ -55,92 +87,67 @@ git_am_opt=
 rebase_root=
 force_rebase=
 allow_rerere_autoupdate=
-
-continue_merge () {
-       test -n "$prev_head" || die "prev_head must be defined"
-       test -d "$dotest" || die "$dotest directory does not exist"
-
-       unmerged=$(git ls-files -u)
-       if test -n "$unmerged"
-       then
-               echo "You still have unmerged paths in your index"
-               echo "did you forget to use git add?"
-               die "$RESOLVEMSG"
-       fi
-
-       cmt=`cat "$dotest/current"`
-       if ! git diff-index --quiet --ignore-submodules HEAD --
+# Non-empty if a rebase was in progress when 'git rebase' was invoked
+in_progress=
+# One of {am, merge, interactive}
+type=
+# One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
+state_dir=
+# One of {'', continue, skip, abort}, as parsed from command line
+action=
+preserve_merges=
+autosquash=
+test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
+
+read_basic_state () {
+       head_name=$(cat "$state_dir"/head-name) &&
+       onto=$(cat "$state_dir"/onto) &&
+       # We always write to orig-head, but interactive rebase used to write to
+       # head. Fall back to reading from head to cover for the case that the
+       # user upgraded git with an ongoing interactive rebase.
+       if test -f "$state_dir"/orig-head
        then
-               if ! git commit --no-verify -C "$cmt"
-               then
-                       echo "Commit failed, please do not call \"git commit\""
-                       echo "directly, but instead do one of the following: "
-                       die "$RESOLVEMSG"
-               fi
-               if test -z "$GIT_QUIET"
-               then
-                       printf "Committed: %0${prec}d " $msgnum
-               fi
-               echo "$cmt $(git rev-parse HEAD^0)" >> "$dotest/rewritten"
+               orig_head=$(cat "$state_dir"/orig-head)
        else
-               if test -z "$GIT_QUIET"
-               then
-                       printf "Already applied: %0${prec}d " $msgnum
-               fi
-       fi
-       test -z "$GIT_QUIET" &&
-       GIT_PAGER='' git log --format=%s -1 "$cmt"
-
-       prev_head=`git rev-parse HEAD^0`
-       # save the resulting commit so we can read-tree on it later
-       echo "$prev_head" > "$dotest/prev_head"
+               orig_head=$(cat "$state_dir"/head)
+       fi &&
+       GIT_QUIET=$(cat "$state_dir"/quiet) &&
+       test -f "$state_dir"/verbose && verbose=t
+       test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
+       test -f "$state_dir"/strategy_opts &&
+               strategy_opts="$(cat "$state_dir"/strategy_opts)"
+       test -f "$state_dir"/allow_rerere_autoupdate &&
+               allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)"
+}
 
-       # onto the next patch:
-       msgnum=$(($msgnum + 1))
-       echo "$msgnum" >"$dotest/msgnum"
+write_basic_state () {
+       echo "$head_name" > "$state_dir"/head-name &&
+       echo "$onto" > "$state_dir"/onto &&
+       echo "$orig_head" > "$state_dir"/orig-head &&
+       echo "$GIT_QUIET" > "$state_dir"/quiet &&
+       test t = "$verbose" && : > "$state_dir"/verbose
+       test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
+       test -n "$strategy_opts" && echo "$strategy_opts" > \
+               "$state_dir"/strategy_opts
+       test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
+               "$state_dir"/allow_rerere_autoupdate
 }
 
-call_merge () {
-       cmt="$(cat "$dotest/cmt.$1")"
-       echo "$cmt" > "$dotest/current"
-       hd=$(git rev-parse --verify HEAD)
-       cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
-       msgnum=$(cat "$dotest/msgnum")
-       end=$(cat "$dotest/end")
-       eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-       eval GITHEAD_$hd='$(cat "$dotest/onto_name")'
-       export GITHEAD_$cmt GITHEAD_$hd
-       if test -n "$GIT_QUIET"
-       then
-               GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
-       fi
-       eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
-       rv=$?
-       case "$rv" in
-       0)
-               unset GITHEAD_$cmt GITHEAD_$hd
-               return
-               ;;
-       1)
-               git rerere $allow_rerere_autoupdate
-               die "$RESOLVEMSG"
-               ;;
-       2)
-               echo "Strategy: $rv $strategy failed, try another" 1>&2
-               die "$RESOLVEMSG"
+output () {
+       case "$verbose" in
+       '')
+               output=$("$@" 2>&1 )
+               status=$?
+               test $status != 0 && printf "%s\n" "$output"
+               return $status
                ;;
        *)
-               die "Unknown exit code ($rv) from command:" \
-                       "git-merge-$strategy $cmt^ -- HEAD $cmt"
+               "$@"
                ;;
        esac
 }
 
 move_to_original_branch () {
-       test -z "$head_name" &&
-               head_name="$(cat "$dotest"/head-name)" &&
-               onto="$(cat "$dotest"/onto)" &&
-               orig_head="$(cat "$dotest"/orig-head)"
        case "$head_name" in
        refs/*)
                message="rebase finished: $head_name onto $onto"
@@ -152,42 +159,16 @@ move_to_original_branch () {
        esac
 }
 
-finish_rb_merge () {
-       move_to_original_branch
-       git notes copy --for-rewrite=rebase < "$dotest"/rewritten
-       if test -x "$GIT_DIR"/hooks/post-rewrite &&
-               test -s "$dotest"/rewritten; then
-               "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
-       fi
-       rm -r "$dotest"
-       say All done.
-}
-
-is_interactive () {
-       while test $# != 0
-       do
-               case "$1" in
-                       -i|--interactive)
-                               interactive_rebase=explicit
-                               break
-                       ;;
-                       -p|--preserve-merges)
-                               interactive_rebase=implied
-                       ;;
-               esac
-               shift
-       done
-
+run_specific_rebase () {
        if [ "$interactive_rebase" = implied ]; then
                GIT_EDITOR=:
                export GIT_EDITOR
        fi
-
-       test -n "$interactive_rebase" || test -f "$dotest"/interactive
+       . git-rebase--$type
 }
 
 run_pre_rebase_hook () {
-       if test -z "$OK_TO_SKIP_PRE_REBASE" &&
+       if test -z "$ok_to_skip_pre_rebase" &&
           test -x "$GIT_DIR/hooks/pre-rebase"
        then
                "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
@@ -195,163 +176,94 @@ run_pre_rebase_hook () {
        fi
 }
 
-test -f "$GIT_DIR"/rebase-apply/applying &&
+test -f "$apply_dir"/applying &&
        die 'It looks like git-am is in progress. Cannot rebase.'
 
-is_interactive "$@" && exec git-rebase--interactive "$@"
+if test -d "$apply_dir"
+then
+       type=am
+       state_dir="$apply_dir"
+elif test -d "$merge_dir"
+then
+       if test -f "$merge_dir"/interactive
+       then
+               type=interactive
+               interactive_rebase=explicit
+       else
+               type=merge
+       fi
+       state_dir="$merge_dir"
+fi
+test -n "$type" && in_progress=t
 
+total_argc=$#
 while test $# != 0
 do
        case "$1" in
        --no-verify)
-               OK_TO_SKIP_PRE_REBASE=yes
+               ok_to_skip_pre_rebase=yes
                ;;
        --verify)
-               OK_TO_SKIP_PRE_REBASE=
-               ;;
-       --continue)
-               test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
-                       die "No rebase in progress?"
-
-               git update-index --ignore-submodules --refresh &&
-               git diff-files --quiet --ignore-submodules || {
-                       echo "You must edit all merge conflicts and then"
-                       echo "mark them as resolved using git add"
-                       exit 1
-               }
-               if test -d "$dotest"
-               then
-                       prev_head=$(cat "$dotest/prev_head")
-                       end=$(cat "$dotest/end")
-                       msgnum=$(cat "$dotest/msgnum")
-                       onto=$(cat "$dotest/onto")
-                       GIT_QUIET=$(cat "$dotest/quiet")
-                       continue_merge
-                       while test "$msgnum" -le "$end"
-                       do
-                               call_merge "$msgnum"
-                               continue_merge
-                       done
-                       finish_rb_merge
-                       exit
-               fi
-               head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
-               onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
-               orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
-               GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
-               git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
-               move_to_original_branch
-               exit
+               ok_to_skip_pre_rebase=
                ;;
-       --skip)
-               test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
-                       die "No rebase in progress?"
-
-               git reset --hard HEAD || exit $?
-               if test -d "$dotest"
-               then
-                       git rerere clear
-                       prev_head=$(cat "$dotest/prev_head")
-                       end=$(cat "$dotest/end")
-                       msgnum=$(cat "$dotest/msgnum")
-                       msgnum=$(($msgnum + 1))
-                       onto=$(cat "$dotest/onto")
-                       GIT_QUIET=$(cat "$dotest/quiet")
-                       while test "$msgnum" -le "$end"
-                       do
-                               call_merge "$msgnum"
-                               continue_merge
-                       done
-                       finish_rb_merge
-                       exit
-               fi
-               head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
-               onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
-               orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
-               GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
-               git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
-               move_to_original_branch
-               exit
-               ;;
-       --abort)
-               test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply ||
-                       die "No rebase in progress?"
-
-               git rerere clear
-
-               test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply
-
-               head_name="$(cat "$dotest"/head-name)" &&
-               case "$head_name" in
-               refs/*)
-                       git symbolic-ref HEAD $head_name ||
-                       die "Could not move back to $head_name"
-                       ;;
-               esac
-               git reset --hard $(cat "$dotest/orig-head")
-               rm -r "$dotest"
-               exit
+       --continue|--skip|--abort)
+               test $total_argc -eq 2 || usage
+               action=${1##--}
                ;;
        --onto)
                test 2 -le "$#" || usage
-               newbase="$2"
+               onto="$2"
                shift
                ;;
-       -M|-m|--m|--me|--mer|--merg|--merge)
+       -i)
+               interactive_rebase=explicit
+               ;;
+       -p)
+               preserve_merges=t
+               test -z "$interactive_rebase" && interactive_rebase=implied
+               ;;
+       --autosquash)
+               autosquash=t
+               ;;
+       --no-autosquash)
+               autosquash=
+               ;;
+       -M|-m)
                do_merge=t
                ;;
-       -X*|--strategy-option*)
-               case "$#,$1" in
-               1,-X|1,--strategy-option)
-                       usage ;;
-               *,-X|*,--strategy-option)
-                       newopt="$2"
-                       shift ;;
-               *,--strategy-option=*)
-                       newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;;
-               *,-X*)
-                       newopt="$(expr " $1" : ' -X\(.*\)')" ;;
-               1,*)
-                       usage ;;
-               esac
-               strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")"
+       -X)
+               shift
+               strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$1")"
                do_merge=t
+               test -z "$strategy" && strategy=recursive
                ;;
-       -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
-               --strateg=*|--strategy=*|\
-       -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
-               case "$#,$1" in
-               *,*=*)
-                       strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
-               1,*)
-                       usage ;;
-               *)
-                       strategy="$2"
-                       shift ;;
-               esac
+       -s)
+               shift
+               strategy="$1"
                do_merge=t
                ;;
-       -n|--no-stat)
+       -n)
                diffstat=
                ;;
        --stat)
                diffstat=t
                ;;
-       -v|--verbose)
+       -v)
                verbose=t
                diffstat=t
                GIT_QUIET=
                ;;
-       -q|--quiet)
+       -q)
                GIT_QUIET=t
                git_am_opt="$git_am_opt -q"
                verbose=
                diffstat=
                ;;
-       --whitespace=*)
-               git_am_opt="$git_am_opt $1"
+       --whitespace)
+               shift
+               git_am_opt="$git_am_opt --whitespace=$1"
                case "$1" in
-               --whitespace=fix|--whitespace=strip)
+               fix|strip)
                        force_rebase=t
                        ;;
                esac
@@ -363,22 +275,21 @@ do
                git_am_opt="$git_am_opt $1"
                force_rebase=t
                ;;
-       -C*)
-               git_am_opt="$git_am_opt $1"
+       -C)
+               shift
+               git_am_opt="$git_am_opt -C$1"
                ;;
        --root)
                rebase_root=t
                ;;
-       -f|--f|--fo|--for|--forc|--force|--force-r|--force-re|--force-reb|--force-reba|--force-rebas|--force-rebase|--no-ff)
+       -f|--no-ff)
                force_rebase=t
                ;;
        --rerere-autoupdate|--no-rerere-autoupdate)
                allow_rerere_autoupdate="$1"
                ;;
-       -*)
-               usage
-               ;;
-       *)
+       --)
+               shift
                break
                ;;
        esac
@@ -386,58 +297,106 @@ do
 done
 test $# -gt 2 && usage
 
-if test $# -eq 0 && test -z "$rebase_root"
+if test -n "$action"
 then
-       test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || usage
-       test -d "$dotest" -o -f "$GIT_DIR"/rebase-apply/rebasing &&
-               die 'A rebase is in progress, try --continue, --skip or --abort.'
+       test -z "$in_progress" && die "No rebase in progress?"
+       # Only interactive rebase uses detailed reflog messages
+       if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
+       then
+               GIT_REFLOG_ACTION="rebase -i ($action)"
+               export GIT_REFLOG_ACTION
+       fi
 fi
 
-# Make sure we do not have $GIT_DIR/rebase-apply
-if test -z "$do_merge"
+case "$action" in
+continue)
+       # Sanity check
+       git rev-parse --verify HEAD >/dev/null ||
+               die "Cannot read HEAD"
+       git update-index --ignore-submodules --refresh &&
+       git diff-files --quiet --ignore-submodules || {
+               echo "You must edit all merge conflicts and then"
+               echo "mark them as resolved using git add"
+               exit 1
+       }
+       read_basic_state
+       run_specific_rebase
+       ;;
+skip)
+       output git reset --hard HEAD || exit $?
+       read_basic_state
+       run_specific_rebase
+       ;;
+abort)
+       git rerere clear
+       read_basic_state
+       case "$head_name" in
+       refs/*)
+               git symbolic-ref HEAD $head_name ||
+               die "Could not move back to $head_name"
+               ;;
+       esac
+       output git reset --hard $orig_head
+       rm -r "$state_dir"
+       exit
+       ;;
+esac
+
+# Make sure no rebase is in progress
+if test -n "$in_progress"
 then
-       if mkdir "$GIT_DIR"/rebase-apply 2>/dev/null
-       then
-               rmdir "$GIT_DIR"/rebase-apply
-       else
-               echo >&2 '
-It seems that I cannot create a rebase-apply directory, and
-I wonder if you are in the middle of patch application or another
-rebase.  If that is not the case, please
-       rm -fr '"$GIT_DIR"'/rebase-apply
+       die '
+It seems that there is already a '"${state_dir##*/}"' directory, and
+I wonder if you are in the middle of another rebase.  If that is the
+case, please try
+       git rebase (--continue | --abort | --skip)
+If that is not the case, please
+       rm -fr '"$state_dir"'
 and run me again.  I am stopping in case you still have something
 valuable there.'
-               exit 1
-       fi
-else
-       if test -d "$dotest"
-       then
-               die "previous rebase directory $dotest still exists." \
-                       'Try git rebase (--continue | --abort | --skip)'
-       fi
 fi
 
-require_clean_work_tree "rebase" "Please commit or stash them."
+if test -n "$interactive_rebase"
+then
+       type=interactive
+       state_dir="$merge_dir"
+elif test -n "$do_merge"
+then
+       type=merge
+       state_dir="$merge_dir"
+else
+       type=am
+       state_dir="$apply_dir"
+fi
 
 if test -z "$rebase_root"
 then
-       # The upstream head must be given.  Make sure it is valid.
-       upstream_name="$1"
-       shift
+       case "$#" in
+       0)
+               if ! upstream_name=$(git rev-parse --symbolic-full-name \
+                       --verify -q @{upstream} 2>/dev/null)
+               then
+                       . git-parse-remote
+                       error_on_missing_default_upstream "rebase" "rebase" \
+                               "against" "git rebase <upstream branch>"
+               fi
+               ;;
+       *)      upstream_name="$1"
+               shift
+               ;;
+       esac
        upstream=`git rev-parse --verify "${upstream_name}^0"` ||
        die "invalid upstream $upstream_name"
-       unset root_flag
        upstream_arg="$upstream_name"
 else
-       test -z "$newbase" && die "--root must be used with --onto"
+       test -z "$onto" && die "You must specify --onto when using --root"
        unset upstream_name
        unset upstream
-       root_flag="--root"
-       upstream_arg="$root_flag"
+       upstream_arg=--root
 fi
 
 # Make sure the branch to rebase onto is valid.
-onto_name=${newbase-"$upstream_name"}
+onto_name=${onto-"$upstream_name"}
 case "$onto_name" in
 *...*)
        if      left=${onto_name%...*} right=${onto_name#*...} &&
@@ -456,13 +415,11 @@ case "$onto_name" in
        fi
        ;;
 *)
-       onto=$(git rev-parse --verify "${onto_name}^0") || exit
+       onto=$(git rev-parse --verify "${onto_name}^0") ||
+       die "Does not point to a valid commit: $1"
        ;;
 esac
 
-# If a hook exists, give it a chance to interrupt
-run_pre_rebase_hook "$upstream_arg" "$@"
-
 # If the branch to rebase is given, that is the branch we will rebase
 # $branch_name -- branch being rebased, or HEAD (already detached)
 # $orig_head -- commit object name of tip of the branch before rebasing
@@ -475,10 +432,10 @@ case "$#" in
        switch_to="$1"
 
        if git show-ref --verify --quiet -- "refs/heads/$1" &&
-          branch=$(git rev-parse -q --verify "refs/heads/$1")
+          orig_head=$(git rev-parse -q --verify "refs/heads/$1")
        then
                head_name="refs/heads/$1"
-       elif branch=$(git rev-parse -q --verify "$1")
+       elif orig_head=$(git rev-parse -q --verify "$1")
        then
                head_name="detached HEAD"
        else
@@ -496,20 +453,23 @@ case "$#" in
                head_name="detached HEAD"
                branch_name=HEAD ;# detached
        fi
-       branch=$(git rev-parse --verify "${branch_name}^0") || exit
+       orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
        ;;
 esac
-orig_head=$branch
 
-# Now we are rebasing commits $upstream..$branch (or with --root,
-# everything leading up to $branch) on top of $onto
+require_clean_work_tree "rebase" "Please commit or stash them."
+
+# Now we are rebasing commits $upstream..$orig_head (or with --root,
+# everything leading up to $orig_head) on top of $onto
 
 # Check if we are already based on $onto with linear history,
-# but this should be done only when upstream and onto are the same.
-mb=$(git merge-base "$onto" "$branch")
-if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
+# but this should be done only when upstream and onto are the same
+# and if this is not an interactive rebase.
+mb=$(git merge-base "$onto" "$orig_head")
+if test "$type" != interactive && test "$upstream" = "$onto" &&
+       test "$mb" = "$onto" &&
        # linear history?
-       ! (git rev-list --parents "$onto".."$branch" | sane_grep " .* ") > /dev/null
+       ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
 then
        if test -z "$force_rebase"
        then
@@ -522,10 +482,8 @@ then
        fi
 fi
 
-# Detach HEAD and reset the tree
-say "First, rewinding head to replay your work on top of it..."
-git checkout -q "$onto^0" || die "could not detach HEAD"
-git update-ref ORIG_HEAD $branch
+# If a hook exists, give it a chance to interrupt
+run_pre_rebase_hook "$upstream_arg" "$@"
 
 if test -n "$diffstat"
 then
@@ -537,9 +495,16 @@ then
        GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
 fi
 
+test "$type" = interactive && run_specific_rebase
+
+# Detach HEAD and reset the tree
+say "First, rewinding head to replay your work on top of it..."
+git checkout -q "$onto^0" || die "could not detach HEAD"
+git update-ref ORIG_HEAD $orig_head
+
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast-forwarded.
-if test "$mb" = "$branch"
+if test "$mb" = "$orig_head"
 then
        say "Fast-forwarded $branch_name to $onto_name."
        move_to_original_branch
@@ -553,51 +518,4 @@ else
        revisions="$upstream..$orig_head"
 fi
 
-if test -z "$do_merge"
-then
-       git format-patch -k --stdout --full-index --ignore-if-in-upstream \
-               --src-prefix=a/ --dst-prefix=b/ \
-               --no-renames $root_flag "$revisions" |
-       git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
-       move_to_original_branch
-       ret=$?
-       test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
-               echo $head_name > "$GIT_DIR"/rebase-apply/head-name &&
-               echo $onto > "$GIT_DIR"/rebase-apply/onto &&
-               echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head &&
-               echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet
-       exit $ret
-fi
-
-# start doing a rebase with git-merge
-# this is rename-aware if the recursive (default) strategy is used
-
-mkdir -p "$dotest"
-echo "$onto" > "$dotest/onto"
-echo "$onto_name" > "$dotest/onto_name"
-prev_head=$orig_head
-echo "$prev_head" > "$dotest/prev_head"
-echo "$orig_head" > "$dotest/orig-head"
-echo "$head_name" > "$dotest/head-name"
-echo "$GIT_QUIET" > "$dotest/quiet"
-
-msgnum=0
-for cmt in `git rev-list --reverse --no-merges "$revisions"`
-do
-       msgnum=$(($msgnum + 1))
-       echo "$cmt" > "$dotest/cmt.$msgnum"
-done
-
-echo 1 >"$dotest/msgnum"
-echo $msgnum >"$dotest/end"
-
-end=$msgnum
-msgnum=1
-
-while test "$msgnum" -le "$end"
-do
-       call_merge "$msgnum"
-       continue_merge
-done
-
-finish_rb_merge
+run_specific_rebase
index 76565de2ee517f48001ffacca32e3c08320cfe38..98ab33aae7e35c2d288bc34ddb2bbc71f8a16cdd 100755 (executable)
@@ -1091,7 +1091,7 @@ X-Mailer: git-send-email $gitversion
                            "VALUES: server=$smtp_server ",
                            "encryption=$smtp_encryption ",
                            "hello=$smtp_domain",
-                           defined $smtp_server_port ? "port=$smtp_server_port" : "";
+                           defined $smtp_server_port ? " port=$smtp_server_port" : "";
                }
 
                if (defined $smtp_authuser) {
index b010a673097a9cfcf009b307114669b6221d066c..bf110e9cb77a0e9930c427408e18d323db2c8916 100755 (executable)
@@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
 USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
-   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
+   or: $dashless [--quiet] update [--init] [-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>
    or: $dashless [--quiet] sync [--] [<path>...]"
@@ -402,6 +402,9 @@ cmd_update()
                -N|--no-fetch)
                        nofetch=1
                        ;;
+               -f|--force)
+                       force=$1
+                       ;;
                -r|--rebase)
                        update="rebase"
                        ;;
@@ -480,10 +483,11 @@ cmd_update()
 
                if test "$subsha1" != "$sha1"
                then
-                       force=
-                       if test -z "$subsha1"
+                       subforce=$force
+                       # If we don't already have a -f flag and the submodule has never been checked out
+                       if test -z "$subsha1" -a -z "$force"
                        then
-                               force="-f"
+                               subforce="-f"
                        fi
 
                        if test -z "$nofetch"
@@ -515,7 +519,7 @@ cmd_update()
                                msg="merged in"
                                ;;
                        *)
-                               command="git checkout $force -q"
+                               command="git checkout $subforce -q"
                                action="checkout"
                                msg="checked out"
                                ;;
diff --git a/git.c b/git.c
index ef598c3e7053b8dd2859f4d582ce2917a804fe42..a5ef3c69ff58434e521d2c42f1b2fa275b872828 100644 (file)
--- a/git.c
+++ b/git.c
@@ -6,7 +6,7 @@
 #include "run-command.h"
 
 const char git_usage_string[] =
-       "git [--version] [--exec-path[=<path>]] [--html-path]\n"
+       "git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
        "           [-p|--paginate|--no-pager] [--no-replace-objects]\n"
        "           [--bare] [--git-dir=<path>] [--work-tree=<path>]\n"
        "           [-c name=value] [--help]\n"
@@ -95,6 +95,12 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                } else if (!strcmp(cmd, "--html-path")) {
                        puts(system_path(GIT_HTML_PATH));
                        exit(0);
+               } else if (!strcmp(cmd, "--man-path")) {
+                       puts(system_path(GIT_MAN_PATH));
+                       exit(0);
+               } else if (!strcmp(cmd, "--info-path")) {
+                       puts(system_path(GIT_INFO_PATH));
+                       exit(0);
                } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
                        use_pager = 1;
                } else if (!strcmp(cmd, "--no-pager")) {
@@ -179,6 +185,8 @@ static int handle_alias(int *argcp, const char ***argv)
                if (alias_string[0] == '!') {
                        const char **alias_argv;
                        int argc = *argcp, i;
+                       struct strbuf sb = STRBUF_INIT;
+                       const char *env[2];
 
                        commit_pager_choice();
 
@@ -189,7 +197,13 @@ static int handle_alias(int *argcp, const char ***argv)
                                alias_argv[i] = (*argv)[i];
                        alias_argv[argc] = NULL;
 
-                       ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+                       strbuf_addstr(&sb, "GIT_PREFIX=");
+                       if (subdir)
+                               strbuf_addstr(&sb, subdir);
+                       env[0] = sb.buf;
+                       env[1] = NULL;
+                       ret = run_command_v_opt_cd_env(alias_argv, RUN_USING_SHELL, NULL, env);
+                       strbuf_release(&sb);
                        if (ret >= 0)   /* normal exit */
                                exit(ret);
 
index ee69ea683aedf81cd6e6eec0f500bddf2ff54450..66eadb4ab2939b193fcf84d8d805e0b29ad5e9d2 100755 (executable)
@@ -186,7 +186,7 @@ our %known_snapshot_formats = (
                'type' => 'application/x-gzip',
                'suffix' => '.tar.gz',
                'format' => 'tar',
-               'compressor' => ['gzip']},
+               'compressor' => ['gzip', '-n']},
 
        'tbz2' => {
                'display' => 'tar.bz2',
@@ -412,20 +412,23 @@ our %feature = (
                'override' => 0,
                'default' => []},
 
-       # Allow gitweb scan project content tags described in ctags/
-       # of project repository, and display the popular Web 2.0-ish
-       # "tag cloud" near the project list. Note that this is something
-       # COMPLETELY different from the normal Git tags.
+       # Allow gitweb scan project content tags of project repository,
+       # and display the popular Web 2.0-ish "tag cloud" near the projects
+       # list.  Note that this is something COMPLETELY different from the
+       # normal Git tags.
 
        # gitweb by itself can show existing tags, but it does not handle
-       # tagging itself; you need an external application for that.
-       # For an example script, check Girocco's cgi/tagproj.cgi.
+       # tagging itself; you need to do it externally, outside gitweb.
+       # The format is described in git_get_project_ctags() subroutine.
        # You may want to install the HTML::TagCloud Perl module to get
        # a pretty tag cloud instead of just a list of tags.
 
        # To enable system wide have in $GITWEB_CONFIG
-       # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
+       # $feature{'ctags'}{'default'} = [1];
        # Project specific override is not supported.
+
+       # In the future whether ctags editing is enabled might depend
+       # on the value, but using 1 should always mean no editing of ctags.
        'ctags' => {
                'override' => 0,
                'default' => [0]},
@@ -703,6 +706,7 @@ our @cgi_param_mapping = (
        snapshot_format => "sf",
        extra_options => "opt",
        search_use_regexp => "sr",
+       ctag => "by_tag",
        # this must be last entry (for manipulation from JavaScript)
        javascript => "js"
 );
@@ -2572,23 +2576,66 @@ sub git_get_project_description {
        return $descr;
 }
 
+# supported formats:
+# * $GIT_DIR/ctags/<tagname> file (in 'ctags' subdirectory)
+#   - if its contents is a number, use it as tag weight,
+#   - otherwise add a tag with weight 1
+# * $GIT_DIR/ctags file, each line is a tag (with weight 1)
+#   the same value multiple times increases tag weight
+# * `gitweb.ctag' multi-valued repo config variable
 sub git_get_project_ctags {
-       my $path = shift;
+       my $project = shift;
        my $ctags = {};
 
-       $git_dir = "$projectroot/$path";
-       opendir my $dh, "$git_dir/ctags"
-               or return $ctags;
-       foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
-               open my $ct, '<', $_ or next;
-               my $val = <$ct>;
-               chomp $val;
-               close $ct;
-               my $ctag = $_; $ctag =~ s#.*/##;
-               $ctags->{$ctag} = $val;
+       $git_dir = "$projectroot/$project";
+       if (opendir my $dh, "$git_dir/ctags") {
+               my @files = grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh);
+               foreach my $tagfile (@files) {
+                       open my $ct, '<', $tagfile
+                               or next;
+                       my $val = <$ct>;
+                       chomp $val if $val;
+                       close $ct;
+
+                       (my $ctag = $tagfile) =~ s#.*/##;
+                       if ($val =~ /\d+/) {
+                               $ctags->{$ctag} = $val;
+                       } else {
+                               $ctags->{$ctag} = 1;
+                       }
+               }
+               closedir $dh;
+
+       } elsif (open my $fh, '<', "$git_dir/ctags") {
+               while (my $line = <$fh>) {
+                       chomp $line;
+                       $ctags->{$line}++ if $line;
+               }
+               close $fh;
+
+       } else {
+               my $taglist = config_to_multi(git_get_project_config('ctag'));
+               foreach my $tag (@$taglist) {
+                       $ctags->{$tag}++;
+               }
        }
-       closedir $dh;
-       $ctags;
+
+       return $ctags;
+}
+
+# return hash, where keys are content tags ('ctags'),
+# and values are sum of weights of given tag in every project
+sub git_gather_all_ctags {
+       my $projects = shift;
+       my $ctags = {};
+
+       foreach my $p (@$projects) {
+               foreach my $ct (keys %{$p->{'ctags'}}) {
+                       $ctags->{$ct} += $p->{'ctags'}->{$ct};
+               }
+       }
+
+       return $ctags;
 }
 
 sub git_populate_project_tagcloud {
@@ -2606,33 +2653,49 @@ sub git_populate_project_tagcloud {
        }
 
        my $cloud;
+       my $matched = $cgi->param('by_tag');
        if (eval { require HTML::TagCloud; 1; }) {
                $cloud = HTML::TagCloud->new;
-               foreach (sort keys %ctags_lc) {
+               foreach my $ctag (sort keys %ctags_lc) {
                        # Pad the title with spaces so that the cloud looks
                        # less crammed.
-                       my $title = $ctags_lc{$_}->{topname};
+                       my $title = esc_html($ctags_lc{$ctag}->{topname});
                        $title =~ s/ /&nbsp;/g;
                        $title =~ s/^/&nbsp;/g;
                        $title =~ s/$/&nbsp;/g;
-                       $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count});
+                       if (defined $matched && $matched eq $ctag) {
+                               $title = qq(<span class="match">$title</span>);
+                       }
+                       $cloud->add($title, href(project=>undef, ctag=>$ctag),
+                                   $ctags_lc{$ctag}->{count});
                }
        } else {
-               $cloud = \%ctags_lc;
+               $cloud = {};
+               foreach my $ctag (keys %ctags_lc) {
+                       my $title = esc_html($ctags_lc{$ctag}->{topname}, -nbsp=>1);
+                       if (defined $matched && $matched eq $ctag) {
+                               $title = qq(<span class="match">$title</span>);
+                       }
+                       $cloud->{$ctag}{count} = $ctags_lc{$ctag}->{count};
+                       $cloud->{$ctag}{ctag} =
+                               $cgi->a({-href=>href(project=>undef, ctag=>$ctag)}, $title);
+               }
        }
-       $cloud;
+       return $cloud;
 }
 
 sub git_show_project_tagcloud {
        my ($cloud, $count) = @_;
-       print STDERR ref($cloud)."..\n";
        if (ref $cloud eq 'HTML::TagCloud') {
                return $cloud->html_and_css($count);
        } else {
-               my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud;
-               return '<p align="center">' . join (', ', map {
-                       $cgi->a({-href=>"$home_link?by_tag=$_"}, $cloud->{$_}->{topname})
-               } splice(@tags, 0, $count)) . '</p>';
+               my @tags = sort { $cloud->{$a}->{'count'} <=> $cloud->{$b}->{'count'} } keys %$cloud;
+               return
+                       '<div id="htmltagcloud"'.($project ? '' : ' align="center"').'>' .
+                       join (', ', map {
+                               $cloud->{$_}->{'ctag'}
+                       } splice(@tags, 0, $count)) .
+                       '</div>';
        }
 }
 
@@ -2651,21 +2714,23 @@ sub git_get_project_url_list {
 }
 
 sub git_get_projects_list {
-       my ($filter) = @_;
+       my $filter = shift || '';
        my @list;
 
-       $filter ||= '';
        $filter =~ s/\.git$//;
 
-       my $check_forks = gitweb_check_feature('forks');
-
        if (-d $projects_list) {
                # search in directory
-               my $dir = $projects_list . ($filter ? "/$filter" : '');
+               my $dir = $projects_list;
                # remove the trailing "/"
                $dir =~ s!/+$!!;
-               my $pfxlen = length("$dir");
-               my $pfxdepth = ($dir =~ tr!/!!);
+               my $pfxlen = length("$projects_list");
+               my $pfxdepth = ($projects_list =~ tr!/!!);
+               # when filtering, search only given subdirectory
+               if ($filter) {
+                       $dir .= "/$filter";
+                       $dir =~ s!/+$!!;
+               }
 
                File::Find::find({
                        follow_fast => 1, # follow symbolic links
@@ -2680,14 +2745,14 @@ sub git_get_projects_list {
                                # only directories can be git repositories
                                return unless (-d $_);
                                # don't traverse too deep (Find is super slow on os x)
+                               # $project_maxdepth excludes depth of $projectroot
                                if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
                                        $File::Find::prune = 1;
                                        return;
                                }
 
-                               my $subdir = substr($File::Find::name, $pfxlen + 1);
+                               my $path = substr($File::Find::name, $pfxlen + 1);
                                # we check related file in $projectroot
-                               my $path = ($filter ? "$filter/" : '') . $subdir;
                                if (check_export_ok("$projectroot/$path")) {
                                        push @list, { path => $path };
                                        $File::Find::prune = 1;
@@ -2700,7 +2765,6 @@ sub git_get_projects_list {
                # 'git%2Fgit.git Linus+Torvalds'
                # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
                # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
-               my %paths;
                open my $fd, '<', $projects_list or return;
        PROJECT:
                while (my $line = <$fd>) {
@@ -2711,32 +2775,9 @@ sub git_get_projects_list {
                        if (!defined $path) {
                                next;
                        }
-                       if ($filter ne '') {
-                               # looking for forks;
-                               my $pfx = substr($path, 0, length($filter));
-                               if ($pfx ne $filter) {
-                                       next PROJECT;
-                               }
-                               my $sfx = substr($path, length($filter));
-                               if ($sfx !~ /^\/.*\.git$/) {
-                                       next PROJECT;
-                               }
-                       } elsif ($check_forks) {
-                       PATH:
-                               foreach my $filter (keys %paths) {
-                                       # looking for forks;
-                                       my $pfx = substr($path, 0, length($filter));
-                                       if ($pfx ne $filter) {
-                                               next PATH;
-                                       }
-                                       my $sfx = substr($path, length($filter));
-                                       if ($sfx !~ /^\/.*\.git$/) {
-                                               next PATH;
-                                       }
-                                       # is a fork, don't include it in
-                                       # the list
-                                       next PROJECT;
-                               }
+                       # if $filter is rpovided, check if $path begins with $filter
+                       if ($filter && $path !~ m!^\Q$filter\E/!) {
+                               next;
                        }
                        if (check_export_ok("$projectroot/$path")) {
                                my $pr = {
@@ -2744,8 +2785,6 @@ sub git_get_projects_list {
                                        owner => to_utf8($owner),
                                };
                                push @list, $pr;
-                               (my $forks_path = $path) =~ s/\.git$//;
-                               $paths{$forks_path}++;
                        }
                }
                close $fd;
@@ -2753,6 +2792,98 @@ sub git_get_projects_list {
        return @list;
 }
 
+# written with help of Tree::Trie module (Perl Artistic License, GPL compatibile)
+# as side effects it sets 'forks' field to list of forks for forked projects
+sub filter_forks_from_projects_list {
+       my $projects = shift;
+
+       my %trie; # prefix tree of directories (path components)
+       # generate trie out of those directories that might contain forks
+       foreach my $pr (@$projects) {
+               my $path = $pr->{'path'};
+               $path =~ s/\.git$//;      # forks of 'repo.git' are in 'repo/' directory
+               next if ($path =~ m!/$!); # skip non-bare repositories, e.g. 'repo/.git'
+               next unless ($path);      # skip '.git' repository: tests, git-instaweb
+               next unless (-d $path);   # containing directory exists
+               $pr->{'forks'} = [];      # there can be 0 or more forks of project
+
+               # add to trie
+               my @dirs = split('/', $path);
+               # walk the trie, until either runs out of components or out of trie
+               my $ref = \%trie;
+               while (scalar @dirs &&
+                      exists($ref->{$dirs[0]})) {
+                       $ref = $ref->{shift @dirs};
+               }
+               # create rest of trie structure from rest of components
+               foreach my $dir (@dirs) {
+                       $ref = $ref->{$dir} = {};
+               }
+               # create end marker, store $pr as a data
+               $ref->{''} = $pr if (!exists $ref->{''});
+       }
+
+       # filter out forks, by finding shortest prefix match for paths
+       my @filtered;
+ PROJECT:
+       foreach my $pr (@$projects) {
+               # trie lookup
+               my $ref = \%trie;
+       DIR:
+               foreach my $dir (split('/', $pr->{'path'})) {
+                       if (exists $ref->{''}) {
+                               # found [shortest] prefix, is a fork - skip it
+                               push @{$ref->{''}{'forks'}}, $pr;
+                               next PROJECT;
+                       }
+                       if (!exists $ref->{$dir}) {
+                               # not in trie, cannot have prefix, not a fork
+                               push @filtered, $pr;
+                               next PROJECT;
+                       }
+                       # If the dir is there, we just walk one step down the trie.
+                       $ref = $ref->{$dir};
+               }
+               # we ran out of trie
+               # (shouldn't happen: it's either no match, or end marker)
+               push @filtered, $pr;
+       }
+
+       return @filtered;
+}
+
+# note: fill_project_list_info must be run first,
+# for 'descr_long' and 'ctags' to be filled
+sub search_projects_list {
+       my ($projlist, %opts) = @_;
+       my $tagfilter  = $opts{'tagfilter'};
+       my $searchtext = $opts{'searchtext'};
+
+       return @$projlist
+               unless ($tagfilter || $searchtext);
+
+       my @projects;
+ PROJECT:
+       foreach my $pr (@$projlist) {
+
+               if ($tagfilter) {
+                       next unless ref($pr->{'ctags'}) eq 'HASH';
+                       next unless
+                               grep { lc($_) eq lc($tagfilter) } keys %{$pr->{'ctags'}};
+               }
+
+               if ($searchtext) {
+                       next unless
+                               $pr->{'path'} =~ /$searchtext/ ||
+                               $pr->{'descr_long'} =~ /$searchtext/;
+               }
+
+               push @projects, $pr;
+       }
+
+       return @projects;
+}
+
 our $gitweb_project_owner = undef;
 sub git_get_project_list_from_file {
 
@@ -4742,7 +4873,7 @@ sub git_patchset_body {
 # project in the list, removing invalid projects from returned list
 # NOTE: modifies $projlist, but does not remove entries from it
 sub fill_project_list_info {
-       my ($projlist, $check_forks) = @_;
+       my $projlist = shift;
        my @projects;
 
        my $show_ctags = gitweb_check_feature('ctags');
@@ -4762,23 +4893,36 @@ sub fill_project_list_info {
                if (!defined $pr->{'owner'}) {
                        $pr->{'owner'} = git_get_project_owner("$pr->{'path'}") || "";
                }
-               if ($check_forks) {
-                       my $pname = $pr->{'path'};
-                       if (($pname =~ s/\.git$//) &&
-                           ($pname !~ /\/$/) &&
-                           (-d "$projectroot/$pname")) {
-                               $pr->{'forks'} = "-d $projectroot/$pname";
-                       } else {
-                               $pr->{'forks'} = 0;
-                       }
+               if ($show_ctags) {
+                       $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
                }
-               $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'});
                push @projects, $pr;
        }
 
        return @projects;
 }
 
+sub sort_projects_list {
+       my ($projlist, $order) = @_;
+       my @projects;
+
+       my %order_info = (
+               project => { key => 'path', type => 'str' },
+               descr => { key => 'descr_long', type => 'str' },
+               owner => { key => 'owner', type => 'str' },
+               age => { key => 'age', type => 'num' }
+       );
+       my $oi = $order_info{$order};
+       return @$projlist unless defined $oi;
+       if ($oi->{'type'} eq 'str') {
+               @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @$projlist;
+       } else {
+               @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @$projlist;
+       }
+
+       return @projects;
+}
+
 # print 'sort by' <th> element, generating 'sort by $name' replay link
 # if that order is not selected
 sub print_sort_th {
@@ -4805,36 +4949,42 @@ sub format_sort_th {
 sub git_project_list_body {
        # actually uses global variable $project
        my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
+       my @projects = @$projlist;
 
        my $check_forks = gitweb_check_feature('forks');
-       my @projects = fill_project_list_info($projlist, $check_forks);
+       my $show_ctags  = gitweb_check_feature('ctags');
+       my $tagfilter = $show_ctags ? $cgi->param('by_tag') : undef;
+       $check_forks = undef
+               if ($tagfilter || $searchtext);
+
+       # filtering out forks before filling info allows to do less work
+       @projects = filter_forks_from_projects_list(\@projects)
+               if ($check_forks);
+       @projects = fill_project_list_info(\@projects);
+       # searching projects require filling to be run before it
+       @projects = search_projects_list(\@projects,
+                                        'searchtext' => $searchtext,
+                                        'tagfilter'  => $tagfilter)
+               if ($tagfilter || $searchtext);
 
        $order ||= $default_projects_order;
        $from = 0 unless defined $from;
        $to = $#projects if (!defined $to || $#projects < $to);
 
-       my %order_info = (
-               project => { key => 'path', type => 'str' },
-               descr => { key => 'descr_long', type => 'str' },
-               owner => { key => 'owner', type => 'str' },
-               age => { key => 'age', type => 'num' }
-       );
-       my $oi = $order_info{$order};
-       if ($oi->{'type'} eq 'str') {
-               @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
-       } else {
-               @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
+       # short circuit
+       if ($from > $to) {
+               print "<center>\n".
+                     "<b>No such projects found</b><br />\n".
+                     "Click ".$cgi->a({-href=>href(project=>undef)},"here")." to view all projects<br />\n".
+                     "</center>\n<br />\n";
+               return;
        }
 
-       my $show_ctags = gitweb_check_feature('ctags');
+       @projects = sort_projects_list(\@projects, $order);
+
        if ($show_ctags) {
-               my %ctags;
-               foreach my $p (@projects) {
-                       foreach my $ct (keys %{$p->{'ctags'}}) {
-                               $ctags{$ct} += $p->{'ctags'}->{$ct};
-                       }
-               }
-               my $cloud = git_populate_project_tagcloud(\%ctags);
+               my $ctags = git_gather_all_ctags(\@projects);
+               my $cloud = git_populate_project_tagcloud($ctags);
                print git_show_project_tagcloud($cloud, 64);
        }
 
@@ -4852,32 +5002,26 @@ sub git_project_list_body {
                      "</tr>\n";
        }
        my $alternate = 1;
-       my $tagfilter = $cgi->param('by_tag');
        for (my $i = $from; $i <= $to; $i++) {
                my $pr = $projects[$i];
 
-               next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
-               next if $searchtext and not $pr->{'path'} =~ /$searchtext/
-                       and not $pr->{'descr_long'} =~ /$searchtext/;
-               # Weed out forks or non-matching entries of search
-               if ($check_forks) {
-                       my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#;
-                       $forkbase="^$forkbase" if $forkbase;
-                       next if not $searchtext and not $tagfilter and $show_ctags
-                               and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe
-               }
-
                if ($alternate) {
                        print "<tr class=\"dark\">\n";
                } else {
                        print "<tr class=\"light\">\n";
                }
                $alternate ^= 1;
+
                if ($check_forks) {
                        print "<td>";
                        if ($pr->{'forks'}) {
-                               print "<!-- $pr->{'forks'} -->\n";
-                               print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks")}, "+");
+                               my $nforks = scalar @{$pr->{'forks'}};
+                               if ($nforks > 0) {
+                                       print $cgi->a({-href => href(project=>$pr->{'path'}, action=>"forks"),
+                                                      -title => "$nforks forks"}, "+");
+                               } else {
+                                       print $cgi->span({-title => "$nforks forks"}, "+");
+                               }
                        }
                        print "</td>\n";
                }
@@ -5357,7 +5501,10 @@ sub git_forks {
 }
 
 sub git_project_index {
-       my @projects = git_get_projects_list($project);
+       my @projects = git_get_projects_list();
+       if (!@projects) {
+               die_error(404, "No projects found");
+       }
 
        print $cgi->header(
                -type => 'text/plain',
@@ -5399,7 +5546,11 @@ sub git_summary {
        my $check_forks = gitweb_check_feature('forks');
 
        if ($check_forks) {
+               # find forks of a project
                @forklist = git_get_projects_list($project);
+               # filter out forks of forks
+               @forklist = filter_forks_from_projects_list(\@forklist)
+                       if (@forklist);
        }
 
        git_header_html();
@@ -5428,13 +5579,14 @@ sub git_summary {
        my $show_ctags = gitweb_check_feature('ctags');
        if ($show_ctags) {
                my $ctags = git_get_project_ctags($project);
-               my $cloud = git_populate_project_tagcloud($ctags);
-               print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
-               print "</td>\n<td>" unless %$ctags;
-               print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
-               print "</td>\n<td>" if %$ctags;
-               print git_show_project_tagcloud($cloud, 48);
-               print "</td></tr>";
+               if (%$ctags) {
+                       # without ability to add tags, don't show if there are none
+                       my $cloud = git_populate_project_tagcloud($ctags);
+                       print "<tr id=\"metadata_ctags\">" .
+                             "<td>content tags</td>" .
+                             "<td>".git_show_project_tagcloud($cloud, 48)."</td>" .
+                             "</tr>\n";
+               }
        }
 
        print "</table>\n";
@@ -7319,6 +7471,9 @@ sub git_atom {
 
 sub git_opml {
        my @list = git_get_projects_list();
+       if (!@list) {
+               die_error(404, "No projects found");
+       }
 
        print $cgi->header(
                -type => 'text/xml',
index d18346c0f5c9ce73f3fe9a1efc7b1b63e7380bb8..28bfe768f7749e455f522fcfedeb2350da646416 100644 (file)
@@ -169,7 +169,7 @@ enum dav_header_flag {
        DAV_HEADER_TIMEOUT = (1u << 2)
 };
 
-static char *xml_entities(char *s)
+static char *xml_entities(const char *s)
 {
        struct strbuf buf = STRBUF_INIT;
        while (*s) {
@@ -197,6 +197,34 @@ static char *xml_entities(char *s)
        return strbuf_detach(&buf, NULL);
 }
 
+static void curl_setup_http_get(CURL *curl, const char *url,
+               const char *custom_req)
+{
+       curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+       curl_easy_setopt(curl, CURLOPT_URL, url);
+       curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, custom_req);
+       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_null);
+}
+
+static void curl_setup_http(CURL *curl, const char *url,
+               const char *custom_req, struct buffer *buffer,
+               curl_write_callback write_fn)
+{
+       curl_easy_setopt(curl, CURLOPT_PUT, 1);
+       curl_easy_setopt(curl, CURLOPT_URL, url);
+       curl_easy_setopt(curl, CURLOPT_INFILE, buffer);
+       curl_easy_setopt(curl, CURLOPT_INFILESIZE, buffer->buf.len);
+       curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
+#ifndef NO_CURL_IOCTL
+       curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
+       curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &buffer);
+#endif
+       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_fn);
+       curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
+       curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, custom_req);
+       curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
+}
+
 static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum dav_header_flag options)
 {
        struct strbuf buf = STRBUF_INIT;
@@ -272,11 +300,8 @@ static void start_mkcol(struct transfer_request *request)
        slot = get_active_slot();
        slot->callback_func = process_response;
        slot->callback_data = request;
-       curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); /* undo PUT setup */
-       curl_easy_setopt(slot->curl, CURLOPT_URL, request->url);
+       curl_setup_http_get(slot->curl, request->url, DAV_MKCOL);
        curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
 
        if (start_active_slot(slot)) {
                request->slot = slot;
@@ -395,19 +420,8 @@ static void start_put(struct transfer_request *request)
        slot = get_active_slot();
        slot->callback_func = process_response;
        slot->callback_data = request;
-       curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
-       curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
-#ifndef NO_CURL_IOCTL
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &request->buffer);
-#endif
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-       curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
-       curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_PUT, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, request->url);
+       curl_setup_http(slot->curl, request->url, DAV_PUT,
+                       &request->buffer, fwrite_null);
 
        if (start_active_slot(slot)) {
                request->slot = slot;
@@ -427,13 +441,10 @@ static void start_move(struct transfer_request *request)
        slot = get_active_slot();
        slot->callback_func = process_response;
        slot->callback_data = request;
-       curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); /* undo PUT setup */
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MOVE);
+       curl_setup_http_get(slot->curl, request->url, DAV_MOVE);
        dav_headers = curl_slist_append(dav_headers, request->dest);
        dav_headers = curl_slist_append(dav_headers, "Overwrite: T");
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, request->url);
 
        if (start_active_slot(slot)) {
                request->slot = slot;
@@ -458,10 +469,7 @@ static int refresh_lock(struct remote_lock *lock)
 
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_LOCK);
+       curl_setup_http_get(slot->curl, lock->url, DAV_LOCK);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
 
        if (start_active_slot(slot)) {
@@ -797,7 +805,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)
        }
 }
 
-static void one_remote_ref(char *refname);
+static void one_remote_ref(const char *refname);
 
 static void
 xml_start_tag(void *userData, const char *name, const char **atts)
@@ -876,10 +884,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
                ep[1] = '\0';
                slot = get_active_slot();
                slot->results = &results;
-               curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
-               curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-               curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);
-               curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
+               curl_setup_http_get(slot->curl, url, DAV_MKCOL);
                if (start_active_slot(slot)) {
                        run_active_slot(slot);
                        if (results.curl_result != CURLE_OK &&
@@ -909,19 +914,9 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
 
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
-       curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
-#ifndef NO_CURL_IOCTL
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
-#endif
-       curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-       curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_LOCK);
+       curl_setup_http(slot->curl, url, DAV_LOCK, &out_buffer, fwrite_buffer);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
+       curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 
        lock = xcalloc(1, sizeof(*lock));
        lock->timeout = -1;
@@ -987,9 +982,7 @@ static int unlock_remote(struct remote_lock *lock)
 
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_UNLOCK);
+       curl_setup_http_get(slot->curl, lock->url, DAV_UNLOCK);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
 
        if (start_active_slot(slot)) {
@@ -1167,19 +1160,10 @@ static void remote_ls(const char *path, int flags,
 
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
-       curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
-#ifndef NO_CURL_IOCTL
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
-#endif
-       curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-       curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PROPFIND);
+       curl_setup_http(slot->curl, url, DAV_PROPFIND,
+                       &out_buffer, fwrite_buffer);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
+       curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 
        if (start_active_slot(slot)) {
                run_active_slot(slot);
@@ -1250,19 +1234,10 @@ static int locking_available(void)
 
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
-       curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
-#ifndef NO_CURL_IOCTL
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
-#endif
-       curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, repo->url);
-       curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PROPFIND);
+       curl_setup_http(slot->curl, repo->url, DAV_PROPFIND,
+                       &out_buffer, fwrite_buffer);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
+       curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 
        if (start_active_slot(slot)) {
                run_active_slot(slot);
@@ -1436,19 +1411,9 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
 
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
-       curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
-#ifndef NO_CURL_IOCTL
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
-       curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &out_buffer);
-#endif
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
+       curl_setup_http(slot->curl, lock->url, DAV_PUT,
+                       &out_buffer, fwrite_null);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
-       curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_PUT, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
 
        if (start_active_slot(slot)) {
                run_active_slot(slot);
@@ -1471,7 +1436,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
 
 static struct ref *remote_refs;
 
-static void one_remote_ref(char *refname)
+static void one_remote_ref(const char *refname)
 {
        struct ref *ref;
        struct object *obj;
@@ -1572,19 +1537,9 @@ static void update_remote_info_refs(struct remote_lock *lock)
 
                slot = get_active_slot();
                slot->results = &results;
-               curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
-               curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
-               curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
-#ifndef NO_CURL_IOCTL
-               curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, ioctl_buffer);
-               curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, &buffer);
-#endif
-               curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-               curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
+               curl_setup_http(slot->curl, lock->url, DAV_PUT,
+                               &buffer, fwrite_null);
                curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
-               curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 1);
-               curl_easy_setopt(slot->curl, CURLOPT_PUT, 1);
-               curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
 
                if (start_active_slot(slot)) {
                        run_active_slot(slot);
@@ -1660,7 +1615,7 @@ static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha
        return (merge_bases && !merge_bases->next && merge_bases->item == branch);
 }
 
-static int delete_remote_branch(char *pattern, int force)
+static int delete_remote_branch(const char *pattern, int force)
 {
        struct ref *refs = remote_refs;
        struct ref *remote_ref = NULL;
@@ -1742,10 +1697,7 @@ static int delete_remote_branch(char *pattern, int force)
        sprintf(url, "%s%s", repo->url, remote_ref->name);
        slot = get_active_slot();
        slot->results = &results;
-       curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
-       curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
-       curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-       curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_DELETE);
+       curl_setup_http_get(slot->curl, url, DAV_DELETE);
        if (start_active_slot(slot)) {
                run_active_slot(slot);
                free(url);
index 9bc8114c3bb2f6f87f7f61962a64c4e5b012dcf8..51a906e9e3316582561304995e1a1bbbdcd6ca7c 100644 (file)
@@ -185,7 +185,7 @@ static void process_alternates_response(void *callback_data)
        struct active_request_slot *slot = alt_req->slot;
        struct alt_base *tail = cdata->alt;
        const char *base = alt_req->base;
-       static const char null_byte = '\0';
+       const char null_byte = '\0';
        char *data;
        int i = 0;
 
@@ -218,7 +218,7 @@ static void process_alternates_response(void *callback_data)
                }
        }
 
-       fwrite_buffer(&null_byte, 1, 1, alt_req->buffer);
+       fwrite_buffer((char *)&null_byte, 1, 1, alt_req->buffer);
        alt_req->buffer->len--;
        data = alt_req->buffer->buf;
 
diff --git a/http.c b/http.c
index 9e767723ed1045445e91e79489cb8ec8bb861965..b2ae8de16db3abe2cad27249ae767f421aa6bb24 100644 (file)
--- a/http.c
+++ b/http.c
@@ -60,7 +60,7 @@ static struct curl_slist *no_pragma_header;
 
 static struct active_request_slot *active_queue_head;
 
-size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
+size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
        size_t size = eltsize * nmemb;
        struct buffer *buffer = buffer_;
@@ -92,7 +92,7 @@ curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp)
 }
 #endif
 
-size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
+size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
 {
        size_t size = eltsize * nmemb;
        struct strbuf *buffer = buffer_;
@@ -102,7 +102,7 @@ size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *buffer
        return size;
 }
 
-size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf)
+size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf)
 {
        data_received++;
        return eltsize * nmemb;
@@ -536,6 +536,7 @@ struct active_request_slot *get_active_slot(void)
        curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL);
        curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, NULL);
        curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, NULL);
+       curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, NULL);
        curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
 
@@ -1166,7 +1167,7 @@ abort:
 }
 
 /* Helpers for fetching objects (loose) */
-static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
+static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
                               void *data)
 {
        unsigned char expn[4096];
@@ -1183,7 +1184,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
        } while (posn < size);
 
        freq->stream.avail_in = size;
-       freq->stream.next_in = ptr;
+       freq->stream.next_in = (void *)ptr;
        do {
                freq->stream.next_out = expn;
                freq->stream.avail_out = sizeof(expn);
@@ -1202,7 +1203,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
        char *filename;
        char prevfile[PATH_MAX];
        int prevlocal;
-       unsigned char prev_buf[PREV_BUF_SIZE];
+       char prev_buf[PREV_BUF_SIZE];
        ssize_t prev_read = 0;
        long prev_posn = 0;
        char range[RANGE_HEADER_SIZE];
diff --git a/http.h b/http.h
index e9ed3c2e8272e43208e75459ec29fd8b6548ae4d..19b7134fa5c7ff9b65565dcbddccae1354f024c7 100644 (file)
--- a/http.h
+++ b/http.h
@@ -66,9 +66,9 @@ struct buffer {
 };
 
 /* Curl request read/write callbacks */
-extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
-extern size_t fwrite_buffer(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
-extern size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf);
+extern size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
+extern size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
+extern size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf);
 #ifndef NO_CURL_IOCTL
 extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);
 #endif
index 838b6a732e4758265432cbc9c8e8fc81568a2b50..0fb44e7ed7e8d7a98b8609778191715148f56c8d 100644 (file)
@@ -68,7 +68,7 @@ static void process_tree(struct rev_info *revs,
        struct tree_desc desc;
        struct name_entry entry;
        struct name_path me;
-       int all_interesting = (revs->diffopt.pathspec.nr == 0);
+       int match = revs->diffopt.pathspec.nr == 0 ? 2 : 0;
        int baselen = base->len;
 
        if (!revs->tree_objects)
@@ -85,7 +85,7 @@ static void process_tree(struct rev_info *revs,
        me.elem = name;
        me.elem_len = strlen(name);
 
-       if (!all_interesting) {
+       if (!match) {
                strbuf_addstr(base, name);
                if (base->len)
                        strbuf_addch(base, '/');
@@ -94,17 +94,13 @@ static void process_tree(struct rev_info *revs,
        init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
-               if (!all_interesting) {
-                       int showit = tree_entry_interesting(&entry,
-                                                           base, 0,
-                                                           &revs->diffopt.pathspec);
-
-                       if (showit < 0)
+               if (match != 2) {
+                       match = tree_entry_interesting(&entry, base, 0,
+                                                      &revs->diffopt.pathspec);
+                       if (match < 0)
                                break;
-                       else if (!showit)
+                       if (match == 0)
                                continue;
-                       else if (showit == 2)
-                               all_interesting = 1;
                }
 
                if (S_ISDIR(entry.mode))
index af131508ec7ffa3ac7b1b1b1cadfcda0040becf2..07ad1a3be4432928872c05859e0fffda026c502f 100644 (file)
 #include "dir.h"
 #include "submodule.h"
 
-static const char rename_limit_advice[] =
-"inexact rename detection was skipped because there were too many\n"
-"  files. You may want to set your merge.renamelimit variable to at least\n"
-"  %d and retry this merge.";
-
 static struct tree *shift_tree_object(struct tree *one, struct tree *two,
                                      const char *subtree_shift)
 {
@@ -278,7 +273,9 @@ static int save_files_dirs(const unsigned char *sha1,
 static int get_files_dirs(struct merge_options *o, struct tree *tree)
 {
        int n;
-       if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs, o))
+       struct pathspec match_all;
+       init_pathspec(&match_all, NULL);
+       if (read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o))
                return 0;
        n = o->current_file_set.nr + o->current_directory_set.nr;
        return n;
@@ -344,10 +341,11 @@ static void make_room_for_directories_of_df_conflicts(struct merge_options *o,
         * make room for the corresponding directory.  Such paths will
         * later be processed in process_df_entry() at the end.  If
         * the corresponding directory ends up being removed by the
-        * merge, then the file will be reinstated at that time;
-        * otherwise, if the file is not supposed to be removed by the
-        * merge, the contents of the file will be placed in another
-        * unique filename.
+        * merge, then the file will be reinstated at that time
+        * (albeit with a different timestamp!); otherwise, if the
+        * file is not supposed to be removed by the merge, the
+        * contents of the file will be placed in another unique
+        * filename.
         *
         * NOTE: This function relies on the fact that entries for a
         * D/F conflict will appear adjacent in the index, with the
@@ -358,6 +356,13 @@ static void make_room_for_directories_of_df_conflicts(struct merge_options *o,
        int last_len = 0;
        int i;
 
+       /*
+        * Do not do any of this crazyness during the recursive; we don't
+        * even write anything to the working tree!
+        */
+       if (o->call_depth)
+               return;
+
        for (i = 0; i < entries->nr; i++) {
                const char *path = entries->items[i].string;
                int len = strlen(path);
@@ -1260,9 +1265,13 @@ static int merge_content(struct merge_options *o,
        }
 
        if (mfi.clean && !df_conflict_remains &&
-           sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode)
+           sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode &&
+           !o->call_depth && !lstat(path, &st)) {
                output(o, 3, "Skipped %s (merged same as existing)", path);
-       else
+               add_cacheinfo(mfi.mode, mfi.sha, path,
+                             0 /*stage*/, 1 /*refresh*/, 0 /*options*/);
+               return mfi.clean;
+       } else
                output(o, 2, "Auto-merging %s", path);
 
        if (!mfi.clean) {
@@ -1652,8 +1661,9 @@ int merge_recursive(struct merge_options *o,
                commit_list_insert(h2, &(*result)->parents->next);
        }
        flush_output(o);
-       if (o->needed_rename_limit)
-               warning(rename_limit_advice, o->needed_rename_limit);
+       if (show(o, 2))
+               diff_warn_rename_limit("merge.renamelimit",
+                                      o->needed_rename_limit, 0);
        return clean;
 }
 
@@ -1711,15 +1721,15 @@ int merge_recursive_generic(struct merge_options *o,
 static int merge_recursive_config(const char *var, const char *value, void *cb)
 {
        struct merge_options *o = cb;
-       if (!strcasecmp(var, "merge.verbosity")) {
+       if (!strcmp(var, "merge.verbosity")) {
                o->verbosity = git_config_int(var, value);
                return 0;
        }
-       if (!strcasecmp(var, "diff.renamelimit")) {
+       if (!strcmp(var, "diff.renamelimit")) {
                o->diff_rename_limit = git_config_int(var, value);
                return 0;
        }
-       if (!strcasecmp(var, "merge.renamelimit")) {
+       if (!strcmp(var, "merge.renamelimit")) {
                o->merge_rename_limit = git_config_int(var, value);
                return 0;
        }
diff --git a/notes.c b/notes.c
index a013c1bc638dbf5a8111183a3f9d154721ec5e04..f6ce8489d31e48d30dfbc6aef4edf6dbb8314234 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -1053,7 +1053,8 @@ void init_display_notes(struct display_notes_opt *opt)
 
        assert(!display_notes_trees);
 
-       if (!opt || !opt->suppress_default_notes) {
+       if (!opt || opt->use_default_notes > 0 ||
+           (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {
                string_list_append(&display_notes_refs, default_notes_ref());
                display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
                if (display_ref_env) {
@@ -1066,9 +1067,9 @@ void init_display_notes(struct display_notes_opt *opt)
 
        git_config(notes_display_config, &load_config_refs);
 
-       if (opt && opt->extra_notes_refs) {
+       if (opt) {
                struct string_list_item *item;
-               for_each_string_list_item(item, opt->extra_notes_refs)
+               for_each_string_list_item(item, &opt->extra_notes_refs)
                        string_list_add_refs_by_glob(&display_notes_refs,
                                                     item->string);
        }
@@ -1285,3 +1286,13 @@ int copy_note(struct notes_tree *t,
 
        return 0;
 }
+
+void expand_notes_ref(struct strbuf *sb)
+{
+       if (!prefixcmp(sb->buf, "refs/notes/"))
+               return; /* we're happy */
+       else if (!prefixcmp(sb->buf, "notes/"))
+               strbuf_insert(sb, 0, "refs/", 5);
+       else
+               strbuf_insert(sb, 0, "refs/notes/", 11);
+}
diff --git a/notes.h b/notes.h
index 83bd6e0ec02a1a8650004f14cd7476eedbdff518..c716694b9e2ec89a59b98d1828fd78f59471e2c4 100644 (file)
--- a/notes.h
+++ b/notes.h
@@ -1,6 +1,8 @@
 #ifndef NOTES_H
 #define NOTES_H
 
+#include "string-list.h"
+
 /*
  * Function type for combining two notes annotating the same object.
  *
@@ -256,8 +258,8 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,
 struct string_list;
 
 struct display_notes_opt {
-       unsigned int suppress_default_notes:1;
-       struct string_list *extra_notes_refs;
+       int use_default_notes;
+       struct string_list extra_notes_refs;
 };
 
 /*
@@ -307,4 +309,7 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob);
 void string_list_add_refs_from_colon_sep(struct string_list *list,
                                         const char *globs);
 
+/* Expand inplace a note ref like "foo" or "notes/foo" into "refs/notes/foo" */
+void expand_notes_ref(struct strbuf *sb);
+
 #endif
index e1d8a8f414bf052a59fbe78d022e611f44ed8361..dff5c8d1831ca4019d1a502a393cb95f20ad18f7 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -208,6 +208,58 @@ int has_non_ascii(const char *s)
        return 0;
 }
 
+static int is_rfc822_special(char ch)
+{
+       switch (ch) {
+       case '(':
+       case ')':
+       case '<':
+       case '>':
+       case '[':
+       case ']':
+       case ':':
+       case ';':
+       case '@':
+       case ',':
+       case '.':
+       case '"':
+       case '\\':
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+static int has_rfc822_specials(const char *s, int len)
+{
+       int i;
+       for (i = 0; i < len; i++)
+               if (is_rfc822_special(s[i]))
+                       return 1;
+       return 0;
+}
+
+static void add_rfc822_quoted(struct strbuf *out, const char *s, int len)
+{
+       int i;
+
+       /* just a guess, we may have to also backslash-quote */
+       strbuf_grow(out, len + 2);
+
+       strbuf_addch(out, '"');
+       for (i = 0; i < len; i++) {
+               switch (s[i]) {
+               case '"':
+               case '\\':
+                       strbuf_addch(out, '\\');
+                       /* fall through */
+               default:
+                       strbuf_addch(out, s[i]);
+               }
+       }
+       strbuf_addch(out, '"');
+}
+
 static int is_rfc2047_special(char ch)
 {
        return (non_ascii(ch) || (ch == '=') || (ch == '?') || (ch == '_'));
@@ -287,13 +339,29 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
        if (fmt == CMIT_FMT_EMAIL) {
                char *name_tail = strchr(line, '<');
                int display_name_length;
+               int final_line;
                if (!name_tail)
                        return;
                while (line < name_tail && isspace(name_tail[-1]))
                        name_tail--;
                display_name_length = name_tail - line;
                strbuf_addstr(sb, "From: ");
-               add_rfc2047(sb, line, display_name_length, encoding);
+               if (!has_rfc822_specials(line, display_name_length)) {
+                       add_rfc2047(sb, line, display_name_length, encoding);
+               } else {
+                       struct strbuf quoted = STRBUF_INIT;
+                       add_rfc822_quoted(&quoted, line, display_name_length);
+                       add_rfc2047(sb, quoted.buf, quoted.len, encoding);
+                       strbuf_release(&quoted);
+               }
+               for (final_line = 0; final_line < sb->len; final_line++)
+                       if (sb->buf[sb->len - final_line - 1] == '\n')
+                               break;
+               if (namelen - display_name_length + final_line > 78) {
+                       strbuf_addch(sb, '\n');
+                       if (!isspace(name_tail[0]))
+                               strbuf_addch(sb, ' ');
+               }
                strbuf_add(sb, name_tail, namelen - display_name_length);
                strbuf_addch(sb, '\n');
        } else {
index 775d6143037aa4573c0202715fe1b1a0f99e2799..17d8a9b377265aeed9765f04d505959e1f7fb9b0 100644 (file)
@@ -347,7 +347,7 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
 }
 #endif
 
-static size_t rpc_in(const void *ptr, size_t eltsize,
+static size_t rpc_in(char *ptr, size_t eltsize,
                size_t nmemb, void *buffer_)
 {
        size_t size = eltsize * nmemb;
index 22dfc843da1528ffd0466d496c50c56702e55a24..dee2cb1514d1e97c47a4999ed66f8996035d71fe 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -671,3 +671,87 @@ int rerere_forget(const char **pathspec)
        }
        return write_rr(&merge_rr, fd);
 }
+
+static time_t rerere_created_at(const char *name)
+{
+       struct stat st;
+       return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
+}
+
+static time_t rerere_last_used_at(const char *name)
+{
+       struct stat st;
+       return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
+}
+
+static void unlink_rr_item(const char *name)
+{
+       unlink(rerere_path(name, "thisimage"));
+       unlink(rerere_path(name, "preimage"));
+       unlink(rerere_path(name, "postimage"));
+       rmdir(git_path("rr-cache/%s", name));
+}
+
+struct rerere_gc_config_cb {
+       int cutoff_noresolve;
+       int cutoff_resolve;
+};
+
+static int git_rerere_gc_config(const char *var, const char *value, void *cb)
+{
+       struct rerere_gc_config_cb *cf = cb;
+
+       if (!strcmp(var, "gc.rerereresolved"))
+               cf->cutoff_resolve = git_config_int(var, value);
+       else if (!strcmp(var, "gc.rerereunresolved"))
+               cf->cutoff_noresolve = git_config_int(var, value);
+       else
+               return git_default_config(var, value, cb);
+       return 0;
+}
+
+void rerere_gc(struct string_list *rr)
+{
+       struct string_list to_remove = STRING_LIST_INIT_DUP;
+       DIR *dir;
+       struct dirent *e;
+       int i, cutoff;
+       time_t now = time(NULL), then;
+       struct rerere_gc_config_cb cf = { 15, 60 };
+
+       git_config(git_rerere_gc_config, &cf);
+       dir = opendir(git_path("rr-cache"));
+       if (!dir)
+               die_errno("unable to open rr-cache directory");
+       while ((e = readdir(dir))) {
+               if (is_dot_or_dotdot(e->d_name))
+                       continue;
+
+               then = rerere_last_used_at(e->d_name);
+               if (then) {
+                       cutoff = cf.cutoff_resolve;
+               } else {
+                       then = rerere_created_at(e->d_name);
+                       if (!then)
+                               continue;
+                       cutoff = cf.cutoff_noresolve;
+               }
+               if (then < now - cutoff * 86400)
+                       string_list_append(&to_remove, e->d_name);
+       }
+       for (i = 0; i < to_remove.nr; i++)
+               unlink_rr_item(to_remove.items[i].string);
+       string_list_clear(&to_remove, 0);
+}
+
+void rerere_clear(struct string_list *merge_rr)
+{
+       int i;
+
+       for (i = 0; i < merge_rr->nr; i++) {
+               const char *name = (const char *)merge_rr->items[i].util;
+               if (!has_rerere_resolution(name))
+                       unlink_rr_item(name);
+       }
+       unlink_or_warn(git_path("MERGE_RR"));
+}
index 595f49f701dc1003927679085ca6eea8ad1083ae..fcd8bc10ba587d023d174d68020a185eab0f8d40 100644 (file)
--- a/rerere.h
+++ b/rerere.h
@@ -19,6 +19,8 @@ extern const char *rerere_path(const char *hex, const char *file);
 extern int has_rerere_resolution(const char *hex);
 extern int rerere_forget(const char **);
 extern int rerere_remaining(struct string_list *);
+extern void rerere_clear(struct string_list *);
+extern void rerere_gc(struct string_list *);
 
 #define OPT_RERERE_AUTOUPDATE(v) OPT_UYN(0, "rerere-autoupdate", (v), \
        "update the index with reused conflict resolution if possible")
index 0f38364cf3f81a9088305ca802adf8b7c9260e91..a7cf79bf2ed3f348f211878005899bebd96629f2 100644 (file)
@@ -955,6 +955,8 @@ void init_revisions(struct rev_info *revs, const char *prefix)
                revs->diffopt.prefix = prefix;
                revs->diffopt.prefix_length = strlen(prefix);
        }
+
+       revs->notes_opt.use_default_notes = -1;
 }
 
 static void add_pending_commit_list(struct rev_info *revs,
@@ -1178,7 +1180,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
            !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
            !strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
            !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
-           !strcmp(arg, "--bisect"))
+           !strcmp(arg, "--bisect") || !prefixcmp(arg, "--glob=") ||
+           !prefixcmp(arg, "--branches=") || !prefixcmp(arg, "--tags=") ||
+           !prefixcmp(arg, "--remotes="))
        {
                unkv[(*unkc)++] = arg;
                return 1;
@@ -1365,32 +1369,39 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->verbose_header = 1;
                revs->pretty_given = 1;
                get_commit_format(arg+9, revs);
-       } else if (!strcmp(arg, "--show-notes")) {
+       } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) {
                revs->show_notes = 1;
                revs->show_notes_given = 1;
-       } else if (!prefixcmp(arg, "--show-notes=")) {
+               revs->notes_opt.use_default_notes = 1;
+       } else if (!prefixcmp(arg, "--show-notes=") ||
+                  !prefixcmp(arg, "--notes=")) {
                struct strbuf buf = STRBUF_INIT;
                revs->show_notes = 1;
                revs->show_notes_given = 1;
-               if (!revs->notes_opt.extra_notes_refs)
-                       revs->notes_opt.extra_notes_refs = xcalloc(1, sizeof(struct string_list));
-               if (!prefixcmp(arg+13, "refs/"))
-                       /* happy */;
-               else if (!prefixcmp(arg+13, "notes/"))
-                       strbuf_addstr(&buf, "refs/");
+               if (!prefixcmp(arg, "--show-notes")) {
+                       if (revs->notes_opt.use_default_notes < 0)
+                               revs->notes_opt.use_default_notes = 1;
+                       strbuf_addstr(&buf, arg+13);
+               }
                else
-                       strbuf_addstr(&buf, "refs/notes/");
-               strbuf_addstr(&buf, arg+13);
-               string_list_append(revs->notes_opt.extra_notes_refs,
+                       strbuf_addstr(&buf, arg+8);
+               expand_notes_ref(&buf);
+               string_list_append(&revs->notes_opt.extra_notes_refs,
                                   strbuf_detach(&buf, NULL));
        } else if (!strcmp(arg, "--no-notes")) {
                revs->show_notes = 0;
                revs->show_notes_given = 1;
+               revs->notes_opt.use_default_notes = -1;
+               /* we have been strdup'ing ourselves, so trick
+                * string_list into free()ing strings */
+               revs->notes_opt.extra_notes_refs.strdup_strings = 1;
+               string_list_clear(&revs->notes_opt.extra_notes_refs, 0);
+               revs->notes_opt.extra_notes_refs.strdup_strings = 0;
        } else if (!strcmp(arg, "--standard-notes")) {
                revs->show_notes_given = 1;
-               revs->notes_opt.suppress_default_notes = 0;
+               revs->notes_opt.use_default_notes = 1;
        } else if (!strcmp(arg, "--no-standard-notes")) {
-               revs->notes_opt.suppress_default_notes = 1;
+               revs->notes_opt.use_default_notes = 0;
        } else if (!strcmp(arg, "--oneline")) {
                revs->verbose_header = 1;
                get_commit_format("oneline", revs);
@@ -1526,6 +1537,69 @@ static void append_prune_data(const char ***prune_data, const char **av)
        *prune_data = prune;
 }
 
+static int handle_revision_pseudo_opt(const char *submodule,
+                               struct rev_info *revs,
+                               int argc, const char **argv, int *flags)
+{
+       const char *arg = argv[0];
+       const char *optarg;
+       int argcount;
+
+       /*
+        * NOTE!
+        *
+        * Commands like "git shortlog" will not accept the options below
+        * unless parse_revision_opt queues them (as opposed to erroring
+        * out).
+        *
+        * When implementing your new pseudo-option, remember to
+        * register it in the list at the top of handle_revision_opt.
+        */
+       if (!strcmp(arg, "--all")) {
+               handle_refs(submodule, revs, *flags, for_each_ref_submodule);
+               handle_refs(submodule, revs, *flags, head_ref_submodule);
+       } else if (!strcmp(arg, "--branches")) {
+               handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);
+       } else if (!strcmp(arg, "--bisect")) {
+               handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);
+               handle_refs(submodule, revs, *flags ^ UNINTERESTING, for_each_good_bisect_ref);
+               revs->bisect = 1;
+       } else if (!strcmp(arg, "--tags")) {
+               handle_refs(submodule, revs, *flags, for_each_tag_ref_submodule);
+       } else if (!strcmp(arg, "--remotes")) {
+               handle_refs(submodule, revs, *flags, for_each_remote_ref_submodule);
+       } else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
+               struct all_refs_cb cb;
+               init_all_refs_cb(&cb, revs, *flags);
+               for_each_glob_ref(handle_one_ref, optarg, &cb);
+               return argcount;
+       } else if (!prefixcmp(arg, "--branches=")) {
+               struct all_refs_cb cb;
+               init_all_refs_cb(&cb, revs, *flags);
+               for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
+       } else if (!prefixcmp(arg, "--tags=")) {
+               struct all_refs_cb cb;
+               init_all_refs_cb(&cb, revs, *flags);
+               for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
+       } else if (!prefixcmp(arg, "--remotes=")) {
+               struct all_refs_cb cb;
+               init_all_refs_cb(&cb, revs, *flags);
+               for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
+       } else if (!strcmp(arg, "--reflog")) {
+               handle_reflog(revs, *flags);
+       } else if (!strcmp(arg, "--not")) {
+               *flags ^= UNINTERESTING;
+       } else if (!strcmp(arg, "--no-walk")) {
+               revs->no_walk = 1;
+       } else if (!strcmp(arg, "--do-walk")) {
+               revs->no_walk = 0;
+       } else {
+               return 0;
+       }
+
+       return 1;
+}
+
 /*
  * Parse revision information, filling in the "rev_info" structure,
  * and removing the used arguments from the argument list.
@@ -1538,8 +1612,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
        int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
        const char **prune_data = NULL;
        const char *submodule = NULL;
-       const char *optarg;
-       int argcount;
 
        if (opt)
                submodule = opt->submodule;
@@ -1566,70 +1638,14 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
                if (*arg == '-') {
                        int opts;
 
-                       if (!strcmp(arg, "--all")) {
-                               handle_refs(submodule, revs, flags, for_each_ref_submodule);
-                               handle_refs(submodule, revs, flags, head_ref_submodule);
-                               continue;
-                       }
-                       if (!strcmp(arg, "--branches")) {
-                               handle_refs(submodule, revs, flags, for_each_branch_ref_submodule);
-                               continue;
-                       }
-                       if (!strcmp(arg, "--bisect")) {
-                               handle_refs(submodule, revs, flags, for_each_bad_bisect_ref);
-                               handle_refs(submodule, revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
-                               revs->bisect = 1;
-                               continue;
-                       }
-                       if (!strcmp(arg, "--tags")) {
-                               handle_refs(submodule, revs, flags, for_each_tag_ref_submodule);
-                               continue;
-                       }
-                       if (!strcmp(arg, "--remotes")) {
-                               handle_refs(submodule, revs, flags, for_each_remote_ref_submodule);
-                               continue;
-                       }
-                       if ((argcount = parse_long_opt("glob", argv + i, &optarg))) {
-                               struct all_refs_cb cb;
-                               i += argcount - 1;
-                               init_all_refs_cb(&cb, revs, flags);
-                               for_each_glob_ref(handle_one_ref, optarg, &cb);
-                               continue;
-                       }
-                       if (!prefixcmp(arg, "--branches=")) {
-                               struct all_refs_cb cb;
-                               init_all_refs_cb(&cb, revs, flags);
-                               for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
-                               continue;
-                       }
-                       if (!prefixcmp(arg, "--tags=")) {
-                               struct all_refs_cb cb;
-                               init_all_refs_cb(&cb, revs, flags);
-                               for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
-                               continue;
-                       }
-                       if (!prefixcmp(arg, "--remotes=")) {
-                               struct all_refs_cb cb;
-                               init_all_refs_cb(&cb, revs, flags);
-                               for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
-                               continue;
-                       }
-                       if (!strcmp(arg, "--reflog")) {
-                               handle_reflog(revs, flags);
-                               continue;
-                       }
-                       if (!strcmp(arg, "--not")) {
-                               flags ^= UNINTERESTING;
-                               continue;
-                       }
-                       if (!strcmp(arg, "--no-walk")) {
-                               revs->no_walk = 1;
-                               continue;
-                       }
-                       if (!strcmp(arg, "--do-walk")) {
-                               revs->no_walk = 0;
+                       opts = handle_revision_pseudo_opt(submodule,
+                                               revs, argc - i, argv + i,
+                                               &flags);
+                       if (opts > 0) {
+                               i += opts - 1;
                                continue;
                        }
+
                        if (!strcmp(arg, "--stdin")) {
                                if (revs->disable_stdin) {
                                        argv[left++] = arg;
index 9fd8f3016fe8f935f176f57c615f72df8ba8d157..bca9947977c50d151b0fed90931ec52112e72bae 100644 (file)
@@ -141,6 +141,7 @@ struct rev_info {
        /* commit counts */
        int count_left;
        int count_right;
+       int count_same;
 };
 
 #define REV_TREE_SAME          0
index f91e446c86be8e27f98554567143d7ce6f934bd1..70e8a249d0fe07b6a32b4da4ac8224d1c2f06b1b 100644 (file)
@@ -67,21 +67,24 @@ static int child_notifier = -1;
 
 static void notify_parent(void)
 {
-       ssize_t unused;
-       unused = write(child_notifier, "", 1);
+       /*
+        * execvp failed.  If possible, we'd like to let start_command
+        * know, so failures like ENOENT can be handled right away; but
+        * otherwise, finish_command will still report the error.
+        */
+       xwrite(child_notifier, "", 1);
 }
 
 static NORETURN void die_child(const char *err, va_list params)
 {
        char msg[4096];
-       ssize_t unused;
        int len = vsnprintf(msg, sizeof(msg), err, params);
        if (len > sizeof(msg))
                len = sizeof(msg);
 
-       unused = write(child_err, "fatal: ", 7);
-       unused = write(child_err, msg, len);
-       unused = write(child_err, "\n", 1);
+       write_in_full(child_err, "fatal: ", 7);
+       write_in_full(child_err, msg, len);
+       write_in_full(child_err, "\n", 1);
        exit(128);
 }
 #endif
diff --git a/setup.c b/setup.c
index 03cd84f2fcbf9cdbc25116308a9c2c9407af8e71..b6e6b5ae272b3ecae7dfa2cb446aef97e826884a 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -325,6 +325,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
        const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
        const char *worktree;
        char *gitfile;
+       int offset;
 
        if (PATH_MAX - 40 < strlen(gitdirenv))
                die("'$%s' too big", GIT_DIR_ENVIRONMENT);
@@ -390,15 +391,15 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
                return NULL;
        }
 
-       if (!prefixcmp(cwd, worktree) &&
-           cwd[strlen(worktree)] == '/') { /* cwd inside worktree */
+       offset = dir_inside_of(cwd, worktree);
+       if (offset >= 0) {      /* cwd inside worktree? */
                set_git_dir(real_path(gitdirenv));
                if (chdir(worktree))
                        die_errno("Could not chdir to '%s'", worktree);
                cwd[len++] = '/';
                cwd[len] = '\0';
                free(gitfile);
-               return cwd + strlen(worktree) + 1;
+               return cwd + offset;
        }
 
        /* cwd outside worktree */
index 889fe7183065ae8bc12821aadebb69a17bc7635c..1a7e41070efa6327859d3c09ede07317cc91ba7d 100644 (file)
@@ -31,8 +31,6 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];
 
-static int git_open_noatime(const char *name, struct packed_git *p);
-
 /*
  * This is meant to hold a *small* number of objects that you would
  * want read_sha1_file() to be able to return, but yet you do not want
@@ -227,6 +225,7 @@ struct alternate_object_database *alt_odb_list;
 static struct alternate_object_database **alt_odb_tail;
 
 static void read_info_alternates(const char * alternates, int depth);
+static int git_open_noatime(const char *name);
 
 /*
  * Prepare alternate object database registry.
@@ -360,7 +359,7 @@ static void read_info_alternates(const char * relative_base, int depth)
        int fd;
 
        sprintf(path, "%s/%s", relative_base, alt_file_name);
-       fd = git_open_noatime(path, NULL);
+       fd = git_open_noatime(path);
        if (fd < 0)
                return;
        if (fstat(fd, &st) || (st.st_size == 0)) {
@@ -475,7 +474,7 @@ static int check_packed_git_idx(const char *path,  struct packed_git *p)
        struct pack_idx_header *hdr;
        size_t idx_size;
        uint32_t version, nr, i, *index;
-       int fd = git_open_noatime(path, p);
+       int fd = git_open_noatime(path);
        struct stat st;
 
        if (fd < 0)
@@ -757,7 +756,7 @@ static int open_packed_git_1(struct packed_git *p)
        while (pack_max_fds <= pack_open_fds && unuse_one_window(NULL, -1))
                ; /* nothing */
 
-       p->pack_fd = git_open_noatime(p->pack_name, p);
+       p->pack_fd = git_open_noatime(p->pack_name);
        if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
                return -1;
        pack_open_fds++;
@@ -1145,7 +1144,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map, unsigned long siz
        return hashcmp(sha1, real_sha1) ? -1 : 0;
 }
 
-static int git_open_noatime(const char *name, struct packed_git *p)
+static int git_open_noatime(const char *name)
 {
        static int sha1_file_open_flag = O_NOATIME;
 
@@ -1170,7 +1169,7 @@ static int open_sha1_file(const unsigned char *sha1)
        char *name = sha1_file_name(sha1);
        struct alternate_object_database *alt;
 
-       fd = git_open_noatime(name, NULL);
+       fd = git_open_noatime(name);
        if (fd >= 0)
                return fd;
 
@@ -1179,7 +1178,7 @@ static int open_sha1_file(const unsigned char *sha1)
        for (alt = alt_odb_list; alt; alt = alt->next) {
                name = alt->name;
                fill_sha1_path(name, sha1);
-               fd = git_open_noatime(alt->base, NULL);
+               fd = git_open_noatime(alt->base);
                if (fd >= 0)
                        return fd;
        }
@@ -1308,7 +1307,7 @@ static void *unpack_sha1_rest(z_stream *stream, void *buffer, unsigned long size
                /*
                 * The above condition must be (bytes <= size), not
                 * (bytes < size).  In other words, even though we
-                * expect no more output and set avail_out to zer0,
+                * expect no more output and set avail_out to zero,
                 * the input zlib stream may have bytes that express
                 * "this concludes the stream", and we *do* want to
                 * eat that input.
diff --git a/shell.c b/shell.c
index dea4cfdd2c230af6afd6233cacfa5c776a9962f9..abb862246ef01743424e4a447ee169f3fdbb9f51 100644 (file)
--- a/shell.c
+++ b/shell.c
@@ -137,6 +137,8 @@ int main(int argc, char **argv)
        int devnull_fd;
        int count;
 
+       git_extract_argv0_path(argv[0]);
+
        /*
         * Always open file descriptors 0/1/2 to avoid clobbering files
         * in die().  It also avoids not messing up when the pipes are
index 07060ce893d8303b7eb4d78db0f7a5575527f88f..9e6d9fa53fc04156452bf850af1a9b2d3ba830f2 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -3,8 +3,6 @@
 
 /* See Documentation/technical/api-strbuf.txt */
 
-#include <assert.h>
-
 extern char strbuf_slopbuf[];
 struct strbuf {
        size_t alloc;
@@ -33,9 +31,8 @@ static inline size_t strbuf_avail(const struct strbuf *sb) {
 extern void strbuf_grow(struct strbuf *, size_t);
 
 static inline void strbuf_setlen(struct strbuf *sb, size_t len) {
-       if (!sb->alloc)
-               strbuf_grow(sb, 0);
-       assert(len < sb->alloc);
+       if (len > (sb->alloc ? sb->alloc - 1 : 0))
+               die("BUG: strbuf_setlen() beyond buffer");
        sb->len = len;
        sb->buf[len] = '\0';
 }
index 428ee05c4a5b844815ff4f9356b71bb147cb42a6..cad36dd7502b81ef8e27476e9686562547b5a1c0 100644 (file)
--- a/t/README
+++ b/t/README
@@ -379,7 +379,7 @@ library for your script to use.
 
  - test_expect_success [<prereq>] <message> <script>
 
-   Usually takes two strings as parameter, and evaluates the
+   Usually takes two strings as parameters, and evaluates the
    <script>.  If it yields success, test is considered
    successful.  <message> should state what it is testing.
 
@@ -390,7 +390,7 @@ library for your script to use.
            'tree=$(git-write-tree)'
 
    If you supply three parameters the first will be taken to be a
-   prerequisite, see the test_set_prereq and test_have_prereq
+   prerequisite; see the test_set_prereq and test_have_prereq
    documentation below:
 
        test_expect_success TTY 'git --paginate rev-list uses a pager' \
@@ -446,7 +446,7 @@ library for your script to use.
    Merges the given rev using the given message.  Like test_commit,
    creates a tag and calls test_tick before committing.
 
- - test_set_prereq SOME_PREREQ
+ - test_set_prereq <prereq>
 
    Set a test prerequisite to be used later with test_have_prereq. The
    test-lib will set some prerequisites for you, see the
@@ -456,7 +456,7 @@ library for your script to use.
    test_have_prereq directly, or the three argument invocation of
    test_expect_success and test_expect_failure.
 
- - test_have_prereq SOME PREREQ
+ - test_have_prereq <prereq>
 
    Check if we have a prerequisite previously set with
    test_set_prereq. The most common use of this directly is to skip
@@ -526,12 +526,13 @@ library for your script to use.
 
    Check whether a file has the length it is expected to.
 
- - test_path_is_file <file> [<diagnosis>]
-   test_path_is_dir <dir> [<diagnosis>]
+ - test_path_is_file <path> [<diagnosis>]
+   test_path_is_dir <path> [<diagnosis>]
    test_path_is_missing <path> [<diagnosis>]
 
-   Check whether a file/directory exists or doesn't. <diagnosis> will
-   be displayed if the test fails.
+   Check if the named path is a file, if the named path is a
+   directory, or if the named path does not exist, respectively,
+   and fail otherwise, showing the <diagnosis> text.
 
  - test_when_finished <script>
 
index d34208cc27623a6105f6b12f863c648429d2d34d..c56a77d2378117006694d4b575445f89446ae80c 100644 (file)
@@ -1,5 +1,5 @@
 # This file isn't used as a test script directly, instead it is
-# sourced from t8001-annotate.sh and t8001-blame.sh.
+# sourced from t8001-annotate.sh and t8002-blame.sh.
 
 check_count () {
        head=
@@ -124,3 +124,14 @@ test_expect_success \
 test_expect_success \
     'some edit' \
     'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'
+
+test_expect_success \
+    'an obfuscated email added' \
+    'echo "No robots allowed" > file.new &&
+     cat file >> file.new &&
+     mv file.new file &&
+     GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" git commit -a -m "norobots"'
+
+test_expect_success \
+    'obfuscated email parsed' \
+    'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1'
index d3829b8d0a18d15590f4cbde4606d130a9293ead..b8996a373a7444b54823f36159ea1a8634e4aeee 100644 (file)
@@ -157,8 +157,7 @@ test_http_push_nonff() {
                grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'non-fast-forward push shows help message' '
-               grep "To prevent you from losing history, non-fast-forward updates were rejected" \
-                       output
+       test_expect_success 'non-fast-forward push shows help message' '
+               test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" output
        '
 }
index 54520f6fa69bef682e200497c531c9cd7367b9ea..8106af8fba918b8de82857d40a7f693224c84e81 100755 (executable)
@@ -180,7 +180,7 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
        fi
 '
 
-test_expect_success C_LOCALE_OUTPUT 'reinit' '
+test_expect_success 'reinit' '
 
        (
                sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG &&
@@ -190,11 +190,11 @@ test_expect_success C_LOCALE_OUTPUT 'reinit' '
                git init >out1 2>err1 &&
                git init >out2 2>err2
        ) &&
-       grep "Initialized empty" again/out1 &&
-       grep "Reinitialized existing" again/out2 &&
+       test_i18ngrep "Initialized empty" again/out1 &&
+       test_i18ngrep "Reinitialized existing" again/out2 &&
        >again/empty &&
-       test_cmp again/empty again/err1 &&
-       test_cmp again/empty again/err2
+       test_i18ncmp again/empty again/err1 &&
+       test_i18ncmp again/empty again/err2
 '
 
 test_expect_success 'init with --template' '
index 10b26e4d8ef3ea7b6b9b2ae7aeebbbae1ee46703..8d4938f019ca406c0f248d19d046356dff1ac09a 100755 (executable)
@@ -7,8 +7,31 @@ test_description='Test run command'
 
 . ./test-lib.sh
 
+cat >hello-script <<-EOF
+       #!$SHELL_PATH
+       cat hello-script
+EOF
+>empty
+
 test_expect_success 'start_command reports ENOENT' '
        test-run-command start-command-ENOENT ./does-not-exist
 '
 
+test_expect_success 'run_command can run a command' '
+       cat hello-script >hello.sh &&
+       chmod +x hello.sh &&
+       test-run-command run-command ./hello.sh >actual 2>err &&
+
+       test_cmp hello-script actual &&
+       test_cmp empty err
+'
+
+test_expect_success POSIXPERM 'run_command reports EACCES' '
+       cat hello-script >hello.sh &&
+       chmod -x hello.sh &&
+       test_must_fail test-run-command run-command ./hello.sh 2>err &&
+
+       grep "fatal: cannot exec.*hello.sh" err
+'
+
 test_done
index 1fd187c5eb188671934f6afe85ca5003c529a942..ddc3921ac6a009dfc706cd19ad94f2b29af4b1cc 100755 (executable)
@@ -118,6 +118,27 @@ test_expect_success 'alias expansion' '
                git ss
        )
 '
+
+test_expect_success '!alias expansion' '
+       pwd >expect &&
+       (
+               git config alias.test !pwd &&
+               cd dir &&
+               git test >../actual
+       ) &&
+       test_cmp expect actual
+'
+
+test_expect_success 'GIT_PREFIX for !alias' '
+       printf "dir/" >expect &&
+       (
+               git config alias.test "!sh -c \"printf \$GIT_PREFIX\"" &&
+               cd dir &&
+               git test >../actual
+       ) &&
+       test_cmp expect actual
+'
+
 test_expect_success 'no file/rev ambiguity check inside .git' '
        git commit -a -m 1 &&
        (
index 3264fefbad8b941bd90b243948f618b65fe4929f..5e29e13782ffad74915128adf163d57eef16f4e8 100755 (executable)
@@ -166,8 +166,8 @@ test_expect_success 'git resolve' '
                -e "s/^Fast[- ]forward /FASTFORWARD /" >resolve.output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'git resolve output' '
-       test_cmp resolve.expect resolve.output
+test_expect_success 'git resolve output' '
+       test_i18ncmp resolve.expect resolve.output
 '
 
 cat > show-branch2.expect << EOF
index ff747f8229bb46df070ea9aad2702f4d1c703420..4fd83a667ac8b08bef090d303bc4434969874780 100755 (executable)
@@ -6,7 +6,7 @@
 test_description='Test git update-ref and basic ref logging'
 . ./test-lib.sh
 
-Z=0000000000000000000000000000000000000000
+Z=$_z40
 
 test_expect_success setup '
 
index da6252b1179c47d39393c983d88c75d84a507cb7..63849836c8b088eb495dc565ff909c367c868301 100755 (executable)
@@ -7,7 +7,6 @@ test_expect_success 'setup' '
        EMPTY_TREE=$(git write-tree) &&
        EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
        CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
-       ZEROES=0000000000000000000000000000000000000000 &&
        EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
        CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
 
@@ -239,10 +238,10 @@ test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
 
 test_expect_success 'diff-index respects work tree under .git dir' '
        cat >diff-index-cached.expected <<-EOF &&
-       :000000 100644 $ZEROES $EMPTY_BLOB A    sub/dir/tracked
+       :000000 100644 $_z40 $EMPTY_BLOB A      sub/dir/tracked
        EOF
        cat >diff-index.expected <<-EOF &&
-       :000000 100644 $ZEROES $ZEROES A        sub/dir/tracked
+       :000000 100644 $_z40 $_z40 A    sub/dir/tracked
        EOF
 
        (
@@ -258,7 +257,7 @@ test_expect_success 'diff-index respects work tree under .git dir' '
 
 test_expect_success 'diff-files respects work tree under .git dir' '
        cat >diff-files.expected <<-EOF &&
-       :100644 100644 $EMPTY_BLOB $ZEROES M    sub/dir/tracked
+       :100644 100644 $EMPTY_BLOB $_z40 M      sub/dir/tracked
        EOF
 
        (
index 4a6396f9e3fb8006969916e12066fa6fc1527b3d..0843a1c13b3e1458418ee59c548e5441f113bbe7 100755 (executable)
@@ -8,8 +8,11 @@ exec </dev/null
 
 test_did_you_mean ()
 {
-       printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected &&
-       printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected &&
+       sq="'" &&
+       cat >expected <<-EOF &&
+       fatal: Path '$2$3' $4, but not ${5:-$sq$3$sq}.
+       Did you mean '$1:$2$3'${2:+ aka $sq$1:./$3$sq}?
+       EOF
        test_cmp expected error
 }
 
index 15ebdc26ebaaf7881b1f51eb788c2eb2922b6d4f..300f8bf25c34cf4ea4e011d1daa525285ca94c5a 100755 (executable)
@@ -15,7 +15,7 @@ test_expect_success 'checkout should not start branch from a tree' '
 '
 
 test_expect_success 'checkout master from invalid HEAD' '
-       echo 0000000000000000000000000000000000000000 >.git/HEAD &&
+       echo $_z40 >.git/HEAD &&
        git checkout master --
 '
 
index cc34e5535bc5ab7441ba375540e5feec2dfb2d6b..b99d5192a96ec77ef6a99cb86518375c447b48a9 100755 (executable)
@@ -29,9 +29,9 @@ test_expect_success 'checkout chooses branch over tag' '
        test_cmp expect file
 '
 
-test_expect_success C_LOCALE_OUTPUT 'checkout reports switch to branch' '
-       grep "Switched to branch" stderr &&
-       ! grep "^HEAD is now at" stderr
+test_expect_success 'checkout reports switch to branch' '
+       test_i18ngrep "Switched to branch" stderr &&
+       test_i18ngrep ! "^HEAD is now at" stderr
 '
 
 test_expect_success 'checkout vague ref succeeds' '
@@ -51,9 +51,9 @@ test_expect_success VAGUENESS_SUCCESS 'checkout chooses branch over tag' '
        test_cmp expect file
 '
 
-test_expect_success VAGUENESS_SUCCESS,C_LOCALE_OUTPUT 'checkout reports switch to branch' '
-       grep "Switched to branch" stderr &&
-       ! grep "^HEAD is now at" stderr
+test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' '
+       test_i18ngrep "Switched to branch" stderr &&
+       test_i18ngrep ! "^HEAD is now at" stderr
 '
 
 test_done
index 569b27fe8d488833c3ec0d9952ae064764a0183f..2366f0f4141656666db9cdcd8975335df57b6a8f 100755 (executable)
@@ -13,10 +13,10 @@ check_not_detached () {
 
 ORPHAN_WARNING='you are leaving .* commit.*behind'
 check_orphan_warning() {
-       grep "$ORPHAN_WARNING" "$1"
+       test_i18ngrep "$ORPHAN_WARNING" "$1"
 }
 check_no_orphan_warning() {
-       ! grep "$ORPHAN_WARNING" "$1"
+       test_i18ngrep ! "$ORPHAN_WARNING" "$1"
 }
 
 reset () {
@@ -108,21 +108,30 @@ test_expect_success 'checkout warns on orphan commits' '
        echo content >orphan &&
        git add orphan &&
        git commit -a -m orphan &&
-       git checkout master 2>stderr &&
+       git checkout master 2>stderr
+'
+
+test_expect_success 'checkout warns on orphan commits: output' '
        check_orphan_warning stderr
 '
 
 test_expect_success 'checkout does not warn leaving ref tip' '
        reset &&
        git checkout --detach two &&
-       git checkout master 2>stderr &&
+       git checkout master 2>stderr
+'
+
+test_expect_success 'checkout does not warn leaving ref tip' '
        check_no_orphan_warning stderr
 '
 
 test_expect_success 'checkout does not warn leaving reachable commit' '
        reset &&
        git checkout --detach HEAD^ &&
-       git checkout master 2>stderr &&
+       git checkout master 2>stderr
+'
+
+test_expect_success 'checkout does not warn leaving reachable commit' '
        check_no_orphan_warning stderr
 '
 
index 856e7da1f2d3aba299d30aca9a1a6d5a288d2d91..4cdebda6a5c9b893f46e99b5b565cc4b70efb2db 100755 (executable)
@@ -111,7 +111,7 @@ test_expect_success 'touch and then add explicitly' '
 
 '
 
-test_expect_success C_LOCALE_OUTPUT 'add -n -u should not add but just report' '
+test_expect_success 'add -n -u should not add but just report' '
 
        (
                echo "add '\''check'\''" &&
@@ -124,7 +124,7 @@ test_expect_success C_LOCALE_OUTPUT 'add -n -u should not add but just report' '
        after=$(git ls-files -s check top) &&
 
        test "$before" = "$after" &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 
 '
 
@@ -149,31 +149,21 @@ test_expect_success 'add -u resolves unmerged paths' '
        echo 3 >path1 &&
        echo 2 >path3 &&
        echo 2 >path5 &&
-       git add -u &&
-       git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
-       {
-               echo "100644 $three 0   path1"
-               echo "100644 $one 1     path3"
-               echo "100644 $one 1     path4"
-               echo "100644 $one 3     path5"
-               echo "100644 $one 3     path6"
-       } >expect &&
-       test_cmp expect actual &&
 
-       # Bonus tests.  Explicit resolving
-       git add path3 path5 &&
+       # Explicit resolving by adding removed paths should fail
        test_must_fail git add path4 &&
        test_must_fail git add path6 &&
-       git rm path4 &&
-       git rm path6 &&
 
-       git ls-files -s "path?" >actual &&
+       # "add -u" should notice removals no matter what stages
+       # the index entries are in.
+       git add -u &&
+       git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
        {
                echo "100644 $three 0   path1"
                echo "100644 $two 0     path3"
                echo "100644 $two 0     path5"
-       } >expect
-
+       } >expect &&
+       test_cmp expect actual
 '
 
 test_expect_success '"add -u non-existent" should fail' '
index 2e8f70245204bd4dc78e67f227e86838e1cdad5b..954fc51e5b560af918661a0ee051521a43f4efba 100755 (executable)
@@ -4,8 +4,6 @@ test_description='more git add -u'
 
 . ./test-lib.sh
 
-_z40=0000000000000000000000000000000000000000
-
 test_expect_success setup '
        >xyzzy &&
        _empty=$(git hash-object --stdin <xyzzy) &&
index 49753362f0974627f1b5e5e11144484238875494..8340ac2f073446963f7f5dab39ac87771264da54 100755 (executable)
@@ -34,8 +34,8 @@ do
                ! test -s out
        '
 
-       test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i output" '
-               grep -e "Use -f if" err
+       test_expect_success "complaints for ignored $i output" '
+               test_i18ngrep -e "Use -f if" err
        '
 
        test_expect_success "complaints for ignored $i with unignored file" '
@@ -44,8 +44,8 @@ do
                git ls-files "$i" >out &&
                ! test -s out
        '
-       test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i with unignored file output" '
-               grep -e "Use -f if" err
+       test_expect_success "complaints for ignored $i with unignored file output" '
+               test_i18ngrep -e "Use -f if" err
        '
 done
 
@@ -61,10 +61,10 @@ do
                )
        '
 
-       test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i in dir output" '
+       test_expect_success "complaints for ignored $i in dir output" '
                (
                        cd dir &&
-                       grep -e "Use -f if" err
+                       test_i18ngrep -e "Use -f if" err
                )
        '
 done
@@ -81,10 +81,10 @@ do
                )
        '
 
-       test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i in sub output" '
+       test_expect_success "complaints for ignored $i in sub output" '
                (
                        cd sub &&
-                       grep -e "Use -f if" err
+                       test_i18ngrep -e "Use -f if" err
                )
        '
 done
index 806fdccce1db994899509cb3dd9d7801b84c48ba..0c02d569520ddc81b32db7d248197562d00bd7ea 100755 (executable)
@@ -312,20 +312,20 @@ test_expect_success 'merge-recursive result' '
 
 '
 
-test_expect_success C_LOCALE_OUTPUT 'fail if the index has unresolved entries' '
+test_expect_success 'fail if the index has unresolved entries' '
 
        rm -fr [abcd] &&
        git checkout -f "$c1" &&
 
        test_must_fail git merge "$c5" &&
        test_must_fail git merge "$c5" 2> out &&
-       grep "not possible because you have unmerged files" out &&
+       test_i18ngrep "not possible because you have unmerged files" out &&
        git add -u &&
        test_must_fail git merge "$c5" 2> out &&
-       grep "You have not concluded your merge" out &&
+       test_i18ngrep "You have not concluded your merge" out &&
        rm -f .git/MERGE_HEAD &&
        test_must_fail git merge "$c5" 2> out &&
-       grep "Your local changes to the following files would be overwritten by merge:" out
+       test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out
 '
 
 test_expect_success 'merge-recursive remove conflict' '
diff --git a/t/t3102-ls-tree-wildcards.sh b/t/t3102-ls-tree-wildcards.sh
new file mode 100755 (executable)
index 0000000..c286854
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+test_description='ls-tree with(out) globs'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       mkdir a aa "a[a]" &&
+       touch a/one aa/two "a[a]/three" &&
+       git add a/one aa/two "a[a]/three" &&
+       git commit -m test
+'
+
+test_expect_success 'ls-tree a[a] matches literally' '
+       cat >expected <<EOF &&
+100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391   a[a]/three
+EOF
+       git ls-tree -r HEAD "a[a]" >actual &&
+       test_cmp expected actual
+'
+
+test_done
index 286a2a68692dd7a70e34851f75098506a1fc783a..9e69c8c926620f06343e64e7b3aa3e4ada5a6b69 100755 (executable)
@@ -46,7 +46,7 @@ test_expect_success \
     'git branch a/b/c && test -f .git/refs/heads/a/b/c'
 
 cat >expect <<EOF
-0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
+$_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' \
@@ -203,10 +203,12 @@ test_expect_success 'test deleting branch deletes branch config' \
      test -z "$(git config branch.my7.remote)" &&
      test -z "$(git config branch.my7.merge)"'
 
-test_expect_success C_LOCALE_OUTPUT 'test deleting branch without config' \
+test_expect_success 'test deleting branch without config' \
     'git branch my7 s &&
      sha1=$(git rev-parse my7 | cut -c 1-7) &&
-     test "$(git branch -d my7 2>&1)" = "Deleted branch my7 (was $sha1)."'
+     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 &&
@@ -230,7 +232,7 @@ test_expect_success \
 
 # Keep this test last, as it changes the current branch
 cat >expect <<EOF
-0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000     branch: Created from master
+$_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' \
index 4ef7d09115678ff97717a5f6a3027a87490dac79..6b7c118e4fcbf3855318b2e9e3b721d07950fd25 100755 (executable)
@@ -72,10 +72,10 @@ cat >expect <<'EOF'
   branch-two
   master
 EOF
-test_expect_success C_LOCALE_OUTPUT 'git branch shows detached HEAD properly' '
+test_expect_success 'git branch shows detached HEAD properly' '
        git checkout HEAD^0 &&
        git branch >actual &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 test_done
index 1921ca3a73370d378e6aedd0820fd8d2a030da03..28e17c8920cbe9f2b13ff5cc30939eab8171bae2 100755 (executable)
@@ -101,8 +101,8 @@ test_expect_success 'edit existing notes' '
        test_must_fail git notes show HEAD^
 '
 
-test_expect_success 'cannot add note where one exists' '
-       ! MSG=b2 git notes add &&
+test_expect_success 'cannot "git notes add -m" where notes already exists' '
+       test_must_fail git notes add -m "b2" &&
        test ! -f .git/NOTES_EDITMSG &&
        test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
        test b3 = $(git notes show) &&
@@ -110,6 +110,24 @@ test_expect_success 'cannot add note where one exists' '
        test_must_fail git notes show HEAD^
 '
 
+test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
+       git notes add -f -m "b1" &&
+       test ! -f .git/NOTES_EDITMSG &&
+       test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
+       test b1 = $(git notes show) &&
+       git show HEAD^ &&
+       test_must_fail git notes show HEAD^
+'
+
+test_expect_success 'add w/no options on existing note morphs into edit' '
+       MSG=b2 git notes add &&
+       test ! -f .git/NOTES_EDITMSG &&
+       test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
+       test b2 = $(git notes show) &&
+       git show HEAD^ &&
+       test_must_fail git notes show HEAD^
+'
+
 test_expect_success 'can overwrite existing note with "git notes add -f"' '
        MSG=b1 git notes add -f &&
        test ! -f .git/NOTES_EDITMSG &&
@@ -194,6 +212,13 @@ test_expect_success 'show -F notes' '
        test_cmp expect-F output
 '
 
+test_expect_success 'Re-adding -F notes without -f fails' '
+       echo "zyxxy" > note5 &&
+       test_must_fail git notes add -F note5 &&
+       git log -3 > output &&
+       test_cmp expect-F output
+'
+
 cat >expect << EOF
 commit 15023535574ded8b1a89052b32673f84cf9582b8
 tree e070e3af51011e47b183c33adf9736736a525709
@@ -247,6 +272,44 @@ do
        '
 done
 
+test_expect_success 'setup alternate notes ref' '
+       git notes --ref=alternate add -m alternate
+'
+
+test_expect_success 'git log --notes shows default notes' '
+       git log -1 --notes >output &&
+       grep xyzzy output &&
+       ! grep alternate output
+'
+
+test_expect_success 'git log --notes=X shows only X' '
+       git log -1 --notes=alternate >output &&
+       ! grep xyzzy output &&
+       grep alternate output
+'
+
+test_expect_success 'git log --notes --notes=X shows both' '
+       git log -1 --notes --notes=alternate >output &&
+       grep xyzzy output &&
+       grep alternate output
+'
+
+test_expect_success 'git log --no-notes resets default state' '
+       git log -1 --notes --notes=alternate \
+               --no-notes --notes=alternate \
+               >output &&
+       ! grep xyzzy output &&
+       grep alternate output
+'
+
+test_expect_success 'git log --no-notes resets ref list' '
+       git log -1 --notes --notes=alternate \
+               --no-notes --notes \
+               >output &&
+       grep xyzzy output &&
+       ! grep alternate output
+'
+
 test_expect_success 'create -m notes (setup)' '
        : > a5 &&
        git add a5 &&
index 349eebd54268c927249322dc22fc478869860f7c..6eaecec906c49749237b243f772f2e33eb0efedd 100755 (executable)
@@ -158,15 +158,24 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '
 '
 rm -f B
 
-test_expect_success 'dump usage when upstream arg is missing' '
-       git checkout -b usage topic &&
-       test_must_fail git rebase 2>error1 &&
-       grep "[Uu]sage" error1 &&
-       test_must_fail git rebase --abort 2>error2 &&
-       grep "No rebase in progress" error2 &&
-       test_must_fail git rebase --onto master 2>error3 &&
-       grep "[Uu]sage" error3 &&
-       ! grep "can.t shift" error3
+test_expect_success 'fail when upstream arg is missing and not on branch' '
+       git checkout topic &&
+       test_must_fail git rebase >output.out &&
+       grep "You are not currently on a branch" output.out
+'
+
+test_expect_success 'fail when upstream arg is missing and not configured' '
+       git checkout -b no-config topic &&
+       test_must_fail git rebase >output.out &&
+       grep "branch.no-config.merge" output.out
+'
+
+test_expect_success 'default to @{upstream} when upstream arg is missing' '
+       git checkout -b default topic &&
+       git config branch.default.remote .
+       git config branch.default.merge refs/heads/master
+       git rebase &&
+       test "$(git rev-parse default~1)" = "$(git rev-parse master)"
 '
 
 test_expect_success 'rebase -q is quiet' '
index 64446e3db3afed68e970de6fc3c0780db25c85d1..826500bd18a520a37e3490b9deeca94fb9e14405 100755 (executable)
@@ -35,6 +35,11 @@ test_expect_success 'rebase with git am -3 (default)' '
        test_must_fail git rebase master
 '
 
+test_expect_success 'rebase --skip can not be used with other options' '
+       test_must_fail git rebase -v --skip &&
+       test_must_fail git rebase --skip -v
+'
+
 test_expect_success 'rebase --skip with am -3' '
        git rebase --skip
        '
index e573dc845b3d72004b2a96f344528c68977c52e1..a6a6c40a98512b190f8610391aa153a294e4b5cb 100755 (executable)
@@ -84,6 +84,16 @@ testrebase() {
                test_cmp reflog_before reflog_after &&
                rm reflog_before reflog_after
        '
+
+       test_expect_success 'rebase --abort can not be used with other options' '
+               cd "$work_dir" &&
+               # Clean up the state from the previous one
+               git reset --hard pre-rebase &&
+               test_must_fail git rebase$type master &&
+               test_must_fail git rebase -v --abort &&
+               test_must_fail git rebase --abort -v &&
+               git rebase --abort
+       '
 }
 
 testrebase "" .git/rebase-apply
index 19341e5ca1c7f415afdf2c82f67930b8fed5478b..08201e2331d36af769d832e3d9551c48331b7033 100755 (executable)
@@ -27,7 +27,17 @@ export GIT_AUTHOR_EMAIL
 #    \
 #     B2       <-- origin/topic
 #
-# In both cases, 'topic' is rebased onto 'origin/topic'.
+# Clone 3 (no-ff merge):
+#
+# A1--A2--B3   <-- origin/master
+#  \
+#   B1------M  <-- topic
+#    \     /
+#     \--A3    <-- topic2
+#      \
+#       B2     <-- origin/topic
+#
+# In all cases, 'topic' is rebased onto 'origin/topic'.
 
 test_expect_success 'setup for merge-preserving rebase' \
        'echo First > A &&
@@ -61,6 +71,16 @@ test_expect_success 'setup for merge-preserving rebase' \
                git commit -m "Merge origin/master into topic"
        ) &&
 
+       git clone ./. clone3 &&
+       (
+               cd clone3 &&
+               git checkout -b topic2 origin/topic &&
+               echo Sixth > A &&
+               git commit -a -m "Modify A3" &&
+               git checkout -b topic origin/topic &&
+               git merge --no-ff topic2
+       ) &&
+
        git checkout topic &&
        echo Fourth >> B &&
        git commit -a -m "Modify B2"
@@ -93,4 +113,14 @@ test_expect_success '--continue works after a conflict' '
        )
 '
 
+test_expect_success 'rebase -p preserves no-ff merges' '
+       (
+       cd clone3 &&
+       git fetch &&
+       git rebase -p origin/topic &&
+       test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
+       test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l)
+       )
+'
+
 test_done
index 3b0d27350e8a0fe43bb7735bc614462347aed3e0..1e855cdae55ff46cbb878b724328b57cdb8069ce 100755 (executable)
@@ -40,4 +40,59 @@ test_expect_success 'non-interactive rebase --continue works with touched file'
        git rebase --continue
 '
 
+test_expect_success 'rebase --continue can not be used with other options' '
+       test_must_fail git rebase -v --continue &&
+       test_must_fail git rebase --continue -v
+'
+
+test_expect_success 'rebase --continue remembers merge strategy and options' '
+       rm -fr .git/rebase-* &&
+       git reset --hard commit-new-file-F2-on-topic-branch &&
+       test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
+       test_when_finished "rm -fr test-bin funny.was.run" &&
+       mkdir test-bin &&
+       cat >test-bin/git-merge-funny <<-EOF
+       #!$SHELL_PATH
+       case "\$1" in --opt) ;; *) exit 2 ;; esac
+       shift &&
+       >funny.was.run &&
+       exec git merge-recursive "\$@"
+       EOF
+       chmod +x test-bin/git-merge-funny &&
+       (
+               PATH=./test-bin:$PATH
+               test_must_fail git rebase -s funny -Xopt master topic
+       ) &&
+       test -f funny.was.run &&
+       rm funny.was.run &&
+       echo "Resolved" >F2 &&
+       git add F2 &&
+       (
+               PATH=./test-bin:$PATH
+               git rebase --continue
+       ) &&
+       test -f funny.was.run
+'
+
+test_expect_success 'rebase --continue remembers --rerere-autoupdate' '
+       rm -fr .git/rebase-* &&
+       git reset --hard commit-new-file-F3-on-topic-branch &&
+       git checkout master
+       test_commit "commit-new-file-F3" F3 3 &&
+       git config rerere.enabled true &&
+       test_must_fail git rebase -m master topic &&
+       echo "Resolved" >F2 &&
+       git add F2 &&
+       test_must_fail git rebase --continue &&
+       echo "Resolved" >F3 &&
+       git add F3 &&
+       git rebase --continue &&
+       git reset --hard topic@{1} &&
+       test_must_fail git rebase -m --rerere-autoupdate master &&
+       test "$(cat F2)" = "Resolved" &&
+       test_must_fail git rebase --continue &&
+       test "$(cat F3)" = "Resolved" &&
+       git rebase --continue
+'
+
 test_done
index 753a6c972cda61d2da3d2ecf7bd9c231004d6ad0..595d2ff990ad3305f47977431c0b7d102ca3866b 100755 (executable)
@@ -91,12 +91,12 @@ test_expect_success 'cherry-pick on stat-dirty working tree' '
        )
 '
 
-test_expect_success C_LOCALE_OUTPUT 'revert forbidden on dirty working tree' '
+test_expect_success 'revert forbidden on dirty working tree' '
 
        echo content >extra_file &&
        git add extra_file &&
        test_must_fail git revert HEAD 2>errors &&
-       grep "Your local changes would be overwritten by " errors
+       test_i18ngrep "Your local changes would be overwritten by " errors
 
 '
 
index c0c8330c20e80f26d51b62c8999533c5692094de..212ec54aaf0d805bbdecd93f3311d248a57d5b08 100755 (executable)
@@ -44,7 +44,7 @@ test_expect_success 'failed cherry-pick does not advance HEAD' '
        test "$head" = "$newhead"
 '
 
-test_expect_success C_LOCALE_OUTPUT 'advice from failed cherry-pick' "
+test_expect_success 'advice from failed cherry-pick' "
        pristine_detach initial &&
 
        picked=\$(git rev-parse --short picked) &&
@@ -56,7 +56,7 @@ test_expect_success C_LOCALE_OUTPUT 'advice from failed cherry-pick' "
        EOF
        test_must_fail git cherry-pick picked 2>actual &&
 
-       test_cmp expected actual
+       test_i18ncmp expected actual
 "
 
 test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' '
index cd093bd34730a3dba6eec7719d3b0170e517fb5e..9fd28bcf3435f831fa24285dd703c82b8396d635 100755 (executable)
@@ -240,11 +240,10 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
 
 test_expect_success 'choking "git rm" should not let it die with cruft' '
        git reset -q --hard &&
-       H=0000000000000000000000000000000000000000 &&
        i=0 &&
        while test $i -lt 12000
        do
-           echo "100644 $H 0   some-file-$i"
+           echo "100644 $_z40 0        some-file-$i"
            i=$(( $i + 1 ))
        done | git update-index --index-info &&
        git rm -n "some-file-*" | :;
index 7de42faf4887c6e8137c2498a96b41a4afe4e672..575d9508a09911f9d95dad2786fb2f1494abc093 100755 (executable)
@@ -271,9 +271,9 @@ test_expect_success 'git add --dry-run of non-existing file' "
        test_must_fail git add --dry-run track-this ignored-file >actual 2>&1
 "
 
-test_expect_success C_LOCALE_OUTPUT 'git add --dry-run of an existing file output' "
+test_expect_success 'git add --dry-run of an existing file output' "
        echo \"fatal: pathspec 'ignored-file' did not match any files\" >expect &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 "
 
 cat >expect.err <<\EOF
@@ -290,9 +290,9 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
        test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual.out 2>actual.err
 '
 
-test_expect_success C_LOCALE_OUTPUT 'git add --dry-run --ignore-missing of non-existing file output' '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+test_expect_success 'git add --dry-run --ignore-missing of non-existing file output' '
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_done
index d6327e7c74cd0cd3d433a71b1e9bb89eaf088ed5..9e236f9cc0bf43155d377c1706c8142d843c417d 100755 (executable)
@@ -82,10 +82,9 @@ EOF
 '
 
 test_expect_success PERL 'setup fake editor' '
-       cat >fake_editor.sh <<EOF
-       EOF
+       >fake_editor.sh &&
        chmod a+x fake_editor.sh &&
-       test_set_editor "$(pwd)/fake_editor.sh" &&
+       test_set_editor "$(pwd)/fake_editor.sh"
 '
 
 test_expect_success PERL 'dummy edit works' '
@@ -295,4 +294,40 @@ test_expect_success PERL 'deleting an empty file' '
        test_cmp expected diff
 '
 
+test_expect_success PERL 'split hunk setup' '
+       git reset --hard &&
+       for i in 10 20 30 40 50 60
+       do
+               echo $i
+       done >test &&
+       git add test &&
+       test_tick &&
+       git commit -m test &&
+
+       for i in 10 15 20 21 22 23 24 30 40 50 60
+       do
+               echo $i
+       done >test
+'
+
+test_expect_success PERL 'split hunk "add -p (edit)"' '
+       # Split, say Edit and do nothing.  Then:
+       #
+       # 1. Broken version results in a patch that does not apply and
+       # only takes [y/n] (edit again) so the first q is discarded
+       # and then n attempts to discard the edit. Repeat q enough
+       # 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
+       #    exits.
+       for a in s e     q n q q
+       do
+               echo $a
+       done |
+       EDITOR=: git add -p &&
+       git diff >actual &&
+       ! grep "^+15" actual
+'
+
 test_done
index cad85450b78891a98a0b60af1422c62c7288265c..844277cfa605f51cccd5d78a48a83fb75c03af9b 100755 (executable)
@@ -64,17 +64,42 @@ test_expect_success \
     'validate the output.' \
     'compare_diff_patch current expected'
 
-test_expect_success C_LOCALE_OUTPUT 'favour same basenames over different ones' '
+test_expect_success 'favour same basenames over different ones' '
        cp path1 another-path &&
        git add another-path &&
        git commit -m 1 &&
        git rm path1 &&
        mkdir subdir &&
        git mv another-path subdir/path1 &&
-       git status | grep "renamed: .*path1 -> subdir/path1"'
+       git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
 
-test_expect_success C_LOCALE_OUTPUT  'favour same basenames even with minor differences' '
+test_expect_success 'favour same basenames even with minor differences' '
        git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
-       git status | grep "renamed: .*path1 -> subdir/path1"'
+       git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
+
+test_expect_success 'setup for many rename source candidates' '
+       git reset --hard &&
+       for i in 0 1 2 3 4 5 6 7 8 9;
+       do
+               for j in 0 1 2 3 4 5 6 7 8 9;
+               do
+                       echo "$i$j" >"path$i$j"
+               done
+       done &&
+       git add "path??" &&
+       test_tick &&
+       git commit -m "hundred" &&
+       (cat path1; echo new) >new-path &&
+       echo old >>path1 &&
+       git add new-path path1 &&
+       git diff -l 4 -C -C --cached --name-status >actual 2>actual.err &&
+       sed -e "s/^\([CM]\)[0-9]*       /\1     /" actual >actual.munged &&
+       cat >expect <<-EOF &&
+       C       path1   new-path
+       M       path1
+       EOF
+       test_cmp expect actual.munged &&
+       grep warning actual.err
+'
 
 test_done
index 9fb8ca06a84b3f3e60f466cc33bc2de786a9fc90..a5e8b830834f4b5feb531f8f4f4d08462325b1de 100755 (executable)
@@ -126,15 +126,12 @@ cat >.test-recursive-AB <<\EOF
 :100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d M     Z/NM
 EOF
 
-x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-x40="$x40$x40$x40$x40$x40$x40$x40$x40"
-z40='0000000000000000000000000000000000000000'
 cmp_diff_files_output () {
     # diff-files never reports additions.  Also it does not fill in the
     # object ID for the changed files because it wants you to look at the
     # filesystem.
     sed <"$2" >.test-tmp \
-       -e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\)    /'$z40'\1       /' &&
+       -e '/^:000000 /d;s/'$_x40'\( [MCRNDU][0-9]*\)   /'$_z40'\1      /' &&
     test_cmp "$1" .test-tmp
 }
 
index 5daa0f2a0c9c8cd6ed2c06e12c8fd421c178d4f0..93a6f208710befc064b7b99bcd758bb8b6381918 100755 (executable)
@@ -80,18 +80,31 @@ test_expect_success setup '
 
        git config log.showroot false &&
        git commit --amend &&
+
+       GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" &&
+       GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
+       export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
+       git checkout -b rearrange initial &&
+       for i in B A; do echo $i; done >dir/sub &&
+       git add dir/sub &&
+       git commit -m "Rearranged lines in dir/sub" &&
+       git checkout master &&
+
        git show-branch
 '
 
 : <<\EOF
 ! [initial] Initial
  * [master] Merge branch 'side'
-  ! [side] Side
----
- -  [master] Merge branch 'side'
- *+ [side] Side
- *  [master^] Second
-+*+ [initial] Initial
+  ! [rearrange] Rearranged lines in dir/sub
+   ! [side] Side
+----
+  +  [rearrange] Rearranged lines in dir/sub
+ -   [master] Merge branch 'side'
+ * + [side] Side
+ *   [master^] Third
+ *   [master~2] Second
++*++ [initial] Initial
 EOF
 
 V=`git version | sed -e 's/^git version //' -e 's/\./\\./g'`
@@ -287,6 +300,8 @@ diff --no-index --name-status -- dir2 dir
 diff --no-index dir dir3
 diff master master^ side
 diff --dirstat master~1 master~2
+diff --dirstat initial rearrange
+diff --dirstat-by-file initial rearrange
 EOF
 
 test_expect_success 'log -S requires an argument' '
diff --git a/t/t4013/diff.diff_--dirstat-by-file_initial_rearrange b/t/t4013/diff.diff_--dirstat-by-file_initial_rearrange
new file mode 100644 (file)
index 0000000..e48e33f
--- /dev/null
@@ -0,0 +1,3 @@
+$ git diff --dirstat-by-file initial rearrange
+ 100.0% dir/
+$
diff --git a/t/t4013/diff.diff_--dirstat_initial_rearrange b/t/t4013/diff.diff_--dirstat_initial_rearrange
new file mode 100644 (file)
index 0000000..5fb02c1
--- /dev/null
@@ -0,0 +1,3 @@
+$ git diff --dirstat initial rearrange
+ 100.0% dir/
+$
index 1f0f9ad44b241e57e867c0676b73f37a1dc93d60..3b4e113012568dc936bd230fe33c251ab8bff3dd 100644 (file)
@@ -1,7 +1,7 @@
 $ git format-patch --stdout --cover-letter -n initial..master^
 From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001
 From: C O Mitter <committer@example.com>
-Date: Mon, 26 Jun 2006 00:05:00 +0000
+Date: Mon, 26 Jun 2006 00:06:00 +0000
 Subject: [DIFFERENT_PREFIX 0/2] *** SUBJECT HERE ***
 
 *** BLURB HERE ***
index d155e0bab29000a99eb797681450be1174185846..44d45257da708f25bd0eb2c631bd7e68a38a7354 100644 (file)
@@ -1,4 +1,10 @@
 $ git log --decorate=full --all
+commit cd4e72fd96faed3f0ba949dc42967430374e2290 (refs/heads/rearrange)
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:06:00 2006 +0000
+
+    Rearranged lines in dir/sub
+
 commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, refs/heads/master)
 Merge: 9a6d494 c7a2ab9
 Author: A U Thor <author@example.com>
index fd7c3e64396b4ea57c3b03d2e120580205263462..27d3eabc26f35401581d64f0a933fb552e5f4d52 100644 (file)
@@ -1,4 +1,10 @@
 $ git log --decorate --all
+commit cd4e72fd96faed3f0ba949dc42967430374e2290 (rearrange)
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:06:00 2006 +0000
+
+    Rearranged lines in dir/sub
+
 commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, master)
 Merge: 9a6d494 c7a2ab9
 Author: A U Thor <author@example.com>
index c3cdb5205350985f3362268b0cd63bc59bee2444..045cee312cdeb515869eeeda3f7b167fb5b91504 100755 (executable)
@@ -614,13 +614,13 @@ echo "fatal: --name-only does not make sense" > expect.name-only
 echo "fatal: --name-status does not make sense" > expect.name-status
 echo "fatal: --check does not make sense" > expect.check
 
-test_expect_success C_LOCALE_OUTPUT 'options no longer allowed for format-patch' '
+test_expect_success 'options no longer allowed for format-patch' '
        test_must_fail git format-patch --name-only 2> output &&
-       test_cmp expect.name-only output &&
+       test_i18ncmp expect.name-only output &&
        test_must_fail git format-patch --name-status 2> output &&
-       test_cmp expect.name-status output &&
+       test_i18ncmp expect.name-status output &&
        test_must_fail git format-patch --check 2> output &&
-       test_cmp expect.check output'
+       test_i18ncmp expect.check output'
 
 test_expect_success 'format-patch --numstat should produce a patch' '
        git format-patch --numstat --stdout master..side > output &&
@@ -793,4 +793,62 @@ test_expect_success 'format-patch wraps extremely long headers (rfc2047)' '
        test_cmp expect subject
 '
 
+M8="foo_bar_"
+M64=$M8$M8$M8$M8$M8$M8$M8$M8
+cat >expect <<EOF
+From: $M64
+ <foobar@foo.bar>
+EOF
+test_expect_success 'format-patch wraps non-quotable headers' '
+       rm -rf patches/ &&
+       echo content >>file &&
+       git add file &&
+       git commit -mfoo --author "$M64 <foobar@foo.bar>" &&
+       git format-patch --stdout -1 >patch &&
+       sed -n "/^From: /p; /^ /p; /^$/q" <patch >from &&
+       test_cmp expect from
+'
+
+check_author() {
+       echo content >>file &&
+       git add file &&
+       GIT_AUTHOR_NAME=$1 git commit -m author-check &&
+       git format-patch --stdout -1 >patch &&
+       grep ^From: patch >actual &&
+       test_cmp expect actual
+}
+
+cat >expect <<'EOF'
+From: "Foo B. Bar" <author@example.com>
+EOF
+test_expect_success 'format-patch quotes dot in headers' '
+       check_author "Foo B. Bar"
+'
+
+cat >expect <<'EOF'
+From: "Foo \"The Baz\" Bar" <author@example.com>
+EOF
+test_expect_success 'format-patch quotes double-quote in headers' '
+       check_author "Foo \"The Baz\" Bar"
+'
+
+cat >expect <<'EOF'
+From: =?UTF-8?q?"F=C3=B6o=20B.=20Bar"?= <author@example.com>
+EOF
+test_expect_success 'rfc2047-encoded headers also double-quote 822 specials' '
+       check_author "Föo B. Bar"
+'
+
+cat >expect <<'EOF'
+Subject: header with . in it
+EOF
+test_expect_success 'subject lines do not have 822 atom-quoting' '
+       echo content >>file &&
+       git add file &&
+       git commit -m "header with . in it" &&
+       git format-patch -k -1 --stdout >patch &&
+       grep ^Subject: patch >actual &&
+       test_cmp expect actual
+'
+
 test_done
index a7602cf923d95a51643753ce44fa65cf406aba9c..083f62d1d6bb6bfd908b0a03db1a47f80071ef91 100755 (executable)
@@ -4,8 +4,6 @@ test_description='external diff interface test'
 
 . ./test-lib.sh
 
-_z40=0000000000000000000000000000000000000000
-
 test_expect_success setup '
 
        test_tick &&
index 2a537a21e8e6793e6ffa2fe1522e30f877b209fe..c00a94b9ba4498e72a31856aac9cf653bbce8ba3 100755 (executable)
@@ -11,7 +11,9 @@ test_expect_success setup '
        tr \
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
          "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
-         <"$TEST_DIRECTORY"/../COPYING >test
+         <"$TEST_DIRECTORY"/../COPYING >test &&
+       echo "to be deleted" >test2 &&
+       git add test2
 
 '
 
@@ -25,5 +27,44 @@ test_expect_success 'detect rewrite' '
 
 '
 
+cat >expect <<EOF
+diff --git a/test2 b/test2
+deleted file mode 100644
+index 4202011..0000000
+--- a/test2
++++ /dev/null
+@@ -1 +0,0 @@
+-to be deleted
+EOF
+test_expect_success 'show deletion diff without -D' '
+
+       rm test2 &&
+       git diff -- test2 >actual &&
+       test_cmp expect actual
+'
+
+cat >expect <<EOF
+diff --git a/test2 b/test2
+deleted file mode 100644
+index 4202011..0000000
+EOF
+test_expect_success 'suppress deletion diff with -D' '
+
+       git diff -D -- test2 >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'show deletion diff with -B' '
+
+       git diff -B -- test >actual &&
+       grep "Linus Torvalds" actual
+'
+
+test_expect_success 'suppress deletion diff with -B -D' '
+
+       git diff -B -D -- test >actual &&
+       grep -v "Linus Torvalds" actual
+'
+
 test_done
 
index 241a74d2a20276d711944d3e203083b515486e77..518bf9524e0b55181f3c440d202b69c12a0b314f 100755 (executable)
@@ -5,7 +5,6 @@ test_description='difference in submodules'
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/diff-lib.sh
 
-_z40=0000000000000000000000000000000000000000
 test_expect_success setup '
        test_tick &&
        test_create_repo sub &&
diff --git a/t/t4046-diff-unmerged.sh b/t/t4046-diff-unmerged.sh
new file mode 100755 (executable)
index 0000000..25d50a6
--- /dev/null
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+test_description='diff with unmerged index entries'
+. ./test-lib.sh
+
+test_expect_success setup '
+       for i in 0 1 2 3
+       do
+               blob=$(echo $i | git hash-object --stdin) &&
+               eval "blob$i=$blob" &&
+               eval "m$i=\"100644 \$blob$i $i\"" || break
+       done &&
+       paths= &&
+       for b in o x
+       do
+               for o in o x
+               do
+                       for t in o x
+                       do
+                               path="$b$o$t" &&
+                               case "$path" in ooo) continue ;; esac
+                               paths="$paths$path " &&
+                               p="     $path" &&
+                               case "$b" in x) echo "$m1$p" ;; esac &&
+                               case "$o" in x) echo "$m2$p" ;; esac &&
+                               case "$t" in x) echo "$m3$p" ;; esac ||
+                               break
+                       done || break
+               done || break
+       done >ls-files-s.expect &&
+       git update-index --index-info <ls-files-s.expect &&
+       git ls-files -s >ls-files-s.actual &&
+       test_cmp ls-files-s.expect ls-files-s.actual
+'
+
+test_expect_success 'diff-files -0' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path"
+       done >diff-files-0.expect &&
+       git diff-files -0 >diff-files-0.actual &&
+       test_cmp diff-files-0.expect diff-files-0.actual
+'
+
+test_expect_success 'diff-files -1' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path" &&
+               case "$path" in
+               x??) echo ":100644 100644 $blob1 $_z40 M        $path"
+               esac
+       done >diff-files-1.expect &&
+       git diff-files -1 >diff-files-1.actual &&
+       test_cmp diff-files-1.expect diff-files-1.actual
+'
+
+test_expect_success 'diff-files -2' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path" &&
+               case "$path" in
+               ?x?) echo ":100644 100644 $blob2 $_z40 M        $path"
+               esac
+       done >diff-files-2.expect &&
+       git diff-files -2 >diff-files-2.actual &&
+       test_cmp diff-files-2.expect diff-files-2.actual &&
+       git diff-files >diff-files-default-2.actual &&
+       test_cmp diff-files-2.expect diff-files-default-2.actual
+'
+
+test_expect_success 'diff-files -3' '
+       for path in $paths
+       do
+               >"$path" &&
+               echo ":000000 100644 $_z40 $_z40 U      $path" &&
+               case "$path" in
+               ??x) echo ":100644 100644 $blob3 $_z40 M        $path"
+               esac
+       done >diff-files-3.expect &&
+       git diff-files -3 >diff-files-3.actual &&
+       test_cmp diff-files-3.expect diff-files-3.actual
+'
+
+test_done
diff --git a/t/t4047-diff-dirstat.sh b/t/t4047-diff-dirstat.sh
new file mode 100755 (executable)
index 0000000..29e80a5
--- /dev/null
@@ -0,0 +1,979 @@
+#!/bin/sh
+
+test_description='diff --dirstat tests'
+. ./test-lib.sh
+
+# set up two commits where the second commit has these files
+# (10 lines in each file):
+#
+#   unchanged/text           (unchanged from 1st commit)
+#   changed/text             (changed 1st line)
+#   rearranged/text          (swapped 1st and 2nd line)
+#   dst/copy/unchanged/text  (copied from src/copy/unchanged/text, unchanged)
+#   dst/copy/changed/text    (copied from src/copy/changed/text, changed)
+#   dst/copy/rearranged/text (copied from src/copy/rearranged/text, rearranged)
+#   dst/move/unchanged/text  (moved from src/move/unchanged/text, unchanged)
+#   dst/move/changed/text    (moved from src/move/changed/text, changed)
+#   dst/move/rearranged/text (moved from src/move/rearranged/text, rearranged)
+
+test_expect_success 'setup' '
+       mkdir unchanged &&
+       mkdir changed &&
+       mkdir rearranged &&
+       mkdir src &&
+       mkdir src/copy &&
+       mkdir src/copy/unchanged &&
+       mkdir src/copy/changed &&
+       mkdir src/copy/rearranged &&
+       mkdir src/move &&
+       mkdir src/move/unchanged &&
+       mkdir src/move/changed &&
+       mkdir src/move/rearranged &&
+       cat <<EOF >unchanged/text &&
+unchanged       line #0
+unchanged       line #1
+unchanged       line #2
+unchanged       line #3
+unchanged       line #4
+unchanged       line #5
+unchanged       line #6
+unchanged       line #7
+unchanged       line #8
+unchanged       line #9
+EOF
+       cat <<EOF >changed/text &&
+changed         line #0
+changed         line #1
+changed         line #2
+changed         line #3
+changed         line #4
+changed         line #5
+changed         line #6
+changed         line #7
+changed         line #8
+changed         line #9
+EOF
+       cat <<EOF >rearranged/text &&
+rearranged      line #0
+rearranged      line #1
+rearranged      line #2
+rearranged      line #3
+rearranged      line #4
+rearranged      line #5
+rearranged      line #6
+rearranged      line #7
+rearranged      line #8
+rearranged      line #9
+EOF
+       cat <<EOF >src/copy/unchanged/text &&
+copy  unchanged line #0
+copy  unchanged line #1
+copy  unchanged line #2
+copy  unchanged line #3
+copy  unchanged line #4
+copy  unchanged line #5
+copy  unchanged line #6
+copy  unchanged line #7
+copy  unchanged line #8
+copy  unchanged line #9
+EOF
+       cat <<EOF >src/copy/changed/text &&
+copy    changed line #0
+copy    changed line #1
+copy    changed line #2
+copy    changed line #3
+copy    changed line #4
+copy    changed line #5
+copy    changed line #6
+copy    changed line #7
+copy    changed line #8
+copy    changed line #9
+EOF
+       cat <<EOF >src/copy/rearranged/text &&
+copy rearranged line #0
+copy rearranged line #1
+copy rearranged line #2
+copy rearranged line #3
+copy rearranged line #4
+copy rearranged line #5
+copy rearranged line #6
+copy rearranged line #7
+copy rearranged line #8
+copy rearranged line #9
+EOF
+       cat <<EOF >src/move/unchanged/text &&
+move  unchanged line #0
+move  unchanged line #1
+move  unchanged line #2
+move  unchanged line #3
+move  unchanged line #4
+move  unchanged line #5
+move  unchanged line #6
+move  unchanged line #7
+move  unchanged line #8
+move  unchanged line #9
+EOF
+       cat <<EOF >src/move/changed/text &&
+move    changed line #0
+move    changed line #1
+move    changed line #2
+move    changed line #3
+move    changed line #4
+move    changed line #5
+move    changed line #6
+move    changed line #7
+move    changed line #8
+move    changed line #9
+EOF
+       cat <<EOF >src/move/rearranged/text &&
+move rearranged line #0
+move rearranged line #1
+move rearranged line #2
+move rearranged line #3
+move rearranged line #4
+move rearranged line #5
+move rearranged line #6
+move rearranged line #7
+move rearranged line #8
+move rearranged line #9
+EOF
+       git add . &&
+       git commit -m "initial" &&
+       mkdir dst &&
+       mkdir dst/copy &&
+       mkdir dst/copy/unchanged &&
+       mkdir dst/copy/changed &&
+       mkdir dst/copy/rearranged &&
+       mkdir dst/move &&
+       mkdir dst/move/unchanged &&
+       mkdir dst/move/changed &&
+       mkdir dst/move/rearranged &&
+       cat <<EOF >changed/text &&
+CHANGED XXXXXXX line #0
+changed         line #1
+changed         line #2
+changed         line #3
+changed         line #4
+changed         line #5
+changed         line #6
+changed         line #7
+changed         line #8
+changed         line #9
+EOF
+       cat <<EOF >rearranged/text &&
+rearranged      line #1
+rearranged      line #0
+rearranged      line #2
+rearranged      line #3
+rearranged      line #4
+rearranged      line #5
+rearranged      line #6
+rearranged      line #7
+rearranged      line #8
+rearranged      line #9
+EOF
+       cat <<EOF >dst/copy/unchanged/text &&
+copy  unchanged line #0
+copy  unchanged line #1
+copy  unchanged line #2
+copy  unchanged line #3
+copy  unchanged line #4
+copy  unchanged line #5
+copy  unchanged line #6
+copy  unchanged line #7
+copy  unchanged line #8
+copy  unchanged line #9
+EOF
+       cat <<EOF >dst/copy/changed/text &&
+copy XXXCHANGED line #0
+copy    changed line #1
+copy    changed line #2
+copy    changed line #3
+copy    changed line #4
+copy    changed line #5
+copy    changed line #6
+copy    changed line #7
+copy    changed line #8
+copy    changed line #9
+EOF
+       cat <<EOF >dst/copy/rearranged/text &&
+copy rearranged line #1
+copy rearranged line #0
+copy rearranged line #2
+copy rearranged line #3
+copy rearranged line #4
+copy rearranged line #5
+copy rearranged line #6
+copy rearranged line #7
+copy rearranged line #8
+copy rearranged line #9
+EOF
+       cat <<EOF >dst/move/unchanged/text &&
+move  unchanged line #0
+move  unchanged line #1
+move  unchanged line #2
+move  unchanged line #3
+move  unchanged line #4
+move  unchanged line #5
+move  unchanged line #6
+move  unchanged line #7
+move  unchanged line #8
+move  unchanged line #9
+EOF
+       cat <<EOF >dst/move/changed/text &&
+move XXXCHANGED line #0
+move    changed line #1
+move    changed line #2
+move    changed line #3
+move    changed line #4
+move    changed line #5
+move    changed line #6
+move    changed line #7
+move    changed line #8
+move    changed line #9
+EOF
+       cat <<EOF >dst/move/rearranged/text &&
+move rearranged line #1
+move rearranged line #0
+move rearranged line #2
+move rearranged line #3
+move rearranged line #4
+move rearranged line #5
+move rearranged line #6
+move rearranged line #7
+move rearranged line #8
+move rearranged line #9
+EOF
+       git add . &&
+       git rm -r src/move/unchanged &&
+       git rm -r src/move/changed &&
+       git rm -r src/move/rearranged &&
+       git commit -m "changes"
+'
+
+cat <<EOF >expect_diff_stat
+ changed/text             |    2 +-
+ dst/copy/changed/text    |   10 ++++++++++
+ dst/copy/rearranged/text |   10 ++++++++++
+ dst/copy/unchanged/text  |   10 ++++++++++
+ dst/move/changed/text    |   10 ++++++++++
+ dst/move/rearranged/text |   10 ++++++++++
+ dst/move/unchanged/text  |   10 ++++++++++
+ rearranged/text          |    2 +-
+ src/move/changed/text    |   10 ----------
+ src/move/rearranged/text |   10 ----------
+ src/move/unchanged/text  |   10 ----------
+ 11 files changed, 62 insertions(+), 32 deletions(-)
+EOF
+
+cat <<EOF >expect_diff_stat_M
+ changed/text                      |    2 +-
+ dst/copy/changed/text             |   10 ++++++++++
+ dst/copy/rearranged/text          |   10 ++++++++++
+ dst/copy/unchanged/text           |   10 ++++++++++
+ {src => dst}/move/changed/text    |    2 +-
+ {src => dst}/move/rearranged/text |    2 +-
+ {src => dst}/move/unchanged/text  |    0
+ rearranged/text                   |    2 +-
+ 8 files changed, 34 insertions(+), 4 deletions(-)
+EOF
+
+cat <<EOF >expect_diff_stat_CC
+ changed/text                      |    2 +-
+ {src => dst}/copy/changed/text    |    2 +-
+ {src => dst}/copy/rearranged/text |    2 +-
+ {src => dst}/copy/unchanged/text  |    0
+ {src => dst}/move/changed/text    |    2 +-
+ {src => dst}/move/rearranged/text |    2 +-
+ {src => dst}/move/unchanged/text  |    0
+ rearranged/text                   |    2 +-
+ 8 files changed, 6 insertions(+), 6 deletions(-)
+EOF
+
+test_expect_success 'sanity check setup (--stat)' '
+       git diff --stat HEAD^..HEAD >actual_diff_stat &&
+       test_cmp expect_diff_stat actual_diff_stat &&
+       git diff --stat -M HEAD^..HEAD >actual_diff_stat_M &&
+       test_cmp expect_diff_stat_M actual_diff_stat_M &&
+       git diff --stat -C -C HEAD^..HEAD >actual_diff_stat_CC &&
+       test_cmp expect_diff_stat_CC actual_diff_stat_CC
+'
+
+# changed/text and rearranged/text falls below default 3% threshold
+cat <<EOF >expect_diff_dirstat
+  10.8% dst/copy/changed/
+  10.8% dst/copy/rearranged/
+  10.8% dst/copy/unchanged/
+  10.8% dst/move/changed/
+  10.8% dst/move/rearranged/
+  10.8% dst/move/unchanged/
+  10.8% src/move/changed/
+  10.8% src/move/rearranged/
+  10.8% src/move/unchanged/
+EOF
+
+# rearranged/text falls below default 3% threshold
+cat <<EOF >expect_diff_dirstat_M
+   5.8% changed/
+  29.3% dst/copy/changed/
+  29.3% dst/copy/rearranged/
+  29.3% dst/copy/unchanged/
+   5.8% dst/move/changed/
+EOF
+
+# rearranged/text falls below default 3% threshold
+cat <<EOF >expect_diff_dirstat_CC
+  32.6% changed/
+  32.6% dst/copy/changed/
+  32.6% dst/move/changed/
+EOF
+
+test_expect_success 'various ways to misspell --dirstat' '
+       test_must_fail git show --dirstat10 &&
+       test_must_fail git show --dirstat10,files &&
+       test_must_fail git show -X=20 &&
+       test_must_fail git show -X=20,cumulative
+'
+
+test_expect_success 'vanilla --dirstat' '
+       git diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'vanilla -X' '
+       git diff -X HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff -X -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff -X -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'explicit defaults: --dirstat=changes,noncumulative,3' '
+       git diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'explicit defaults: -Xchanges,noncumulative,3' '
+       git diff -Xchanges,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff -Xchanges,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff -Xchanges,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'later options override earlier options:' '
+       git diff --dirstat=files,10,cumulative,changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,10,cumulative,changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,10,cumulative,changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+       git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files --dirstat=10 --dirstat=cumulative --dirstat=changes --dirstat=noncumulative -X3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'non-defaults in config overridden by explicit defaults on command line' '
+       git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=files,cumulative,50 diff --dirstat=changes,noncumulative,3 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+   2.1% changed/
+  10.8% dst/copy/changed/
+  10.8% dst/copy/rearranged/
+  10.8% dst/copy/unchanged/
+  10.8% dst/move/changed/
+  10.8% dst/move/rearranged/
+  10.8% dst/move/unchanged/
+   0.0% rearranged/
+  10.8% src/move/changed/
+  10.8% src/move/rearranged/
+  10.8% src/move/unchanged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+   5.8% changed/
+  29.3% dst/copy/changed/
+  29.3% dst/copy/rearranged/
+  29.3% dst/copy/unchanged/
+   5.8% dst/move/changed/
+   0.1% dst/move/rearranged/
+   0.1% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  32.6% changed/
+  32.6% dst/copy/changed/
+   0.6% dst/copy/rearranged/
+  32.6% dst/move/changed/
+   0.6% dst/move/rearranged/
+   0.6% rearranged/
+EOF
+
+test_expect_success '--dirstat=0' '
+       git diff --dirstat=0 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '-X0' '
+       git diff -X0 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff -X0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff -X0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=0' '
+       git -c diff.dirstat=0 diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=0 diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=0 diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+   2.1% changed/
+  10.8% dst/copy/changed/
+  10.8% dst/copy/rearranged/
+  10.8% dst/copy/unchanged/
+  32.5% dst/copy/
+  10.8% dst/move/changed/
+  10.8% dst/move/rearranged/
+  10.8% dst/move/unchanged/
+  32.5% dst/move/
+  65.1% dst/
+   0.0% rearranged/
+  10.8% src/move/changed/
+  10.8% src/move/rearranged/
+  10.8% src/move/unchanged/
+  32.5% src/move/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+   5.8% changed/
+  29.3% dst/copy/changed/
+  29.3% dst/copy/rearranged/
+  29.3% dst/copy/unchanged/
+  88.0% dst/copy/
+   5.8% dst/move/changed/
+   0.1% dst/move/rearranged/
+   5.9% dst/move/
+  94.0% dst/
+   0.1% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  32.6% changed/
+  32.6% dst/copy/changed/
+   0.6% dst/copy/rearranged/
+  33.3% dst/copy/
+  32.6% dst/move/changed/
+   0.6% dst/move/rearranged/
+  33.3% dst/move/
+  66.6% dst/
+   0.6% rearranged/
+EOF
+
+test_expect_success '--dirstat=0 --cumulative' '
+       git diff --dirstat=0 --cumulative HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=0 --cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=0 --cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=0,cumulative' '
+       git diff --dirstat=0,cumulative HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=0,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=0,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '-X0,cumulative' '
+       git diff -X0,cumulative HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff -X0,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff -X0,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=0,cumulative' '
+       git -c diff.dirstat=0,cumulative diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=0,cumulative diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=0,cumulative diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=0 & --dirstat=cumulative' '
+       git -c diff.dirstat=0 diff --dirstat=cumulative HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=0 diff --dirstat=cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=0 diff --dirstat=cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+   9.0% changed/
+   9.0% dst/copy/changed/
+   9.0% dst/copy/rearranged/
+   9.0% dst/copy/unchanged/
+   9.0% dst/move/changed/
+   9.0% dst/move/rearranged/
+   9.0% dst/move/unchanged/
+   9.0% rearranged/
+   9.0% src/move/changed/
+   9.0% src/move/rearranged/
+   9.0% src/move/unchanged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+  14.2% changed/
+  14.2% dst/copy/changed/
+  14.2% dst/copy/rearranged/
+  14.2% dst/copy/unchanged/
+  14.2% dst/move/changed/
+  14.2% dst/move/rearranged/
+  14.2% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  16.6% changed/
+  16.6% dst/copy/changed/
+  16.6% dst/copy/rearranged/
+  16.6% dst/move/changed/
+  16.6% dst/move/rearranged/
+  16.6% rearranged/
+EOF
+
+test_expect_success '--dirstat-by-file' '
+       git diff --dirstat-by-file HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat-by-file -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat-by-file -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=files' '
+       git diff --dirstat=files HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=files' '
+       git -c diff.dirstat=files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+  27.2% dst/copy/
+  27.2% dst/move/
+  27.2% src/move/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+  14.2% changed/
+  14.2% dst/copy/changed/
+  14.2% dst/copy/rearranged/
+  14.2% dst/copy/unchanged/
+  14.2% dst/move/changed/
+  14.2% dst/move/rearranged/
+  14.2% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  16.6% changed/
+  16.6% dst/copy/changed/
+  16.6% dst/copy/rearranged/
+  16.6% dst/move/changed/
+  16.6% dst/move/rearranged/
+  16.6% rearranged/
+EOF
+
+test_expect_success '--dirstat-by-file=10' '
+       git diff --dirstat-by-file=10 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat-by-file=10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat-by-file=10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=files,10' '
+       git diff --dirstat=files,10 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=10,files' '
+       git -c diff.dirstat=10,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=10,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=10,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+   9.0% changed/
+   9.0% dst/copy/changed/
+   9.0% dst/copy/rearranged/
+   9.0% dst/copy/unchanged/
+  27.2% dst/copy/
+   9.0% dst/move/changed/
+   9.0% dst/move/rearranged/
+   9.0% dst/move/unchanged/
+  27.2% dst/move/
+  54.5% dst/
+   9.0% rearranged/
+   9.0% src/move/changed/
+   9.0% src/move/rearranged/
+   9.0% src/move/unchanged/
+  27.2% src/move/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+  14.2% changed/
+  14.2% dst/copy/changed/
+  14.2% dst/copy/rearranged/
+  14.2% dst/copy/unchanged/
+  42.8% dst/copy/
+  14.2% dst/move/changed/
+  14.2% dst/move/rearranged/
+  28.5% dst/move/
+  71.4% dst/
+  14.2% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  16.6% changed/
+  16.6% dst/copy/changed/
+  16.6% dst/copy/rearranged/
+  33.3% dst/copy/
+  16.6% dst/move/changed/
+  16.6% dst/move/rearranged/
+  33.3% dst/move/
+  66.6% dst/
+  16.6% rearranged/
+EOF
+
+test_expect_success '--dirstat-by-file --cumulative' '
+       git diff --dirstat-by-file --cumulative HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat-by-file --cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat-by-file --cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=files,cumulative' '
+       git diff --dirstat=files,cumulative HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,cumulative -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,cumulative -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=cumulative,files' '
+       git -c diff.dirstat=cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+  27.2% dst/copy/
+  27.2% dst/move/
+  54.5% dst/
+  27.2% src/move/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+  14.2% changed/
+  14.2% dst/copy/changed/
+  14.2% dst/copy/rearranged/
+  14.2% dst/copy/unchanged/
+  42.8% dst/copy/
+  14.2% dst/move/changed/
+  14.2% dst/move/rearranged/
+  28.5% dst/move/
+  71.4% dst/
+  14.2% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  16.6% changed/
+  16.6% dst/copy/changed/
+  16.6% dst/copy/rearranged/
+  33.3% dst/copy/
+  16.6% dst/move/changed/
+  16.6% dst/move/rearranged/
+  33.3% dst/move/
+  66.6% dst/
+  16.6% rearranged/
+EOF
+
+test_expect_success '--dirstat=files,cumulative,10' '
+       git diff --dirstat=files,cumulative,10 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,cumulative,10 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,cumulative,10 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=10,cumulative,files' '
+       git -c diff.dirstat=10,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=10,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=10,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+  27.2% dst/copy/
+  27.2% dst/move/
+  54.5% dst/
+  27.2% src/move/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+  42.8% dst/copy/
+  28.5% dst/move/
+  71.4% dst/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  33.3% dst/copy/
+  33.3% dst/move/
+  66.6% dst/
+EOF
+
+test_expect_success '--dirstat=files,cumulative,16.7' '
+       git diff --dirstat=files,cumulative,16.7 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,cumulative,16.7 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,cumulative,16.7 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=16.7,cumulative,files' '
+       git -c diff.dirstat=16.7,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=16.7,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=16.7,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=16.70,cumulative,files' '
+       git -c diff.dirstat=16.70,cumulative,files diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=16.70,cumulative,files diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=16.70,cumulative,files diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=files,cumulative,27.2' '
+       git diff --dirstat=files,cumulative,27.2 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,cumulative,27.2 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,cumulative,27.2 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=files,cumulative,27.09' '
+       git diff --dirstat=files,cumulative,27.09 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=files,cumulative,27.09 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=files,cumulative,27.09 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+  10.6% dst/copy/changed/
+  10.6% dst/copy/rearranged/
+  10.6% dst/copy/unchanged/
+  10.6% dst/move/changed/
+  10.6% dst/move/rearranged/
+  10.6% dst/move/unchanged/
+  10.6% src/move/changed/
+  10.6% src/move/rearranged/
+  10.6% src/move/unchanged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+   5.2% changed/
+  26.3% dst/copy/changed/
+  26.3% dst/copy/rearranged/
+  26.3% dst/copy/unchanged/
+   5.2% dst/move/changed/
+   5.2% dst/move/rearranged/
+   5.2% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  16.6% changed/
+  16.6% dst/copy/changed/
+  16.6% dst/copy/rearranged/
+  16.6% dst/move/changed/
+  16.6% dst/move/rearranged/
+  16.6% rearranged/
+EOF
+
+test_expect_success '--dirstat=lines' '
+       git diff --dirstat=lines HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=lines -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=lines -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=lines' '
+       git -c diff.dirstat=lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+cat <<EOF >expect_diff_dirstat
+   2.1% changed/
+  10.6% dst/copy/changed/
+  10.6% dst/copy/rearranged/
+  10.6% dst/copy/unchanged/
+  10.6% dst/move/changed/
+  10.6% dst/move/rearranged/
+  10.6% dst/move/unchanged/
+   2.1% rearranged/
+  10.6% src/move/changed/
+  10.6% src/move/rearranged/
+  10.6% src/move/unchanged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_M
+   5.2% changed/
+  26.3% dst/copy/changed/
+  26.3% dst/copy/rearranged/
+  26.3% dst/copy/unchanged/
+   5.2% dst/move/changed/
+   5.2% dst/move/rearranged/
+   5.2% rearranged/
+EOF
+
+cat <<EOF >expect_diff_dirstat_CC
+  16.6% changed/
+  16.6% dst/copy/changed/
+  16.6% dst/copy/rearranged/
+  16.6% dst/move/changed/
+  16.6% dst/move/rearranged/
+  16.6% rearranged/
+EOF
+
+test_expect_success '--dirstat=lines,0' '
+       git diff --dirstat=lines,0 HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git diff --dirstat=lines,0 -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git diff --dirstat=lines,0 -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success 'diff.dirstat=0,lines' '
+       git -c diff.dirstat=0,lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       git -c diff.dirstat=0,lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       git -c diff.dirstat=0,lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC
+'
+
+test_expect_success '--dirstat=future_param,lines,0 should fail loudly' '
+       test_must_fail git diff --dirstat=future_param,lines,0 HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
+       test_debug "cat actual_error" &&
+       test_cmp /dev/null actual_diff_dirstat &&
+       test_i18ngrep -q "future_param" actual_error &&
+       test_i18ngrep -q "\--dirstat" actual_error
+'
+
+test_expect_success '--dirstat=dummy1,cumulative,2dummy should report both unrecognized parameters' '
+       test_must_fail git diff --dirstat=dummy1,cumulative,2dummy HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
+       test_debug "cat actual_error" &&
+       test_cmp /dev/null actual_diff_dirstat &&
+       test_i18ngrep -q "dummy1" actual_error &&
+       test_i18ngrep -q "2dummy" actual_error &&
+       test_i18ngrep -q "\--dirstat" actual_error
+'
+
+test_expect_success 'diff.dirstat=future_param,0,lines should warn, but still work' '
+       git -c diff.dirstat=future_param,0,lines diff --dirstat HEAD^..HEAD >actual_diff_dirstat 2>actual_error &&
+       test_debug "cat actual_error" &&
+       test_cmp expect_diff_dirstat actual_diff_dirstat &&
+       test_i18ngrep -q "future_param" actual_error &&
+       test_i18ngrep -q "diff\\.dirstat" actual_error &&
+
+       git -c diff.dirstat=future_param,0,lines diff --dirstat -M HEAD^..HEAD >actual_diff_dirstat_M 2>actual_error &&
+       test_debug "cat actual_error" &&
+       test_cmp expect_diff_dirstat_M actual_diff_dirstat_M &&
+       test_i18ngrep -q "future_param" actual_error &&
+       test_i18ngrep -q "diff\\.dirstat" actual_error &&
+
+       git -c diff.dirstat=future_param,0,lines diff --dirstat -C -C HEAD^..HEAD >actual_diff_dirstat_CC 2>actual_error &&
+       test_debug "cat actual_error" &&
+       test_cmp expect_diff_dirstat_CC actual_diff_dirstat_CC &&
+       test_i18ngrep -q "future_param" actual_error &&
+       test_i18ngrep -q "diff\\.dirstat" actual_error
+'
+
+test_done
index b0b2684a1f879cc173bf2bc67902724ed8f25d48..0eace37a03d75a7205575c36a0ec0de3ec401b1b 100755 (executable)
@@ -190,7 +190,7 @@ test_expect_success 'pushing explicit refspecs respects forcing' '
                +refs/heads/master:refs/heads/master
        ) &&
        parent_head=$(cd parent && git rev-parse --verify master) &&
-       child_head=$(cd parent && git rev-parse --verify master) &&
+       child_head=$(cd child && git rev-parse --verify master) &&
        test "$parent_head" = "$child_head"
 '
 
@@ -210,7 +210,7 @@ test_expect_success 'pushing wildcard refspecs respects forcing' '
                "+refs/heads/*:refs/heads/*"
        ) &&
        parent_head=$(cd parent && git rev-parse --verify master) &&
-       child_head=$(cd parent && git rev-parse --verify master) &&
+       child_head=$(cd child && git rev-parse --verify master) &&
        test "$parent_head" = "$child_head"
 '
 
index af78e21ba913b465e7bf2e4149549d32de9d4240..a1fddd4d15fb2c3cb5d0ab6e09a461314fb4b1f1 100755 (executable)
@@ -66,12 +66,9 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" '
        (
                cd downstream &&
                git fetch --recurse-submodules >../actual.out 2>../actual.err
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "fetch --recurse-submodules recurses into submodules: output" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "fetch alone only fetches superproject" '
@@ -98,12 +95,9 @@ test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses i
                cd downstream &&
                git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
                git fetch >../actual.out 2>../actual.err
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
@@ -132,12 +126,9 @@ test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setti
                git fetch --recurse-submodules >../actual.out 2>../actual.err &&
                git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
                git config --unset submodule.submodule.fetchRecurseSubmodules
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config: output" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "--quiet propagates to submodules" '
@@ -154,24 +145,18 @@ test_expect_success "--dry-run propagates to submodules" '
        (
                cd downstream &&
                git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "--dry-run propagates to submodules: output" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "Without --dry-run propagates to submodules" '
        (
                cd downstream &&
                git fetch --recurse-submodules >../actual.out 2>../actual.err
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "Without --dry-run propagates to submodules: output" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "recurseSubmodules=true propagates into submodules" '
@@ -180,12 +165,9 @@ test_expect_success "recurseSubmodules=true propagates into submodules" '
                cd downstream &&
                git config fetch.recurseSubmodules true
                git fetch >../actual.out 2>../actual.err
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "recurseSubmodules=true propagates into submodules: output" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "--recurse-submodules overrides config in submodule" '
@@ -197,12 +179,9 @@ test_expect_success "--recurse-submodules overrides config in submodule" '
                        git config fetch.recurseSubmodules false
                ) &&
                git fetch --recurse-submodules >../actual.out 2>../actual.err
-       )
-'
-
-test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides config in submodule: output" '
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       ) &&
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "--no-recurse-submodules overrides config setting" '
@@ -243,8 +222,8 @@ test_expect_success "Recursion stops when no new submodule commits are fetched"
                cd downstream &&
                git fetch >../actual.out 2>../actual.err
        ) &&
-       test_cmp expect.err.sub actual.err &&
-       test_cmp expect.out.sub actual.out
+       test_i18ncmp expect.err.sub actual.err &&
+       test_i18ncmp expect.out.sub actual.out
 '
 
 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
@@ -261,7 +240,7 @@ test_expect_success "Recursion doesn't happen when new superproject commits don'
                git fetch >../actual.out 2>../actual.err
        ) &&
        ! test -s actual.out &&
-       test_cmp expect.err.file actual.err
+       test_i18ncmp expect.err.file actual.err
 '
 
 test_expect_success "Recursion picks up config in submodule" '
@@ -289,8 +268,8 @@ test_expect_success "Recursion picks up config in submodule" '
                        git config --unset fetch.recurseSubmodules
                )
        ) &&
-       test_cmp expect.err.sub actual.err &&
-       test_cmp expect.out actual.out
+       test_i18ncmp expect.err.sub actual.err &&
+       test_i18ncmp expect.out actual.out
 '
 
 test_expect_success "Recursion picks up all submodules when necessary" '
@@ -321,8 +300,8 @@ test_expect_success "Recursion picks up all submodules when necessary" '
                cd downstream &&
                git fetch >../actual.out 2>../actual.err
        ) &&
-       test_cmp expect.err.2 actual.err &&
-       test_cmp expect.out actual.out
+       test_i18ncmp expect.err.2 actual.err &&
+       test_i18ncmp expect.out actual.out
 '
 
 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
@@ -375,8 +354,8 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess
                        git config --unset -f .gitmodules submodule.deepsubmodule.fetchRecursive
                )
        ) &&
-       test_cmp expect.out actual.out &&
-       test_cmp expect.err actual.err
+       test_i18ncmp expect.out actual.out &&
+       test_i18ncmp expect.err actual.err
 '
 
 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
@@ -393,7 +372,7 @@ test_expect_success "'--recurse-submodules=on-demand' stops when no new submodul
                git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
        ) &&
        ! test -s actual.out &&
-       test_cmp expect.err.file actual.err
+       test_i18ncmp expect.err.file actual.err
 '
 
 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
@@ -420,8 +399,8 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
                cd downstream &&
                git config --unset fetch.recurseSubmodules
        ) &&
-       test_cmp expect.out.sub actual.out &&
-       test_cmp expect.err.2 actual.err
+       test_i18ncmp expect.out.sub actual.out &&
+       test_i18ncmp expect.err.2 actual.err
 '
 
 test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
@@ -448,8 +427,8 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override
                cd downstream &&
                git config --unset submodule.submodule.fetchRecurseSubmodules
        ) &&
-       test_cmp expect.out.sub actual.out &&
-       test_cmp expect.err.2 actual.err
+       test_i18ncmp expect.out.sub actual.out &&
+       test_i18ncmp expect.err.2 actual.err
 '
 
 test_expect_success "don't fetch submodule when newly recorded commits are already present" '
@@ -468,7 +447,7 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
                git fetch >../actual.out 2>../actual.err
        ) &&
        ! test -s actual.out &&
-       test_cmp expect.err actual.err
+       test_i18ncmp expect.err actual.err
 '
 
 test_done
index 0492877d516b8f33a8fd1555ec77a2aa3b34352c..a73c82635ff6fba6fcef4f139ff09205c1b9b6de 100755 (executable)
@@ -65,14 +65,16 @@ test_expect_success 'clone remote repository' '
        git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
 '
 
-test_expect_success 'push to remote repository' '
+test_expect_success 'push to remote repository (standard)' '
        cd "$ROOT_PATH"/test_repo_clone &&
        : >path2 &&
        git add path2 &&
        test_tick &&
        git commit -m path2 &&
        HEAD=$(git rev-parse --verify HEAD) &&
-       git push &&
+       GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
+       ! grep "Expect: 100-continue" err &&
+       grep "POST git-receive-pack ([0-9]* bytes)" err &&
        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
         test $HEAD = $(git rev-parse --verify HEAD))
 '
@@ -135,10 +137,22 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he
        grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
-       grep "To prevent you from losing history, non-fast-forward updates were rejected" \
+test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
+       test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" \
                output
 '
 
+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" &&
+       git push -v -v origin $BRANCH 2>err &&
+       grep "POST git-receive-pack (chunked)" err &&
+       (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
+        test $HEAD = $(git rev-parse --verify HEAD))
+'
+
 stop_httpd
 test_done
index 5a068b21e4aeac79863df657d6388ec4c2732d55..151ea531bdfeb5a012e57407749beb4f26de6d2a 100755 (executable)
@@ -194,11 +194,14 @@ test_expect_success 'do not respect url-encoding of non-url path' '
 test_expect_success 'clone separate gitdir' '
        rm -rf dst &&
        git clone --separate-git-dir realgitdir src dst &&
-       echo "gitdir: `pwd`/realgitdir" >expected &&
-       test_cmp expected dst/.git &&
        test -d realgitdir/refs
 '
 
+test_expect_success 'clone separate gitdir: output' '
+       echo "gitdir: `pwd`/realgitdir" >expected &&
+       test_cmp expected dst/.git
+'
+
 test_expect_success 'clone separate gitdir where target already exists' '
        rm -rf dst &&
        test_must_fail git clone --separate-git-dir realgitdir src dst
index cacf3de6c9f31889fd8df0bc0cebbbc74e3525bd..28d4f6b259c1696435698cb3826c837c8eaf90e3 100755 (executable)
@@ -157,6 +157,33 @@ test_expect_success '--cherry' '
        test_cmp actual.named expect
 '
 
+cat >expect <<EOF
+1      1
+EOF
+
+test_expect_success '--cherry --count' '
+       git rev-list --cherry --count F...E -- bar > actual &&
+       test_cmp actual expect
+'
+
+cat >expect <<EOF
+2      2
+EOF
+
+test_expect_success '--cherry-mark --count' '
+       git rev-list --cherry-mark --count F...E -- bar > actual &&
+       test_cmp actual expect
+'
+
+cat >expect <<EOF
+1      1       2
+EOF
+
+test_expect_success '--cherry-mark --left-right --count' '
+       git rev-list --cherry-mark --left-right --count F...E -- bar > actual &&
+       test_cmp actual expect
+'
+
 test_expect_success '--cherry-pick with independent, but identical branches' '
        git symbolic-ref HEAD refs/heads/independent &&
        rm .git/index &&
index 082032edc36268f1b8e26ca6f409080093ac0f2b..f80bba871cb45a4afb098c96e7925b6361cf7f95 100755 (executable)
@@ -8,38 +8,38 @@ test_description='Merge base and parent list computation.
 
 . ./test-lib.sh
 
-test_expect_success 'setup' '
-       T=$(git write-tree) &&
+M=1130000000
+Z=+0000
 
-       M=1130000000 &&
-       Z=+0000 &&
+GIT_COMMITTER_EMAIL=git@comm.iter.xz
+GIT_COMMITTER_NAME='C O Mmiter'
+GIT_AUTHOR_NAME='A U Thor'
+GIT_AUTHOR_EMAIL=git@au.thor.xz
+export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
 
-       GIT_COMMITTER_EMAIL=git@comm.iter.xz &&
-       GIT_COMMITTER_NAME="C O Mmiter" &&
-       GIT_AUTHOR_NAME="A U Thor" &&
-       GIT_AUTHOR_EMAIL=git@au.thor.xz &&
-       export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
+doit () {
+       OFFSET=$1 &&
+       NAME=$2 &&
+       shift 2 &&
 
-       doit() {
-               OFFSET=$1 &&
-               NAME=$2 &&
-               shift 2 &&
+       PARENTS= &&
+       for P
+       do
+               PARENTS="${PARENTS}-p $P "
+       done &&
 
-               PARENTS= &&
-               for P
-               do
-                       PARENTS="${PARENTS}-p $P "
-               done &&
+       GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z" &&
+       GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE &&
+       export GIT_COMMITTER_DATE GIT_AUTHOR_DATE &&
 
-               GIT_COMMITTER_DATE="$(($M + $OFFSET)) $Z" &&
-               GIT_AUTHOR_DATE=$GIT_COMMITTER_DATE &&
-               export GIT_COMMITTER_DATE GIT_AUTHOR_DATE &&
+       commit=$(echo $NAME | git commit-tree $T $PARENTS) &&
 
-               commit=$(echo $NAME | git commit-tree $T $PARENTS) &&
+       echo $commit >.git/refs/tags/$NAME &&
+       echo $commit
+}
 
-               echo $commit >.git/refs/tags/$NAME &&
-               echo $commit
-       }
+test_expect_success 'setup' '
+       T=$(git mktree </dev/null)
 '
 
 test_expect_success 'set up G and H' '
index fb8291c812854608777dd8d35edfcda78df5069a..f00cebff3e42cf0a38d06a03b6f14ef08dd16372 100755 (executable)
@@ -69,6 +69,18 @@ test_expect_success 'rev-parse --glob=heads/subspace' '
 
 '
 
+test_expect_failure 'rev-parse accepts --glob as detached option' '
+
+       compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
+
+'
+
+test_expect_failure 'rev-parse is not confused by option-like glob' '
+
+       compare rev-parse "master" "--glob --symbolic master"
+
+'
+
 test_expect_success 'rev-parse --branches=subspace/*' '
 
        compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
@@ -129,6 +141,12 @@ test_expect_success 'rev-list --glob refs/heads/subspace/*' '
 
 '
 
+test_expect_success 'rev-list not confused by option-like --glob arg' '
+
+       compare rev-list "master" "--glob -0 master"
+
+'
+
 test_expect_success 'rev-list --glob=heads/subspace/*' '
 
        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
@@ -213,4 +231,36 @@ test_expect_success 'rev-list --remotes=foo' '
 
 '
 
+test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
+
+       compare shortlog "subspace/one subspace/two" --branches=subspace &&
+       compare shortlog \
+         "master subspace-x someref other/three subspace/one subspace/two" \
+         --branches &&
+       compare shortlog master "--glob=heads/someref/* master" &&
+       compare shortlog "subspace/one subspace/two other/three" \
+         "--glob=heads/subspace/* --glob=heads/other/*" &&
+       compare shortlog \
+         "master other/three someref subspace-x subspace/one subspace/two" \
+         "--glob=heads/*" &&
+       compare shortlog foo/bar --tags=foo &&
+       compare shortlog foo/bar --tags &&
+       compare shortlog foo/baz --remotes=foo
+
+'
+
+test_expect_failure 'shortlog accepts --glob as detached option' '
+
+       compare shortlog \
+         "master other/three someref subspace-x subspace/one subspace/two" \
+         "--glob heads/*"
+
+'
+
+test_expect_failure 'shortlog --glob is not confused by option-like argument' '
+
+       compare shortlog master "--glob -e master"
+
+'
+
 test_done
index 1ed259d864b4ef4c8c7060fa5f22634a25c8e032..5f3b604fd99b22c73cfdebf0f1cf13539e1af3e4 100755 (executable)
@@ -609,4 +609,67 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
        ! test -f original
 '
 
+test_expect_success 'setup avoid unnecessary update, normal rename' '
+       git reset --hard &&
+       git checkout --orphan avoid-unnecessary-update-1 &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original &&
+       git add -A &&
+       git commit -m "Common commmit" &&
+
+       git mv original rename &&
+       echo 11 >>rename &&
+       git add -u &&
+       git commit -m "Renamed and modified" &&
+
+       git checkout -b merge-branch-1 HEAD~1 &&
+       echo "random content" >random-file &&
+       git add -A &&
+       git commit -m "Random, unrelated changes"
+'
+
+test_expect_success 'avoid unnecessary update, normal rename' '
+       git checkout -q avoid-unnecessary-update-1^0 &&
+       test-chmtime =1000000000 rename &&
+       test-chmtime -v +0 rename >expect &&
+       git merge merge-branch-1 &&
+       test-chmtime -v +0 rename >actual &&
+       test_cmp expect actual # "rename" should have stayed intact
+'
+
+test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' '
+       git reset --hard &&
+       git checkout --orphan avoid-unnecessary-update-2 &&
+       git rm -rf . &&
+       git clean -fdqx &&
+
+       mkdir df &&
+       printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file &&
+       git add -A &&
+       git commit -m "Common commmit" &&
+
+       git mv df/file temp &&
+       rm -rf df &&
+       git mv temp df &&
+       echo 11 >>df &&
+       git add -u &&
+       git commit -m "Renamed and modified" &&
+
+       git checkout -b merge-branch-2 HEAD~1 &&
+       >unrelated-change &&
+       git add unrelated-change &&
+       git commit -m "Only unrelated changes"
+'
+
+test_expect_failure 'avoid unnecessary update, with D/F conflict' '
+       git checkout -q avoid-unnecessary-update-2^0 &&
+       test-chmtime =1000000000 df &&
+       test-chmtime -v +0 df >expect &&
+       git merge merge-branch-2 &&
+       test-chmtime -v +0 df >actual &&
+       test_cmp expect actual # "df" should have stayed intact
+'
+
 test_done
index 6c3719141aa567b97de1228f53a6c49eaf139e8e..a9b0ac1efc0eac3f50bd9fe26e5900307eddaba2 100755 (executable)
@@ -42,13 +42,13 @@ b3 behind 1
 b4 ahead 2
 EOF
 
-test_expect_success C_LOCALE_OUTPUT 'branch -v' '
+test_expect_success 'branch -v' '
        (
                cd test &&
                git branch -v
        ) |
        sed -n -e "$script" >actual &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 test_expect_success 'checkout' '
diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh
new file mode 100755 (executable)
index 0000000..debadbd
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/sh
+
+test_description='basic git merge-index / git-merge-one-file tests'
+. ./test-lib.sh
+
+test_expect_success 'setup diverging branches' '
+       for i in 1 2 3 4 5 6 7 8 9 10; do
+               echo $i
+       done >file &&
+       git add file &&
+       git commit -m base &&
+       git tag base &&
+       sed s/2/two/ <file >tmp &&
+       mv tmp file &&
+       git commit -a -m two &&
+       git tag two &&
+       git checkout -b other HEAD^ &&
+       sed s/10/ten/ <file >tmp &&
+       mv tmp file &&
+       git commit -a -m ten &&
+       git tag ten
+'
+
+cat >expect-merged <<'EOF'
+1
+two
+3
+4
+5
+6
+7
+8
+9
+ten
+EOF
+
+test_expect_success 'read-tree does not resolve content merge' '
+       git read-tree -i -m base ten two &&
+       echo file >expect &&
+       git diff-files --name-only --diff-filter=U >unmerged &&
+       test_cmp expect unmerged
+'
+
+test_expect_success 'git merge-index git-merge-one-file resolves' '
+       git merge-index git-merge-one-file -a &&
+       git diff-files --name-only --diff-filter=U >unmerged &&
+       >expect &&
+       test_cmp expect unmerged &&
+       test_cmp expect-merged file &&
+       git cat-file blob :file >file-index &&
+       test_cmp expect-merged file-index
+'
+
+test_expect_success 'setup bare merge' '
+       git clone --bare . bare.git &&
+       (cd bare.git &&
+        GIT_INDEX_FILE=$PWD/merge.index &&
+        export GIT_INDEX_FILE &&
+        git read-tree -i -m base ten two
+       )
+'
+
+test_expect_success 'merge-one-file fails without a work tree' '
+       (cd bare.git &&
+        GIT_INDEX_FILE=$PWD/merge.index &&
+        export GIT_INDEX_FILE &&
+        test_must_fail git merge-index git-merge-one-file -a
+       )
+'
+
+test_expect_success 'merge-one-file respects GIT_WORK_TREE' '
+       (cd bare.git &&
+        mkdir work &&
+        GIT_WORK_TREE=$PWD/work &&
+        export GIT_WORK_TREE &&
+        GIT_INDEX_FILE=$PWD/merge.index &&
+        export GIT_INDEX_FILE &&
+        git merge-index git-merge-one-file -a &&
+        git cat-file blob :file >work/file-index
+       ) &&
+       test_cmp expect-merged bare.git/work/file &&
+       test_cmp expect-merged bare.git/work/file-index
+'
+
+test_expect_success 'merge-one-file respects core.worktree' '
+       mkdir subdir &&
+       git clone . subdir/child &&
+       (cd subdir &&
+        GIT_DIR=$PWD/child/.git &&
+        export GIT_DIR &&
+        git config core.worktree "$PWD/child" &&
+        git read-tree -i -m base ten two &&
+        git merge-index git-merge-one-file -a &&
+        git cat-file blob :file >file-index
+       ) &&
+       test_cmp expect-merged subdir/child/file &&
+       test_cmp expect-merged subdir/file-index
+'
+
+test_done
index 18269962458248034598d2bb15315f0d2a121027..f67aa6ff6a3c2af2d0c1999e8203da3a922b0555 100755 (executable)
@@ -123,8 +123,8 @@ cat - >err.expect <<EOF
 warning: tag 'A' is really 'Q' here
 EOF
 check_describe A-* HEAD
-test_expect_success C_LOCALE_OUTPUT 'warning was displayed for Q' '
-       test_cmp err.expect err.actual
+test_expect_success 'warning was displayed for Q' '
+       test_i18ncmp err.expect err.actual
 '
 test_expect_success 'rename tag Q back to A' '
        mv .git/refs/tags/Q .git/refs/tags/A
index 1dedfd0c836c06eb3d2f66aa8e4e7eac54368508..2ac1c66079b7656a60a25fbbb91c48c0b1db010b 100755 (executable)
@@ -1120,13 +1120,11 @@ test_expect_success \
        ! (GIT_EDITOR=cat git tag -a initial-comment > actual)
 '
 
-test_expect_success \
-       C_LOCALE_OUTPUT \
-       'message in editor has initial comment: first line' '
+test_expect_success 'message in editor has initial comment: first line' '
        # check the first line --- should be empty
        echo >first.expect &&
        sed -e 1q <actual >first.actual &&
-       test_cmp first.expect first.actual
+       test_i18ncmp first.expect first.actual
 '
 
 test_expect_success \
index bb4066f76762520b98caeba1cddaf442d80a4bf2..8f3b54d826f5a9c8e7b08df7f6a58398b5a62480 100755 (executable)
@@ -24,7 +24,7 @@ H sub/2
 EOF
 
 NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
-ZERO_SHA0=0000000000000000000000000000000000000000
+
 setup_absent() {
        test -f 1 && rm 1
        git update-index --remove 1 &&
@@ -120,7 +120,7 @@ test_expect_success 'grep with skip-worktree file' '
        test "$(git grep --no-ext-grep test)" = "1:test"
 '
 
-echo ":000000 100644 $ZERO_SHA0 $NULL_SHA1 A   1" > expected
+echo ":000000 100644 $_z40 $NULL_SHA1 A        1" > expected
 test_expect_success 'diff-index does not examine skip-worktree absent entries' '
        setup_absent &&
        git diff-index HEAD -- 1 > result &&
index 14fcb1c7f5d8366827bc6e3256f118a757d2e996..9ceaa4049f960f20ca37d58e58e9e6c4e9ff4398 100755 (executable)
@@ -54,7 +54,7 @@ test_expect_success 'read-tree removes worktree, dirty case' '
 '
 
 NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
-ZERO_SHA0=0000000000000000000000000000000000000000
+
 setup_absent() {
        test -f 1 && rm 1
        git update-index --remove 1 &&
@@ -124,16 +124,16 @@ cat >expected <<EOF
 Would remove expected
 Would remove result
 EOF
-test_expect_success C_LOCALE_OUTPUT 'git-clean, absent case' '
+test_expect_success 'git-clean, absent case' '
        setup_absent &&
        git clean -n > result &&
-       test_cmp expected result
+       test_i18ncmp expected result
 '
 
-test_expect_success C_LOCALE_OUTPUT 'git-clean, dirty case' '
+test_expect_success 'git-clean, dirty case' '
        setup_dirty &&
        git clean -n > result &&
-       test_cmp expected result
+       test_i18ncmp expected result
 '
 
 #TODO test_expect_failure 'git-apply adds file' false
index b4fcc86a10f15178da25da159e160b38d717f318..b8cb4906aa7de022543b594399b6fa9a83ffc847 100755 (executable)
@@ -38,7 +38,7 @@ cat >expect <<EOF
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
 
-test_expect_success C_LOCALE_OUTPUT 'M/D conflict does not segfault' '
+test_expect_success 'M/D conflict does not segfault' '
        mkdir mdconflict &&
        (
                cd mdconflict &&
@@ -50,10 +50,72 @@ test_expect_success C_LOCALE_OUTPUT 'M/D conflict does not segfault' '
                git commit -m delete &&
                test_must_fail git merge master &&
                test_must_fail git commit --dry-run >../actual &&
-               test_cmp ../expect ../actual &&
+               test_i18ncmp ../expect ../actual &&
                git status >../actual &&
-               test_cmp ../expect ../actual
+               test_i18ncmp ../expect ../actual
        )
 '
 
+test_expect_success 'rename & unmerged setup' '
+       git rm -f -r . &&
+       cat "$TEST_DIRECTORY/README" >ONE &&
+       git add ONE &&
+       test_tick &&
+       git commit -m "One commit with ONE" &&
+
+       echo Modified >TWO &&
+       cat ONE >>TWO &&
+       cat ONE >>THREE &&
+       git add TWO THREE &&
+       sha1=$(git rev-parse :ONE) &&
+       git rm --cached ONE &&
+       (
+               echo "100644 $sha1 1    ONE" &&
+               echo "100644 $sha1 2    ONE" &&
+               echo "100644 $sha1 3    ONE"
+       ) | git update-index --index-info &&
+       echo Further >>THREE
+'
+
+test_expect_success 'rename & unmerged status' '
+       git status -suno >actual &&
+       cat >expect <<-EOF &&
+       UU ONE
+       AM THREE
+       A  TWO
+       EOF
+       test_cmp expect actual
+'
+
+test_expect_success 'git diff-index --cached shows 2 added + 1 unmerged' '
+       cat >expected <<-EOF &&
+       U       ONE
+       A       THREE
+       A       TWO
+       EOF
+       git diff-index --cached --name-status HEAD >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'git diff-index --cached -M shows 2 added + 1 unmerged' '
+       cat >expected <<-EOF &&
+       U       ONE
+       A       THREE
+       A       TWO
+       EOF
+       git diff-index --cached --name-status HEAD >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'git diff-index --cached -C shows 2 copies + 1 unmerged' '
+       cat >expected <<-EOF &&
+       U       ONE
+       C       ONE     THREE
+       C       ONE     TWO
+       EOF
+       git diff-index --cached -C --name-status HEAD |
+       sed "s/^C[0-9]*/C/g" >actual &&
+       test_cmp expected actual
+'
+
 test_done
index 7be2ff38fc92088d4caff9ea13b1d78a1b040b40..f1cfc9ac959ee281d50f7b8a51fdcefd2d0670e7 100755 (executable)
@@ -423,10 +423,10 @@ Unstaged changes after reset:
 M      file2
 EOF
 
-test_expect_success C_LOCALE_OUTPUT '--mixed refreshes the index' '
+test_expect_success '--mixed refreshes the index' '
        echo 123 >> file2 &&
        git reset --mixed HEAD > output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 test_expect_success 'disambiguation (1)' '
index b42820ad6976590fe195637d5e85d1b4db963cda..a82a07a04a8500cdac2cfb7ef39fb3f5981f437f 100755 (executable)
@@ -233,11 +233,11 @@ test_expect_success '"reset --merge HEAD^" is ok with pending merge' '
 #           working index HEAD target         working index HEAD
 #           ----------------------------------------------------
 # file1:     X       U     B    C     --keep   (disallowed)
-test_expect_success C_LOCALE_OUTPUT '"reset --keep HEAD^" fails with pending merge' '
+test_expect_success '"reset --keep HEAD^" fails with pending merge' '
     git reset --hard third &&
     test_must_fail git merge branch1 &&
     test_must_fail git reset --keep HEAD^ 2>err.log &&
-    grep "middle of a merge" err.log
+    test_i18ngrep "middle of a merge" err.log
 '
 
 # The next test will test the following:
@@ -259,11 +259,11 @@ test_expect_success '"reset --merge HEAD" is ok with pending merge' '
 #           working index HEAD target         working index HEAD
 #           ----------------------------------------------------
 # file1:     X       U     B    B     --keep   (disallowed)
-test_expect_success C_LOCALE_OUTPUT '"reset --keep HEAD" fails with pending merge' '
+test_expect_success '"reset --keep HEAD" fails with pending merge' '
     git reset --hard third &&
     test_must_fail git merge branch1 &&
     test_must_fail git reset --keep HEAD 2>err.log &&
-    grep "middle of a merge" err.log
+    test_i18ngrep "middle of a merge" err.log
 '
 
 test_expect_success '--merge is ok with added/deleted merge' '
@@ -280,7 +280,7 @@ test_expect_success '--merge is ok with added/deleted merge' '
     git diff --exit-code --cached
 '
 
-test_expect_success C_LOCALE_OUTPUT '--keep fails with added/deleted merge' '
+test_expect_success '--keep fails with added/deleted merge' '
     git reset --hard third &&
     rm -f file2 &&
     test_must_fail git merge branch3 &&
@@ -289,7 +289,7 @@ test_expect_success C_LOCALE_OUTPUT '--keep fails with added/deleted merge' '
     git diff --exit-code file3 &&
     git diff --exit-code branch3 file3 &&
     test_must_fail git reset --keep HEAD 2>err.log &&
-    grep "middle of a merge" err.log
+    test_i18ngrep "middle of a merge" err.log
 '
 
 test_done
index 37ed0931d9499791a6b3336efb97385356df6157..07fb53adcbc06e260b078de546bd07f11093071d 100755 (executable)
@@ -223,12 +223,12 @@ test_expect_success 'checkout --merge --conflict=diff3 <branch>' '
        test_cmp two expect
 '
 
-test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD (with advice declined)' '
+test_expect_success 'checkout to detach HEAD (with advice declined)' '
 
        git config advice.detachedHead false &&
        git checkout -f renamer && git clean -f &&
        git checkout renamer^ 2>messages &&
-       grep "HEAD is now at 7329388" messages &&
+       test_i18ngrep "HEAD is now at 7329388" messages &&
        test 1 -eq $(wc -l <messages) &&
        H=$(git rev-parse --verify HEAD) &&
        M=$(git show-ref -s --verify refs/heads/master) &&
@@ -242,11 +242,11 @@ test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD (with advice declin
        fi
 '
 
-test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD' '
+test_expect_success 'checkout to detach HEAD' '
        git config advice.detachedHead true &&
        git checkout -f renamer && git clean -f &&
        git checkout renamer^ 2>messages &&
-       grep "HEAD is now at 7329388" messages &&
+       test_i18ngrep "HEAD is now at 7329388" messages &&
        test 1 -lt $(wc -l <messages) &&
        H=$(git rev-parse --verify HEAD) &&
        M=$(git show-ref -s --verify refs/heads/master) &&
@@ -260,7 +260,7 @@ test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD' '
        fi
 '
 
-test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with branchname^' '
+test_expect_success 'checkout to detach HEAD with branchname^' '
 
        git checkout -f master && git clean -f &&
        git checkout renamer^ &&
@@ -276,7 +276,7 @@ test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with branchname^' '
        fi
 '
 
-test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with :/message' '
+test_expect_success 'checkout to detach HEAD with :/message' '
 
        git checkout -f master && git clean -f &&
        git checkout ":/Initial" &&
@@ -292,7 +292,7 @@ test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with :/message' '
        fi
 '
 
-test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with HEAD^0' '
+test_expect_success 'checkout to detach HEAD with HEAD^0' '
 
        git checkout -f master && git clean -f &&
        git checkout HEAD^0 &&
index bf7c788735d6e3e0ecf56e7a2f82826701ee1789..4f16fcce2bfcb63f437fa6b495fdb5c4370fccc1 100755 (executable)
@@ -94,6 +94,29 @@ test_expect_success 'submodule update does not fetch already present commits' '
        ! test -s actual.err
 '
 
+test_expect_success 'submodule update should fail due to local changes' '
+       (cd super/submodule &&
+        git reset --hard HEAD~1 &&
+        echo "local change" > file
+       ) &&
+       (cd super &&
+        (cd submodule &&
+         compare_head
+        ) &&
+        test_must_fail git submodule update submodule
+       )
+'
+test_expect_success 'submodule update should throw away changes with --force ' '
+       (cd super &&
+        (cd submodule &&
+         compare_head
+        ) &&
+        git submodule update --force submodule &&
+        cd submodule &&
+        ! compare_head
+       )
+'
+
 test_expect_success 'submodule update --rebase staying on master' '
        (cd super/submodule &&
          git checkout master
index bcdf0847d0970f544e96afa0036ec12800422fd8..1c908f4d3966cb9a2769465652981bef831f312d 100755 (executable)
@@ -15,7 +15,7 @@ commit_msg_is () {
 
        printf "%s" "$(git log --pretty=format:%s%b -1)" >$expect &&
        printf "%s" "$1" >$actual &&
-       test_cmp $expect $actual
+       test_i18ncmp $expect $actual
 }
 
 # A sanity check to see if commit is working at all.
@@ -72,7 +72,7 @@ test_expect_success 'adding comments to a template should not commit' '
        )
 '
 
-test_expect_success C_LOCALE_OUTPUT 'adding real content to a template should commit' '
+test_expect_success 'adding real content to a template should commit' '
        (
                test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
                git commit --template "$TEMPLATE"
@@ -80,7 +80,7 @@ test_expect_success C_LOCALE_OUTPUT 'adding real content to a template should co
        commit_msg_is "template linecommit message"
 '
 
-test_expect_success C_LOCALE_OUTPUT '-t option should be short for --template' '
+test_expect_success '-t option should be short for --template' '
        echo "short template" > "$TEMPLATE" &&
        echo "new content" >> foo &&
        git add foo &&
@@ -91,7 +91,7 @@ test_expect_success C_LOCALE_OUTPUT '-t option should be short for --template' '
        commit_msg_is "short templatecommit message"
 '
 
-test_expect_success C_LOCALE_OUTPUT 'config-specified template should commit' '
+test_expect_success 'config-specified template should commit' '
        echo "new template" > "$TEMPLATE" &&
        git config commit.template "$TEMPLATE" &&
        echo "more content" >> foo &&
@@ -123,6 +123,20 @@ test_expect_success 'commit message from file should override template' '
        commit_msg_is "standard input msg"
 '
 
+cat >"$TEMPLATE" <<\EOF
+
+
+### template
+
+EOF
+test_expect_success 'commit message from template with whitespace issue' '
+       echo "content galore" >>foo &&
+       git add foo &&
+       GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-whitespaced-content git commit \
+               --template "$TEMPLATE" &&
+       commit_msg_is "commit message"
+'
+
 test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
 
        cp .git/index saved-index &&
@@ -290,7 +304,7 @@ test_expect_success 'commit --squash works with -c for same commit' '
        commit_msg_is "squash! edited commit"
 '
 
-test_expect_success C_LOCALE_OUTPUT 'commit --squash works with editor' '
+test_expect_success 'commit --squash works with editor' '
        commit_for_rebase_autosquash_setup &&
        test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
        git commit --squash HEAD~1 &&
diff --git a/t/t7500/add-whitespaced-content b/t/t7500/add-whitespaced-content
new file mode 100755 (executable)
index 0000000..ccf07c6
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+sed -e 's/|$//' >>"$1" <<\EOF
+
+ |
+commit message          |
+
+EOF
+exit 0
index a76c47419590ed16c53b8d4d82c2d92c11853154..7f7f7c7b95475b3b0673de00b68914a08098aead 100755 (executable)
@@ -16,9 +16,10 @@ test_expect_success \
        "echo 'bongo bongo' >file &&
         git add file"
 
-test_expect_success C_LOCALE_OUTPUT \
-       "Constructing initial commit" \
-       "git status | grep 'Initial commit'"
+test_expect_success "Constructing initial commit" '
+       git status >actual &&
+       test_i18ngrep "Initial commit" actual
+'
 
 test_expect_success \
        "fail initial amend" \
index cfb569eaba657501cf0361bee8c3f7c172ed1c06..3f3adc31b98773d26715089c25d8d923dd342717 100755 (executable)
@@ -22,10 +22,7 @@ check_summary_oneline() {
        SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')"
        echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp &&
 
-       if test_have_prereq C_LOCALE_OUTPUT
-       then
-               test_cmp exp act
-       fi
+       test_i18ncmp exp act
 }
 
 test_expect_success 'output summary format' '
@@ -234,23 +231,19 @@ echo "sample
 # Please enter the commit message for your changes. Lines starting
 # with '#' will be ignored, and an empty message aborts the commit." >expect
 
-test_expect_success C_LOCALE_OUTPUT 'cleanup commit messages (strip,-F,-e): output' '
-       test_cmp expect actual
+test_expect_success 'cleanup commit messages (strip,-F,-e): output' '
+       test_i18ncmp expect actual
 '
 
 echo "#
 # Author:    $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
 #" >> expect
 
-test_expect_success C_LOCALE_OUTPUT 'author different from committer' '
-
+test_expect_success 'author different from committer' '
        echo >>negative &&
-       git commit -e -m "sample"
-       head -n 7 .git/COMMIT_EDITMSG >actual
-'
-
-test_expect_success C_LOCALE_OUTPUT 'author different from committer: output' '
-       test_cmp expect actual
+       test_might_fail git commit -e -m "sample" &&
+       head -n 7 .git/COMMIT_EDITMSG >actual &&
+       test_i18ncmp expect actual
 '
 
 mv expect expect.tmp
@@ -259,7 +252,7 @@ rm -f expect.tmp
 echo "# Committer:
 #" >> expect
 
-test_expect_success C_LOCALE_OUTPUT 'committer is automatic' '
+test_expect_success 'committer is automatic' '
 
        echo >>negative &&
        (
@@ -270,10 +263,7 @@ test_expect_success C_LOCALE_OUTPUT 'committer is automatic' '
        ) &&
        head -n 8 .git/COMMIT_EDITMSG | \
        sed "s/^# Committer: .*/# Committer:/" >actual
-'
-
-test_expect_success C_LOCALE_OUTPUT 'committer is automatic: output' '
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 pwd=`pwd`
@@ -376,78 +366,78 @@ try_commit () {
        GIT_EDITOR=.git/FAKE_EDITOR git commit -a $* $use_template &&
        case "$use_template" in
        '')
-               ! grep "^## Custom template" .git/COMMIT_EDITMSG ;;
+               test_i18ngrep ! "^## Custom template" .git/COMMIT_EDITMSG ;;
        *)
-               grep "^## Custom template" .git/COMMIT_EDITMSG ;;
+               test_i18ngrep "^## Custom template" .git/COMMIT_EDITMSG ;;
        esac
 }
 
 try_commit_status_combo () {
 
-       test_expect_success C_LOCALE_OUTPUT 'commit' '
+       test_expect_success 'commit' '
                clear_config commit.status &&
                try_commit "" &&
-               grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit' '
+       test_expect_success 'commit' '
                clear_config commit.status &&
                try_commit "" &&
-               grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit --status' '
+       test_expect_success 'commit --status' '
                clear_config commit.status &&
                try_commit --status &&
-               grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit --no-status' '
+       test_expect_success 'commit --no-status' '
                clear_config commit.status &&
                try_commit --no-status &&
-               ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit with commit.status = yes' '
+       test_expect_success 'commit with commit.status = yes' '
                clear_config commit.status &&
                git config commit.status yes &&
                try_commit "" &&
-               grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit with commit.status = no' '
+       test_expect_success 'commit with commit.status = no' '
                clear_config commit.status &&
                git config commit.status no &&
                try_commit "" &&
-               ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit --status with commit.status = yes' '
+       test_expect_success 'commit --status with commit.status = yes' '
                clear_config commit.status &&
                git config commit.status yes &&
                try_commit --status &&
-               grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit --no-status with commit.status = yes' '
+       test_expect_success 'commit --no-status with commit.status = yes' '
                clear_config commit.status &&
                git config commit.status yes &&
                try_commit --no-status &&
-               ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit --status with commit.status = no' '
+       test_expect_success 'commit --status with commit.status = no' '
                clear_config commit.status &&
                git config commit.status no &&
                try_commit --status &&
-               grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
-       test_expect_success C_LOCALE_OUTPUT 'commit --no-status with commit.status = no' '
+       test_expect_success 'commit --no-status with commit.status = no' '
                clear_config commit.status &&
                git config commit.status no &&
                try_commit --no-status &&
-               ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG
+               test_i18ngrep ! "^# Changes to be committed:" .git/COMMIT_EDITMSG
        '
 
 }
index c56733253fe335af9cbd12d19e776e35bd335994..c8d50a65672fdc00ccb42e6b7cece44b255623f1 100755 (executable)
@@ -20,21 +20,21 @@ test_expect_success 'setup' '
        git commit -m "Add submodule sub"
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status clean' '
+test_expect_success 'status clean' '
        git status >output &&
-       grep "nothing to commit" output
+       test_i18ngrep "nothing to commit" output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'commit --dry-run -a clean' '
+test_expect_success 'commit --dry-run -a clean' '
        test_must_fail git commit --dry-run -a >output &&
-       grep "nothing to commit" output
+       test_i18ngrep "nothing to commit" output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with modified file in submodule' '
+test_expect_success 'status with modified file in submodule' '
        (cd sub && git reset --hard) &&
        echo "changed" >sub/foo &&
        git status >output &&
-       grep "modified:   sub (modified content)" output
+       test_i18ngrep "modified:   sub (modified content)" output
 '
 
 test_expect_success 'status with modified file in submodule (porcelain)' '
@@ -46,10 +46,10 @@ test_expect_success 'status with modified file in submodule (porcelain)' '
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with added file in submodule' '
+test_expect_success 'status with added file in submodule' '
        (cd sub && git reset --hard && echo >foo && git add foo) &&
        git status >output &&
-       grep "modified:   sub (modified content)" output
+       test_i18ngrep "modified:   sub (modified content)" output
 '
 
 test_expect_success 'status with added file in submodule (porcelain)' '
@@ -60,16 +60,16 @@ test_expect_success 'status with added file in submodule (porcelain)' '
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with untracked file in submodule' '
+test_expect_success 'status with untracked file in submodule' '
        (cd sub && git reset --hard) &&
        echo "content" >sub/new-file &&
        git status >output &&
-       grep "modified:   sub (untracked content)" output
+       test_i18ngrep "modified:   sub (untracked content)" output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status -uno with untracked file in submodule' '
+test_expect_success 'status -uno with untracked file in submodule' '
        git status -uno >output &&
-       grep "^nothing to commit" output
+       test_i18ngrep "^nothing to commit" output
 '
 
 test_expect_success 'status with untracked file in submodule (porcelain)' '
@@ -79,11 +79,11 @@ test_expect_success 'status with untracked file in submodule (porcelain)' '
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with added and untracked file in submodule' '
+test_expect_success 'status with added and untracked file in submodule' '
        (cd sub && git reset --hard && echo >foo && git add foo) &&
        echo "content" >sub/new-file &&
        git status >output &&
-       grep "modified:   sub (modified content, untracked content)" output
+       test_i18ngrep "modified:   sub (modified content, untracked content)" output
 '
 
 test_expect_success 'status with added and untracked file in submodule (porcelain)' '
@@ -95,13 +95,13 @@ test_expect_success 'status with added and untracked file in submodule (porcelai
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with modified file in modified submodule' '
+test_expect_success 'status with modified file in modified submodule' '
        (cd sub && git reset --hard) &&
        rm sub/new-file &&
        (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
        echo "changed" >sub/foo &&
        git status >output &&
-       grep "modified:   sub (new commits, modified content)" output
+       test_i18ngrep "modified:   sub (new commits, modified content)" output
 '
 
 test_expect_success 'status with modified file in modified submodule (porcelain)' '
@@ -113,10 +113,10 @@ test_expect_success 'status with modified file in modified submodule (porcelain)
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with added file in modified submodule' '
+test_expect_success 'status with added file in modified submodule' '
        (cd sub && git reset --hard && echo >foo && git add foo) &&
        git status >output &&
-       grep "modified:   sub (new commits, modified content)" output
+       test_i18ngrep "modified:   sub (new commits, modified content)" output
 '
 
 test_expect_success 'status with added file in modified submodule (porcelain)' '
@@ -127,11 +127,11 @@ test_expect_success 'status with added file in modified submodule (porcelain)' '
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with untracked file in modified submodule' '
+test_expect_success 'status with untracked file in modified submodule' '
        (cd sub && git reset --hard) &&
        echo "content" >sub/new-file &&
        git status >output &&
-       grep "modified:   sub (new commits, untracked content)" output
+       test_i18ngrep "modified:   sub (new commits, untracked content)" output
 '
 
 test_expect_success 'status with untracked file in modified submodule (porcelain)' '
@@ -141,11 +141,11 @@ test_expect_success 'status with untracked file in modified submodule (porcelain
        EOF
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with added and untracked file in modified submodule' '
+test_expect_success 'status with added and untracked file in modified submodule' '
        (cd sub && git reset --hard && echo >foo && git add foo) &&
        echo "content" >sub/new-file &&
        git status >output &&
-       grep "modified:   sub (new commits, modified content, untracked content)" output
+       test_i18ngrep "modified:   sub (new commits, modified content, untracked content)" output
 '
 
 test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
@@ -167,24 +167,24 @@ test_expect_success 'setup .git file for sub' '
         git commit -m "added .real to .gitignore" .gitignore
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with added file in modified submodule with .git file' '
+test_expect_success 'status with added file in modified submodule with .git file' '
        (cd sub && git reset --hard && echo >foo && git add foo) &&
        git status >output &&
-       grep "modified:   sub (new commits, modified content)" output
+       test_i18ngrep "modified:   sub (new commits, modified content)" output
 '
 
 test_expect_success 'rm submodule contents' '
        rm -rf sub/* sub/.git
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status clean (empty submodule dir)' '
+test_expect_success 'status clean (empty submodule dir)' '
        git status >output &&
-       grep "nothing to commit" output
+       test_i18ngrep "nothing to commit" output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status -a clean (empty submodule dir)' '
+test_expect_success 'status -a clean (empty submodule dir)' '
        test_must_fail git commit --dry-run -a >output &&
-       grep "nothing to commit" output
+       test_i18ngrep "nothing to commit" output
 '
 
 test_done
index a93e70fac446f0b062abe9109658d54b7c321819..cd6e2c5e871230a43f504e165498139d8ec7a3d2 100755 (executable)
@@ -16,7 +16,7 @@ test_expect_success 'status -h in broken repository' '
                echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
                test_expect_code 129 git status -h >usage 2>&1
        ) &&
-       grep "[Uu]sage" broken/usage
+       test_i18ngrep "[Uu]sage" broken/usage
 '
 
 test_expect_success 'commit -h in broken repository' '
@@ -28,7 +28,7 @@ test_expect_success 'commit -h in broken repository' '
                echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
                test_expect_code 129 git commit -h >usage 2>&1
        ) &&
-       grep "[Uu]sage" broken/usage
+       test_i18ngrep "[Uu]sage" broken/usage
 '
 
 test_expect_success 'setup' '
@@ -55,10 +55,8 @@ test_expect_success 'setup' '
        git add dir2/added
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status (1)' '
-
-       grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
-
+test_expect_success 'status (1)' '
+       test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
 '
 
 cat >expect <<\EOF
@@ -85,11 +83,9 @@ cat >expect <<\EOF
 #      untracked
 EOF
 
-test_expect_success C_LOCALE_OUTPUT 'status (2)' '
-
+test_expect_success 'status (2)' '
        git status >output &&
-       test_cmp expect output
-
+       test_i18ncmp expect output
 '
 
 cat >expect <<\EOF
@@ -109,17 +105,14 @@ cat >expect <<\EOF
 #      untracked
 EOF
 
-git config advice.statusHints false
-
-test_expect_success C_LOCALE_OUTPUT 'status (advice.statusHints false)' '
-
+test_expect_success 'status (advice.statusHints false)' '
+       test_when_finished "git config --unset advice.statusHints" &&
+       git config advice.statusHints false &&
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 
 '
 
-git config --unset advice.statusHints
-
 cat >expect <<\EOF
  M dir1/modified
 A  dir2/added
@@ -178,16 +171,16 @@ cat >expect <<EOF
 #
 # Untracked files not listed (use -u option to show untracked files)
 EOF
-test_expect_success C_LOCALE_OUTPUT 'status -uno' '
+test_expect_success 'status -uno' '
        git status -uno >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status (status.showUntrackedFiles no)' '
+test_expect_success 'status (status.showUntrackedFiles no)' '
        git config status.showuntrackedfiles no
        test_when_finished "git config --unset status.showuntrackedfiles" &&
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 cat >expect <<EOF
@@ -201,9 +194,9 @@ cat >expect <<EOF
 # Untracked files not listed
 EOF
 git config advice.statusHints false
-test_expect_success C_LOCALE_OUTPUT 'status -uno (advice.statusHints false)' '
+test_expect_success 'status -uno (advice.statusHints false)' '
        git status -uno >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 git config --unset advice.statusHints
 
@@ -246,16 +239,16 @@ cat >expect <<EOF
 #      output
 #      untracked
 EOF
-test_expect_success C_LOCALE_OUTPUT 'status -unormal' '
+test_expect_success 'status -unormal' '
        git status -unormal >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status (status.showUntrackedFiles normal)' '
+test_expect_success 'status (status.showUntrackedFiles normal)' '
        git config status.showuntrackedfiles normal
        test_when_finished "git config --unset status.showuntrackedfiles" &&
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 cat >expect <<EOF
@@ -305,15 +298,16 @@ cat >expect <<EOF
 #      output
 #      untracked
 EOF
-test_expect_success C_LOCALE_OUTPUT 'status -uall' '
+test_expect_success 'status -uall' '
        git status -uall >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
-test_expect_success C_LOCALE_OUTPUT 'status (status.showUntrackedFiles all)' '
+
+test_expect_success 'status (status.showUntrackedFiles all)' '
        git config status.showuntrackedfiles all
        test_when_finished "git config --unset status.showuntrackedfiles" &&
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 test_expect_success 'teardown dir3' '
@@ -367,11 +361,9 @@ cat >expect <<\EOF
 #      ../untracked
 EOF
 
-test_expect_success C_LOCALE_OUTPUT 'status with relative paths' '
-
+test_expect_success 'status with relative paths' '
        (cd dir1 && git status) >output &&
-       test_cmp expect output
-
+       test_i18ncmp expect output
 '
 
 cat >expect <<\EOF
@@ -440,22 +432,18 @@ cat >expect <<\EOF
 #      <BLUE>untracked<RESET>
 EOF
 
-test_expect_success C_LOCALE_OUTPUT 'status with color.ui' '
-
+test_expect_success 'status with color.ui' '
        git config color.ui always &&
        test_when_finished "git config --unset color.ui" &&
        git status | test_decode_color >output &&
-       test_cmp expect output
-
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT 'status with color.status' '
-
+test_expect_success 'status with color.status' '
        git config color.status always &&
        test_when_finished "git config --unset color.status" &&
        git status | test_decode_color >output &&
-       test_cmp expect output
-
+       test_i18ncmp expect output
 '
 
 cat >expect <<\EOF
@@ -570,12 +558,12 @@ cat >expect <<\EOF
 EOF
 
 
-test_expect_success C_LOCALE_OUTPUT 'status without relative paths' '
+test_expect_success 'status without relative paths' '
 
        git config status.relativePaths false &&
        test_when_finished "git config --unset status.relativePaths" &&
        (cd dir1 && git status) >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 
 '
 
@@ -616,11 +604,8 @@ cat <<EOF >expect
 #      untracked
 EOF
 test_expect_success 'dry-run of partial commit excluding new file in index' '
-       git commit --dry-run dir1/modified >output
-'
-
-test_expect_success C_LOCALE_OUTPUT 'dry-run of partial commit excluding new file in index: output' '
-       test_cmp expect output
+       git commit --dry-run dir1/modified >output &&
+       test_i18ncmp expect output
 '
 
 cat >expect <<EOF
@@ -667,15 +652,15 @@ cat >expect <<EOF
 #      output
 #      untracked
 EOF
-test_expect_success C_LOCALE_OUTPUT 'status submodule summary is disabled by default' '
+test_expect_success 'status submodule summary is disabled by default' '
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 # we expect the same as the previous test
-test_expect_success C_LOCALE_OUTPUT 'status --untracked-files=all does not show submodule' '
+test_expect_success 'status --untracked-files=all does not show submodule' '
        git status --untracked-files=all >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 cat >expect <<EOF
@@ -731,10 +716,10 @@ cat >expect <<EOF
 #      output
 #      untracked
 EOF
-test_expect_success C_LOCALE_OUTPUT 'status submodule summary' '
+test_expect_success 'status submodule summary' '
        git config status.submodulesummary 10 &&
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 cat >expect <<EOF
@@ -773,15 +758,12 @@ cat >expect <<EOF
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
 test_expect_success 'status submodule summary (clean submodule): commit' '
-       git commit -m "commit submodule"
-'
-
-test_expect_success C_LOCALE_OUTPUT 'status submodule summary (clean submodule): output' '
+       git commit -m "commit submodule" &&
        git config status.submodulesummary 10 &&
        test_must_fail git commit --dry-run >output &&
-       test_cmp expect output &&
+       test_i18ncmp expect output &&
        git status >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 cat >expect <<EOF
@@ -827,10 +809,10 @@ cat >expect <<EOF
 #      output
 #      untracked
 EOF
-test_expect_success C_LOCALE_OUTPUT 'commit --dry-run submodule summary (--amend)' '
+test_expect_success 'commit --dry-run submodule summary (--amend)' '
        git config status.submodulesummary 10 &&
        git commit --dry-run --amend >output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
@@ -882,84 +864,84 @@ cat > expect << EOF
 #      untracked
 EOF
 
-test_expect_success C_LOCALE_OUTPUT '--ignore-submodules=untracked suppresses submodules with untracked content' '
-       echo modified > sm/untracked &&
-       git status --ignore-submodules=untracked > output &&
-       test_cmp expect output
+test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
+       echo modified  sm/untracked &&
+       git status --ignore-submodules=untracked >output &&
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT '.gitmodules ignore=untracked suppresses submodules with untracked content' '
+test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
        git config diff.ignoreSubmodules dirty &&
        git status >output &&
-       test_cmp expect 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_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config -f .gitmodules  --remove-section submodule.subname &&
        git config --unset diff.ignoreSubmodules
 '
 
-test_expect_success C_LOCALE_OUTPUT '.git/config ignore=untracked suppresses submodules with untracked content' '
+test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore untracked &&
        git config --add submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config --remove-section submodule.subname &&
        git config --remove-section -f .gitmodules submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT '--ignore-submodules=dirty suppresses submodules with untracked content' '
-       git status --ignore-submodules=dirty > output &&
-       test_cmp expect output
+test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
+       git status --ignore-submodules=dirty >output &&
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT '.gitmodules ignore=dirty suppresses submodules with untracked content' '
+test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
        git 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_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config -f .gitmodules  --remove-section submodule.subname &&
        git config --unset diff.ignoreSubmodules
 '
 
-test_expect_success C_LOCALE_OUTPUT '.git/config ignore=dirty suppresses submodules with untracked content' '
+test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore dirty &&
        git config --add submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config --remove-section submodule.subname &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT '--ignore-submodules=dirty suppresses submodules with modified content' '
-       echo modified > sm/foo &&
-       git status --ignore-submodules=dirty > output &&
-       test_cmp expect output
+test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
+       echo modified >sm/foo &&
+       git status --ignore-submodules=dirty >output &&
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT '.gitmodules ignore=dirty suppresses submodules with modified content' '
+test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
        git config --add -f .gitmodules submodule.subname.ignore dirty &&
        git config --add -f .gitmodules submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT '.git/config ignore=dirty suppresses submodules with modified content' '
+test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore dirty &&
        git config --add submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config --remove-section submodule.subname &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
@@ -996,26 +978,26 @@ cat > expect << EOF
 #      untracked
 EOF
 
-test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
+test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
        git status --ignore-submodules=untracked > output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
+test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
        git config --add -f .gitmodules submodule.subname.ignore untracked &&
        git config --add -f .gitmodules submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT ".git/config ignore=untracked doesn't suppress submodules with modified content" '
+test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore untracked &&
        git config --add submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config --remove-section submodule.subname &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
@@ -1058,49 +1040,49 @@ cat > expect << EOF
 #      untracked
 EOF
 
-test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=untracked doesn't suppress submodule summary" '
+test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
        git status --ignore-submodules=untracked > output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
-test_expect_success C_LOCALE_OUTPUT ".gitmodules ignore=untracked doesn't suppress submodule summary" '
+test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
        git config --add -f .gitmodules submodule.subname.ignore untracked &&
        git config --add -f .gitmodules submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT ".git/config ignore=untracked doesn't suppress submodule summary" '
+test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore untracked &&
        git config --add submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config --remove-section submodule.subname &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=dirty doesn't suppress submodule summary" '
+test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
        git status --ignore-submodules=dirty > output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
-test_expect_success C_LOCALE_OUTPUT ".gitmodules ignore=dirty doesn't suppress submodule summary" '
+test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
        git config --add -f .gitmodules submodule.subname.ignore dirty &&
        git config --add -f .gitmodules submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
 
-test_expect_success C_LOCALE_OUTPUT ".git/config ignore=dirty doesn't suppress submodule summary" '
+test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
        git config --add -f .gitmodules submodule.subname.ignore none &&
        git config --add -f .gitmodules submodule.subname.path sm &&
        git config --add submodule.subname.ignore dirty &&
        git config --add submodule.subname.path sm &&
-       git status > output &&
-       test_cmp expect output &&
+       git status >output &&
+       test_i18ncmp expect output &&
        git config --remove-section submodule.subname &&
        git config -f .gitmodules  --remove-section submodule.subname
 '
@@ -1126,9 +1108,9 @@ cat > expect << EOF
 no changes added to commit (use "git add" and/or "git commit -a")
 EOF
 
-test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=all suppresses submodule summary" '
+test_expect_success "--ignore-submodules=all suppresses submodule summary" '
        git status --ignore-submodules=all > output &&
-       test_cmp expect output
+       test_i18ncmp expect output
 '
 
 test_expect_failure '.gitmodules ignore=all suppresses submodule summary' '
index 87d5d788cb1884fdfe218ec30582f5d3da8b5d7d..87aac835a1b864eab083b25940892b93af491326 100755 (executable)
@@ -28,80 +28,80 @@ Testing basic merge operations/option parsing.
 
 . ./test-lib.sh
 
-test_expect_success 'set up test data and helpers' '
-       printf "%s\n" 1 2 3 4 5 6 7 8 9 >file &&
-       printf "%s\n" "1 X" 2 3 4 5 6 7 8 9 >file.1 &&
-       printf "%s\n" 1 2 3 4 "5 X" 6 7 8 9 >file.5 &&
-       printf "%s\n" 1 2 3 4 5 6 7 8 "9 X" >file.9 &&
-       printf "%s\n" "1 X" 2 3 4 5 6 7 8 9 >result.1 &&
-       printf "%s\n" "1 X" 2 3 4 "5 X" 6 7 8 9 >result.1-5 &&
-       printf "%s\n" "1 X" 2 3 4 "5 X" 6 7 8 "9 X" >result.1-5-9 &&
-
-       create_merge_msgs() {
-               echo "Merge commit '\''c2'\''" >msg.1-5 &&
-               echo "Merge commit '\''c2'\''; commit '\''c3'\''" >msg.1-5-9 &&
-               {
-                       echo "Squashed commit of the following:" &&
-                       echo &&
-                       git log --no-merges ^HEAD c1
-               } >squash.1 &&
-               {
-                       echo "Squashed commit of the following:" &&
-                       echo &&
-                       git log --no-merges ^HEAD c2
-               } >squash.1-5 &&
-               {
-                       echo "Squashed commit of the following:" &&
-                       echo &&
-                       git log --no-merges ^HEAD c2 c3
-               } >squash.1-5-9 &&
-               echo >msg.nolog &&
-               {
-                       echo "* commit '\''c3'\'':" &&
-                       echo "  commit 3" &&
-                       echo
-               } >msg.log
-       } &&
-
-       verify_merge() {
-               test_cmp "$2" "$1" &&
-               git update-index --refresh &&
-               git diff --exit-code &&
-               if test -n "$3"
-               then
-                       git show -s --pretty=format:%s HEAD >msg.act &&
-                       test_cmp "$3" msg.act
-               fi
-       } &&
-
-       verify_head() {
-               echo "$1" >head.expected &&
-               git rev-parse HEAD >head.actual &&
-               test_cmp head.expected head.actual
-       } &&
-
-       verify_parents() {
-               printf "%s\n" "$@" >parents.expected &&
-               >parents.actual &&
-               i=1 &&
-               while test $i -le $#
-               do
-                       git rev-parse HEAD^$i >>parents.actual &&
-                       i=$(expr $i + 1) ||
-                       return 1
-               done &&
-               test_cmp parents.expected parents.actual
-       } &&
-
-       verify_mergeheads() {
-               printf "%s\n" "$@" >mergehead.expected &&
-               test_cmp mergehead.expected .git/MERGE_HEAD
-       } &&
-
-       verify_no_mergehead() {
-               ! test -e .git/MERGE_HEAD
-       }
-'
+printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
+printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
+printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
+printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
+printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1
+printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
+printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
+>empty
+
+create_merge_msgs () {
+       echo "Merge commit 'c2'" >msg.1-5 &&
+       echo "Merge commit 'c2'; commit 'c3'" >msg.1-5-9 &&
+       {
+               echo "Squashed commit of the following:" &&
+               echo &&
+               git log --no-merges ^HEAD c1
+       } >squash.1 &&
+       {
+               echo "Squashed commit of the following:" &&
+               echo &&
+               git log --no-merges ^HEAD c2
+       } >squash.1-5 &&
+       {
+               echo "Squashed commit of the following:" &&
+               echo &&
+               git log --no-merges ^HEAD c2 c3
+       } >squash.1-5-9 &&
+       echo >msg.nolog &&
+       {
+               echo "* commit 'c3':" &&
+               echo "  commit 3" &&
+               echo
+       } >msg.log
+}
+
+verify_merge () {
+       test_cmp "$2" "$1" &&
+       git update-index --refresh &&
+       git diff --exit-code &&
+       if test -n "$3"
+       then
+               git show -s --pretty=format:%s HEAD >msg.act &&
+               test_cmp "$3" msg.act
+       fi
+}
+
+verify_head () {
+       echo "$1" >head.expected &&
+       git rev-parse HEAD >head.actual &&
+       test_cmp head.expected head.actual
+}
+
+verify_parents () {
+       printf '%s\n' "$@" >parents.expected &&
+       >parents.actual &&
+       i=1 &&
+       while test $i -le $#
+       do
+               git rev-parse HEAD^$i >>parents.actual &&
+               i=$(expr $i + 1) ||
+               return 1
+       done &&
+       test_must_fail git rev-parse --verify "HEAD^$i" &&
+       test_cmp parents.expected parents.actual
+}
+
+verify_mergeheads () {
+       printf '%s\n' "$@" >mergehead.expected &&
+       test_cmp mergehead.expected .git/MERGE_HEAD
+}
+
+verify_no_mergehead () {
+       ! test -e .git/MERGE_HEAD
+}
 
 test_expect_success 'setup' '
        git add file &&
@@ -225,12 +225,28 @@ test_expect_success 'merge c1 with c2 and c3' '
 
 test_debug 'git log --graph --decorate --oneline --all'
 
-test_expect_success 'failing merges with --ff-only' '
+test_expect_success 'merges with --ff-only' '
        git reset --hard c1 &&
        test_tick &&
        test_must_fail git merge --ff-only c2 &&
        test_must_fail git merge --ff-only c3 &&
-       test_must_fail git merge --ff-only c2 c3
+       test_must_fail git merge --ff-only c2 c3 &&
+       git reset --hard c0 &&
+       git merge c3 &&
+       verify_head $c3
+'
+
+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_must_fail git merge c2 &&
+       test_must_fail git merge c3 &&
+       test_must_fail git merge c2 c3 &&
+       git reset --hard c0 &&
+       git merge c3 &&
+       verify_head $c3
 '
 
 test_expect_success 'merge c0 with c1 (no-commit)' '
@@ -324,6 +340,39 @@ 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 &&
+       git reset --hard c1 &&
+       git merge c2 &&
+       git show -s --pretty=tformat:%s%n%b >actual &&
+
+       test_cmp expect actual
+'
+
+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 &&
+       git reset --hard c1 &&
+       git merge c2 &&
+       git show -s --pretty=tformat:%s%n%b >actual &&
+
+       test_cmp expect actual
+'
+
 test_expect_success 'merge c1 with c2 (squash in config)' '
        git reset --hard c1 &&
        git config branch.master.mergeoptions "--squash" &&
@@ -415,7 +464,41 @@ test_expect_success 'merge c0 with c1 (no-ff)' '
 
 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_tick &&
+       git merge c1 &&
+       git config --remove-section merge &&
+       verify_merge file result.1 &&
+       verify_parents $c0 $c1
+'
+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_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_tick &&
+       git merge c1 2>message &&
+       git config --remove-section "merge" &&
+       verify_head "$c1" &&
+       test_cmp empty message
+'
+
 test_expect_success 'combining --squash and --no-ff is refused' '
+       git reset --hard c0 &&
        test_must_fail git merge --squash --no-ff c1 &&
        test_must_fail git merge --no-ff --squash c1
 '
@@ -495,10 +578,10 @@ test_expect_success 'merge fast-forward in a dirty tree' '
 
 test_debug 'git log --graph --decorate --oneline --all'
 
-test_expect_success C_LOCALE_OUTPUT 'in-index merge' '
+test_expect_success 'in-index merge' '
        git reset --hard c0 &&
        git merge --no-ff -s resolve c1 >out &&
-       grep "Wonderful." out &&
+       test_i18ngrep "Wonderful." out &&
        verify_parents $c0 $c1
 '
 
index ef84f04102ed067768c66ea9608b98d47851eb8b..72a8731d5e28d71577d0c53fc25a5ddc1d2ad6de 100755 (executable)
@@ -150,11 +150,8 @@ test_expect_success 'will not overwrite untracked file on unborn branch' '
        git rm -fr . &&
        git checkout --orphan new &&
        cp important c0.c &&
-       test_must_fail git merge c0 2>out
-'
-
-test_expect_success C_LOCALE_OUTPUT 'will not overwrite untracked file on unborn branch: output' '
-       test_cmp out expect
+       test_must_fail git merge c0 2>out &&
+       test_i18ncmp out expect
 '
 
 test_expect_success 'will not overwrite untracked file on unborn branch .git/MERGE_HEAD sanity etc.' '
index dc838c93bcb00a80ad56c4d1233009fe9220b90e..cbc08e32761c6e35a3eb25519873e74218fd441a 100755 (executable)
@@ -22,26 +22,50 @@ test_expect_success 'setup' '
     echo master file14 >file14 &&
     mkdir subdir &&
     echo master sub >subdir/file3 &&
-    git add file1 file1[1-4] subdir/file3 &&
+    test_create_repo submod &&
+    (
+       cd submod &&
+       : >foo &&
+       git add foo &&
+       git commit -m "Add foo"
+    ) &&
+    git submodule add git://example.com/submod submod &&
+    git add file1 file1[1-4] subdir/file3 .gitmodules submod &&
     git commit -m "add initial versions" &&
 
     git checkout -b branch1 master &&
+    git submodule update -N &&
     echo branch1 change >file1 &&
     echo branch1 newfile >file2 &&
     echo branch1 change file11 >file11 &&
     echo branch1 change file13 >file13 &&
     echo branch1 sub >subdir/file3 &&
-    git add file1 file11 file13 file2 subdir/file3 &&
+    (
+       cd submod &&
+       echo branch1 submodule >bar &&
+       git add bar &&
+       git commit -m "Add bar on branch1" &&
+       git checkout -b submod-branch1
+    ) &&
+    git add file1 file11 file13 file2 subdir/file3 submod &&
     git rm file12 &&
     git commit -m "branch1 changes" &&
 
     git checkout master &&
+    git submodule update -N &&
     echo master updated >file1 &&
     echo master new >file2 &&
     echo master updated file12 >file12 &&
     echo master updated file14 >file14 &&
     echo master new sub >subdir/file3 &&
-    git add file1 file12 file14 file2 subdir/file3 &&
+    (
+       cd submod &&
+       echo master submodule >bar &&
+       git add bar &&
+       git commit -m "Add bar on master" &&
+       git checkout -b submod-master
+    ) &&
+    git add file1 file12 file14 file2 subdir/file3 submod &&
     git rm file11 &&
     git commit -m "master updates" &&
 
@@ -52,15 +76,18 @@ test_expect_success 'setup' '
 
 test_expect_success 'custom mergetool' '
     git checkout -b test1 branch1 &&
+    git submodule update -N &&
     test_must_fail git merge master >/dev/null 2>&1 &&
     ( yes "" | git mergetool file1 >/dev/null 2>&1 ) &&
     ( yes "" | git mergetool file2 >/dev/null 2>&1 ) &&
     ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
     ( 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 ) &&
     test "$(cat file1)" = "master updated" &&
     test "$(cat file2)" = "master new" &&
     test "$(cat subdir/file3)" = "master new sub" &&
+    test "$(cat submod/bar)" = "branch1 submodule" &&
     git commit -m "branch1 resolved with mergetool"
 '
 
@@ -73,9 +100,12 @@ test_expect_success 'mergetool crlf' '
     ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
     ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
+    ( yes "r" | git mergetool submod >/dev/null 2>&1 ) &&
     test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" &&
     test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
     test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
     git commit -m "branch1 resolved with mergetool - autocrlf" &&
     git config core.autocrlf false &&
     git reset --hard
@@ -83,6 +113,7 @@ test_expect_success 'mergetool crlf' '
 
 test_expect_success 'mergetool in subdir' '
     git checkout -b test3 branch1 &&
+    git submodule update -N &&
     (
        cd subdir &&
        test_must_fail git merge master >/dev/null 2>&1 &&
@@ -98,18 +129,22 @@ test_expect_success 'mergetool on file in parent dir' '
        ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) &&
        ( 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 ) &&
        test "$(cat ../file1)" = "master updated" &&
        test "$(cat ../file2)" = "master new" &&
+       test "$(cat ../submod/bar)" = "branch1 submodule" &&
        git commit -m "branch1 resolved with mergetool - subdir"
     )
 '
 
 test_expect_success 'mergetool skips autoresolved' '
     git checkout -b test4 branch1 &&
+    git submodule update -N &&
     test_must_fail git merge master &&
     test -n "$(git ls-files -u)" &&
     ( 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 ) &&
     output="$(git mergetool --no-prompt)" &&
     test "$output" = "No files need merging" &&
     git reset --hard
@@ -120,10 +155,13 @@ test_expect_success 'mergetool merges all from subdir' '
        cd subdir &&
        git config rerere.enabled false &&
        test_must_fail git merge master &&
+       ( yes "r" | git mergetool ../submod ) &&
        ( yes "d" "d" | git mergetool --no-prompt ) &&
        test "$(cat ../file1)" = "master updated" &&
        test "$(cat ../file2)" = "master new" &&
        test "$(cat file3)" = "master new sub" &&
+       ( cd .. && git submodule update -N ) &&
+       test "$(cat ../submod/bar)" = "master submodule" &&
        git commit -m "branch2 resolved by mergetool from subdir"
     )
 '
@@ -132,11 +170,257 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' '
     git config rerere.enabled true &&
     rm -rf .git/rr-cache &&
     git checkout -b test5 branch1
+    git submodule update -N &&
     test_must_fail git merge master >/dev/null 2>&1 &&
+    ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) &&
     ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) &&
+    git submodule update -N &&
     output="$(yes "n" | git mergetool --no-prompt)" &&
     test "$output" = "No files need merging" &&
     git reset --hard
 '
 
+test_expect_success 'deleted vs modified submodule' '
+    git checkout -b test6 branch1 &&
+    git submodule update -N &&
+    mv submod submod-movedaside &&
+    git rm submod &&
+    git commit -m "Submodule deleted from branch" &&
+    git checkout -b test6.a test6 &&
+    test_must_fail git merge master &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "r" | git mergetool submod ) &&
+    rmdir submod && mv submod-movedaside submod &&
+    test "$(cat submod/bar)" = "branch1 submodule" &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by keeping module" &&
+
+    mv submod submod-movedaside &&
+    git checkout -b test6.b test6 &&
+    git submodule update -N &&
+    test_must_fail git merge master &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "l" | git mergetool submod ) &&
+    test ! -e submod &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by deleting module" &&
+
+    mv submod-movedaside submod &&
+    git checkout -b test6.c master &&
+    git submodule update -N &&
+    test_must_fail git merge test6 &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "r" | git mergetool submod ) &&
+    test ! -e submod &&
+    test -d submod.orig &&
+    git submodule update -N &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by deleting module" &&
+    mv submod.orig submod &&
+
+    git checkout -b test6.d master &&
+    git submodule update -N &&
+    test_must_fail git merge test6 &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "l" | git mergetool submod ) &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by keeping module" &&
+    git reset --hard HEAD
+'
+
+test_expect_success 'file vs modified submodule' '
+    git checkout -b test7 branch1 &&
+    git submodule update -N &&
+    mv submod submod-movedaside &&
+    git rm submod &&
+    echo not a submodule >submod &&
+    git add submod &&
+    git commit -m "Submodule path becomes file" &&
+    git checkout -b test7.a branch1 &&
+    test_must_fail git merge master &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "r" | git mergetool submod ) &&
+    rmdir submod && mv submod-movedaside submod &&
+    test "$(cat submod/bar)" = "branch1 submodule" &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by keeping module" &&
+
+    mv submod submod-movedaside &&
+    git checkout -b test7.b test7 &&
+    test_must_fail git merge master &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "l" | git mergetool submod ) &&
+    git submodule update -N &&
+    test "$(cat submod)" = "not a submodule" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by keeping file" &&
+
+    git checkout -b test7.c master &&
+    rmdir submod && mv submod-movedaside submod &&
+    test ! -e submod.orig &&
+    git submodule update -N &&
+    test_must_fail git merge test7 &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "r" | git mergetool submod ) &&
+    test -d submod.orig &&
+    git submodule update -N &&
+    test "$(cat submod)" = "not a submodule" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by keeping file" &&
+
+    git checkout -b test7.d master &&
+    rmdir submod && mv submod.orig submod &&
+    git submodule update -N &&
+    test_must_fail git merge test7 &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) &&
+    ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) &&
+    ( yes "l" | git mergetool submod ) &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    output="$(git mergetool --no-prompt)" &&
+    test "$output" = "No files need merging" &&
+    git commit -m "Merge resolved by keeping module"
+'
+
+test_expect_success 'submodule in subdirectory' '
+    git checkout -b test10 branch1 &&
+    git submodule update -N &&
+    (
+       cd subdir &&
+       test_create_repo subdir_module &&
+       (
+           cd subdir_module &&
+           : >file15 &&
+           git add file15 &&
+           git commit -m "add initial versions"
+       )
+    ) &&
+    git submodule add git://example.com/subsubmodule subdir/subdir_module &&
+    git add subdir/subdir_module &&
+    git commit -m "add submodule in subdirectory" &&
+
+    git checkout -b test10.a test10 &&
+    git submodule update -N &&
+    (
+       cd subdir/subdir_module &&
+       git checkout -b super10.a &&
+       echo test10.a >file15 &&
+       git add file15 &&
+       git commit -m "on branch 10.a"
+    ) &&
+    git add subdir/subdir_module &&
+    git commit -m "change submodule in subdirectory on test10.a" &&
+
+    git checkout -b test10.b test10 &&
+    git submodule update -N &&
+    (
+       cd subdir/subdir_module &&
+       git checkout -b super10.b &&
+       echo test10.b >file15 &&
+       git add file15 &&
+       git commit -m "on branch 10.b"
+    ) &&
+    git add subdir/subdir_module &&
+    git commit -m "change submodule in subdirectory on test10.b" &&
+
+    test_must_fail git merge test10.a >/dev/null 2>&1 &&
+    (
+       cd subdir &&
+       ( yes "l" | git mergetool subdir_module )
+    ) &&
+    test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
+    git submodule update -N &&
+    test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
+    git reset --hard &&
+    git submodule update -N &&
+
+    test_must_fail git merge test10.a >/dev/null 2>&1 &&
+    ( yes "r" | git mergetool subdir/subdir_module ) &&
+    test "$(cat subdir/subdir_module/file15)" = "test10.b" &&
+    git submodule update -N &&
+    test "$(cat subdir/subdir_module/file15)" = "test10.a" &&
+    git commit -m "branch1 resolved with mergetool" &&
+    rm -rf subdir/subdir_module
+'
+
+test_expect_success 'directory vs modified submodule' '
+    git checkout -b test11 branch1 &&
+    mv submod submod-movedaside &&
+    git rm submod &&
+    mkdir submod &&
+    echo not a submodule >submod/file16 &&
+    git add submod/file16 &&
+    git commit -m "Submodule path becomes directory" &&
+
+    test_must_fail git merge master &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "l" | git mergetool submod ) &&
+    test "$(cat submod/file16)" = "not a submodule" &&
+    rm -rf submod.orig &&
+
+    git reset --hard &&
+    test_must_fail git merge master &&
+    test -n "$(git ls-files -u)" &&
+    test ! -e submod.orig &&
+    ( yes "r" | git mergetool submod ) &&
+    test -d submod.orig &&
+    test "$(cat submod.orig/file16)" = "not a submodule" &&
+    rm -r submod.orig &&
+    mv submod-movedaside/.git submod &&
+    ( cd submod && git clean -f && git reset --hard ) &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
+    git reset --hard && rm -rf submod-movedaside &&
+
+    git checkout -b test11.c master &&
+    git submodule update -N &&
+    test_must_fail git merge test11 &&
+    test -n "$(git ls-files -u)" &&
+    ( yes "l" | git mergetool submod ) &&
+    git submodule update -N &&
+    test "$(cat submod/bar)" = "master submodule" &&
+
+    git reset --hard &&
+    git submodule update -N &&
+    test_must_fail git merge test11 &&
+    test -n "$(git ls-files -u)" &&
+    test ! -e submod.orig &&
+    ( yes "r" | git mergetool submod ) &&
+    test "$(cat submod/file16)" = "not a submodule" &&
+
+    git reset --hard master &&
+    ( cd submod && git clean -f && git reset --hard ) &&
+    git submodule update -N
+'
+
 test_done
index cdb3f444cd4a5970df6f375382f5cea82ccaee06..7b4798e8e4791c78e94da1354ef7279fa456983d 100755 (executable)
@@ -46,11 +46,8 @@ test_expect_success 'setup' '
 pre_merge_head="$(git rev-parse HEAD)"
 
 test_expect_success 'fails without MERGE_HEAD (unstarted merge)' '
-       test_must_fail git merge --abort 2>output
-'
-
-test_expect_success C_LOCALE_OUTPUT 'fails without MERGE_HEAD (unstarted merge): fatal output' '
-       grep -q MERGE_HEAD output
+       test_must_fail git merge --abort 2>output &&
+       test_i18ngrep MERGE_HEAD output
 '
 
 test_expect_success 'fails without MERGE_HEAD (unstarted merge): .git/MERGE_HEAD sanity' '
@@ -63,11 +60,8 @@ test_expect_success 'fails without MERGE_HEAD (completed merge)' '
        test ! -f .git/MERGE_HEAD &&
        # Merge successfully completed
        post_merge_head="$(git rev-parse HEAD)" &&
-       test_must_fail git merge --abort 2>output
-'
-
-test_expect_success C_LOCALE_OUTPUT 'fails without MERGE_HEAD (completed merge): output' '
-       grep -q MERGE_HEAD output
+       test_must_fail git merge --abort 2>output &&
+       test_i18ngrep MERGE_HEAD output
 '
 
 test_expect_success 'fails without MERGE_HEAD (completed merge): .git/MERGE_HEAD sanity' '
index aedf484feeb9da05054f18ab2f4913865048fe35..a8957782cfb8fae4b7c171d4c9db24ce6cd5505e 100755 (executable)
@@ -61,9 +61,9 @@ test_expect_success SIMPLEPAGER 'git grep -O' '
        test_cmp empty out
 '
 
-test_expect_success C_LOCALE_OUTPUT 'git grep -O --cached' '
+test_expect_success 'git grep -O --cached' '
        test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg &&
-       grep open-files-in-pager msg
+       test_i18ngrep open-files-in-pager msg
 '
 
 test_expect_success 'git grep -O --no-index' '
index d3a51e12698bed50d4eef1474e75dbfd0be0d034..e2896cffc17c519d208c26f215e4605d85edb918 100755 (executable)
@@ -8,7 +8,7 @@ PROG='git blame -c'
 
 PROG='git blame -c -e'
 test_expect_success 'Blame --show-email works' '
-    check_count "<A@test.git>" 1 "<B@test.git>" 1 "<B1@test.git>" 1 "<B2@test.git>" 1 "<author@example.com>" 1 "<C@test.git>" 1 "<D@test.git>" 1
+    check_count "<A@test.git>" 1 "<B@test.git>" 1 "<B1@test.git>" 1 "<B2@test.git>" 1 "<author@example.com>" 1 "<C@test.git>" 1 "<D@test.git>" 1 "<E at test dot git>" 1
 '
 
 test_done
index afac5b56a87f3dcc6467b8ad260e1b59d041eb03..71ef0acb1ba64d36a7909b5308ab6b6e89c31466 100755 (executable)
@@ -595,4 +595,53 @@ test_expect_success HIGHLIGHT \
         git commit -m "Add test.sh" &&
         gitweb_run "p=.git;a=blob;f=test.sh"'
 
+# ----------------------------------------------------------------------
+# forks of projects
+
+cat >>gitweb_config.perl <<\EOF &&
+$feature{'forks'}{'default'} = [1];
+EOF
+
+test_expect_success \
+       'forks: prepare' \
+       'git init --bare foo.git &&
+        git --git-dir=foo.git --work-tree=. add file &&
+        git --git-dir=foo.git --work-tree=. commit -m "Initial commit" &&
+        echo "foo" > foo.git/description &&
+        mkdir -p foo &&
+        (cd foo &&
+         git clone --shared --bare ../foo.git foo-forked.git &&
+         echo "fork of foo" > foo-forked.git/description)'
+
+test_expect_success \
+       'forks: projects list' \
+       'gitweb_run'
+
+test_expect_success \
+       'forks: forks action' \
+       'gitweb_run "p=foo.git;a=forks"'
+
+# ----------------------------------------------------------------------
+# content tags (tag cloud)
+
+cat >>gitweb_config.perl <<-\EOF &&
+# we don't test _setting_ content tags, so any true value is good
+$feature{'ctags'}{'default'} = ['ctags_script.cgi'];
+EOF
+
+test_expect_success \
+       'ctags: tag cloud in projects list' \
+       'mkdir .git/ctags &&
+        echo "2" > .git/ctags/foo &&
+        echo "1" > .git/ctags/bar &&
+       gitweb_run'
+
+test_expect_success \
+       'ctags: search projects by existing tag' \
+       'gitweb_run "by_tag=foo"'
+
+test_expect_success \
+       'ctags: search projects by non existent tag' \
+       'gitweb_run "by_tag=non-existent"'
+
 test_done
index dd8389000187b11fe126f6ca76f578324075bd6f..731e64c3adbd4d887bfa2c96eb060aa890377cfc 100755 (executable)
@@ -112,4 +112,78 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
 '
 test_debug 'cat gitweb.headers'
 
+# ----------------------------------------------------------------------
+# forks of projects
+
+test_expect_success 'forks: setup' '
+       git init --bare foo.git &&
+       echo file > file &&
+       git --git-dir=foo.git --work-tree=. add file &&
+       git --git-dir=foo.git --work-tree=. commit -m "Initial commit" &&
+       echo "foo" > foo.git/description &&
+       git clone --bare foo.git foo.bar.git &&
+       echo "foo.bar" > foo.bar.git/description &&
+       git clone --bare foo.git foo_baz.git &&
+       echo "foo_baz" > foo_baz.git/description &&
+       rm -fr   foo &&
+       mkdir -p foo &&
+       (
+               cd foo &&
+               git clone --shared --bare ../foo.git foo-forked.git &&
+               echo "fork of foo" > foo-forked.git/description
+       )
+'
+
+test_expect_success 'forks: not skipped unless "forks" feature enabled' '
+       gitweb_run "a=project_list" &&
+       grep -q ">\\.git<"               gitweb.body &&
+       grep -q ">foo\\.git<"            gitweb.body &&
+       grep -q ">foo_baz\\.git<"        gitweb.body &&
+       grep -q ">foo\\.bar\\.git<"      gitweb.body &&
+       grep -q ">foo_baz\\.git<"        gitweb.body &&
+       grep -q ">foo/foo-forked\\.git<" gitweb.body &&
+       grep -q ">fork of .*<"           gitweb.body
+'
+
+cat >>gitweb_config.perl <<\EOF &&
+$feature{'forks'}{'default'} = [1];
+EOF
+
+test_expect_success 'forks: forks skipped if "forks" feature enabled' '
+       gitweb_run "a=project_list" &&
+       grep -q ">\\.git<"               gitweb.body &&
+       grep -q ">foo\\.git<"            gitweb.body &&
+       grep -q ">foo_baz\\.git<"        gitweb.body &&
+       grep -q ">foo\\.bar\\.git<"      gitweb.body &&
+       grep -q ">foo_baz\\.git<"        gitweb.body &&
+       grep -v ">foo/foo-forked\\.git<" gitweb.body &&
+       grep -v ">fork of .*<"           gitweb.body
+'
+
+test_expect_success 'forks: "forks" action for forked repository' '
+       gitweb_run "p=foo.git;a=forks" &&
+       grep -q ">foo/foo-forked\\.git<" gitweb.body &&
+       grep -q ">fork of foo<"          gitweb.body
+'
+
+test_expect_success 'forks: can access forked repository' '
+       gitweb_run "p=foo/foo-forked.git;a=summary" &&
+       grep -q "200 OK"        gitweb.headers &&
+       grep -q ">fork of foo<" gitweb.body
+'
+
+test_expect_success 'forks: project_index lists all projects (incl. forks)' '
+       cat >expected <<-\EOF
+       .git
+       foo.bar.git
+       foo.git
+       foo/foo-forked.git
+       foo_baz.git
+       EOF
+       gitweb_run "a=project_index" &&
+       sed -e "s/ .*//" <gitweb.body | sort >actual &&
+       test_cmp expected actual
+'
+
+
 test_done
index abc47f3abc5d925ed217d0d95f10bf078bc26034..b2ce2bc4b22f43c0b324ab3f596a7f865fa58cc1 100644 (file)
@@ -89,6 +89,9 @@ esac
 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
 
+# Zero SHA-1
+_z40=0000000000000000000000000000000000000000
+
 # Each test should start with something like this, after copyright notices:
 #
 # test_description='Description of this test...
@@ -575,7 +578,7 @@ test_external () {
 test_external_without_stderr () {
        # The temporary file has no (and must have no) security
        # implications.
-       tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
+       tmp=${TMPDIR:-/tmp}
        stderr="$tmp/git-external-stderr.$$.tmp"
        test_external "$@" 4> "$stderr"
        [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
@@ -801,12 +804,14 @@ test_done () {
                mkdir -p "$test_results_dir"
                test_results_path="$test_results_dir/${0%.sh}-$$.counts"
 
-               echo "total $test_count" >> $test_results_path
-               echo "success $test_success" >> $test_results_path
-               echo "fixed $test_fixed" >> $test_results_path
-               echo "broken $test_broken" >> $test_results_path
-               echo "failed $test_failure" >> $test_results_path
-               echo "" >> $test_results_path
+               cat >>"$test_results_path" <<-EOF
+               total $test_count
+               success $test_success
+               fixed $test_fixed
+               broken $test_broken
+               failed $test_failure
+
+               EOF
        fi
 
        if test "$test_fixed" != 0
@@ -1077,6 +1082,32 @@ else
        test_set_prereq C_LOCALE_OUTPUT
 fi
 
+# Use this instead of test_cmp to compare files that contain expected and
+# actual output from git commands that can be translated.  When running
+# under GETTEXT_POISON this pretends that the command produced expected
+# results.
+test_i18ncmp () {
+       test -n "$GETTEXT_POISON" || test_cmp "$@"
+}
+
+# Use this instead of "grep expected-string actual" to see if the
+# output from a git command that can be translated either contains an
+# expected string, or does not contain an unwanted one.  When running
+# under GETTEXT_POISON this pretends that the command produced expected
+# results.
+test_i18ngrep () {
+       if test -n "$GETTEXT_POISON"
+       then
+           : # pretend success
+       elif test "x!" = "x$1"
+       then
+               shift
+               ! grep "$@"
+       else
+               grep "$@"
+       fi
+}
+
 # test whether the filesystem supports symbolic links
 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
 rm -f y
index 0612bfa7cd1909c8c4292b384fd7a56b8baf3c2a..37918e15f5ce06d0079ce09ae1a7be7b14533c48 100644 (file)
@@ -29,6 +29,8 @@ int main(int argc, char **argv)
                fprintf(stderr, "FAIL %s\n", argv[1]);
                return 1;
        }
+       if (!strcmp(argv[1], "run-command"))
+               exit(run_command(&proc));
 
        fprintf(stderr, "check usage\n");
        return 1;
index 76f83fcc27e50b12ddbc8f72badd8d29f5b4230d..3f4072525b9489a86b2231748abe13c611e05274 100644 (file)
@@ -64,23 +64,17 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2,
 static void show_tree(struct diff_options *opt, const char *prefix,
                      struct tree_desc *desc, struct strbuf *base)
 {
-       int all_interesting = 0;
-       while (desc->size) {
-               int show;
-
-               if (all_interesting)
-                       show = 1;
-               else {
-                       show = tree_entry_interesting(&desc->entry, base, 0,
-                                                     &opt->pathspec);
-                       if (show == 2)
-                               all_interesting = 1;
+       int match = 0;
+       for (; desc->size; update_tree_entry(desc)) {
+               if (match != 2) {
+                       match = tree_entry_interesting(&desc->entry, base, 0,
+                                                      &opt->pathspec);
+                       if (match < 0)
+                               break;
+                       if (match == 0)
+                               continue;
                }
-               if (show < 0)
-                       break;
-               if (show)
-                       show_entry(opt, prefix, desc, base);
-               update_tree_entry(desc);
+               show_entry(opt, prefix, desc, base);
        }
 }
 
@@ -120,20 +114,16 @@ static void show_entry(struct diff_options *opt, const char *prefix,
 }
 
 static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
-                              struct diff_options *opt, int *all_interesting)
+                              struct diff_options *opt, int *match)
 {
        while (t->size) {
-               int show = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec);
-               if (show == 2)
-                       *all_interesting = 1;
-               if (!show) {
-                       update_tree_entry(t);
-                       continue;
+               *match = tree_entry_interesting(&t->entry, base, 0, &opt->pathspec);
+               if (*match) {
+                       if (*match < 0)
+                               t->size = 0;
+                       break;
                }
-               /* Skip it all? */
-               if (show < 0)
-                       t->size = 0;
-               return;
+               update_tree_entry(t);
        }
 }
 
@@ -142,8 +132,7 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
 {
        struct strbuf base;
        int baselen = strlen(base_str);
-       int all_t1_interesting = 0;
-       int all_t2_interesting = 0;
+       int t1_match = 0, t2_match = 0;
 
        /* Enable recursion indefinitely */
        opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);
@@ -157,10 +146,8 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
                    DIFF_OPT_TST(opt, HAS_CHANGES))
                        break;
                if (opt->pathspec.nr) {
-                       if (!all_t1_interesting)
-                               skip_uninteresting(t1, &base, opt, &all_t1_interesting);
-                       if (!all_t2_interesting)
-                               skip_uninteresting(t2, &base, opt, &all_t2_interesting);
+                       skip_uninteresting(t1, &base, opt, &t1_match);
+                       skip_uninteresting(t2, &base, opt, &t2_match);
                }
                if (!t1->size) {
                        if (!t2->size)
index 322becc3b4ad50b8e87fae8f6d5d38f7edc51f01..33f749e1e77484694e7b8f40a65755a7818c4abb 100644 (file)
@@ -598,7 +598,7 @@ int tree_entry_interesting(const struct name_entry *entry,
                                        &never_interesting))
                                return 1;
 
-                       if (ps->items[i].has_wildcard) {
+                       if (ps->items[i].use_wildcard) {
                                if (!fnmatch(match + baselen, entry->path, 0))
                                        return 1;
 
@@ -614,7 +614,7 @@ int tree_entry_interesting(const struct name_entry *entry,
                }
 
 match_wildcards:
-               if (!ps->items[i].has_wildcard)
+               if (!ps->items[i].use_wildcard)
                        continue;
 
                /*
diff --git a/tree.c b/tree.c
index 5ab90af256a664366f3f92b467f52634c0df3f79..698ecf7af13871cf9639e969f368ba5d7b2e940a 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -45,62 +45,14 @@ static int read_one_entry_quick(const unsigned char *sha1, const char *base, int
                                  ADD_CACHE_JUST_APPEND);
 }
 
-static int match_tree_entry(const char *base, int baselen, const char *path, unsigned int mode, const char **paths)
-{
-       const char *match;
-       int pathlen;
-
-       if (!paths)
-               return 1;
-       pathlen = strlen(path);
-       while ((match = *paths++) != NULL) {
-               int matchlen = strlen(match);
-
-               if (baselen >= matchlen) {
-                       /* If it doesn't match, move along... */
-                       if (strncmp(base, match, matchlen))
-                               continue;
-                       /* pathspecs match only at the directory boundaries */
-                       if (!matchlen ||
-                           baselen == matchlen ||
-                           base[matchlen] == '/' ||
-                           match[matchlen - 1] == '/')
-                               return 1;
-                       continue;
-               }
-
-               /* Does the base match? */
-               if (strncmp(base, match, baselen))
-                       continue;
-
-               match += baselen;
-               matchlen -= baselen;
-
-               if (pathlen > matchlen)
-                       continue;
-
-               if (matchlen > pathlen) {
-                       if (match[pathlen] != '/')
-                               continue;
-                       if (!S_ISDIR(mode))
-                               continue;
-               }
-
-               if (strncmp(path, match, pathlen))
-                       continue;
-
-               return 1;
-       }
-       return 0;
-}
-
-int read_tree_recursive(struct tree *tree,
-                       const char *base, int baselen,
-                       int stage, const char **match,
-                       read_tree_fn_t fn, void *context)
+static int read_tree_1(struct tree *tree, struct strbuf *base,
+                      int stage, struct pathspec *pathspec,
+                      read_tree_fn_t fn, void *context)
 {
        struct tree_desc desc;
        struct name_entry entry;
+       unsigned char sha1[20];
+       int len, retval = 0, oldlen = base->len;
 
        if (parse_tree(tree))
                return -1;
@@ -108,10 +60,16 @@ int read_tree_recursive(struct tree *tree,
        init_tree_desc(&desc, tree->buffer, tree->size);
 
        while (tree_entry(&desc, &entry)) {
-               if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
-                       continue;
+               if (retval != 2) {
+                       retval = tree_entry_interesting(&entry, base, 0, pathspec);
+                       if (retval < 0)
+                               break;
+                       if (retval == 0)
+                               continue;
+               }
 
-               switch (fn(entry.sha1, base, baselen, entry.path, entry.mode, stage, context)) {
+               switch (fn(entry.sha1, base->buf, base->len,
+                          entry.path, entry.mode, stage, context)) {
                case 0:
                        continue;
                case READ_TREE_RECURSIVE:
@@ -119,56 +77,55 @@ int read_tree_recursive(struct tree *tree,
                default:
                        return -1;
                }
-               if (S_ISDIR(entry.mode)) {
-                       int retval;
-                       char *newbase;
-                       unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
-
-                       newbase = xmalloc(baselen + 1 + pathlen);
-                       memcpy(newbase, base, baselen);
-                       memcpy(newbase + baselen, entry.path, pathlen);
-                       newbase[baselen + pathlen] = '/';
-                       retval = read_tree_recursive(lookup_tree(entry.sha1),
-                                                    newbase,
-                                                    baselen + pathlen + 1,
-                                                    stage, match, fn, context);
-                       free(newbase);
-                       if (retval)
-                               return -1;
-                       continue;
-               } else if (S_ISGITLINK(entry.mode)) {
-                       int retval;
-                       struct strbuf path;
-                       unsigned int entrylen;
-                       struct commit *commit;
 
-                       entrylen = tree_entry_len(entry.path, entry.sha1);
-                       strbuf_init(&path, baselen + entrylen + 1);
-                       strbuf_add(&path, base, baselen);
-                       strbuf_add(&path, entry.path, entrylen);
-                       strbuf_addch(&path, '/');
+               if (S_ISDIR(entry.mode))
+                       hashcpy(sha1, entry.sha1);
+               else if (S_ISGITLINK(entry.mode)) {
+                       struct commit *commit;
 
                        commit = lookup_commit(entry.sha1);
                        if (!commit)
-                               die("Commit %s in submodule path %s not found",
-                                   sha1_to_hex(entry.sha1), path.buf);
+                               die("Commit %s in submodule path %s%s not found",
+                                   sha1_to_hex(entry.sha1),
+                                   base->buf, entry.path);
 
                        if (parse_commit(commit))
-                               die("Invalid commit %s in submodule path %s",
-                                   sha1_to_hex(entry.sha1), path.buf);
-
-                       retval = read_tree_recursive(commit->tree,
-                                                    path.buf, path.len,
-                                                    stage, match, fn, context);
-                       strbuf_release(&path);
-                       if (retval)
-                               return -1;
-                       continue;
+                               die("Invalid commit %s in submodule path %s%s",
+                                   sha1_to_hex(entry.sha1),
+                                   base->buf, entry.path);
+
+                       hashcpy(sha1, commit->tree->object.sha1);
                }
+               else
+                       continue;
+
+               len = tree_entry_len(entry.path, entry.sha1);
+               strbuf_add(base, entry.path, len);
+               strbuf_addch(base, '/');
+               retval = read_tree_1(lookup_tree(sha1),
+                                    base, stage, pathspec,
+                                    fn, context);
+               strbuf_setlen(base, oldlen);
+               if (retval)
+                       return -1;
        }
        return 0;
 }
 
+int read_tree_recursive(struct tree *tree,
+                       const char *base, int baselen,
+                       int stage, struct pathspec *pathspec,
+                       read_tree_fn_t fn, void *context)
+{
+       struct strbuf sb = STRBUF_INIT;
+       int ret;
+
+       strbuf_add(&sb, base, baselen);
+       ret = read_tree_1(tree, &sb, stage, pathspec, fn, context);
+       strbuf_release(&sb);
+       return ret;
+}
+
 static int cmp_cache_name_compare(const void *a_, const void *b_)
 {
        const struct cache_entry *ce1, *ce2;
@@ -179,7 +136,7 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
                                  ce2->name, ce2->ce_flags);
 }
 
-int read_tree(struct tree *tree, int stage, const char **match)
+int read_tree(struct tree *tree, int stage, struct pathspec *match)
 {
        read_tree_fn_t fn = NULL;
        int i, err;
diff --git a/tree.h b/tree.h
index 2ff01a4f839ecc2206fcc1c13fee9d5d202b1128..69bcb5e0ec27de6699e349b8dcec26f1cbc4e741 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -25,9 +25,9 @@ typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const ch
 
 extern int read_tree_recursive(struct tree *tree,
                               const char *base, int baselen,
-                              int stage, const char **match,
+                              int stage, struct pathspec *pathspec,
                               read_tree_fn_t fn, void *context);
 
-extern int read_tree(struct tree *tree, int stage, const char **paths);
+extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec);
 
 #endif /* TREE_H */
index 164581f87f49935f0d1b1885420960a4d11dea56..0e2c169227ad29b5bf546c6c1b97e1a1d8ed7409 100644 (file)
@@ -347,7 +347,7 @@ int git_xmerge_style = -1;
 
 int git_xmerge_config(const char *var, const char *value, void *cb)
 {
-       if (!strcasecmp(var, "merge.conflictstyle")) {
+       if (!strcmp(var, "merge.conflictstyle")) {
                if (!value)
                        die("'%s' is not a boolean", var);
                if (!strcmp(value, "diff3"))