Merge branch 'js/completion-hide-not-a-repo'
authorJunio C Hamano <gitster@pobox.com>
Tue, 21 Oct 2014 20:28:50 +0000 (13:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Oct 2014 20:28:50 +0000 (13:28 -0700)
Some internal error messages leaked out of the bash completion when
typing "git cmd <TAB>" and the machinery tried to complete
refnames.

* js/completion-hide-not-a-repo:
completion: silence "fatal: Not a git repository" error

102 files changed:
.gitignore
Documentation/Makefile
Documentation/RelNotes/2.2.0.txt
Documentation/config.txt
Documentation/everyday.txt [deleted file]
Documentation/everyday.txto [new file with mode: 0644]
Documentation/git-imap-send.txt
Documentation/git-interpret-trailers.txt [new file with mode: 0644]
Documentation/git-prune-packed.txt
Documentation/git-push.txt
Documentation/git-quiltimport.txt
Documentation/git-stage.txt
Documentation/git.txt
Documentation/gitcore-tutorial.txt
Documentation/gitcvs-migration.txt
Documentation/giteveryday.txt [new file with mode: 0644]
Documentation/gitglossary.txt
Documentation/gittutorial-2.txt
Documentation/gittutorial.txt
Makefile
README
archive-tar.c
branch.c
builtin.h
builtin/blame.c
builtin/branch.c
builtin/checkout.c
builtin/clean.c
builtin/clone.c
builtin/commit.c
builtin/config.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/for-each-ref.c
builtin/fsck.c
builtin/help.c
builtin/interpret-trailers.c [new file with mode: 0644]
builtin/log.c
builtin/merge.c
builtin/notes.c
builtin/receive-pack.c
builtin/remote.c
builtin/replace.c
builtin/show-branch.c
builtin/symbolic-ref.c
builtin/tag.c
builtin/update-ref.c
bundle.c
cache.h
color.c
color.h
command-list.txt
contrib/completion/git-completion.bash
contrib/contacts/.gitignore [new file with mode: 0644]
contrib/contacts/Makefile [new file with mode: 0644]
contrib/subtree/.gitignore
contrib/subtree/Makefile
diff.c
fast-import.c
git-compat-util.h
git-difftool.perl
git-mergetool.sh
git-sh-setup.sh
git.c
gitweb/gitweb.perl
grep.c
http-backend.c
lockfile.c
lockfile.h
log-tree.c
log-tree.h
mergetools/meld
notes-merge.c
pretty.c
reflog-walk.c
refs.c
refs.h
remote.c
sequencer.c
t/README
t/t1308-config-set.sh
t/t1400-update-ref.sh
t/t1413-reflog-detach.sh [new file with mode: 0755]
t/t1430-bad-ref-name.sh [new file with mode: 0755]
t/t3200-branch.sh
t/t5004-archive-corner-cases.sh
t/t5304-prune.sh
t/t7001-mv.sh
t/t7513-interpret-trailers.sh [new file with mode: 0755]
t/t7610-mergetool.sh
t/t9300-fast-import.sh
t/test-lib-functions.sh
t/test-lib.sh
trace.c
trailer.c [new file with mode: 0644]
trailer.h [new file with mode: 0644]
transport-helper.c
transport.c
upload-pack.c
walker.c
wrapper.c
wt-status.c
index 9ec40fa9fbc645532c9bc36b65521e6771d14324..a05241916c9c9a3760a6e98670a7f6427d553d77 100644 (file)
@@ -74,6 +74,7 @@
 /git-index-pack
 /git-init
 /git-init-db
+/git-interpret-trailers
 /git-instaweb
 /git-log
 /git-ls-files
index cea0e7ae3db37dcd366e094abdd2a2f32514a247..8d0f70938e6d6f04c9edfb9a3ec8ef45d38502c5 100644 (file)
@@ -5,6 +5,7 @@ MAN7_TXT =
 TECH_DOCS =
 ARTICLES =
 SP_ARTICLES =
+OBSOLETE_HTML =
 
 MAN1_TXT += $(filter-out \
                $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
@@ -26,6 +27,7 @@ MAN7_TXT += gitcore-tutorial.txt
 MAN7_TXT += gitcredentials.txt
 MAN7_TXT += gitcvs-migration.txt
 MAN7_TXT += gitdiffcore.txt
+MAN7_TXT += giteveryday.txt
 MAN7_TXT += gitglossary.txt
 MAN7_TXT += gitnamespaces.txt
 MAN7_TXT += gitrevisions.txt
@@ -37,11 +39,11 @@ MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)
 MAN_XML = $(patsubst %.txt,%.xml,$(MAN_TXT))
 MAN_HTML = $(patsubst %.txt,%.html,$(MAN_TXT))
 
-OBSOLETE_HTML = git-remote-helpers.html
+OBSOLETE_HTML += everyday.html
+OBSOLETE_HTML += git-remote-helpers.html
 DOC_HTML = $(MAN_HTML) $(OBSOLETE_HTML)
 
 ARTICLES += howto-index
-ARTICLES += everyday
 ARTICLES += git-tools
 ARTICLES += git-bisect-lk2009
 # with their own formatting rules.
index 95891765a139ffe6e2bd8fa524c61f2018dcb432..af876e2ce998762071cbddf2adbb845eb8d90f37 100644 (file)
@@ -58,6 +58,14 @@ UI, Workflows & Features
    public repository really point the commits the pusher wanted to,
    without having to "trust" the server.
 
+ * "git interpret-trailers" is a new filter to programatically edit
+    the tail end of the commit log messages.
+
+ * "git help everyday" shows the "Everyday Git in 20 commands or so"
+   document, whose contents have been updated to more modern Git
+   practice.
+
+
 Performance, Internal Implementation, etc.
 
  * The API to manipulate the "refs" is currently undergoing a revamp
@@ -124,6 +132,10 @@ Performance, Internal Implementation, etc.
    original before feeding the filter.  Instead, stream the file
    contents directly to the filter and process its output.
 
+ * The scripts in the test suite can be run with "-x" option to show
+   a shell-trace of each command run in them.
+
+
 Also contains various documentation updates and code clean-ups.
 
 
@@ -138,11 +150,6 @@ notes for details).
    mean the more obvious "No output whatsoever" but "Use default
    format", which was counterintuitive.
 
- * Implementations of "tar" that do not understand an extended pax
-   header would extract the contents of it in a regular file; make
-   sure the permission bits of this file follows the same tar.umask
-   configuration setting.
-
  * "git -c section.var command" and "git -c section.var= command"
    should pass the configuration differently (the former should be a
    boolean true, the latter should be an empty string).
@@ -236,3 +243,8 @@ notes for details).
  * A few documentation pages had example sections marked up not quite
    correctly, which passed AsciiDoc but failed with AsciiDoctor.
    (merge c30c43c bc/asciidoc-pretty-formats-fix later to maint).
+   (merge f8a48af bc/asciidoc later to maint).
+
+ * "gitweb" used deprecated CGI::startfrom, which was removed from
+   CGI.pm as of 4.04; use CGI::start_from instead.
+   (merge 4750f4b rm/gitweb-start-form later to maint).
index 04a1e2f37e938f004c899d3fb6c59d282c2071ce..400dcad21d627d7fc1dba9ec31d86f046bb49396 100644 (file)
@@ -1755,6 +1755,15 @@ mergetool.<tool>.trustExitCode::
        if the file has been updated, otherwise the user is prompted to
        indicate the success of the merge.
 
+mergetool.meld.hasOutput::
+       Older versions of `meld` do not support the `--output` option.
+       Git will attempt to detect whether `meld` supports `--output`
+       by inspecting the output of `meld --help`.  Configuring
+       `mergetool.meld.hasOutput` will make Git skip these checks and
+       use the configured value instead.  Setting `mergetool.meld.hasOutput`
+       to `true` tells Git to unconditionally use the `--output` option,
+       and `false` avoids using `--output`.
+
 mergetool.keepBackup::
        After performing a merge, the original file with conflict markers
        can be saved as a file with a `.orig` extension.  If this variable
@@ -1768,6 +1777,12 @@ mergetool.keepTemporaries::
        preserved, otherwise they will be removed after the tool has
        exited. Defaults to `false`.
 
+mergetool.writeToTemp::
+       Git writes temporary 'BASE', 'LOCAL', and 'REMOTE' versions of
+       conflicting files in the worktree by default.  Git will attempt
+       to use a temporary directory for these files when set `true`.
+       Defaults to `false`.
+
 mergetool.prompt::
        Prompt before each invocation of the merge resolution program.
 
diff --git a/Documentation/everyday.txt b/Documentation/everyday.txt
deleted file mode 100644 (file)
index b2548ef..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-Everyday Git With 20 Commands Or So
-===================================
-
-<<Individual Developer (Standalone)>> commands are essential for
-anybody who makes a commit, even for somebody who works alone.
-
-If you work with other people, you will need commands listed in
-the <<Individual Developer (Participant)>> section as well.
-
-People who play the <<Integrator>> role need to learn some more
-commands in addition to the above.
-
-<<Repository Administration>> commands are for system
-administrators who are responsible for the care and feeding
-of Git repositories.
-
-
-Individual Developer (Standalone)[[Individual Developer (Standalone)]]
-----------------------------------------------------------------------
-
-A standalone individual developer does not exchange patches with
-other people, and works alone in a single repository, using the
-following commands.
-
-  * linkgit:git-init[1] to create a new repository.
-
-  * linkgit:git-show-branch[1] to see where you are.
-
-  * linkgit:git-log[1] to see what happened.
-
-  * linkgit:git-checkout[1] and linkgit:git-branch[1] to switch
-    branches.
-
-  * linkgit:git-add[1] to manage the index file.
-
-  * linkgit:git-diff[1] and linkgit:git-status[1] to see what
-    you are in the middle of doing.
-
-  * linkgit:git-commit[1] to advance the current branch.
-
-  * linkgit:git-reset[1] and linkgit:git-checkout[1] (with
-    pathname parameters) to undo changes.
-
-  * linkgit:git-merge[1] to merge between local branches.
-
-  * linkgit:git-rebase[1] to maintain topic branches.
-
-  * linkgit:git-tag[1] to mark known point.
-
-Examples
-~~~~~~~~
-
-Use a tarball as a starting point for a new repository.::
-+
-------------
-$ tar zxf frotz.tar.gz
-$ cd frotz
-$ git init
-$ git add . <1>
-$ git commit -m "import of frotz source tree."
-$ git tag v2.43 <2>
-------------
-+
-<1> add everything under the current directory.
-<2> make a lightweight, unannotated tag.
-
-Create a topic branch and develop.::
-+
-------------
-$ git checkout -b alsa-audio <1>
-$ edit/compile/test
-$ git checkout -- curses/ux_audio_oss.c <2>
-$ git add curses/ux_audio_alsa.c <3>
-$ edit/compile/test
-$ git diff HEAD <4>
-$ git commit -a -s <5>
-$ edit/compile/test
-$ git reset --soft HEAD^ <6>
-$ edit/compile/test
-$ git diff ORIG_HEAD <7>
-$ git commit -a -c ORIG_HEAD <8>
-$ git checkout master <9>
-$ git merge alsa-audio <10>
-$ git log --since='3 days ago' <11>
-$ git log v2.43.. curses/ <12>
-------------
-+
-<1> create a new topic branch.
-<2> revert your botched changes in `curses/ux_audio_oss.c`.
-<3> you need to tell Git if you added a new file; removal and
-modification will be caught if you do `git commit -a` later.
-<4> to see what changes you are committing.
-<5> commit everything as you have tested, with your sign-off.
-<6> take the last commit back, keeping what is in the working tree.
-<7> look at the changes since the premature commit we took back.
-<8> redo the commit undone in the previous step, using the message
-you originally wrote.
-<9> switch to the master branch.
-<10> merge a topic branch into your master branch.
-<11> review commit logs; other forms to limit output can be
-combined and include `--max-count=10` (show 10 commits),
-`--until=2005-12-10`, etc.
-<12> view only the changes that touch what's in `curses/`
-directory, since `v2.43` tag.
-
-
-Individual Developer (Participant)[[Individual Developer (Participant)]]
-------------------------------------------------------------------------
-
-A developer working as a participant in a group project needs to
-learn how to communicate with others, and uses these commands in
-addition to the ones needed by a standalone developer.
-
-  * linkgit:git-clone[1] from the upstream to prime your local
-    repository.
-
-  * linkgit:git-pull[1] and linkgit:git-fetch[1] from "origin"
-    to keep up-to-date with the upstream.
-
-  * linkgit:git-push[1] to shared repository, if you adopt CVS
-    style shared repository workflow.
-
-  * linkgit:git-format-patch[1] to prepare e-mail submission, if
-    you adopt Linux kernel-style public forum workflow.
-
-Examples
-~~~~~~~~
-
-Clone the upstream and work on it.  Feed changes to upstream.::
-+
-------------
-$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
-$ cd my2.6
-$ edit/compile/test; git commit -a -s <1>
-$ git format-patch origin <2>
-$ git pull <3>
-$ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <4>
-$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <5>
-$ git reset --hard ORIG_HEAD <6>
-$ git gc <7>
-$ git fetch --tags <8>
-------------
-+
-<1> repeat as needed.
-<2> extract patches from your branch for e-mail submission.
-<3> `git pull` fetches from `origin` by default and merges into the
-current branch.
-<4> immediately after pulling, look at the changes done upstream
-since last time we checked, only in the
-area we are interested in.
-<5> fetch from a specific branch from a specific repository and merge.
-<6> revert the pull.
-<7> garbage collect leftover objects from reverted pull.
-<8> from time to time, obtain official tags from the `origin`
-and store them under `.git/refs/tags/`.
-
-
-Push into another repository.::
-+
-------------
-satellite$ git clone mothership:frotz frotz <1>
-satellite$ cd frotz
-satellite$ git config --get-regexp '^(remote|branch)\.' <2>
-remote.origin.url mothership:frotz
-remote.origin.fetch refs/heads/*:refs/remotes/origin/*
-branch.master.remote origin
-branch.master.merge refs/heads/master
-satellite$ git config remote.origin.push \
-           master:refs/remotes/satellite/master <3>
-satellite$ edit/compile/test/commit
-satellite$ git push origin <4>
-
-mothership$ cd frotz
-mothership$ git checkout master
-mothership$ git merge satellite/master <5>
-------------
-+
-<1> mothership machine has a frotz repository under your home
-directory; clone from it to start a repository on the satellite
-machine.
-<2> clone sets these configuration variables by default.
-It arranges `git pull` to fetch and store the branches of mothership
-machine to local `remotes/origin/*` remote-tracking branches.
-<3> arrange `git push` to push local `master` branch to
-`remotes/satellite/master` branch of the mothership machine.
-<4> push will stash our work away on `remotes/satellite/master`
-remote-tracking branch on the mothership machine.  You could use this
-as a back-up method.
-<5> on mothership machine, merge the work done on the satellite
-machine into the master branch.
-
-Branch off of a specific tag.::
-+
-------------
-$ git checkout -b private2.6.14 v2.6.14 <1>
-$ edit/compile/test; git commit -a
-$ git checkout master
-$ git format-patch -k -m --stdout v2.6.14..private2.6.14 |
-  git am -3 -k <2>
-------------
-+
-<1> create a private branch based on a well known (but somewhat behind)
-tag.
-<2> forward port all changes in `private2.6.14` branch to `master` branch
-without a formal "merging".
-
-
-Integrator[[Integrator]]
-------------------------
-
-A fairly central person acting as the integrator in a group
-project receives changes made by others, reviews and integrates
-them and publishes the result for others to use, using these
-commands in addition to the ones needed by participants.
-
-  * linkgit:git-am[1] to apply patches e-mailed in from your
-    contributors.
-
-  * linkgit:git-pull[1] to merge from your trusted lieutenants.
-
-  * linkgit:git-format-patch[1] to prepare and send suggested
-    alternative to contributors.
-
-  * linkgit:git-revert[1] to undo botched commits.
-
-  * linkgit:git-push[1] to publish the bleeding edge.
-
-
-Examples
-~~~~~~~~
-
-My typical Git day.::
-+
-------------
-$ git status <1>
-$ git show-branch <2>
-$ mailx <3>
-& s 2 3 4 5 ./+to-apply
-& s 7 8 ./+hold-linus
-& q
-$ git checkout -b topic/one master
-$ git am -3 -i -s -u ./+to-apply <4>
-$ compile/test
-$ git checkout -b hold/linus && git am -3 -i -s -u ./+hold-linus <5>
-$ git checkout topic/one && git rebase master <6>
-$ git checkout pu && git reset --hard next <7>
-$ git merge topic/one topic/two && git merge hold/linus <8>
-$ git checkout maint
-$ git cherry-pick master~4 <9>
-$ compile/test
-$ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
-$ git fetch ko && git show-branch master maint 'tags/ko-*' <11>
-$ git push ko <12>
-$ git push ko v0.99.9x <13>
-------------
-+
-<1> see what I was in the middle of doing, if any.
-<2> see what topic branches I have and think about how ready
-they are.
-<3> read mails, save ones that are applicable, and save others
-that are not quite ready.
-<4> apply them, interactively, with my sign-offs.
-<5> create topic branch as needed and apply, again with my
-sign-offs.
-<6> rebase internal topic branch that has not been merged to the
-master or exposed as a part of a stable branch.
-<7> restart `pu` every time from the next.
-<8> and bundle topic branches still cooking.
-<9> backport a critical fix.
-<10> create a signed tag.
-<11> make sure I did not accidentally rewind master beyond what I
-already pushed out.  `ko` shorthand points at the repository I have
-at kernel.org, and looks like this:
-+
-------------
-$ cat .git/remotes/ko
-URL: kernel.org:/pub/scm/git/git.git
-Pull: master:refs/tags/ko-master
-Pull: next:refs/tags/ko-next
-Pull: maint:refs/tags/ko-maint
-Push: master
-Push: next
-Push: +pu
-Push: maint
-------------
-+
-In the output from `git show-branch`, `master` should have
-everything `ko-master` has, and `next` should have
-everything `ko-next` has.
-
-<12> push out the bleeding edge.
-<13> push the tag out, too.
-
-
-Repository Administration[[Repository Administration]]
-------------------------------------------------------
-
-A repository administrator uses the following tools to set up
-and maintain access to the repository by developers.
-
-  * linkgit:git-daemon[1] to allow anonymous download from
-    repository.
-
-  * linkgit:git-shell[1] can be used as a 'restricted login shell'
-    for shared central repository users.
-
-link:howto/update-hook-example.html[update hook howto] has a good
-example of managing a shared central repository.
-
-
-Examples
-~~~~~~~~
-We assume the following in /etc/services::
-+
-------------
-$ grep 9418 /etc/services
-git            9418/tcp                # Git Version Control System
-------------
-
-Run git-daemon to serve /pub/scm from inetd.::
-+
-------------
-$ grep git /etc/inetd.conf
-git    stream  tcp     nowait  nobody \
-  /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
-------------
-+
-The actual configuration line should be on one line.
-
-Run git-daemon to serve /pub/scm from xinetd.::
-+
-------------
-$ cat /etc/xinetd.d/git-daemon
-# default: off
-# description: The Git server offers access to Git repositories
-service git
-{
-        disable = no
-        type            = UNLISTED
-        port            = 9418
-        socket_type     = stream
-        wait            = no
-        user            = nobody
-        server          = /usr/bin/git-daemon
-        server_args     = --inetd --export-all --base-path=/pub/scm
-        log_on_failure  += USERID
-}
-------------
-+
-Check your xinetd(8) documentation and setup, this is from a Fedora system.
-Others might be different.
-
-Give push/pull only access to developers.::
-+
-------------
-$ grep git /etc/passwd <1>
-alice:x:1000:1000::/home/alice:/usr/bin/git-shell
-bob:x:1001:1001::/home/bob:/usr/bin/git-shell
-cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
-david:x:1003:1003::/home/david:/usr/bin/git-shell
-$ grep git /etc/shells <2>
-/usr/bin/git-shell
-------------
-+
-<1> log-in shell is set to /usr/bin/git-shell, which does not
-allow anything but `git push` and `git pull`.  The users should
-get an ssh access to the machine.
-<2> in many distributions /etc/shells needs to list what is used
-as the login shell.
-
-CVS-style shared repository.::
-+
-------------
-$ grep git /etc/group <1>
-git:x:9418:alice,bob,cindy,david
-$ cd /home/devo.git
-$ ls -l <2>
-  lrwxrwxrwx   1 david git    17 Dec  4 22:40 HEAD -> refs/heads/master
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 branches
-  -rw-rw-r--   1 david git    84 Dec  4 22:40 config
-  -rw-rw-r--   1 david git    58 Dec  4 22:40 description
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 hooks
-  -rw-rw-r--   1 david git 37504 Dec  4 22:40 index
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 info
-  drwxrwsr-x   4 david git  4096 Dec  4 22:40 objects
-  drwxrwsr-x   4 david git  4096 Nov  7 14:58 refs
-  drwxrwsr-x   2 david git  4096 Dec  4 22:40 remotes
-$ ls -l hooks/update <3>
-  -r-xr-xr-x   1 david git  3536 Dec  4 22:40 update
-$ cat info/allowed-users <4>
-refs/heads/master      alice\|cindy
-refs/heads/doc-update  bob
-refs/tags/v[0-9]*      david
-------------
-+
-<1> place the developers into the same git group.
-<2> and make the shared repository writable by the group.
-<3> use update-hook example by Carl from Documentation/howto/
-for branch policy control.
-<4> alice and cindy can push into master, only bob can push into doc-update.
-david is the release manager and is the only person who can
-create and push version tags.
-
-HTTP server to support dumb protocol transfer.::
-+
-------------
-dev$ git update-server-info <1>
-dev$ ftp user@isp.example.com <2>
-ftp> cp -r .git /home/user/myproject.git
-------------
-+
-<1> make sure your info/refs and objects/info/packs are up-to-date
-<2> upload to public HTTP server hosted by your ISP.
diff --git a/Documentation/everyday.txto b/Documentation/everyday.txto
new file mode 100644 (file)
index 0000000..c5047d8
--- /dev/null
@@ -0,0 +1,9 @@
+Everyday Git With 20 Commands Or So
+===================================
+
+This document has been moved to linkgit:giteveryday[1].
+
+Please let the owners of the referring site know so that they can update the
+link you clicked to get here.
+
+Thanks.
index 7d991d919ccf3378fdc924418aede45f8cb38632..c7c0d21429bb745d1abcfc775308e8ccac8f499a 100644 (file)
@@ -97,7 +97,7 @@ Using direct mode:
     host = imap://imap.example.com
     user = bob
     pass = p4ssw0rd
-..........................
+.........................
 
 Using direct mode with SSL:
 
@@ -109,7 +109,7 @@ Using direct mode with SSL:
     pass = p4ssw0rd
     port = 123
     sslverify = false
-..........................
+.........................
 
 
 EXAMPLE
diff --git a/Documentation/git-interpret-trailers.txt b/Documentation/git-interpret-trailers.txt
new file mode 100644 (file)
index 0000000..81fac3d
--- /dev/null
@@ -0,0 +1,314 @@
+git-interpret-trailers(1)
+=========================
+
+NAME
+----
+git-interpret-trailers - help add stuctured information into commit messages
+
+SYNOPSIS
+--------
+[verse]
+'git interpret-trailers' [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]
+
+DESCRIPTION
+-----------
+Help adding 'trailers' lines, that look similar to RFC 822 e-mail
+headers, at the end of the otherwise free-form part of a commit
+message.
+
+This command reads some patches or commit messages from either the
+<file> arguments or the standard input if no <file> is specified. Then
+this command applies the arguments passed using the `--trailer`
+option, if any, to the commit message part of each input file. The
+result is emitted on the standard output.
+
+Some configuration variables control the way the `--trailer` arguments
+are applied to each commit message and the way any existing trailer in
+the commit message is changed. They also make it possible to
+automatically add some trailers.
+
+By default, a '<token>=<value>' or '<token>:<value>' argument given
+using `--trailer` will be appended after the existing trailers only if
+the last trailer has a different (<token>, <value>) pair (or if there
+is no existing trailer). The <token> and <value> parts will be trimmed
+to remove starting and trailing whitespace, and the resulting trimmed
+<token> and <value> will appear in the message like this:
+
+------------------------------------------------
+token: value
+------------------------------------------------
+
+This means that the trimmed <token> and <value> will be separated by
+`': '` (one colon followed by one space).
+
+By default the new trailer will appear at the end of all the existing
+trailers. If there is no existing trailer, the new trailer will appear
+after the commit message part of the ouput, and, if there is no line
+with only spaces at the end of the commit message part, one blank line
+will be added before the new trailer.
+
+Existing trailers are extracted from the input message by looking for
+a group of one or more lines that contain a colon (by default), where
+the group is preceded by one or more empty (or whitespace-only) lines.
+The group must either be at the end of the message or be the last
+non-whitespace lines before a line that starts with '---'. Such three
+minus signs start the patch part of the message.
+
+When reading trailers, there can be whitespaces before and after the
+token, the separator and the value. There can also be whitespaces
+indide the token and the value.
+
+Note that 'trailers' do not follow and are not intended to follow many
+rules for RFC 822 headers. For example they do not follow the line
+folding rules, the encoding rules and probably many other rules.
+
+OPTIONS
+-------
+--trim-empty::
+       If the <value> part of any trailer contains only whitespace,
+       the whole trailer will be removed from the resulting message.
+       This apply to existing trailers as well as new trailers.
+
+--trailer <token>[(=|:)<value>]::
+       Specify a (<token>, <value>) pair that should be applied as a
+       trailer to the input messages. See the description of this
+       command.
+
+CONFIGURATION VARIABLES
+-----------------------
+
+trailer.separators::
+       This option tells which characters are recognized as trailer
+       separators. By default only ':' is recognized as a trailer
+       separator, except that '=' is always accepted on the command
+       line for compatibility with other git commands.
++
+The first character given by this option will be the default character
+used when another separator is not specified in the config for this
+trailer.
++
+For example, if the value for this option is "%=$", then only lines
+using the format '<token><sep><value>' with <sep> containing '%', '='
+or '$' and then spaces will be considered trailers. And '%' will be
+the default separator used, so by default trailers will appear like:
+'<token>% <value>' (one percent sign and one space will appear between
+the token and the value).
+
+trailer.where::
+       This option tells where a new trailer will be added.
++
+This can be `end`, which is the default, `start`, `after` or `before`.
++
+If it is `end`, then each new trailer will appear at the end of the
+existing trailers.
++
+If it is `start`, then each new trailer will appear at the start,
+instead of the end, of the existing trailers.
++
+If it is `after`, then each new trailer will appear just after the
+last trailer with the same <token>.
++
+If it is `before`, then each new trailer will appear just before the
+first trailer with the same <token>.
+
+trailer.ifexists::
+       This option makes it possible to choose what action will be
+       performed when there is already at least one trailer with the
+       same <token> in the message.
++
+The valid values for this option are: `addIfDifferentNeighbor` (this
+is the default), `addIfDifferent`, `add`, `overwrite` or `doNothing`.
++
+With `addIfDifferentNeighbor`, a new trailer will be added only if no
+trailer with the same (<token>, <value>) pair is above or below the line
+where the new trailer will be added.
++
+With `addIfDifferent`, a new trailer will be added only if no trailer
+with the same (<token>, <value>) pair is already in the message.
++
+With `add`, a new trailer will be added, even if some trailers with
+the same (<token>, <value>) pair are already in the message.
++
+With `replace`, an existing trailer with the same <token> will be
+deleted and the new trailer will be added. The deleted trailer will be
+the closest one (with the same <token>) to the place where the new one
+will be added.
++
+With `doNothing`, nothing will be done; that is no new trailer will be
+added if there is already one with the same <token> in the message.
+
+trailer.ifmissing::
+       This option makes it possible to choose what action will be
+       performed when there is not yet any trailer with the same
+       <token> in the message.
++
+The valid values for this option are: `add` (this is the default) and
+`doNothing`.
++
+With `add`, a new trailer will be added.
++
+With `doNothing`, nothing will be done.
+
+trailer.<token>.key::
+       This `key` will be used instead of <token> in the trailer. At
+       the end of this key, a separator can appear and then some
+       space characters. By default the only valid separator is ':',
+       but this can be changed using the `trailer.separators` config
+       variable.
++
+If there is a separator, then the key will be used instead of both the
+<token> and the default separator when adding the trailer.
+
+trailer.<token>.where::
+       This option takes the same values as the 'trailer.where'
+       configuration variable and it overrides what is specified by
+       that option for trailers with the specified <token>.
+
+trailer.<token>.ifexist::
+       This option takes the same values as the 'trailer.ifexist'
+       configuration variable and it overrides what is specified by
+       that option for trailers with the specified <token>.
+
+trailer.<token>.ifmissing::
+       This option takes the same values as the 'trailer.ifmissing'
+       configuration variable and it overrides what is specified by
+       that option for trailers with the specified <token>.
+
+trailer.<token>.command::
+       This option can be used to specify a shell command that will
+       be called to automatically add or modify a trailer with the
+       specified <token>.
++
+When this option is specified, the behavior is as if a special
+'<token>=<value>' argument were added at the beginning of the command
+line, where <value> is taken to be the standard output of the
+specified command with any leading and trailing whitespace trimmed
+off.
++
+If the command contains the `$ARG` string, this string will be
+replaced with the <value> part of an existing trailer with the same
+<token>, if any, before the command is launched.
++
+If some '<token>=<value>' arguments are also passed on the command
+line, when a 'trailer.<token>.command' is configured, the command will
+also be executed for each of these arguments. And the <value> part of
+these arguments, if any, will be used to replace the `$ARG` string in
+the command.
+
+EXAMPLES
+--------
+
+* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
+  add two of these trailers to a message:
++
+------------
+$ git config trailer.sign.key "Signed-off-by"
+$ cat msg.txt
+subject
+
+message
+$ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
+subject
+
+message
+
+Signed-off-by: Alice <alice@example.com>
+Signed-off-by: Bob <bob@example.com>
+------------
+
+* Extract the last commit as a patch, and add a 'Cc' and a
+  'Reviewed-by' trailer to it:
++
+------------
+$ git format-patch -1
+0001-foo.patch
+$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
+------------
+
+* Configure a 'sign' trailer with a command to automatically add a
+  'Signed-off-by: ' with the author information only if there is no
+  'Signed-off-by: ' already, and show how it works:
++
+------------
+$ git config trailer.sign.key "Signed-off-by: "
+$ git config trailer.sign.ifmissing add
+$ git config trailer.sign.ifexists doNothing
+$ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
+$ git interpret-trailers <<EOF
+> EOF
+
+Signed-off-by: Bob <bob@example.com>
+$ git interpret-trailers <<EOF
+> Signed-off-by: Alice <alice@example.com>
+> EOF
+
+Signed-off-by: Alice <alice@example.com>
+------------
+
+* Configure a 'fix' trailer with a key that contains a '#' and no
+  space after this character, and show how it works:
++
+------------
+$ git config trailer.separators ":#"
+$ git config trailer.fix.key "Fix #"
+$ echo "subject" | git interpret-trailers --trailer fix=42
+subject
+
+Fix #42
+------------
+
+* Configure a 'see' trailer with a command to show the subject of a
+  commit that is related, and show how it works:
++
+------------
+$ git config trailer.see.key "See-also: "
+$ git config trailer.see.ifExists "replace"
+$ git config trailer.see.ifMissing "doNothing"
+$ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
+$ git interpret-trailers <<EOF
+> subject
+> 
+> message
+> 
+> see: HEAD~2
+> EOF
+subject
+
+message
+
+See-also: fe3187489d69c4 (subject of related commit)
+------------
+
+* Configure a commit template with some trailers with empty values
+  (using sed to show and keep the trailing spaces at the end of the
+  trailers), then configure a commit-msg hook that uses
+  'git interpret-trailers' to remove trailers with empty values and
+  to add a 'git-version' trailer:
++
+------------
+$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
+> ***subject***
+> 
+> ***message***
+> 
+> Fixes: Z
+> Cc: Z
+> Reviewed-by: Z
+> Signed-off-by: Z
+> EOF
+$ git config commit.template commit_template.txt
+$ cat >.git/hooks/commit-msg <<EOF
+> #!/bin/sh
+> git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
+> mv "\$1.new" "\$1"
+> EOF
+$ chmod +x .git/hooks/commit-msg
+------------
+
+SEE ALSO
+--------
+linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
+
+GIT
+---
+Part of the linkgit:git[1] suite
index 6738055bd3083825c06c82d1b7678ef453854253..9fed59a31724c4dccd7364c03c32c72d9c8d4664 100644 (file)
@@ -1,5 +1,5 @@
 git-prune-packed(1)
-=====================
+===================
 
 NAME
 ----
index b17283ab7a1cc73c5ec741e0da1128bea2a57a65..21b3f29c3bc603df74e07226d27ad63faa6fae24 100644 (file)
@@ -34,7 +34,7 @@ When the command line does not specify what to push with `<refspec>...`
 arguments or `--all`, `--mirror`, `--tags` options, the command finds
 the default `<refspec>` by consulting `remote.*.push` configuration,
 and if it is not found, honors `push.default` configuration to decide
-what to push (See linkgit:git-config[1] for the meaning of `push.default`).
+what to push (See gitlink:git-config[1] for the meaning of `push.default`).
 
 
 OPTIONS[[OPTIONS]]
index a356196586e2cfd472e1e087fb12e981b3a1480f..d64388cb8e454be17e4c20caf95897a71619c11f 100644 (file)
@@ -1,5 +1,5 @@
 git-quiltimport(1)
-================
+==================
 
 NAME
 ----
index ba3fe0d7f59b1ae4c9ae9e3d32675d2e281ccf13..25bcda936dbe8b171e0195a569d58ba8ce42e714 100644 (file)
@@ -1,5 +1,5 @@
 git-stage(1)
-==============
+============
 
 NAME
 ----
index c6175d45e4257efa96995853f00e42baf4b221f9..9e0a42ce5673c1fc11c311c63b5452181110fd8f 100644 (file)
@@ -22,7 +22,7 @@ unusually rich command set that provides both high-level operations
 and full access to internals.
 
 See linkgit:gittutorial[7] to get started, then see
-link:everyday.html[Everyday Git] for a useful minimum set of
+linkgit:giteveryday[7] for a useful minimum set of
 commands.  The link:user-manual.html[Git User's Manual] has a more
 in-depth introduction.
 
@@ -1098,7 +1098,7 @@ subscribed to the list to send a message there.
 SEE ALSO
 --------
 linkgit:gittutorial[7], linkgit:gittutorial-2[7],
-link:everyday.html[Everyday Git], linkgit:gitcvs-migration[7],
+linkgit:giteveryday[7], linkgit:gitcvs-migration[7],
 linkgit:gitglossary[7], linkgit:gitcore-tutorial[7],
 linkgit:gitcli[7], link:user-manual.html[The Git User's Manual],
 linkgit:gitworkflows[7]
index d2d7c213dd56f3886b7ab7e3651e1e80eec3b2ef..8475c079325103fe102027fccd5f5f02818667f3 100644 (file)
@@ -1667,7 +1667,7 @@ linkgit:gittutorial[7],
 linkgit:gittutorial-2[7],
 linkgit:gitcvs-migration[7],
 linkgit:git-help[1],
-link:everyday.html[Everyday git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 5f4e89005c5e554353920fe858bc74399e438a14..b06e852a85587ffd46820c9dfb832784cbf1dfd9 100644 (file)
@@ -194,7 +194,7 @@ linkgit:gittutorial[7],
 linkgit:gittutorial-2[7],
 linkgit:gitcore-tutorial[7],
 linkgit:gitglossary[7],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
diff --git a/Documentation/giteveryday.txt b/Documentation/giteveryday.txt
new file mode 100644 (file)
index 0000000..7be6e64
--- /dev/null
@@ -0,0 +1,455 @@
+giteveryday(7)
+===============
+
+NAME
+----
+giteveryday - A useful minimum set of commands for Everyday Git
+
+SYNOPSIS
+--------
+
+Everyday Git With 20 Commands Or So
+
+DESCRIPTION
+-----------
+
+Git users can broadly be grouped into four categories for the purposes of
+describing here a small set of useful command for everyday Git.
+
+*      <<STANDALONE,Individual Developer (Standalone)>> commands are essential
+       for anybody who makes a commit, even for somebody who works alone.
+
+*      If you work with other people, you will need commands listed in
+       the <<PARTICIPANT,Individual Developer (Participant)>> section as well.
+
+*      People who play the <<INTEGRATOR,Integrator>> role need to learn some
+       more commands in addition to the above.
+
+*      <<ADMINISTRATION,Repository Administration>> commands are for system
+       administrators who are responsible for the care and feeding
+       of Git repositories.
+
+
+Individual Developer (Standalone)[[STANDALONE]]
+-----------------------------------------------
+
+A standalone individual developer does not exchange patches with
+other people, and works alone in a single repository, using the
+following commands.
+
+  * linkgit:git-init[1] to create a new repository.
+
+  * linkgit:git-log[1] to see what happened.
+
+  * linkgit:git-checkout[1] and linkgit:git-branch[1] to switch
+    branches.
+
+  * linkgit:git-add[1] to manage the index file.
+
+  * linkgit:git-diff[1] and linkgit:git-status[1] to see what
+    you are in the middle of doing.
+
+  * linkgit:git-commit[1] to advance the current branch.
+
+  * linkgit:git-reset[1] and linkgit:git-checkout[1] (with
+    pathname parameters) to undo changes.
+
+  * linkgit:git-merge[1] to merge between local branches.
+
+  * linkgit:git-rebase[1] to maintain topic branches.
+
+  * linkgit:git-tag[1] to mark a known point.
+
+Examples
+~~~~~~~~
+
+Use a tarball as a starting point for a new repository.::
++
+------------
+$ tar zxf frotz.tar.gz
+$ cd frotz
+$ git init
+$ git add . <1>
+$ git commit -m "import of frotz source tree."
+$ git tag v2.43 <2>
+------------
++
+<1> add everything under the current directory.
+<2> make a lightweight, unannotated tag.
+
+Create a topic branch and develop.::
++
+------------
+$ git checkout -b alsa-audio <1>
+$ edit/compile/test
+$ git checkout -- curses/ux_audio_oss.c <2>
+$ git add curses/ux_audio_alsa.c <3>
+$ edit/compile/test
+$ git diff HEAD <4>
+$ git commit -a -s <5>
+$ edit/compile/test
+$ git diff HEAD^ <6>
+$ git commit -a --amend <7>
+$ git checkout master <8>
+$ git merge alsa-audio <9>
+$ git log --since='3 days ago' <10>
+$ git log v2.43.. curses/ <11>
+------------
++
+<1> create a new topic branch.
+<2> revert your botched changes in `curses/ux_audio_oss.c`.
+<3> you need to tell Git if you added a new file; removal and
+modification will be caught if you do `git commit -a` later.
+<4> to see what changes you are committing.
+<5> commit everything, as you have tested, with your sign-off.
+<6> look at all your changes including the previous commit.
+<7> amend the previous commit, adding all your new changes,
+using your original message.
+<8> switch to the master branch.
+<9> merge a topic branch into your master branch.
+<10> review commit logs; other forms to limit output can be
+combined and include `-10` (to show up to 10 commits),
+`--until=2005-12-10`, etc.
+<11> view only the changes that touch what's in `curses/`
+directory, since `v2.43` tag.
+
+
+Individual Developer (Participant)[[PARTICIPANT]]
+-------------------------------------------------
+
+A developer working as a participant in a group project needs to
+learn how to communicate with others, and uses these commands in
+addition to the ones needed by a standalone developer.
+
+  * linkgit:git-clone[1] from the upstream to prime your local
+    repository.
+
+  * linkgit:git-pull[1] and linkgit:git-fetch[1] from "origin"
+    to keep up-to-date with the upstream.
+
+  * linkgit:git-push[1] to shared repository, if you adopt CVS
+    style shared repository workflow.
+
+  * linkgit:git-format-patch[1] to prepare e-mail submission, if
+    you adopt Linux kernel-style public forum workflow.
+
+  * linkgit:git-send-email[1] to send your e-mail submission without
+    corruption by your MUA.
+
+  * linkgit:git-request-pull[1] to create a summary of changes
+    for your upstream to pull.
+
+
+Examples
+~~~~~~~~
+
+Clone the upstream and work on it.  Feed changes to upstream.::
++
+------------
+$ git clone git://git.kernel.org/pub/scm/.../torvalds/linux-2.6 my2.6
+$ cd my2.6
+$ git checkout -b mine master <1>
+$ edit/compile/test; git commit -a -s <2>
+$ git format-patch master <3>
+$ git send-email --to="person <email@example.com>" 00*.patch <4>
+$ git checkout master <5>
+$ git pull <6>
+$ git log -p ORIG_HEAD.. arch/i386 include/asm-i386 <7>
+$ git ls-remote --heads http://git.kernel.org/.../jgarzik/libata-dev.git <8>
+$ git pull git://git.kernel.org/pub/.../jgarzik/libata-dev.git ALL <9>
+$ git reset --hard ORIG_HEAD <10>
+$ git gc <11>
+------------
++
+<1> checkout a new branch `mine` from master.
+<2> repeat as needed.
+<3> extract patches from your branch, relative to master,
+<4> and email them.
+<5> return to `master`, ready to see what's new
+<6> `git pull` fetches from `origin` by default and merges into the
+current branch.
+<7> immediately after pulling, look at the changes done upstream
+since last time we checked, only in the
+area we are interested in.
+<8> check the branch names in an external repository (if not known).
+<9> fetch from a specific branch `ALL` from a specific repository
+and merge it.
+<10> revert the pull.
+<11> garbage collect leftover objects from reverted pull.
+
+
+Push into another repository.::
++
+------------
+satellite$ git clone mothership:frotz frotz <1>
+satellite$ cd frotz
+satellite$ git config --get-regexp '^(remote|branch)\.' <2>
+remote.origin.url mothership:frotz
+remote.origin.fetch refs/heads/*:refs/remotes/origin/*
+branch.master.remote origin
+branch.master.merge refs/heads/master
+satellite$ git config remote.origin.push \
+          +refs/heads/*:refs/remotes/satellite/* <3>
+satellite$ edit/compile/test/commit
+satellite$ git push origin <4>
+
+mothership$ cd frotz
+mothership$ git checkout master
+mothership$ git merge satellite/master <5>
+------------
++
+<1> mothership machine has a frotz repository under your home
+directory; clone from it to start a repository on the satellite
+machine.
+<2> clone sets these configuration variables by default.
+It arranges `git pull` to fetch and store the branches of mothership
+machine to local `remotes/origin/*` remote-tracking branches.
+<3> arrange `git push` to push all local branches to
+their corresponding branch of the mothership machine.
+<4> push will stash all our work away on `remotes/satellite/*`
+remote-tracking branches on the mothership machine.  You could use this
+as a back-up method. Likewise, you can pretend that mothership
+"fetched" from you (useful when access is one sided).
+<5> on mothership machine, merge the work done on the satellite
+machine into the master branch.
+
+Branch off of a specific tag.::
++
+------------
+$ git checkout -b private2.6.14 v2.6.14 <1>
+$ edit/compile/test; git commit -a
+$ git checkout master
+$ git cherry-pick v2.6.14..private2.6.14 <2>
+------------
++
+<1> create a private branch based on a well known (but somewhat behind)
+tag.
+<2> forward port all changes in `private2.6.14` branch to `master` branch
+without a formal "merging". Or longhand +
+`git format-patch -k -m --stdout v2.6.14..private2.6.14 |
+  git am -3 -k`
+
+An alternate participant submission mechanism is using the
+`git request-pull` or pull-request mechanisms (e.g as used on
+GitHub (www.github.com) to notify your upstream of your
+contribution.
+
+Integrator[[INTEGRATOR]]
+------------------------
+
+A fairly central person acting as the integrator in a group
+project receives changes made by others, reviews and integrates
+them and publishes the result for others to use, using these
+commands in addition to the ones needed by participants.
+
+This section can also be used by those who respond to `git
+request-pull` or pull-request on GitHub (www.github.com) to
+integrate the work of others into their history. An sub-area
+lieutenant for a repository will act both as a participant and
+as an integrator.
+
+
+  * linkgit:git-am[1] to apply patches e-mailed in from your
+    contributors.
+
+  * linkgit:git-pull[1] to merge from your trusted lieutenants.
+
+  * linkgit:git-format-patch[1] to prepare and send suggested
+    alternative to contributors.
+
+  * linkgit:git-revert[1] to undo botched commits.
+
+  * linkgit:git-push[1] to publish the bleeding edge.
+
+
+Examples
+~~~~~~~~
+
+A typical integrator's Git day.::
++
+------------
+$ git status <1>
+$ git branch --no-merged master <2>
+$ mailx <3>
+& s 2 3 4 5 ./+to-apply
+& s 7 8 ./+hold-linus
+& q
+$ git checkout -b topic/one master
+$ git am -3 -i -s ./+to-apply <4>
+$ compile/test
+$ git checkout -b hold/linus && git am -3 -i -s ./+hold-linus <5>
+$ git checkout topic/one && git rebase master <6>
+$ git checkout pu && git reset --hard next <7>
+$ git merge topic/one topic/two && git merge hold/linus <8>
+$ git checkout maint
+$ git cherry-pick master~4 <9>
+$ compile/test
+$ git tag -s -m "GIT 0.99.9x" v0.99.9x <10>
+$ git fetch ko && for branch in master maint next pu <11>
+    do
+       git show-branch ko/$branch $branch <12>
+    done
+$ git push --follow-tags ko <13>
+------------
++
+<1> see what you were in the middle of doing, if anything.
+<2> see which branches haven't been merged into `master` yet.
+Likewise for any other integration branches e.g. `maint`, `next`
+and `pu` (potential updates).
+<3> read mails, save ones that are applicable, and save others
+that are not quite ready (other mail readers are available).
+<4> apply them, interactively, with your sign-offs.
+<5> create topic branch as needed and apply, again with sign-offs.
+<6> rebase internal topic branch that has not been merged to the
+master or exposed as a part of a stable branch.
+<7> restart `pu` every time from the next.
+<8> and bundle topic branches still cooking.
+<9> backport a critical fix.
+<10> create a signed tag.
+<11> make sure master was not accidentally rewound beyond that
+already pushed out.  `ko` shorthand points at the Git maintainer's
+repository at kernel.org, and looks like this:
++
+------------
+(in .git/config)
+[remote "ko"]
+       url = kernel.org:/pub/scm/git/git.git
+       fetch = refs/heads/*:refs/remotes/ko/*
+       push = refs/heads/master
+       push = refs/heads/next
+       push = +refs/heads/pu
+       push = refs/heads/maint
+------------
++
+<12> In the output from `git show-branch`, `master` should have
+everything `ko/master` has, and `next` should have
+everything `ko/next` has, etc.
+<13> push out the bleeding edge, together with new tags that point
+into the pushed history.
+
+
+Repository Administration[[ADMINISTRATION]]
+-------------------------------------------
+
+A repository administrator uses the following tools to set up
+and maintain access to the repository by developers.
+
+  * linkgit:git-daemon[1] to allow anonymous download from
+    repository.
+
+  * linkgit:git-shell[1] can be used as a 'restricted login shell'
+    for shared central repository users.
+
+  * linkgit:git-http-backend[1] provides a server side implementation
+    of Git-over-HTTP ("Smart http") allowing both fetch and push services.
+
+  * linkgit:gitweb[1] provides a web front-end to Git repositories,
+    which can be set-up using the linkgit:git-instaweb[1] script.
+
+link:howto/update-hook-example.html[update hook howto] has a good
+example of managing a shared central repository.
+
+In addition there are a number of other widely deployed hosting, browsing
+and reviewing solutions such as:
+
+  * gitolite, gerrit code review, cgit and others.
+
+Examples
+~~~~~~~~
+We assume the following in /etc/services::
++
+------------
+$ grep 9418 /etc/services
+git            9418/tcp                # Git Version Control System
+------------
+
+Run git-daemon to serve /pub/scm from inetd.::
++
+------------
+$ grep git /etc/inetd.conf
+git    stream  tcp     nowait  nobody \
+  /usr/bin/git-daemon git-daemon --inetd --export-all /pub/scm
+------------
++
+The actual configuration line should be on one line.
+
+Run git-daemon to serve /pub/scm from xinetd.::
++
+------------
+$ cat /etc/xinetd.d/git-daemon
+# default: off
+# description: The Git server offers access to Git repositories
+service git
+{
+       disable = no
+       type            = UNLISTED
+       port            = 9418
+       socket_type     = stream
+       wait            = no
+       user            = nobody
+       server          = /usr/bin/git-daemon
+       server_args     = --inetd --export-all --base-path=/pub/scm
+       log_on_failure  += USERID
+}
+------------
++
+Check your xinetd(8) documentation and setup, this is from a Fedora system.
+Others might be different.
+
+Give push/pull only access to developers using git-over-ssh.::
+
+e.g. those using:
+`$ git push/pull ssh://host.xz/pub/scm/project`
++
+------------
+$ grep git /etc/passwd <1>
+alice:x:1000:1000::/home/alice:/usr/bin/git-shell
+bob:x:1001:1001::/home/bob:/usr/bin/git-shell
+cindy:x:1002:1002::/home/cindy:/usr/bin/git-shell
+david:x:1003:1003::/home/david:/usr/bin/git-shell
+$ grep git /etc/shells <2>
+/usr/bin/git-shell
+------------
++
+<1> log-in shell is set to /usr/bin/git-shell, which does not
+allow anything but `git push` and `git pull`.  The users require
+ssh access to the machine.
+<2> in many distributions /etc/shells needs to list what is used
+as the login shell.
+
+CVS-style shared repository.::
++
+------------
+$ grep git /etc/group <1>
+git:x:9418:alice,bob,cindy,david
+$ cd /home/devo.git
+$ ls -l <2>
+  lrwxrwxrwx   1 david git    17 Dec  4 22:40 HEAD -> refs/heads/master
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 branches
+  -rw-rw-r--   1 david git    84 Dec  4 22:40 config
+  -rw-rw-r--   1 david git    58 Dec  4 22:40 description
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 hooks
+  -rw-rw-r--   1 david git 37504 Dec  4 22:40 index
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 info
+  drwxrwsr-x   4 david git  4096 Dec  4 22:40 objects
+  drwxrwsr-x   4 david git  4096 Nov  7 14:58 refs
+  drwxrwsr-x   2 david git  4096 Dec  4 22:40 remotes
+$ ls -l hooks/update <3>
+  -r-xr-xr-x   1 david git  3536 Dec  4 22:40 update
+$ cat info/allowed-users <4>
+refs/heads/master      alice\|cindy
+refs/heads/doc-update  bob
+refs/tags/v[0-9]*      david
+------------
++
+<1> place the developers into the same git group.
+<2> and make the shared repository writable by the group.
+<3> use update-hook example by Carl from Documentation/howto/
+for branch policy control.
+<4> alice and cindy can push into master, only bob can push into doc-update.
+david is the release manager and is the only person who can
+create and push version tags.
+
+GIT
+---
+Part of the linkgit:git[1] suite
index e52de7dbb48ce84e3a82d84953a01bf0e6bfcdb4..212e254adc057fa3f67bc50cc23a995059a24585 100644 (file)
@@ -19,7 +19,7 @@ SEE ALSO
 linkgit:gittutorial[7],
 linkgit:gittutorial-2[7],
 linkgit:gitcvs-migration[7],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 3109ea8aade1ceb47de67823388d865a1505e616..f6fbf814fba14d230f623aa9b2e44a7bde88adbd 100644 (file)
@@ -403,7 +403,7 @@ What next?
 
 At this point you should know everything necessary to read the man
 pages for any of the git commands; one good place to start would be
-with the commands mentioned in link:everyday.html[Everyday Git].  You
+with the commands mentioned in linkgit:giteveryday[7].  You
 should be able to find any unknown jargon in linkgit:gitglossary[7].
 
 The link:user-manual.html[Git User's Manual] provides a more
@@ -427,7 +427,7 @@ linkgit:gitcvs-migration[7],
 linkgit:gitcore-tutorial[7],
 linkgit:gitglossary[7],
 linkgit:git-help[1],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 82621963189d1800087c8eca63add642c0743a96..af9f709ccf36b37ab4b143eaad218372af3e0ee4 100644 (file)
@@ -656,7 +656,7 @@ digressions that may be interesting at this point are:
   * linkgit:gitworkflows[7]: Gives an overview of recommended
     workflows.
 
-  * link:everyday.html[Everyday Git with 20 Commands Or So]
+  * linkgit:giteveryday[7]: Everyday Git with 20 Commands Or So.
 
   * linkgit:gitcvs-migration[7]: Git for CVS users.
 
@@ -668,7 +668,7 @@ linkgit:gitcore-tutorial[7],
 linkgit:gitglossary[7],
 linkgit:git-help[1],
 linkgit:gitworkflows[7],
-link:everyday.html[Everyday Git],
+linkgit:giteveryday[7],
 link:user-manual.html[The Git User's Manual]
 
 GIT
index 356feb5c86023d00a41ac8bca7d44f9779c39ad0..fcd51ac463a2f4ae2d748b30df36604d6190fb90 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -764,6 +764,7 @@ LIB_OBJS += submodule.o
 LIB_OBJS += symlinks.o
 LIB_OBJS += tag.o
 LIB_OBJS += trace.o
+LIB_OBJS += trailer.o
 LIB_OBJS += transport.o
 LIB_OBJS += transport-helper.o
 LIB_OBJS += tree-diff.o
@@ -828,6 +829,7 @@ BUILTIN_OBJS += builtin/hash-object.o
 BUILTIN_OBJS += builtin/help.o
 BUILTIN_OBJS += builtin/index-pack.o
 BUILTIN_OBJS += builtin/init-db.o
+BUILTIN_OBJS += builtin/interpret-trailers.o
 BUILTIN_OBJS += builtin/log.o
 BUILTIN_OBJS += builtin/ls-files.o
 BUILTIN_OBJS += builtin/ls-remote.o
diff --git a/README b/README
index 15a8e235012a247e6f22abd2c298a2e43c940c61..1083735d1cddaba394eb5c99ce470a31050dad4b 100644 (file)
--- a/README
+++ b/README
@@ -27,7 +27,7 @@ Torvalds with help of a group of hackers around the net.
 Please read the file INSTALL for installation instructions.
 
 See Documentation/gittutorial.txt to get started, then see
-Documentation/everyday.txt for a useful minimum set of commands, and
+Documentation/giteveryday.txt for a useful minimum set of commands, and
 Documentation/git-commandname.txt for documentation of each command.
 If git has been correctly installed, then the tutorial can also be
 read with "man gittutorial" or "git help tutorial", and the
index df2f4c8a643796ee96a31185f2a49fa7e00ca991..0d1e6bd7542dd7c76d2f349de0d0238a8d1b55af 100644 (file)
@@ -192,7 +192,7 @@ static int write_extended_header(struct archiver_args *args,
        unsigned int mode;
        memset(&header, 0, sizeof(header));
        *header.typeflag = TYPEFLAG_EXT_HEADER;
-       mode = 0100666 & ~tar_umask;
+       mode = 0100666;
        sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
        prepare_header(args, &header, mode, size);
        write_blocked(&header, sizeof(header));
@@ -300,7 +300,7 @@ static int write_global_extended_header(struct archiver_args *args)
        strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
        memset(&header, 0, sizeof(header));
        *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
-       mode = 0100666 & ~tar_umask;
+       mode = 0100666;
        strcpy(header.name, "pax_global_header");
        prepare_header(args, &header, mode, ext_header.len);
        write_blocked(&header, sizeof(header));
index 9a2228ebb46df721741db2249ab25cce5dfb4282..4bab55a9a85e187e2a3906312f1e771f4a214f45 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -170,7 +170,7 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
                const char *head;
                unsigned char sha1[20];
 
-               head = resolve_ref_unsafe("HEAD", sha1, 0, NULL);
+               head = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
                if (!is_bare_repository() && head && !strcmp(head, ref->buf))
                        die(_("Cannot force update the current branch."));
        }
@@ -285,8 +285,8 @@ void create_branch(const char *head,
                transaction = ref_transaction_begin(&err);
                if (!transaction ||
                    ref_transaction_update(transaction, ref.buf, sha1,
-                                          null_sha1, 0, !forcing, &err) ||
-                   ref_transaction_commit(transaction, msg, &err))
+                                          null_sha1, 0, !forcing, msg, &err) ||
+                   ref_transaction_commit(transaction, &err))
                        die("%s", err.buf);
                ref_transaction_free(transaction);
                strbuf_release(&err);
index 5d91f31ca25e0c16fca0e8c23d83706840bf6c57..b87df70f96d0f43e4b838f34d7492d116d4d97db 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -73,6 +73,7 @@ extern int cmd_hash_object(int argc, const char **argv, const char *prefix);
 extern int cmd_help(int argc, const char **argv, const char *prefix);
 extern int cmd_index_pack(int argc, const char **argv, const char *prefix);
 extern int cmd_init_db(int argc, const char **argv, const char *prefix);
+extern int cmd_interpret_trailers(int argc, const char **argv, const char *prefix);
 extern int cmd_log(int argc, const char **argv, const char *prefix);
 extern int cmd_log_reflog(int argc, const char **argv, const char *prefix);
 extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
index 3838be2b0274fbd72b200c2bf294e4d2842a020c..303e217ae919f21aa4d4574bd1720b5f4d635c32 100644 (file)
@@ -2286,7 +2286,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
        commit->date = now;
        parent_tail = &commit->parents;
 
-       if (!resolve_ref_unsafe("HEAD", head_sha1, 1, NULL))
+       if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
                die("no such ref: HEAD");
 
        parent_tail = append_parent(parent_tail, head_sha1);
index 67850975e7bebbf122ec961a527497c40c2c3f27..3b79c5087fbf1157d1bdfa2cccc99547f8abdb09 100644 (file)
@@ -62,19 +62,19 @@ static unsigned char merge_filter_ref[20];
 static struct string_list output = STRING_LIST_INIT_DUP;
 static unsigned int colopts;
 
-static int parse_branch_color_slot(const char *var, int ofs)
+static int parse_branch_color_slot(const char *slot)
 {
-       if (!strcasecmp(var+ofs, "plain"))
+       if (!strcasecmp(slot, "plain"))
                return BRANCH_COLOR_PLAIN;
-       if (!strcasecmp(var+ofs, "reset"))
+       if (!strcasecmp(slot, "reset"))
                return BRANCH_COLOR_RESET;
-       if (!strcasecmp(var+ofs, "remote"))
+       if (!strcasecmp(slot, "remote"))
                return BRANCH_COLOR_REMOTE;
-       if (!strcasecmp(var+ofs, "local"))
+       if (!strcasecmp(slot, "local"))
                return BRANCH_COLOR_LOCAL;
-       if (!strcasecmp(var+ofs, "current"))
+       if (!strcasecmp(slot, "current"))
                return BRANCH_COLOR_CURRENT;
-       if (!strcasecmp(var+ofs, "upstream"))
+       if (!strcasecmp(slot, "upstream"))
                return BRANCH_COLOR_UPSTREAM;
        return -1;
 }
@@ -90,13 +90,12 @@ static int git_branch_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (skip_prefix(var, "color.branch.", &slot_name)) {
-               int slot = parse_branch_color_slot(var, slot_name - var);
+               int slot = parse_branch_color_slot(slot_name);
                if (slot < 0)
                        return 0;
                if (!value)
                        return config_error_nonbool(var);
-               color_parse(value, var, branch_colors[slot]);
-               return 0;
+               return color_parse(value, branch_colors[slot]);
        }
        return git_color_default_config(var, value, cb);
 }
@@ -131,7 +130,8 @@ static int branch_merged(int kind, const char *name,
                    branch->merge[0] &&
                    branch->merge[0]->dst &&
                    (reference_name = reference_name_to_free =
-                    resolve_refdup(branch->merge[0]->dst, sha1, 1, NULL)) != NULL)
+                    resolve_refdup(branch->merge[0]->dst, RESOLVE_REF_READING,
+                                   sha1, NULL)) != NULL)
                        reference_rev = lookup_commit_reference(sha1);
        }
        if (!reference_rev)
@@ -235,9 +235,12 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                free(name);
 
                name = mkpathdup(fmt, bname.buf);
-               target = resolve_ref_unsafe(name, sha1, 0, &flags);
-               if (!target ||
-                   (!(flags & REF_ISSYMREF) && is_null_sha1(sha1))) {
+               target = resolve_ref_unsafe(name,
+                                           RESOLVE_REF_READING
+                                           | RESOLVE_REF_NO_RECURSE
+                                           | RESOLVE_REF_ALLOW_BAD_NAME,
+                                           sha1, &flags);
+               if (!target) {
                        error(remote_branch
                              ? _("remote branch '%s' not found.")
                              : _("branch '%s' not found."), bname.buf);
@@ -245,7 +248,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                        continue;
                }
 
-               if (!(flags & REF_ISSYMREF) &&
+               if (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
                    check_branch_commit(bname.buf, name, sha1, head_rev, kinds,
                                        force)) {
                        ret = 1;
@@ -265,8 +268,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                               ? _("Deleted remote branch %s (was %s).\n")
                               : _("Deleted branch %s (was %s).\n"),
                               bname.buf,
-                              (flags & REF_ISSYMREF)
-                              ? target
+                              (flags & REF_ISBROKEN) ? "broken"
+                              : (flags & REF_ISSYMREF) ? target
                               : find_unique_abbrev(sha1, DEFAULT_ABBREV));
                }
                delete_branch_config(bname.buf);
@@ -299,7 +302,7 @@ static char *resolve_symref(const char *src, const char *prefix)
        int flag;
        const char *dst;
 
-       dst = resolve_ref_unsafe(src, sha1, 0, &flag);
+       dst = resolve_ref_unsafe(src, 0, sha1, &flag);
        if (!(dst && (flag & REF_ISSYMREF)))
                return NULL;
        if (prefix)
@@ -869,7 +872,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 
        track = git_branch_track;
 
-       head = resolve_refdup("HEAD", head_sha1, 0, NULL);
+       head = resolve_refdup("HEAD", 0, head_sha1, NULL);
        if (!head)
                die(_("Failed to resolve HEAD as a valid ref."));
        if (!strcmp(head, "HEAD"))
index b4decd5b19c6ec9399f80c7a063343331fe8fd38..5410dacea0699f70cd942837394c06eac99873d1 100644 (file)
@@ -355,7 +355,7 @@ static int checkout_paths(const struct checkout_opts *opts,
        if (write_locked_index(&the_index, lock_file, COMMIT_LOCK))
                die(_("unable to write new index file"));
 
-       read_ref_full("HEAD", rev, 0, &flag);
+       read_ref_full("HEAD", 0, rev, &flag);
        head = lookup_commit_reference_gently(rev, 1);
 
        errs |= post_checkout_hook(head, head, 0);
@@ -775,7 +775,7 @@ static int switch_branches(const struct checkout_opts *opts,
        unsigned char rev[20];
        int flag, writeout_error = 0;
        memset(&old, 0, sizeof(old));
-       old.path = path_to_free = resolve_refdup("HEAD", rev, 0, &flag);
+       old.path = path_to_free = resolve_refdup("HEAD", 0, rev, &flag);
        old.commit = lookup_commit_reference_gently(rev, 1);
        if (!(flag & REF_ISSYMREF))
                old.path = NULL;
@@ -1072,7 +1072,7 @@ static int checkout_branch(struct checkout_opts *opts,
                unsigned char rev[20];
                int flag;
 
-               if (!read_ref_full("HEAD", rev, 0, &flag) &&
+               if (!read_ref_full("HEAD", 0, rev, &flag) &&
                    (flag & REF_ISSYMREF) && is_null_sha1(rev))
                        return switch_unborn_to_new_branch(opts);
        }
index c35505ee6b4030eedc61861081fd21e655b2b3e4..77846762b55bd42f4ab97823ee1b6850dff81714 100644 (file)
@@ -117,8 +117,7 @@ static int git_clean_config(const char *var, const char *value, void *cb)
                        return 0;
                if (!value)
                        return config_error_nonbool(var);
-               color_parse(value, var, clean_colors[slot]);
-               return 0;
+               return color_parse(value, clean_colors[slot]);
        }
 
        if (!strcmp(var, "clean.requireforce")) {
index d3bf9532d60fd52dfb440fc991e91544e8353fbe..7f509d06a81dca46ceeba0b15c48453c9a20fe6f 100644 (file)
@@ -623,7 +623,7 @@ static int checkout(void)
        if (option_no_checkout)
                return 0;
 
-       head = resolve_refdup("HEAD", sha1, 1, NULL);
+       head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL);
        if (!head) {
                warning(_("remote HEAD refers to nonexistent ref, "
                          "unable to checkout.\n"));
index 81dc622a3b72040daca199f05d0a3322f316e6f6..e108c5301564a86d396d72169f40cd24a9916a1f 100644 (file)
@@ -1272,22 +1272,21 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
        return commitable ? 0 : 1;
 }
 
-static int parse_status_slot(const char *var, int offset)
+static int parse_status_slot(const char *slot)
 {
-       if (!strcasecmp(var+offset, "header"))
+       if (!strcasecmp(slot, "header"))
                return WT_STATUS_HEADER;
-       if (!strcasecmp(var+offset, "branch"))
+       if (!strcasecmp(slot, "branch"))
                return WT_STATUS_ONBRANCH;
-       if (!strcasecmp(var+offset, "updated")
-               || !strcasecmp(var+offset, "added"))
+       if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added"))
                return WT_STATUS_UPDATED;
-       if (!strcasecmp(var+offset, "changed"))
+       if (!strcasecmp(slot, "changed"))
                return WT_STATUS_CHANGED;
-       if (!strcasecmp(var+offset, "untracked"))
+       if (!strcasecmp(slot, "untracked"))
                return WT_STATUS_UNTRACKED;
-       if (!strcasecmp(var+offset, "nobranch"))
+       if (!strcasecmp(slot, "nobranch"))
                return WT_STATUS_NOBRANCH;
-       if (!strcasecmp(var+offset, "unmerged"))
+       if (!strcasecmp(slot, "unmerged"))
                return WT_STATUS_UNMERGED;
        return -1;
 }
@@ -1327,13 +1326,12 @@ static int git_status_config(const char *k, const char *v, void *cb)
        }
        if (skip_prefix(k, "status.color.", &slot_name) ||
            skip_prefix(k, "color.status.", &slot_name)) {
-               int slot = parse_status_slot(k, slot_name - k);
+               int slot = parse_status_slot(slot_name);
                if (slot < 0)
                        return 0;
                if (!v)
                        return config_error_nonbool(k);
-               color_parse(v, k, s->color_palette[slot]);
-               return 0;
+               return color_parse(v, s->color_palette[slot]);
        }
        if (!strcmp(k, "status.relativepaths")) {
                s->relative_paths = git_config_bool(k, v);
@@ -1515,7 +1513,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
        rev.diffopt.break_opt = 0;
        diff_setup_done(&rev.diffopt);
 
-       head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
+       head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL);
        if (!strcmp(head, "HEAD"))
                head = _("detached HEAD");
        else
@@ -1811,8 +1809,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
            ref_transaction_update(transaction, "HEAD", sha1,
                                   current_head
                                   ? current_head->object.sha1 : NULL,
-                                  0, !!current_head, &err) ||
-           ref_transaction_commit(transaction, sb.buf, &err)) {
+                                  0, !!current_head, sb.buf, &err) ||
+           ref_transaction_commit(transaction, &err)) {
                rollback_index_files();
                die("%s", err.buf);
        }
index 37305e93e937ade83072501df6b5d07033ee89d3..8cc2604069cd008297081988ac807412ba9901a7 100644 (file)
@@ -296,7 +296,8 @@ static int git_get_color_config(const char *var, const char *value, void *cb)
        if (!strcmp(var, get_color_slot)) {
                if (!value)
                        config_error_nonbool(var);
-               color_parse(value, var, parsed_color);
+               if (color_parse(value, parsed_color) < 0)
+                       return -1;
                get_color_found = 1;
        }
        return 0;
@@ -309,8 +310,10 @@ static void get_color(const char *def_color)
        git_config_with_options(git_get_color_config, NULL,
                                &given_config_source, respect_includes);
 
-       if (!get_color_found && def_color)
-               color_parse(def_color, "command line", parsed_color);
+       if (!get_color_found && def_color) {
+               if (color_parse(def_color, parsed_color) < 0)
+                       die(_("unable to parse default color value"));
+       }
 
        fputs(parsed_color, stdout);
 }
index 159fb7e91614253cf7820b0c4cd7d07407c76762..6ffd02388b732c270cf9abef0c310d7855a69de8 100644 (file)
@@ -404,23 +404,37 @@ static int s_update_ref(const char *action,
 {
        char msg[1024];
        char *rla = getenv("GIT_REFLOG_ACTION");
-       static struct ref_lock *lock;
+       struct ref_transaction *transaction;
+       struct strbuf err = STRBUF_INIT;
+       int ret, df_conflict = 0;
 
        if (dry_run)
                return 0;
        if (!rla)
                rla = default_rla.buf;
        snprintf(msg, sizeof(msg), "%s: %s", rla, action);
-       lock = lock_any_ref_for_update(ref->name,
-                                      check_old ? ref->old_sha1 : NULL,
-                                      0, NULL);
-       if (!lock)
-               return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
-                                         STORE_REF_ERROR_OTHER;
-       if (write_ref_sha1(lock, ref->new_sha1, msg) < 0)
-               return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
-                                         STORE_REF_ERROR_OTHER;
+
+       transaction = ref_transaction_begin(&err);
+       if (!transaction ||
+           ref_transaction_update(transaction, ref->name, ref->new_sha1,
+                                  ref->old_sha1, 0, check_old, msg, &err))
+               goto fail;
+
+       ret = ref_transaction_commit(transaction, &err);
+       if (ret) {
+               df_conflict = (ret == TRANSACTION_NAME_CONFLICT);
+               goto fail;
+       }
+
+       ref_transaction_free(transaction);
+       strbuf_release(&err);
        return 0;
+fail:
+       ref_transaction_free(transaction);
+       error("%s", err.buf);
+       strbuf_release(&err);
+       return df_conflict ? STORE_REF_ERROR_DF_CONFLICT
+                          : STORE_REF_ERROR_OTHER;
 }
 
 #define REFCOL_WIDTH  10
index 79df05ef526bcd1a3be2971c9d467a930001639d..37177c6c2928b926cf55cacfdcfcf033bf012e80 100644 (file)
@@ -602,7 +602,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
 
        /* get current branch */
        current_branch = current_branch_to_free =
-               resolve_refdup("HEAD", head_sha1, 1, NULL);
+               resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
        if (!current_branch)
                die("No current branch");
        if (starts_with(current_branch, "refs/heads/"))
index fda0f047125f16f080288c1cda76b0e337784a54..603a90e29b808a86fa39f031d13a1ca94f5d236e 100644 (file)
@@ -635,7 +635,8 @@ static void populate_value(struct refinfo *ref)
 
        if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
                unsigned char unused1[20];
-               ref->symref = resolve_refdup(ref->refname, unused1, 1, NULL);
+               ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
+                                            unused1, NULL);
                if (!ref->symref)
                        ref->symref = "";
        }
@@ -671,7 +672,8 @@ static void populate_value(struct refinfo *ref)
                } else if (starts_with(name, "color:")) {
                        char color[COLOR_MAXLEN] = "";
 
-                       color_parse(name + 6, "--format", color);
+                       if (color_parse(name + 6, color) < 0)
+                               die(_("unable to parse format"));
                        v->s = xstrdup(color);
                        continue;
                } else if (!strcmp(name, "flag")) {
@@ -693,7 +695,8 @@ static void populate_value(struct refinfo *ref)
                        const char *head;
                        unsigned char sha1[20];
 
-                       head = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
+                       head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
+                                                 sha1, NULL);
                        if (!strcmp(ref->refname, head))
                                v->s = "*";
                        else
@@ -837,6 +840,11 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
        struct refinfo *ref;
        int cnt;
 
+       if (flag & REF_BAD_NAME) {
+                 warning("ignoring ref with broken name %s", refname);
+                 return 0;
+       }
+
        if (*cb->grab_pattern) {
                const char **pattern;
                int namelen = strlen(refname);
@@ -1004,7 +1012,8 @@ static void show_ref(struct refinfo *info, const char *format, int quote_style)
                struct atom_value resetv;
                char color[COLOR_MAXLEN] = "";
 
-               color_parse("reset", "--format", color);
+               if (color_parse("reset", color) < 0)
+                       die("BUG: couldn't parse 'reset' as a color");
                resetv.s = color;
                print_value(&resetv, quote_style);
        }
index e9ba576c1fe85cab505eb13fc20ae68dcfc19ff3..a27515aeaa2debabdb14a03d271fe423d13b19d2 100644 (file)
@@ -556,7 +556,7 @@ static int fsck_head_link(void)
        if (verbose)
                fprintf(stderr, "Checking HEAD link\n");
 
-       head_points_at = resolve_ref_unsafe("HEAD", head_sha1, 0, &flag);
+       head_points_at = resolve_ref_unsafe("HEAD", 0, head_sha1, &flag);
        if (!head_points_at)
                return error("Invalid HEAD");
        if (!strcmp(head_points_at, "HEAD"))
index 8343b4027d458d77a720f79d64c9a4c116208f84..b3c818ee01b6f64c7cf00f2e58d372f4dc8f0250 100644 (file)
@@ -421,6 +421,7 @@ static struct {
        const char *help;
 } common_guides[] = {
        { "attributes", N_("Defining attributes per path") },
+       { "everyday", N_("Everyday Git With 20 Commands Or So") },
        { "glossary", N_("A Git glossary") },
        { "ignore", N_("Specifies intentionally untracked files to ignore") },
        { "modules", N_("Defining submodule properties") },
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c
new file mode 100644 (file)
index 0000000..46838d2
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Builtin "git interpret-trailers"
+ *
+ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
+ *
+ */
+
+#include "cache.h"
+#include "builtin.h"
+#include "parse-options.h"
+#include "string-list.h"
+#include "trailer.h"
+
+static const char * const git_interpret_trailers_usage[] = {
+       N_("git interpret-trailers [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]"),
+       NULL
+};
+
+int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
+{
+       int trim_empty = 0;
+       struct string_list trailers = STRING_LIST_INIT_DUP;
+
+       struct option options[] = {
+               OPT_BOOL(0, "trim-empty", &trim_empty, N_("trim empty trailers")),
+               OPT_STRING_LIST(0, "trailer", &trailers, N_("trailer"),
+                               N_("trailer(s) to add")),
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix, options,
+                            git_interpret_trailers_usage, 0);
+
+       if (argc) {
+               int i;
+               for (i = 0; i < argc; i++)
+                       process_trailers(argv[i], trim_empty, &trailers);
+       } else
+               process_trailers(NULL, trim_empty, &trailers);
+
+       string_list_clear(&trailers, 0);
+
+       return 0;
+}
index 1202eba8b65c019662c5f6b82c13af947bd4d41c..734aab3a73185964d18c82fe5eb31008bbc409b7 100644 (file)
@@ -391,7 +391,7 @@ static int git_log_config(const char *var, const char *value, void *cb)
                return 0;
        }
        if (skip_prefix(var, "color.decorate.", &slot_name))
-               return parse_decorate_color_config(var, slot_name - var, value);
+               return parse_decorate_color_config(var, slot_name, value);
        if (!strcmp(var, "log.mailmap")) {
                use_mailmap_config = git_config_bool(var, value);
                return 0;
@@ -1400,7 +1400,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                if (check_head) {
                        unsigned char sha1[20];
                        const char *ref, *v;
-                       ref = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
+                       ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
+                                                sha1, NULL);
                        if (ref && skip_prefix(ref, "refs/heads/", &v))
                                branch_name = xstrdup(v);
                        else
index 4513fadc5fc3c631591d1a9b65ec939ada5d2de3..bebbe5b3081ebe2602abaf0dc9508a1342f01086 100644 (file)
@@ -1101,7 +1101,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * Check if we are _not_ on a detached HEAD, i.e. if there is a
         * current branch.
         */
-       branch = branch_to_free = resolve_refdup("HEAD", head_sha1, 0, &flag);
+       branch = branch_to_free = resolve_refdup("HEAD", 0, head_sha1, &flag);
        if (branch && starts_with(branch, "refs/heads/"))
                branch += 11;
        if (!branch || is_null_sha1(head_sha1))
index 67d0bb14f8f18003d6a073b0c264f5b46ca12685..68b6cd8cc1ded390df592e1c6536d70bf1ffc8a0 100644 (file)
@@ -702,7 +702,7 @@ static int merge_commit(struct notes_merge_options *o)
        init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
 
        o->local_ref = local_ref_to_free =
-               resolve_refdup("NOTES_MERGE_REF", sha1, 0, NULL);
+               resolve_refdup("NOTES_MERGE_REF", 0, sha1, NULL);
        if (!o->local_ref)
                die("Failed to resolve NOTES_MERGE_REF");
 
index f2f6c67359cb5941c2d57b6692ce1fbbc86edccc..916315ff5c2f08bed1e52c8188939405c0b7a0e1 100644 (file)
@@ -842,8 +842,9 @@ static const char *update(struct command *cmd, struct shallow_info *si)
                transaction = ref_transaction_begin(&err);
                if (!transaction ||
                    ref_transaction_update(transaction, namespaced_name,
-                                          new_sha1, old_sha1, 0, 1, &err) ||
-                   ref_transaction_commit(transaction, "push", &err)) {
+                                          new_sha1, old_sha1, 0, 1, "push",
+                                          &err) ||
+                   ref_transaction_commit(transaction, &err)) {
                        ref_transaction_free(transaction);
 
                        rp_error("%s", err.buf);
@@ -908,7 +909,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
        int flag;
 
        strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
-       dst_name = resolve_ref_unsafe(buf.buf, sha1, 0, &flag);
+       dst_name = resolve_ref_unsafe(buf.buf, 0, sha1, &flag);
        strbuf_release(&buf);
 
        if (!(flag & REF_ISSYMREF))
@@ -1069,7 +1070,7 @@ static void execute_commands(struct command *commands,
        check_aliased_updates(commands);
 
        free(head_name_to_free);
-       head_name = head_name_to_free = resolve_refdup("HEAD", sha1, 0, NULL);
+       head_name = head_name_to_free = resolve_refdup("HEAD", 0, sha1, NULL);
 
        checked_connectivity = 1;
        for (cmd = commands; cmd; cmd = cmd->next) {
@@ -1230,7 +1231,6 @@ static const char *pack_lockfile;
 static const char *unpack(int err_fd, struct shallow_info *si)
 {
        struct pack_header hdr;
-       struct argv_array av = ARGV_ARRAY_INIT;
        const char *hdr_err;
        int status;
        char hdr_arg[38];
@@ -1253,16 +1253,16 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 
        if (si->nr_ours || si->nr_theirs) {
                alt_shallow_file = setup_temporary_shallow(si->shallow);
-               argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL);
+               argv_array_push(&child.args, "--shallow-file");
+               argv_array_push(&child.args, alt_shallow_file);
        }
 
        if (ntohl(hdr.hdr_entries) < unpack_limit) {
-               argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL);
+               argv_array_pushl(&child.args, "unpack-objects", hdr_arg, NULL);
                if (quiet)
-                       argv_array_push(&av, "-q");
+                       argv_array_push(&child.args, "-q");
                if (fsck_objects)
-                       argv_array_push(&av, "--strict");
-               child.argv = av.argv;
+                       argv_array_push(&child.args, "--strict");
                child.no_stdout = 1;
                child.err = err_fd;
                child.git_cmd = 1;
@@ -1277,13 +1277,12 @@ static const char *unpack(int err_fd, struct shallow_info *si)
                if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
                        strcpy(keep_arg + s, "localhost");
 
-               argv_array_pushl(&av, "index-pack",
+               argv_array_pushl(&child.args, "index-pack",
                                 "--stdin", hdr_arg, keep_arg, NULL);
                if (fsck_objects)
-                       argv_array_push(&av, "--strict");
+                       argv_array_push(&child.args, "--strict");
                if (fix_thin)
-                       argv_array_push(&av, "--fix-thin");
-               child.argv = av.argv;
+                       argv_array_push(&child.args, "--fix-thin");
                child.out = -1;
                child.err = err_fd;
                child.git_cmd = 1;
index 9a4640dbf0150bff38efcbb0126abdf1aeae7ed4..7f28f92a378a4e89d8c938beac23cbe053f1ce33 100644 (file)
@@ -567,7 +567,8 @@ static int read_remote_branches(const char *refname,
        strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
        if (starts_with(refname, buf.buf)) {
                item = string_list_append(rename->remote_branches, xstrdup(refname));
-               symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
+               symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
+                                           orig_sha1, &flag);
                if (flag & REF_ISSYMREF)
                        item->util = xstrdup(symref);
                else
@@ -703,7 +704,7 @@ static int mv(int argc, const char **argv)
                int flag = 0;
                unsigned char sha1[20];
 
-               read_ref_full(item->string, sha1, 1, &flag);
+               read_ref_full(item->string, RESOLVE_REF_READING, sha1, &flag);
                if (!(flag & REF_ISSYMREF))
                        continue;
                if (delete_ref(item->string, NULL, REF_NODEREF))
@@ -748,13 +749,16 @@ static int mv(int argc, const char **argv)
 
 static int remove_branches(struct string_list *branches)
 {
+       struct strbuf err = STRBUF_INIT;
        const char **branch_names;
        int i, result = 0;
 
        branch_names = xmalloc(branches->nr * sizeof(*branch_names));
        for (i = 0; i < branches->nr; i++)
                branch_names[i] = branches->items[i].string;
-       result |= repack_without_refs(branch_names, branches->nr, NULL);
+       if (repack_without_refs(branch_names, branches->nr, &err))
+               result |= error("%s", err.buf);
+       strbuf_release(&err);
        free(branch_names);
 
        for (i = 0; i < branches->nr; i++) {
@@ -1331,9 +1335,13 @@ static int prune_remote(const char *remote, int dry_run)
                delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));
                for (i = 0; i < states.stale.nr; i++)
                        delete_refs[i] = states.stale.items[i].util;
-               if (!dry_run)
-                       result |= repack_without_refs(delete_refs,
-                                                     states.stale.nr, NULL);
+               if (!dry_run) {
+                       struct strbuf err = STRBUF_INIT;
+                       if (repack_without_refs(delete_refs, states.stale.nr,
+                                               &err))
+                               result |= error("%s", err.buf);
+                       strbuf_release(&err);
+               }
                free(delete_refs);
        }
 
index 8020db850092691f55df3815173a6eefce0ca6a0..85d39b58d8aa35f0cd644273821ffd047ac50df0 100644 (file)
@@ -171,8 +171,9 @@ static int replace_object_sha1(const char *object_ref,
 
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
-           ref_transaction_update(transaction, ref, repl, prev, 0, 1, &err) ||
-           ref_transaction_commit(transaction, NULL, &err))
+           ref_transaction_update(transaction, ref, repl, prev,
+                                  0, 1, NULL, &err) ||
+           ref_transaction_commit(transaction, &err))
                die("%s", err.buf);
 
        ref_transaction_free(transaction);
index 199b081e9b805cceb1f2097f2d33966e5f8ff167..270e39c6c1b0855181a19b12739425035db9ad1d 100644 (file)
@@ -728,7 +728,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                if (ac == 0) {
                        static const char *fake_av[2];
 
-                       fake_av[0] = resolve_refdup("HEAD", sha1, 1, NULL);
+                       fake_av[0] = resolve_refdup("HEAD",
+                                                   RESOLVE_REF_READING,
+                                                   sha1, NULL);
                        fake_av[1] = NULL;
                        av = fake_av;
                        ac = 1;
@@ -789,7 +791,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
                }
        }
 
-       head_p = resolve_ref_unsafe("HEAD", head_sha1, 1, NULL);
+       head_p = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
+                                   head_sha1, NULL);
        if (head_p) {
                head_len = strlen(head_p);
                memcpy(head, head_p, head_len + 1);
index b6a711d3191a729e5f07aae20e3fc5343148c9b2..29fb3f1c201682674f8a473c235dd2f1f539f287 100644 (file)
@@ -13,7 +13,7 @@ static int check_symref(const char *HEAD, int quiet, int shorten, int print)
 {
        unsigned char sha1[20];
        int flag;
-       const char *refname = resolve_ref_unsafe(HEAD, sha1, 0, &flag);
+       const char *refname = resolve_ref_unsafe(HEAD, 0, sha1, &flag);
 
        if (!refname)
                die("No such ref: %s", HEAD);
index a81b9e4174c77fc10d9f0a37c547723505208c3c..e633f4efdbb8963449fddb5c3357fa657283430e 100644 (file)
@@ -733,8 +733,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_update(transaction, ref.buf, object, prev,
-                                  0, 1, &err) ||
-           ref_transaction_commit(transaction, NULL, &err))
+                                  0, 1, NULL, &err) ||
+           ref_transaction_commit(transaction, &err))
                die("%s", err.buf);
        ref_transaction_free(transaction);
        if (force && !is_null_sha1(prev) && hashcmp(prev, object))
index 54a48c0cfaab57122fc7ce57c525638c2c95408c..6c9be051284a78cbdbe6630dbcaae4846288c667 100644 (file)
@@ -14,6 +14,7 @@ static const char * const git_update_ref_usage[] = {
 
 static char line_termination = '\n';
 static int update_flags;
+static const char *msg;
 
 /*
  * Parse one whitespace- or NUL-terminated, possibly C-quoted argument
@@ -198,7 +199,7 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
                die("update %s: extra input: %s", refname, next);
 
        if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
-                                  update_flags, have_old, &err))
+                                  update_flags, have_old, msg, &err))
                die("%s", err.buf);
 
        update_flags = 0;
@@ -229,7 +230,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
                die("create %s: extra input: %s", refname, next);
 
        if (ref_transaction_create(transaction, refname, new_sha1,
-                                  update_flags, &err))
+                                  update_flags, msg, &err))
                die("%s", err.buf);
 
        update_flags = 0;
@@ -264,7 +265,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
                die("delete %s: extra input: %s", refname, next);
 
        if (ref_transaction_delete(transaction, refname, old_sha1,
-                                  update_flags, have_old, &err))
+                                  update_flags, have_old, msg, &err))
                die("%s", err.buf);
 
        update_flags = 0;
@@ -300,7 +301,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
                die("verify %s: extra input: %s", refname, next);
 
        if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
-                                  update_flags, have_old, &err))
+                                  update_flags, have_old, msg, &err))
                die("%s", err.buf);
 
        update_flags = 0;
@@ -354,7 +355,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
 
 int cmd_update_ref(int argc, const char **argv, const char *prefix)
 {
-       const char *refname, *oldval, *msg = NULL;
+       const char *refname, *oldval;
        unsigned char sha1[20], oldsha1[20];
        int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0, flags = 0;
        struct option options[] = {
@@ -385,7 +386,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                if (end_null)
                        line_termination = '\0';
                update_refs_stdin(transaction);
-               if (ref_transaction_commit(transaction, msg, &err))
+               if (ref_transaction_commit(transaction, &err))
                        die("%s", err.buf);
                ref_transaction_free(transaction);
                strbuf_release(&err);
index 9a22ab5c02582fbdb3eb36f2142c03ce33bcfc95..fa67057e60fe638825cc80e65cb1fa0be5b26ed9 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -310,7 +310,7 @@ int create_bundle(struct bundle_header *header, const char *path,
                        continue;
                if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
                        continue;
-               if (read_ref_full(e->name, sha1, 1, &flag))
+               if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &flag))
                        flag = 0;
                display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
 
diff --git a/cache.h b/cache.h
index 5b8606581563584c2ff274089ad16429a81a1742..0501f7dca855b85f408bac32d4f457fdf799cae4 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -950,8 +950,8 @@ extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
 
 extern char *sha1_to_hex(const unsigned char *sha1);   /* static buffer result! */
-extern int read_ref_full(const char *refname, unsigned char *sha1,
-                        int reading, int *flags);
+extern int read_ref_full(const char *refname, int resolve_flags,
+                        unsigned char *sha1, int *flags);
 extern int read_ref(const char *refname, unsigned char *sha1);
 
 /*
@@ -963,29 +963,49 @@ extern int read_ref(const char *refname, unsigned char *sha1);
  * or the input ref.
  *
  * If the reference cannot be resolved to an object, the behavior
- * depends on the "reading" argument:
+ * depends on the RESOLVE_REF_READING flag:
  *
- * - If reading is set, return NULL.
+ * - If RESOLVE_REF_READING is set, return NULL.
  *
- * - If reading is not set, clear sha1 and return the name of the last
- *   reference name in the chain, which will either be a non-symbolic
+ * - If RESOLVE_REF_READING is not set, clear sha1 and return the name of
+ *   the last reference name in the chain, which will either be a non-symbolic
  *   reference or an undefined reference.  If this is a prelude to
  *   "writing" to the ref, the return value is the name of the ref
  *   that will actually be created or changed.
  *
- * If flag is non-NULL, set the value that it points to the
+ * If the RESOLVE_REF_NO_RECURSE flag is passed, only resolves one
+ * level of symbolic reference.  The value stored in sha1 for a symbolic
+ * reference will always be null_sha1 in this case, and the return
+ * value is the reference that the symref refers to directly.
+ *
+ * If flags is non-NULL, set the value that it points to the
  * combination of REF_ISPACKED (if the reference was found among the
- * packed references) and REF_ISSYMREF (if the initial reference was a
- * symbolic reference).
+ * packed references), REF_ISSYMREF (if the initial reference was a
+ * symbolic reference), REF_BAD_NAME (if the reference name is ill
+ * formed --- see RESOLVE_REF_ALLOW_BAD_NAME below), and REF_ISBROKEN
+ * (if the ref is malformed or has a bad name). See refs.h for more detail
+ * on each flag.
  *
  * If ref is not a properly-formatted, normalized reference, return
  * NULL.  If more than MAXDEPTH recursive symbolic lookups are needed,
  * give up and return NULL.
  *
- * errno is set to something meaningful on error.
+ * RESOLVE_REF_ALLOW_BAD_NAME allows resolving refs even when their
+ * name is invalid according to git-check-ref-format(1).  If the name
+ * is bad then the value stored in sha1 will be null_sha1 and the two
+ * flags REF_ISBROKEN and REF_BAD_NAME will be set.
+ *
+ * Even with RESOLVE_REF_ALLOW_BAD_NAME, names that escape the refs/
+ * directory and do not consist of all caps and underscores cannot be
+ * resolved. The function returns NULL for such ref names.
+ * Caps and underscores refers to the special refs, such as HEAD,
+ * FETCH_HEAD and friends, that all live outside of the refs/ directory.
  */
-extern const char *resolve_ref_unsafe(const char *ref, unsigned char *sha1, int reading, int *flag);
-extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag);
+#define RESOLVE_REF_READING 0x01
+#define RESOLVE_REF_NO_RECURSE 0x02
+#define RESOLVE_REF_ALLOW_BAD_NAME 0x04
+extern const char *resolve_ref_unsafe(const char *ref, int resolve_flags, unsigned char *sha1, int *flags);
+extern char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, int *flags);
 
 extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
 extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
diff --git a/color.c b/color.c
index f672885b71acef4108c8cefc9cf887c220f614d3..7941e932d2fb7cb0af5d15dcb2754bc8c96ec657 100644 (file)
--- a/color.c
+++ b/color.c
@@ -60,13 +60,12 @@ static int parse_attr(const char *name, int len)
        return -1;
 }
 
-void color_parse(const char *value, const char *var, char *dst)
+int color_parse(const char *value, char *dst)
 {
-       color_parse_mem(value, strlen(value), var, dst);
+       return color_parse_mem(value, strlen(value), dst);
 }
 
-void color_parse_mem(const char *value, int value_len, const char *var,
-               char *dst)
+int color_parse_mem(const char *value, int value_len, char *dst)
 {
        const char *ptr = value;
        int len = value_len;
@@ -76,7 +75,7 @@ void color_parse_mem(const char *value, int value_len, const char *var,
 
        if (!strncasecmp(value, "reset", len)) {
                strcpy(dst, GIT_COLOR_RESET);
-               return;
+               return 0;
        }
 
        /* [fg [bg]] [attr]... */
@@ -153,9 +152,9 @@ void color_parse_mem(const char *value, int value_len, const char *var,
                *dst++ = 'm';
        }
        *dst = 0;
-       return;
+       return 0;
 bad:
-       die("bad color value '%.*s' for variable '%s'", value_len, value, var);
+       return error(_("invalid color value: %.*s"), value_len, value);
 }
 
 int git_config_colorbool(const char *var, const char *value)
diff --git a/color.h b/color.h
index 9a8495bb7ff06eb4e94e190d902b48c23fc021f9..f5beab1ed782549eb08ad11392ed8e6331bdd653 100644 (file)
--- a/color.h
+++ b/color.h
@@ -77,8 +77,8 @@ int git_color_default_config(const char *var, const char *value, void *cb);
 
 int git_config_colorbool(const char *var, const char *value);
 int want_color(int var);
-void color_parse(const char *value, const char *var, char *dst);
-void color_parse_mem(const char *value, int len, const char *var, char *dst);
+int color_parse(const char *value, char *dst);
+int color_parse_mem(const char *value, int len, char *dst);
 __attribute__((format (printf, 3, 4)))
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
 __attribute__((format (printf, 3, 4)))
index a3ff0c9e60148e6dc98a6bd0d71d98cba4a7eae2..f1eae0810de9d7e405759190221742534c293745 100644 (file)
@@ -62,6 +62,7 @@ git-imap-send                           foreignscminterface
 git-index-pack                          plumbingmanipulators
 git-init                                mainporcelain common
 git-instaweb                            ancillaryinterrogators
+git-interpret-trailers                  purehelpers
 gitk                                    mainporcelain
 git-log                                 mainporcelain common
 git-ls-files                            plumbinginterrogators
index 80e422f9d933307cac43572828c49de6feb0e03e..8704451e52e9ed4239ec7a8e96d3fd8e6be4cb01 100644 (file)
@@ -281,16 +281,12 @@ __gitcomp_file ()
 # argument, and using the options specified in the second argument.
 __git_ls_files_helper ()
 {
-       (
-               test -n "${CDPATH+set}" && unset CDPATH
-               cd "$1"
-               if [ "$2" == "--committable" ]; then
-                       git diff-index --name-only --relative HEAD
-               else
-                       # NOTE: $2 is not quoted in order to support multiple options
-                       git ls-files --exclude-standard $2
-               fi
-       ) 2>/dev/null
+       if [ "$2" == "--committable" ]; then
+               git -C "$1" diff-index --name-only --relative HEAD
+       else
+               # NOTE: $2 is not quoted in order to support multiple options
+               git -C "$1" ls-files --exclude-standard $2
+       fi 2>/dev/null
 }
 
 
@@ -523,7 +519,7 @@ __git_complete_index_file ()
                ;;
        esac
 
-       __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
+       __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_"
 }
 
 __git_complete_file ()
diff --git a/contrib/contacts/.gitignore b/contrib/contacts/.gitignore
new file mode 100644 (file)
index 0000000..f385ee6
--- /dev/null
@@ -0,0 +1,3 @@
+git-contacts.1
+git-contacts.html
+git-contacts.xml
diff --git a/contrib/contacts/Makefile b/contrib/contacts/Makefile
new file mode 100644 (file)
index 0000000..a2990f0
--- /dev/null
@@ -0,0 +1,71 @@
+# The default target of this Makefile is...
+all::
+
+-include ../../config.mak.autogen
+-include ../../config.mak
+
+prefix ?= /usr/local
+gitexecdir ?= $(prefix)/libexec/git-core
+mandir ?= $(prefix)/share/man
+man1dir ?= $(mandir)/man1
+htmldir ?= $(prefix)/share/doc/git-doc
+
+../../GIT-VERSION-FILE: FORCE
+       $(MAKE) -C ../../ GIT-VERSION-FILE
+
+-include ../../GIT-VERSION-FILE
+
+# this should be set to a 'standard' bsd-type install program
+INSTALL  ?= install
+RM       ?= rm -f
+
+ASCIIDOC = asciidoc
+XMLTO    = xmlto
+
+ifndef SHELL_PATH
+       SHELL_PATH = /bin/sh
+endif
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+
+ASCIIDOC_CONF = ../../Documentation/asciidoc.conf
+MANPAGE_XSL   = ../../Documentation/manpage-normal.xsl
+
+GIT_CONTACTS := git-contacts
+
+GIT_CONTACTS_DOC := git-contacts.1
+GIT_CONTACTS_XML := git-contacts.xml
+GIT_CONTACTS_TXT := git-contacts.txt
+GIT_CONTACTS_HTML := git-contacts.html
+
+doc: $(GIT_CONTACTS_DOC) $(GIT_CONTACTS_HTML)
+
+install: $(GIT_CONTACTS)
+       $(INSTALL) -d -m 755 $(DESTDIR)$(gitexecdir)
+       $(INSTALL) -m 755 $(GIT_CONTACTS) $(DESTDIR)$(gitexecdir)
+
+install-doc: install-man install-html
+
+install-man: $(GIT_CONTACTS_DOC)
+       $(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)
+       $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
+
+install-html: $(GIT_CONTACTS_HTML)
+       $(INSTALL) -d -m 755 $(DESTDIR)$(htmldir)
+       $(INSTALL) -m 644 $^ $(DESTDIR)$(htmldir)
+
+$(GIT_CONTACTS_DOC): $(GIT_CONTACTS_XML)
+       $(XMLTO) -m $(MANPAGE_XSL) man $^
+
+$(GIT_CONTACTS_XML): $(GIT_CONTACTS_TXT)
+       $(ASCIIDOC) -b docbook -d manpage -f $(ASCIIDOC_CONF) \
+               -agit_version=$(GIT_VERSION) $^
+
+$(GIT_CONTACTS_HTML): $(GIT_CONTACTS_TXT)
+       $(ASCIIDOC) -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \
+               -agit_version=$(GIT_VERSION) $^
+
+clean:
+       $(RM) $(GIT_CONTACTS)
+       $(RM) *.xml *.html *.1
+
+.PHONY: FORCE
index 91360a3d7f0ad2d589dfe0365d4456d56853e7c0..0b9381abcad34e79a1cdfa129bb9b3e4e187a62e 100644 (file)
@@ -1,6 +1,7 @@
 *~
 git-subtree
-git-subtree.xml
 git-subtree.1
+git-subtree.html
+git-subtree.xml
 mainline
 subproj
index c2bd703ee3aa0fd734c71dc50c01085455d33773..3071baf493442e8bfb3f34252f9c0d13801343b1 100644 (file)
@@ -5,9 +5,10 @@ all::
 -include ../../config.mak
 
 prefix ?= /usr/local
-mandir ?= $(prefix)/share/man
 gitexecdir ?= $(prefix)/libexec/git-core
+mandir ?= $(prefix)/share/man
 man1dir ?= $(mandir)/man1
+htmldir ?= $(prefix)/share/doc/git-doc
 
 ../../GIT-VERSION-FILE: FORCE
        $(MAKE) -C ../../ GIT-VERSION-FILE
@@ -49,12 +50,16 @@ install: $(GIT_SUBTREE)
        $(INSTALL) -d -m 755 $(DESTDIR)$(gitexecdir)
        $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(gitexecdir)
 
-install-doc: install-man
+install-doc: install-man install-html
 
 install-man: $(GIT_SUBTREE_DOC)
        $(INSTALL) -d -m 755 $(DESTDIR)$(man1dir)
        $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir)
 
+install-html: $(GIT_SUBTREE_HTML)
+       $(INSTALL) -d -m 755 $(DESTDIR)$(htmldir)
+       $(INSTALL) -m 644 $^ $(DESTDIR)$(htmldir)
+
 $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
        $(XMLTO) -m $(MANPAGE_XSL) man $^
 
diff --git a/diff.c b/diff.c
index d7a5c81bb8545584ce5fe652dc42f2ee8bc1e2fd..d1bd534caeaf662b0ee0d547d3aa2012310fff57 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -248,8 +248,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
                        return 0;
                if (!value)
                        return config_error_nonbool(var);
-               color_parse(value, var, diff_colors[slot]);
-               return 0;
+               return color_parse(value, diff_colors[slot]);
        }
 
        /* like GNU diff's --suppress-blank-empty option  */
index fee7906e51792f4bfbfab0b1db2dec3082025edb..d0bd285a16d0161b50d0b43e0315f8fa003e0e32 100644 (file)
@@ -1716,8 +1716,8 @@ static int update_branch(struct branch *b)
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_update(transaction, b->name, b->sha1, old_sha1,
-                                  0, 1, &err) ||
-           ref_transaction_commit(transaction, msg, &err)) {
+                                  0, 1, msg, &err) ||
+           ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
                error("%s", err.buf);
                strbuf_release(&err);
@@ -1757,12 +1757,12 @@ static void dump_tags(void)
                strbuf_addf(&ref_name, "refs/tags/%s", t->name);
 
                if (ref_transaction_update(transaction, ref_name.buf, t->sha1,
-                                          NULL, 0, 0, &err)) {
+                                          NULL, 0, 0, msg, &err)) {
                        failure |= error("%s", err.buf);
                        goto cleanup;
                }
        }
-       if (ref_transaction_commit(transaction, msg, &err))
+       if (ref_transaction_commit(transaction, &err))
                failure |= error("%s", err.buf);
 
  cleanup:
index fb41118c0705c628bed093c4a915a58aa01a5a1a..59ecf218cbca417dc7d6e0a571f6c82111041225 100644 (file)
@@ -326,6 +326,8 @@ static inline char *git_find_last_dir_sep(const char *path)
 
 #include "wildmatch.h"
 
+struct strbuf;
+
 /* General helper functions */
 extern void vreportf(const char *prefix, const char *err, va_list params);
 extern void vwritef(int fd, const char *prefix, const char *err, va_list params);
@@ -777,11 +779,21 @@ void git_qsort(void *base, size_t nmemb, size_t size,
 
 /*
  * Preserves errno, prints a message, but gives no warning for ENOENT.
- * Always returns the return value of unlink(2).
+ * Returns 0 on success, which includes trying to unlink an object that does
+ * not exist.
  */
 int unlink_or_warn(const char *path);
+ /*
+  * Tries to unlink file.  Returns 0 if unlink succeeded
+  * or the file already didn't exist.  Returns -1 and
+  * appends a message to err suitable for
+  * 'error("%s", err->buf)' on error.
+  */
+int unlink_or_msg(const char *file, struct strbuf *err);
 /*
- * Likewise for rmdir(2).
+ * Preserves errno, prints a message, but gives no warning for ENOENT.
+ * Returns 0 on success, which includes trying to remove a directory that does
+ * not exist.
  */
 int rmdir_or_warn(const char *path);
 /*
index 18ca61e8d0493bde9c21ed337043bc72fa5c73a7..598fcc23b930832a8cd3cfcff0c0d0c84ecd32bc 100755 (executable)
@@ -47,13 +47,9 @@ sub find_worktree
 
 sub print_tool_help
 {
-       my $cmd = 'TOOL_MODE=diff';
-       $cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"';
-       $cmd .= ' && show_tool_help';
-
        # See the comment at the bottom of file_diff() for the reason behind
        # using system() followed by exit() instead of exec().
-       my $rc = system('sh', '-c', $cmd);
+       my $rc = system(qw(git mergetool --tool-help=diff));
        exit($rc | ($rc >> 8));
 }
 
index 9a046b75d1dd810202d784d3fffe8afe6dd1963c..ff050e58ff3b752113105ba3ea5e20c6b633aae9 100755 (executable)
 
 USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
+NONGIT_OK=Yes
 OPTIONS_SPEC=
 TOOL_MODE=merge
 . git-sh-setup
 . git-mergetool--lib
-require_work_tree
 
 # Returns true if the mode reflects a symlink
 is_symlink () {
@@ -37,6 +37,19 @@ base_present () {
        test -n "$base_mode"
 }
 
+mergetool_tmpdir_init () {
+       if test "$(git config --bool mergetool.writeToTemp)" != true
+       then
+               MERGETOOL_TMPDIR=.
+               return 0
+       fi
+       if MERGETOOL_TMPDIR=$(mktemp -d -t "git-mergetool-XXXXXX" 2>/dev/null)
+       then
+               return 0
+       fi
+       die "error: mktemp is needed when 'mergetool.writeToTemp' is true"
+}
+
 cleanup_temp_files () {
        if test "$1" = --save-backup
        then
@@ -46,6 +59,10 @@ cleanup_temp_files () {
        else
                rm -f -- "$LOCAL" "$REMOTE" "$BASE" "$BACKUP"
        fi
+       if test "$MERGETOOL_TMPDIR" != "."
+       then
+               rmdir "$MERGETOOL_TMPDIR"
+       fi
 }
 
 describe_file () {
@@ -228,11 +245,27 @@ merge_file () {
                return 1
        fi
 
-       ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')"
-       BACKUP="./$MERGED.BACKUP.$ext"
-       LOCAL="./$MERGED.LOCAL.$ext"
-       REMOTE="./$MERGED.REMOTE.$ext"
-       BASE="./$MERGED.BASE.$ext"
+       if BASE=$(expr "$MERGED" : '\(.*\)\.[^/]*$')
+       then
+               ext=$(expr "$MERGED" : '.*\(\.[^/]*\)$')
+       else
+               BASE=$MERGED
+               ext=
+       fi
+
+       mergetool_tmpdir_init
+
+       if test "$MERGETOOL_TMPDIR" != "."
+       then
+               # If we're using a temporary directory then write to the
+               # top-level of that directory.
+               BASE=${BASE##*/}
+       fi
+
+       BACKUP="$MERGETOOL_TMPDIR/${BASE}_BACKUP_$$$ext"
+       LOCAL="$MERGETOOL_TMPDIR/${BASE}_LOCAL_$$$ext"
+       REMOTE="$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext"
+       BASE="$MERGETOOL_TMPDIR/${BASE}_BASE_$$$ext"
 
        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;}')
@@ -321,6 +354,10 @@ guessed_merge_tool=false
 while test $# != 0
 do
        case "$1" in
+       --tool-help=*)
+               TOOL_MODE=${1#--tool-help=}
+               show_tool_help
+               ;;
        --tool-help)
                show_tool_help
                ;;
@@ -372,6 +409,9 @@ prompt_after_failed_merge () {
        done
 }
 
+git_dir_init
+require_work_tree
+
 if test -z "$merge_tool"
 then
        # Check if a merge tool has been configured
index 9447980330ce7892757f9b11fa45cfeb3e6fcb34..d968760139b0e7b9219a1602a2e646a3ed398136 100644 (file)
@@ -330,8 +330,7 @@ esac
 
 # Make sure we are in a valid repository of a vintage we understand,
 # if we require to be in a git repository.
-if test -z "$NONGIT_OK"
-then
+git_dir_init () {
        GIT_DIR=$(git rev-parse --git-dir) || exit
        if [ -z "$SUBDIRECTORY_OK" ]
        then
@@ -346,6 +345,11 @@ then
                exit 1
        }
        : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
+}
+
+if test -z "$NONGIT_OK"
+then
+       git_dir_init
 fi
 
 peel_committish () {
diff --git a/git.c b/git.c
index 4cebf32126014938533b66cb57164c6602a1675c..18fbf79430687a473e9306f2bb65abbaec161bb4 100644 (file)
--- a/git.c
+++ b/git.c
@@ -417,6 +417,7 @@ static struct cmd_struct commands[] = {
        { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY },
        { "init", cmd_init_db, NO_SETUP },
        { "init-db", cmd_init_db, NO_SETUP },
+       { "interpret-trailers", cmd_interpret_trailers, RUN_SETUP },
        { "log", cmd_log, RUN_SETUP },
        { "ls-files", cmd_ls_files, RUN_SETUP },
        { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY },
index a9f57d6f9024b2c23d6a2a67d33d84638e3bfb07..ccf75169dd6fb50e2f8ce584af8fa7841fa55fd6 100755 (executable)
@@ -4100,7 +4100,7 @@ sub print_search_form {
        if ($use_pathinfo) {
                $action .= "/".esc_url($project);
        }
-       print $cgi->startform(-method => "get", -action => $action) .
+       print $cgi->start_form(-method => "get", -action => $action) .
              "<div class=\"search\">\n" .
              (!$use_pathinfo &&
              $cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
@@ -5510,7 +5510,7 @@ sub git_project_search_form {
        }
 
        print "<div class=\"projsearch\">\n";
-       print $cgi->startform(-method => 'get', -action => $my_uri) .
+       print $cgi->start_form(-method => 'get', -action => $my_uri) .
              $cgi->hidden(-name => 'a', -value => 'project_list')  . "\n";
        print $cgi->hidden(-name => 'pf', -value => $project_filter). "\n"
                if (defined $project_filter);
diff --git a/grep.c b/grep.c
index 99217dc04f5d04c761f094069f1053cb090baaf1..4dc31ea38656f72c51bae96155053cd1cd0f6d64 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -111,7 +111,7 @@ int grep_config(const char *var, const char *value, void *cb)
        if (color) {
                if (!value)
                        return config_error_nonbool(var);
-               color_parse(value, var, color);
+               return color_parse(value, color);
        }
        return 0;
 }
index 404e682593ecfca218d0aee0634f5c21356ef69c..9977c5d499e0397bf009c5e9954fe670ea7b034c 100644 (file)
@@ -412,7 +412,9 @@ static int show_head_ref(const char *refname, const unsigned char *sha1,
 
        if (flag & REF_ISSYMREF) {
                unsigned char unused[20];
-               const char *target = resolve_ref_unsafe(refname, unused, 1, NULL);
+               const char *target = resolve_ref_unsafe(refname,
+                                                       RESOLVE_REF_READING,
+                                                       unused, NULL);
                const char *target_nons = strip_namespace(target);
 
                strbuf_addf(buf, "ref: %s\n", target_nons);
index d098adebf1454ea9c9204c9dd2fda4d51b63a1e5..4f16ee78ce3dbc263a762a8800dfe9ddfcfaecd5 100644 (file)
@@ -162,16 +162,6 @@ void unable_to_lock_message(const char *path, int err, struct strbuf *buf)
                            absolute_path(path), strerror(err));
 }
 
-int unable_to_lock_error(const char *path, int err)
-{
-       struct strbuf buf = STRBUF_INIT;
-
-       unable_to_lock_message(path, err, &buf);
-       error("%s", buf.buf);
-       strbuf_release(&buf);
-       return -1;
-}
-
 NORETURN void unable_to_lock_die(const char *path, int err)
 {
        struct strbuf buf = STRBUF_INIT;
index dc066d1783327844f256892f75ab097d7ea8493d..cd2ec95d3003be5ff28f84e9e5b33cc85d9990c3 100644 (file)
@@ -71,7 +71,6 @@ struct lock_file {
 #define LOCK_DIE_ON_ERROR 1
 #define LOCK_NO_DEREF 2
 
-extern int unable_to_lock_error(const char *path, int err);
 extern void unable_to_lock_message(const char *path, int err,
                                   struct strbuf *buf);
 extern NORETURN void unable_to_lock_die(const char *path, int err);
index cff7ac1dbd8942f3013e6fa91d30d2ea33495854..7f0890e4ac14348e78f7f1e305629fa745a79392 100644 (file)
@@ -56,15 +56,14 @@ static int parse_decorate_color_slot(const char *slot)
        return -1;
 }
 
-int parse_decorate_color_config(const char *var, const int ofs, const char *value)
+int parse_decorate_color_config(const char *var, const char *slot_name, const char *value)
 {
-       int slot = parse_decorate_color_slot(var + ofs);
+       int slot = parse_decorate_color_slot(slot_name);
        if (slot < 0)
                return 0;
        if (!value)
                return config_error_nonbool(var);
-       color_parse(value, var, decoration_colors[slot]);
-       return 0;
+       return color_parse(value, decoration_colors[slot]);
 }
 
 /*
index b26160c4d64b041ed31826a61d4b898c8608c0a2..c8116e60cde34032da6f2044881d5a4970cd96fe 100644 (file)
@@ -7,7 +7,7 @@ struct log_info {
        struct commit *commit, *parent;
 };
 
-int parse_decorate_color_config(const char *var, const int ofs, const char *value);
+int parse_decorate_color_config(const char *var, const char *slot_name, const char *value);
 void init_log_tree_opt(struct rev_info *);
 int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);
index cb672a55192cb44335aa2cbe1f10004bb26d86ff..83ebdfb4c328ac79af38bfe935f0dbfa7fb6f53b 100644 (file)
@@ -18,13 +18,18 @@ merge_cmd () {
        check_unchanged
 }
 
-# Check whether 'meld --output <file>' is supported
+# Check whether we should use 'meld --output <file>'
 check_meld_for_output_version () {
        meld_path="$(git config mergetool.meld.path)"
        meld_path="${meld_path:-meld}"
 
-       if "$meld_path" --help 2>&1 | grep -e --output >/dev/null
+       if meld_has_output_option=$(git config --bool mergetool.meld.hasOutput)
        then
+               : use configured value
+       elif "$meld_path" --help 2>&1 |
+               grep -e '--output=' -e '\[OPTION\.\.\.\]' >/dev/null
+       then
+               : old ones mention --output and new ones just say OPTION...
                meld_has_output_option=true
        else
                meld_has_output_option=false
index fd5fae255d2760d6b7895e95cee627b5e28f776e..7eb9d7a0103ad8447e4fde50976a5669a75d8cdd 100644 (file)
@@ -549,7 +549,7 @@ int notes_merge(struct notes_merge_options *o,
               o->local_ref, o->remote_ref);
 
        /* Dereference o->local_ref into local_sha1 */
-       if (read_ref_full(o->local_ref, local_sha1, 0, NULL))
+       if (read_ref_full(o->local_ref, 0, local_sha1, NULL))
                die("Failed to resolve local notes ref '%s'", o->local_ref);
        else if (!check_refname_format(o->local_ref, 0) &&
                is_null_sha1(local_sha1))
index a181ac66875a158514bba48a21911adf9c5cd8be..9d34d02db11bd6761d48484327fbc6d1704ad555 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -964,9 +964,8 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
                        if (!want_color(c->pretty_ctx->color))
                                return end - placeholder + 1;
                }
-               color_parse_mem(begin,
-                               end - begin,
-                               "--pretty format", color);
+               if (color_parse_mem(begin, end - begin, color) < 0)
+                       die(_("unable to parse --pretty format"));
                strbuf_addstr(sb, color);
                return end - placeholder + 1;
        }
index 0e5174b6059174d2bcdb15ab584b747205e782dd..222de762eb2b1893d63da838251cbad9c902880b 100644 (file)
@@ -48,7 +48,8 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
                unsigned char sha1[20];
                const char *name;
                void *name_to_free;
-               name = name_to_free = resolve_refdup(ref, sha1, 1, NULL);
+               name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
+                                                    sha1, NULL);
                if (name) {
                        for_each_reflog_ent(name, read_one_reflog, reflogs);
                        free(name_to_free);
@@ -174,7 +175,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
                if (*branch == '\0') {
                        unsigned char sha1[20];
                        free(branch);
-                       branch = resolve_refdup("HEAD", sha1, 0, NULL);
+                       branch = resolve_refdup("HEAD", 0, sha1, NULL);
                        if (!branch)
                                die ("No current branch");
 
diff --git a/refs.c b/refs.c
index a77458f2f6eb108a90a1cf3d2cc4a771549c05f9..0368ed461f3ef913a60da322247bca0f9d121a82 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -70,16 +70,8 @@ static int check_refname_component(const char *refname, int flags)
 out:
        if (cp == refname)
                return 0; /* Component has zero length. */
-       if (refname[0] == '.') {
-               if (!(flags & REFNAME_DOT_COMPONENT))
-                       return -1; /* Component starts with '.'. */
-               /*
-                * Even if leading dots are allowed, don't allow "."
-                * as a component (".." is prevented by a rule above).
-                */
-               if (refname[1] == '\0')
-                       return -1; /* Component equals ".". */
-       }
+       if (refname[0] == '.')
+               return -1; /* Component starts with '.'. */
        if (cp - refname >= LOCK_SUFFIX_LEN &&
            !memcmp(cp - LOCK_SUFFIX_LEN, LOCK_SUFFIX, LOCK_SUFFIX_LEN))
                return -1; /* Refname ends with ".lock". */
@@ -195,8 +187,8 @@ struct ref_dir {
 
 /*
  * Bit values for ref_entry::flag.  REF_ISSYMREF=0x01,
- * REF_ISPACKED=0x02, and REF_ISBROKEN=0x04 are public values; see
- * refs.h.
+ * REF_ISPACKED=0x02, REF_ISBROKEN=0x04 and REF_BAD_NAME=0x08 are
+ * public values; see refs.h.
  */
 
 /*
@@ -204,16 +196,16 @@ struct ref_dir {
  * the correct peeled value for the reference, which might be
  * null_sha1 if the reference is not a tag or if it is broken.
  */
-#define REF_KNOWS_PEELED 0x08
+#define REF_KNOWS_PEELED 0x10
 
 /* ref_entry represents a directory of references */
-#define REF_DIR 0x10
+#define REF_DIR 0x20
 
 /*
  * Entry has not yet been read from disk (used only for REF_DIR
  * entries representing loose references)
  */
-#define REF_INCOMPLETE 0x20
+#define REF_INCOMPLETE 0x40
 
 /*
  * A ref_entry represents either a reference or a "subdirectory" of
@@ -282,6 +274,39 @@ static struct ref_dir *get_ref_dir(struct ref_entry *entry)
        return dir;
 }
 
+/*
+ * Check if a refname is safe.
+ * For refs that start with "refs/" we consider it safe as long they do
+ * not try to resolve to outside of refs/.
+ *
+ * For all other refs we only consider them safe iff they only contain
+ * upper case characters and '_' (like "HEAD" AND "MERGE_HEAD", and not like
+ * "config").
+ */
+static int refname_is_safe(const char *refname)
+{
+       if (starts_with(refname, "refs/")) {
+               char *buf;
+               int result;
+
+               buf = xmalloc(strlen(refname) + 1);
+               /*
+                * Does the refname try to escape refs/?
+                * For example: refs/foo/../bar is safe but refs/foo/../../bar
+                * is not.
+                */
+               result = !normalize_path_copy(buf, refname + strlen("refs/"));
+               free(buf);
+               return result;
+       }
+       while (*refname) {
+               if (!isupper(*refname) && *refname != '_')
+                       return 0;
+               refname++;
+       }
+       return 1;
+}
+
 static struct ref_entry *create_ref_entry(const char *refname,
                                          const unsigned char *sha1, int flag,
                                          int check_name)
@@ -290,8 +315,10 @@ static struct ref_entry *create_ref_entry(const char *refname,
        struct ref_entry *ref;
 
        if (check_name &&
-           check_refname_format(refname, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
+           check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
                die("Reference has invalid format: '%s'", refname);
+       if (!check_name && !refname_is_safe(refname))
+               die("Reference has invalid name: '%s'", refname);
        len = strlen(refname) + 1;
        ref = xmalloc(sizeof(struct ref_entry) + len);
        hashcpy(ref->u.value.sha1, sha1);
@@ -787,13 +814,13 @@ static void prime_ref_dir(struct ref_dir *dir)
        }
 }
 
-static int entry_matches(struct ref_entry *entry, const char *refname)
+static int entry_matches(struct ref_entry *entry, const struct string_list *list)
 {
-       return refname && !strcmp(entry->name, refname);
+       return list && string_list_has_string(list, entry->name);
 }
 
 struct nonmatching_ref_data {
-       const char *skip;
+       const struct string_list *skip;
        struct ref_entry *found;
 };
 
@@ -817,16 +844,19 @@ static void report_refname_conflict(struct ref_entry *entry,
 /*
  * Return true iff a reference named refname could be created without
  * conflicting with the name of an existing reference in dir.  If
- * oldrefname is non-NULL, ignore potential conflicts with oldrefname
- * (e.g., because oldrefname is scheduled for deletion in the same
+ * skip is non-NULL, ignore potential conflicts with refs in skip
+ * (e.g., because they are scheduled for deletion in the same
  * operation).
  *
  * Two reference names conflict if one of them exactly matches the
  * leading components of the other; e.g., "foo/bar" conflicts with
  * both "foo" and with "foo/bar/baz" but not with "foo/bar" or
  * "foo/barbados".
+ *
+ * skip must be sorted.
  */
-static int is_refname_available(const char *refname, const char *oldrefname,
+static int is_refname_available(const char *refname,
+                               const struct string_list *skip,
                                struct ref_dir *dir)
 {
        const char *slash;
@@ -840,12 +870,12 @@ static int is_refname_available(const char *refname, const char *oldrefname,
                 * looking for a conflict with a leaf entry.
                 *
                 * If we find one, we still must make sure it is
-                * not "oldrefname".
+                * not in "skip".
                 */
                pos = search_ref_dir(dir, refname, slash - refname);
                if (pos >= 0) {
                        struct ref_entry *entry = dir->entries[pos];
-                       if (entry_matches(entry, oldrefname))
+                       if (entry_matches(entry, skip))
                                return 1;
                        report_refname_conflict(entry, refname);
                        return 0;
@@ -878,13 +908,13 @@ static int is_refname_available(const char *refname, const char *oldrefname,
                /*
                 * We found a directory named "refname". It is a
                 * problem iff it contains any ref that is not
-                * "oldrefname".
+                * in "skip".
                 */
                struct ref_entry *entry = dir->entries[pos];
                struct ref_dir *dir = get_ref_dir(entry);
                struct nonmatching_ref_data data;
 
-               data.skip = oldrefname;
+               data.skip = skip;
                sort_ref_dir(dir);
                if (!do_for_each_entry_in_dir(dir, 0, nonmatching_ref_fn, &data))
                        return 1;
@@ -1116,7 +1146,13 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
 
                refname = parse_ref_line(refline, sha1);
                if (refname) {
-                       last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
+                       int flag = REF_ISPACKED;
+
+                       if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
+                               hashclr(sha1);
+                               flag |= REF_BAD_NAME | REF_ISBROKEN;
+                       }
+                       last = create_ref_entry(refname, sha1, flag, 0);
                        if (peeled == PEELED_FULLY ||
                            (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/")))
                                last->flag |= REF_KNOWS_PEELED;
@@ -1248,12 +1284,19 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
                                        hashclr(sha1);
                                        flag |= REF_ISBROKEN;
                                }
-                       } else if (read_ref_full(refname.buf, sha1, 1, &flag)) {
+                       } else if (read_ref_full(refname.buf,
+                                                RESOLVE_REF_READING,
+                                                sha1, &flag)) {
                                hashclr(sha1);
                                flag |= REF_ISBROKEN;
                        }
+                       if (check_refname_format(refname.buf,
+                                                REFNAME_ALLOW_ONELEVEL)) {
+                               hashclr(sha1);
+                               flag |= REF_BAD_NAME | REF_ISBROKEN;
+                       }
                        add_entry_to_dir(dir,
-                                        create_ref_entry(refname.buf, sha1, flag, 1));
+                                        create_ref_entry(refname.buf, sha1, flag, 0));
                }
                strbuf_setlen(&refname, dirnamelen);
        }
@@ -1372,10 +1415,10 @@ static struct ref_entry *get_packed_ref(const char *refname)
  * A loose ref file doesn't exist; check for a packed ref.  The
  * options are forwarded from resolve_safe_unsafe().
  */
-static const char *handle_missing_loose_ref(const char *refname,
-                                           unsigned char *sha1,
-                                           int reading,
-                                           int *flag)
+static int resolve_missing_loose_ref(const char *refname,
+                                    int resolve_flags,
+                                    unsigned char *sha1,
+                                    int *flags)
 {
        struct ref_entry *entry;
 
@@ -1386,35 +1429,51 @@ static const char *handle_missing_loose_ref(const char *refname,
        entry = get_packed_ref(refname);
        if (entry) {
                hashcpy(sha1, entry->u.value.sha1);
-               if (flag)
-                       *flag |= REF_ISPACKED;
-               return refname;
+               if (flags)
+                       *flags |= REF_ISPACKED;
+               return 0;
        }
        /* The reference is not a packed reference, either. */
-       if (reading) {
-               return NULL;
+       if (resolve_flags & RESOLVE_REF_READING) {
+               errno = ENOENT;
+               return -1;
        } else {
                hashclr(sha1);
-               return refname;
+               return 0;
        }
 }
 
 /* This function needs to return a meaningful errno on failure */
-const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int reading, int *flag)
+const char *resolve_ref_unsafe(const char *refname, int resolve_flags, unsigned char *sha1, int *flags)
 {
        int depth = MAXDEPTH;
        ssize_t len;
        char buffer[256];
        static char refname_buffer[256];
+       int bad_name = 0;
 
-       if (flag)
-               *flag = 0;
+       if (flags)
+               *flags = 0;
 
        if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
-               errno = EINVAL;
-               return NULL;
-       }
+               if (flags)
+                       *flags |= REF_BAD_NAME;
 
+               if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
+                   !refname_is_safe(refname)) {
+                       errno = EINVAL;
+                       return NULL;
+               }
+               /*
+                * dwim_ref() uses REF_ISBROKEN to distinguish between
+                * missing refs and refs that were present but invalid,
+                * to complain about the latter to stderr.
+                *
+                * We don't know whether the ref exists, so don't set
+                * REF_ISBROKEN yet.
+                */
+               bad_name = 1;
+       }
        for (;;) {
                char path[PATH_MAX];
                struct stat st;
@@ -1439,11 +1498,17 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
                 */
        stat_ref:
                if (lstat(path, &st) < 0) {
-                       if (errno == ENOENT)
-                               return handle_missing_loose_ref(refname, sha1,
-                                                               reading, flag);
-                       else
+                       if (errno != ENOENT)
+                               return NULL;
+                       if (resolve_missing_loose_ref(refname, resolve_flags,
+                                                     sha1, flags))
                                return NULL;
+                       if (bad_name) {
+                               hashclr(sha1);
+                               if (flags)
+                                       *flags |= REF_ISBROKEN;
+                       }
+                       return refname;
                }
 
                /* Follow "normalized" - ie "refs/.." symlinks by hand */
@@ -1461,8 +1526,12 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
                                        !check_refname_format(buffer, 0)) {
                                strcpy(refname_buffer, buffer);
                                refname = refname_buffer;
-                               if (flag)
-                                       *flag |= REF_ISSYMREF;
+                               if (flags)
+                                       *flags |= REF_ISSYMREF;
+                               if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
+                                       hashclr(sha1);
+                                       return refname;
+                               }
                                continue;
                        }
                }
@@ -1507,31 +1576,45 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
                         */
                        if (get_sha1_hex(buffer, sha1) ||
                            (buffer[40] != '\0' && !isspace(buffer[40]))) {
-                               if (flag)
-                                       *flag |= REF_ISBROKEN;
+                               if (flags)
+                                       *flags |= REF_ISBROKEN;
                                errno = EINVAL;
                                return NULL;
                        }
+                       if (bad_name) {
+                               hashclr(sha1);
+                               if (flags)
+                                       *flags |= REF_ISBROKEN;
+                       }
                        return refname;
                }
-               if (flag)
-                       *flag |= REF_ISSYMREF;
+               if (flags)
+                       *flags |= REF_ISSYMREF;
                buf = buffer + 4;
                while (isspace(*buf))
                        buf++;
+               refname = strcpy(refname_buffer, buf);
+               if (resolve_flags & RESOLVE_REF_NO_RECURSE) {
+                       hashclr(sha1);
+                       return refname;
+               }
                if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) {
-                       if (flag)
-                               *flag |= REF_ISBROKEN;
-                       errno = EINVAL;
-                       return NULL;
+                       if (flags)
+                               *flags |= REF_ISBROKEN;
+
+                       if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
+                           !refname_is_safe(buf)) {
+                               errno = EINVAL;
+                               return NULL;
+                       }
+                       bad_name = 1;
                }
-               refname = strcpy(refname_buffer, buf);
        }
 }
 
-char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag)
+char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, int *flags)
 {
-       const char *ret = resolve_ref_unsafe(ref, sha1, reading, flag);
+       const char *ret = resolve_ref_unsafe(ref, resolve_flags, sha1, flags);
        return ret ? xstrdup(ret) : NULL;
 }
 
@@ -1542,22 +1625,22 @@ struct ref_filter {
        void *cb_data;
 };
 
-int read_ref_full(const char *refname, unsigned char *sha1, int reading, int *flags)
+int read_ref_full(const char *refname, int resolve_flags, unsigned char *sha1, int *flags)
 {
-       if (resolve_ref_unsafe(refname, sha1, reading, flags))
+       if (resolve_ref_unsafe(refname, resolve_flags, sha1, flags))
                return 0;
        return -1;
 }
 
 int read_ref(const char *refname, unsigned char *sha1)
 {
-       return read_ref_full(refname, sha1, 1, NULL);
+       return read_ref_full(refname, RESOLVE_REF_READING, sha1, NULL);
 }
 
 int ref_exists(const char *refname)
 {
        unsigned char sha1[20];
-       return !!resolve_ref_unsafe(refname, sha1, 1, NULL);
+       return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);
 }
 
 static int filter_refs(const char *refname, const unsigned char *sha1, int flags,
@@ -1670,7 +1753,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
                return 0;
        }
 
-       if (read_ref_full(refname, base, 1, &flag))
+       if (read_ref_full(refname, RESOLVE_REF_READING, base, &flag))
                return -1;
 
        /*
@@ -1711,7 +1794,7 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha
        if (!(flags & REF_ISSYMREF))
                return 0;
 
-       resolves_to = resolve_ref_unsafe(refname, junk, 0, NULL);
+       resolves_to = resolve_ref_unsafe(refname, 0, junk, NULL);
        if (!resolves_to
            || (d->refname
                ? strcmp(resolves_to, d->refname)
@@ -1836,7 +1919,7 @@ static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)
                return 0;
        }
 
-       if (!read_ref_full("HEAD", sha1, 1, &flag))
+       if (!read_ref_full("HEAD", RESOLVE_REF_READING, sha1, &flag))
                return fn("HEAD", sha1, flag, cb_data);
 
        return 0;
@@ -1916,7 +1999,7 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data)
        int flag;
 
        strbuf_addf(&buf, "%sHEAD", get_git_namespace());
-       if (!read_ref_full(buf.buf, sha1, 1, &flag))
+       if (!read_ref_full(buf.buf, RESOLVE_REF_READING, sha1, &flag))
                ret = fn(buf.buf, sha1, flag, cb_data);
        strbuf_release(&buf);
 
@@ -2011,7 +2094,9 @@ int refname_match(const char *abbrev_name, const char *full_name)
 static struct ref_lock *verify_lock(struct ref_lock *lock,
        const unsigned char *old_sha1, int mustexist)
 {
-       if (read_ref_full(lock->ref_name, lock->old_sha1, mustexist, NULL)) {
+       if (read_ref_full(lock->ref_name,
+                         mustexist ? RESOLVE_REF_READING : 0,
+                         lock->old_sha1, NULL)) {
                int save_errno = errno;
                error("Can't verify ref %s", lock->ref_name);
                unlock_ref(lock);
@@ -2084,7 +2169,8 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
 
                this_result = refs_found ? sha1_from_ref : sha1;
                mksnpath(fullref, sizeof(fullref), *p, len, str);
-               r = resolve_ref_unsafe(fullref, this_result, 1, &flag);
+               r = resolve_ref_unsafe(fullref, RESOLVE_REF_READING,
+                                      this_result, &flag);
                if (r) {
                        if (!refs_found++)
                                *ref = xstrdup(r);
@@ -2113,7 +2199,8 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
                const char *ref, *it;
 
                mksnpath(path, sizeof(path), *p, len, str);
-               ref = resolve_ref_unsafe(path, hash, 1, NULL);
+               ref = resolve_ref_unsafe(path, RESOLVE_REF_READING,
+                                        hash, NULL);
                if (!ref)
                        continue;
                if (reflog_exists(path))
@@ -2134,11 +2221,12 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
 }
 
 /*
- * Locks a "refs/" ref returning the lock on success and NULL on failure.
+ * Locks a ref returning the lock on success and NULL on failure.
  * On failure errno is set to something meaningful.
  */
 static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                                            const unsigned char *old_sha1,
+                                           const struct string_list *skip,
                                            int flags, int *type_p)
 {
        char *ref_file;
@@ -2147,13 +2235,23 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
        int last_errno = 0;
        int type, lflags;
        int mustexist = (old_sha1 && !is_null_sha1(old_sha1));
+       int resolve_flags = 0;
        int missing = 0;
        int attempts_remaining = 3;
 
        lock = xcalloc(1, sizeof(struct ref_lock));
        lock->lock_fd = -1;
 
-       refname = resolve_ref_unsafe(refname, lock->old_sha1, mustexist, &type);
+       if (mustexist)
+               resolve_flags |= RESOLVE_REF_READING;
+       if (flags & REF_DELETING) {
+               resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
+               if (flags & REF_NODEREF)
+                       resolve_flags |= RESOLVE_REF_NO_RECURSE;
+       }
+
+       refname = resolve_ref_unsafe(refname, resolve_flags,
+                                    lock->old_sha1, &type);
        if (!refname && errno == EISDIR) {
                /* we are trying to lock foo but we used to
                 * have foo/bar which now does not exist;
@@ -2166,7 +2264,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
                        error("there are still refs under '%s'", orig_refname);
                        goto error_return;
                }
-               refname = resolve_ref_unsafe(orig_refname, lock->old_sha1, mustexist, &type);
+               refname = resolve_ref_unsafe(orig_refname, resolve_flags,
+                                            lock->old_sha1, &type);
        }
        if (type_p)
            *type_p = type;
@@ -2183,7 +2282,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
         * name is a proper prefix of our refname.
         */
        if (missing &&
-            !is_refname_available(refname, NULL, get_packed_refs(&ref_cache))) {
+            !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) {
                last_errno = ENOTDIR;
                goto error_return;
        }
@@ -2241,9 +2340,7 @@ struct ref_lock *lock_any_ref_for_update(const char *refname,
                                         const unsigned char *old_sha1,
                                         int flags, int *type_p)
 {
-       if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
-               return NULL;
-       return lock_ref_sha1_basic(refname, old_sha1, flags, type_p);
+       return lock_ref_sha1_basic(refname, old_sha1, NULL, flags, type_p);
 }
 
 /*
@@ -2445,8 +2542,8 @@ static void prune_ref(struct ref_to_prune *r)
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_delete(transaction, r->name, r->sha1,
-                                  REF_ISPRUNING, 1, &err) ||
-           ref_transaction_commit(transaction, NULL, &err)) {
+                                  REF_ISPRUNING, 1, NULL, &err) ||
+           ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
                error("%s", err.buf);
                strbuf_release(&err);
@@ -2510,7 +2607,7 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)
                unsigned char sha1[20];
                int flags;
 
-               if (read_ref_full(entry->name, sha1, 0, &flags))
+               if (read_ref_full(entry->name, 0, sha1, &flags))
                        /* We should at least have found the packed ref. */
                        die("Internal error");
                if ((flags & REF_ISSYMREF) || !(flags & REF_ISPACKED)) {
@@ -2549,6 +2646,8 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
        struct string_list_item *ref_to_delete;
        int i, ret, removed = 0;
 
+       assert(err);
+
        /* Look for a packed ref */
        for (i = 0; i < n; i++)
                if (get_packed_ref(refnames[i]))
@@ -2559,13 +2658,8 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
                return 0; /* no refname exists in packed refs */
 
        if (lock_packed_refs(0)) {
-               if (err) {
-                       unable_to_lock_message(git_path("packed-refs"), errno,
-                                              err);
-                       return -1;
-               }
-               unable_to_lock_error(git_path("packed-refs"), errno);
-               return error("cannot delete '%s' from packed refs", refnames[i]);
+               unable_to_lock_message(git_path("packed-refs"), errno, err);
+               return -1;
        }
        packed = get_packed_refs(&ref_cache);
 
@@ -2591,23 +2685,25 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
 
        /* Write what remains */
        ret = commit_packed_refs();
-       if (ret && err)
+       if (ret)
                strbuf_addf(err, "unable to overwrite old ref-pack file: %s",
                            strerror(errno));
        return ret;
 }
 
-static int delete_ref_loose(struct ref_lock *lock, int flag)
+static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
 {
+       assert(err);
+
        if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
                /*
                 * loose.  The loose file name is the same as the
                 * lockfile name, minus ".lock":
                 */
                char *loose_filename = get_locked_file_path(lock->lk);
-               int err = unlink_or_warn(loose_filename);
+               int res = unlink_or_msg(loose_filename, err);
                free(loose_filename);
-               if (err && errno != ENOENT)
+               if (res)
                        return 1;
        }
        return 0;
@@ -2621,8 +2717,8 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_delete(transaction, refname, sha1, delopt,
-                                  sha1 && !is_null_sha1(sha1), &err) ||
-           ref_transaction_commit(transaction, NULL, &err)) {
+                                  sha1 && !is_null_sha1(sha1), NULL, &err) ||
+           ref_transaction_commit(transaction, &err)) {
                error("%s", err.buf);
                ref_transaction_free(transaction);
                strbuf_release(&err);
@@ -2687,6 +2783,21 @@ static int rename_tmp_log(const char *newrefname)
        return 0;
 }
 
+static int rename_ref_available(const char *oldname, const char *newname)
+{
+       struct string_list skip = STRING_LIST_INIT_NODUP;
+       int ret;
+
+       string_list_insert(&skip, oldname);
+       ret = is_refname_available(newname, &skip, get_packed_refs(&ref_cache))
+           && is_refname_available(newname, &skip, get_loose_refs(&ref_cache));
+       string_list_clear(&skip, 0);
+       return ret;
+}
+
+static int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1,
+                         const char *logmsg);
+
 int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
 {
        unsigned char sha1[20], orig_sha1[20];
@@ -2699,17 +2810,15 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
        if (log && S_ISLNK(loginfo.st_mode))
                return error("reflog for %s is a symlink", oldrefname);
 
-       symref = resolve_ref_unsafe(oldrefname, orig_sha1, 1, &flag);
+       symref = resolve_ref_unsafe(oldrefname, RESOLVE_REF_READING,
+                                   orig_sha1, &flag);
        if (flag & REF_ISSYMREF)
                return error("refname %s is a symbolic ref, renaming it is not supported",
                        oldrefname);
        if (!symref)
                return error("refname %s not found", oldrefname);
 
-       if (!is_refname_available(newrefname, oldrefname, get_packed_refs(&ref_cache)))
-               return 1;
-
-       if (!is_refname_available(newrefname, oldrefname, get_loose_refs(&ref_cache)))
+       if (!rename_ref_available(oldrefname, newrefname))
                return 1;
 
        if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))
@@ -2721,7 +2830,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
                goto rollback;
        }
 
-       if (!read_ref_full(newrefname, sha1, 1, &flag) &&
+       if (!read_ref_full(newrefname, RESOLVE_REF_READING, sha1, NULL) &&
            delete_ref(newrefname, sha1, REF_NODEREF)) {
                if (errno==EISDIR) {
                        if (remove_empty_directories(git_path("%s", newrefname))) {
@@ -2739,7 +2848,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
 
        logmoved = log;
 
-       lock = lock_ref_sha1_basic(newrefname, NULL, 0, NULL);
+       lock = lock_ref_sha1_basic(newrefname, NULL, NULL, 0, NULL);
        if (!lock) {
                error("unable to lock %s for update", newrefname);
                goto rollback;
@@ -2754,7 +2863,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
        return 0;
 
  rollback:
-       lock = lock_ref_sha1_basic(oldrefname, NULL, 0, NULL);
+       lock = lock_ref_sha1_basic(oldrefname, NULL, NULL, 0, NULL);
        if (!lock) {
                error("unable to lock %s for rollback", oldrefname);
                goto rollbacklog;
@@ -2934,8 +3043,11 @@ int is_branch(const char *refname)
        return !strcmp(refname, "HEAD") || starts_with(refname, "refs/heads/");
 }
 
-/* This function must return a meaningful errno */
-int write_ref_sha1(struct ref_lock *lock,
+/*
+ * Write sha1 into the ref specified by the lock. Make sure that errno
+ * is sane on error.
+ */
+static int write_ref_sha1(struct ref_lock *lock,
        const unsigned char *sha1, const char *logmsg)
 {
        static char term = '\n';
@@ -2996,7 +3108,8 @@ int write_ref_sha1(struct ref_lock *lock,
                unsigned char head_sha1[20];
                int head_flag;
                const char *head_ref;
-               head_ref = resolve_ref_unsafe("HEAD", head_sha1, 1, &head_flag);
+               head_ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
+                                             head_sha1, &head_flag);
                if (head_ref && (head_flag & REF_ISSYMREF) &&
                    !strcmp(head_ref, lock->ref_name))
                        log_ref_write("HEAD", lock->old_sha1, sha1, logmsg);
@@ -3367,7 +3480,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data
                                retval = do_for_each_reflog(name, fn, cb_data);
                        } else {
                                unsigned char sha1[20];
-                               if (read_ref_full(name->buf, sha1, 0, NULL))
+                               if (read_ref_full(name->buf, 0, sha1, NULL))
                                        retval = error("bad ref for %s", name->buf);
                                else
                                        retval = fn(name->buf, sha1, 0, cb_data);
@@ -3404,6 +3517,7 @@ struct ref_update {
        int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
        struct ref_lock *lock;
        int type;
+       char *msg;
        const char refname[FLEX_ARRAY];
 };
 
@@ -3436,6 +3550,8 @@ struct ref_transaction {
 
 struct ref_transaction *ref_transaction_begin(struct strbuf *err)
 {
+       assert(err);
+
        return xcalloc(1, sizeof(struct ref_transaction));
 }
 
@@ -3446,9 +3562,10 @@ void ref_transaction_free(struct ref_transaction *transaction)
        if (!transaction)
                return;
 
-       for (i = 0; i < transaction->nr; i++)
+       for (i = 0; i < transaction->nr; i++) {
+               free(transaction->updates[i]->msg);
                free(transaction->updates[i]);
-
+       }
        free(transaction->updates);
        free(transaction);
 }
@@ -3469,57 +3586,80 @@ int ref_transaction_update(struct ref_transaction *transaction,
                           const char *refname,
                           const unsigned char *new_sha1,
                           const unsigned char *old_sha1,
-                          int flags, int have_old,
+                          int flags, int have_old, const char *msg,
                           struct strbuf *err)
 {
        struct ref_update *update;
 
+       assert(err);
+
        if (transaction->state != REF_TRANSACTION_OPEN)
                die("BUG: update called for transaction that is not open");
 
        if (have_old && !old_sha1)
                die("BUG: have_old is true but old_sha1 is NULL");
 
+       if (!is_null_sha1(new_sha1) &&
+           check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
+               strbuf_addf(err, "refusing to update ref with bad name %s",
+                           refname);
+               return -1;
+       }
+
        update = add_update(transaction, refname);
        hashcpy(update->new_sha1, new_sha1);
        update->flags = flags;
        update->have_old = have_old;
        if (have_old)
                hashcpy(update->old_sha1, old_sha1);
+       if (msg)
+               update->msg = xstrdup(msg);
        return 0;
 }
 
 int ref_transaction_create(struct ref_transaction *transaction,
                           const char *refname,
                           const unsigned char *new_sha1,
-                          int flags,
+                          int flags, const char *msg,
                           struct strbuf *err)
 {
        struct ref_update *update;
 
+       assert(err);
+
        if (transaction->state != REF_TRANSACTION_OPEN)
                die("BUG: create called for transaction that is not open");
 
        if (!new_sha1 || is_null_sha1(new_sha1))
                die("BUG: create ref with null new_sha1");
 
+       if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
+               strbuf_addf(err, "refusing to create ref with bad name %s",
+                           refname);
+               return -1;
+       }
+
        update = add_update(transaction, refname);
 
        hashcpy(update->new_sha1, new_sha1);
        hashclr(update->old_sha1);
        update->flags = flags;
        update->have_old = 1;
+       if (msg)
+               update->msg = xstrdup(msg);
        return 0;
 }
 
 int ref_transaction_delete(struct ref_transaction *transaction,
                           const char *refname,
                           const unsigned char *old_sha1,
-                          int flags, int have_old,
+                          int flags, int have_old, const char *msg,
                           struct strbuf *err)
 {
        struct ref_update *update;
 
+       assert(err);
+
        if (transaction->state != REF_TRANSACTION_OPEN)
                die("BUG: delete called for transaction that is not open");
 
@@ -3533,6 +3673,8 @@ int ref_transaction_delete(struct ref_transaction *transaction,
                assert(!is_null_sha1(old_sha1));
                hashcpy(update->old_sha1, old_sha1);
        }
+       if (msg)
+               update->msg = xstrdup(msg);
        return 0;
 }
 
@@ -3546,8 +3688,8 @@ int update_ref(const char *action, const char *refname,
        t = ref_transaction_begin(&err);
        if (!t ||
            ref_transaction_update(t, refname, sha1, oldval, flags,
-                                  !!oldval, &err) ||
-           ref_transaction_commit(t, action, &err)) {
+                                  !!oldval, action, &err) ||
+           ref_transaction_commit(t, &err)) {
                const char *str = "update_ref failed for ref '%s': %s";
 
                ref_transaction_free(t);
@@ -3580,26 +3722,29 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
                                        struct strbuf *err)
 {
        int i;
+
+       assert(err);
+
        for (i = 1; i < n; i++)
                if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) {
-                       const char *str =
-                               "Multiple updates for ref '%s' not allowed.";
-                       if (err)
-                               strbuf_addf(err, str, updates[i]->refname);
-
+                       strbuf_addf(err,
+                                   "Multiple updates for ref '%s' not allowed.",
+                                   updates[i]->refname);
                        return 1;
                }
        return 0;
 }
 
 int ref_transaction_commit(struct ref_transaction *transaction,
-                          const char *msg, struct strbuf *err)
+                          struct strbuf *err)
 {
        int ret = 0, delnum = 0, i;
        const char **delnames;
        int n = transaction->nr;
        struct ref_update **updates = transaction->updates;
 
+       assert(err);
+
        if (transaction->state != REF_TRANSACTION_OPEN)
                die("BUG: commit called for transaction that is not open");
 
@@ -3613,25 +3758,31 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 
        /* Copy, sort, and reject duplicate refs */
        qsort(updates, n, sizeof(*updates), ref_update_compare);
-       ret = ref_update_reject_duplicates(updates, n, err);
-       if (ret)
+       if (ref_update_reject_duplicates(updates, n, err)) {
+               ret = TRANSACTION_GENERIC_ERROR;
                goto cleanup;
+       }
 
        /* Acquire all locks while verifying old values */
        for (i = 0; i < n; i++) {
                struct ref_update *update = updates[i];
-
-               update->lock = lock_any_ref_for_update(update->refname,
-                                                      (update->have_old ?
-                                                       update->old_sha1 :
-                                                       NULL),
-                                                      update->flags,
-                                                      &update->type);
+               int flags = update->flags;
+
+               if (is_null_sha1(update->new_sha1))
+                       flags |= REF_DELETING;
+               update->lock = lock_ref_sha1_basic(update->refname,
+                                                  (update->have_old ?
+                                                   update->old_sha1 :
+                                                   NULL),
+                                                  NULL,
+                                                  flags,
+                                                  &update->type);
                if (!update->lock) {
-                       if (err)
-                               strbuf_addf(err, "Cannot lock the ref '%s'.",
-                                           update->refname);
-                       ret = 1;
+                       ret = (errno == ENOTDIR)
+                               ? TRANSACTION_NAME_CONFLICT
+                               : TRANSACTION_GENERIC_ERROR;
+                       strbuf_addf(err, "Cannot lock the ref '%s'.",
+                                   update->refname);
                        goto cleanup;
                }
        }
@@ -3641,15 +3792,15 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                struct ref_update *update = updates[i];
 
                if (!is_null_sha1(update->new_sha1)) {
-                       ret = write_ref_sha1(update->lock, update->new_sha1,
-                                            msg);
-                       update->lock = NULL; /* freed by write_ref_sha1 */
-                       if (ret) {
-                               if (err)
-                                       strbuf_addf(err, "Cannot update the ref '%s'.",
-                                                   update->refname);
+                       if (write_ref_sha1(update->lock, update->new_sha1,
+                                          update->msg)) {
+                               update->lock = NULL; /* freed by write_ref_sha1 */
+                               strbuf_addf(err, "Cannot update the ref '%s'.",
+                                           update->refname);
+                               ret = TRANSACTION_GENERIC_ERROR;
                                goto cleanup;
                        }
+                       update->lock = NULL; /* freed by write_ref_sha1 */
                }
        }
 
@@ -3658,13 +3809,20 @@ int ref_transaction_commit(struct ref_transaction *transaction,
                struct ref_update *update = updates[i];
 
                if (update->lock) {
-                       ret |= delete_ref_loose(update->lock, update->type);
+                       if (delete_ref_loose(update->lock, update->type, err)) {
+                               ret = TRANSACTION_GENERIC_ERROR;
+                               goto cleanup;
+                       }
+
                        if (!(update->flags & REF_ISPRUNING))
                                delnames[delnum++] = update->lock->ref_name;
                }
        }
 
-       ret |= repack_without_refs(delnames, delnum, err);
+       if (repack_without_refs(delnames, delnum, err)) {
+               ret = TRANSACTION_GENERIC_ERROR;
+               goto cleanup;
+       }
        for (i = 0; i < delnum; i++)
                unlink_or_warn(git_path("logs/%s", delnames[i]));
        clear_loose_ref_cache(&ref_cache);
diff --git a/refs.h b/refs.h
index 2328f06e77d34d76a1f4affedcca2c51ff9e0093..2bc3556874a7b1cbccb4cebf4e3dc2fa13cc780f 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -56,11 +56,19 @@ struct ref_transaction;
 
 /*
  * Reference cannot be resolved to an object name: dangling symbolic
- * reference (directly or indirectly), corrupt reference file, or
- * symbolic reference refers to ill-formatted reference name.
+ * reference (directly or indirectly), corrupt reference file,
+ * reference exists but name is bad, or symbolic reference refers to
+ * ill-formatted reference name.
  */
 #define REF_ISBROKEN 0x04
 
+/*
+ * Reference name is not well formed.
+ *
+ * See git-check-ref-format(1) for the definition of well formed ref names.
+ */
+#define REF_BAD_NAME 0x08
+
 /*
  * The signature for the callback function for the for_each_*()
  * functions below.  The memory pointed to by the refname and sha1
@@ -177,10 +185,12 @@ extern int peel_ref(const char *refname, unsigned char *sha1);
  * ref_transaction_create(), etc.
  * REF_NODEREF: act on the ref directly, instead of dereferencing
  *              symbolic references.
+ * REF_DELETING: tolerate broken refs
  *
  * Flags >= 0x100 are reserved for internal use.
  */
 #define REF_NODEREF    0x01
+#define REF_DELETING   0x02
 /*
  * This function sets errno to something meaningful on failure.
  */
@@ -197,9 +207,6 @@ extern int commit_ref(struct ref_lock *lock);
 /** Release any lock taken but not written. **/
 extern void unlock_ref(struct ref_lock *lock);
 
-/** Writes sha1 into the ref specified by the lock. **/
-extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg);
-
 /*
  * Setup reflog before using. Set errno to something meaningful on failure.
  */
@@ -230,7 +237,6 @@ extern int for_each_reflog(each_ref_fn, void *);
 
 #define REFNAME_ALLOW_ONELEVEL 1
 #define REFNAME_REFSPEC_PATTERN 2
-#define REFNAME_DOT_COMPONENT 4
 
 /*
  * Return 0 iff refname has the correct format for a refname according
@@ -238,10 +244,7 @@ extern int for_each_reflog(each_ref_fn, void *);
  * If REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level
  * reference names.  If REFNAME_REFSPEC_PATTERN is set in flags, then
  * allow a "*" wildcard character in place of one of the name
- * components.  No leading or repeated slashes are accepted.  If
- * REFNAME_DOT_COMPONENT is set in flags, then allow refname
- * components to start with "." (but not a whole component equal to
- * "." or "..").
+ * components.  No leading or repeated slashes are accepted.
  */
 extern int check_refname_format(const char *refname, int flags);
 
@@ -274,8 +277,8 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
  * The following functions add a reference check or update to a
  * ref_transaction.  In all of them, refname is the name of the
  * reference to be affected.  The functions make internal copies of
- * refname, so the caller retains ownership of the parameter.  flags
- * can be REF_NODEREF; it is passed to update_ref_lock().
+ * refname and msg, so the caller retains ownership of these parameters.
+ * flags can be REF_NODEREF; it is passed to update_ref_lock().
  */
 
 /*
@@ -292,7 +295,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
                           const char *refname,
                           const unsigned char *new_sha1,
                           const unsigned char *old_sha1,
-                          int flags, int have_old,
+                          int flags, int have_old, const char *msg,
                           struct strbuf *err);
 
 /*
@@ -307,7 +310,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
 int ref_transaction_create(struct ref_transaction *transaction,
                           const char *refname,
                           const unsigned char *new_sha1,
-                          int flags,
+                          int flags, const char *msg,
                           struct strbuf *err);
 
 /*
@@ -321,16 +324,21 @@ int ref_transaction_create(struct ref_transaction *transaction,
 int ref_transaction_delete(struct ref_transaction *transaction,
                           const char *refname,
                           const unsigned char *old_sha1,
-                          int flags, int have_old,
+                          int flags, int have_old, const char *msg,
                           struct strbuf *err);
 
 /*
  * Commit all of the changes that have been queued in transaction, as
- * atomically as possible.  Return a nonzero value if there is a
- * problem.
+ * atomically as possible.
+ *
+ * Returns 0 for success, or one of the below error codes for errors.
  */
+/* Naming conflict (for example, the ref names A and A/B conflict). */
+#define TRANSACTION_NAME_CONFLICT -1
+/* All other errors. */
+#define TRANSACTION_GENERIC_ERROR -2
 int ref_transaction_commit(struct ref_transaction *transaction,
-                          const char *msg, struct strbuf *err);
+                          struct strbuf *err);
 
 /*
  * Free an existing transaction and all associated data.
index ce785f8953bd8a51ef1c3ce57da5c8e7cce7cef5..f62421702f66bb9b8f64247dd339d01f2fbfb4c1 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -508,7 +508,7 @@ static void read_config(void)
                return;
        default_remote_name = "origin";
        current_branch = NULL;
-       head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
+       head_ref = resolve_ref_unsafe("HEAD", 0, sha1, &flag);
        if (head_ref && (flag & REF_ISSYMREF) &&
            skip_prefix(head_ref, "refs/heads/", &head_ref)) {
                current_branch = make_branch(head_ref, 0);
@@ -1138,7 +1138,8 @@ static char *guess_ref(const char *name, struct ref *peer)
        struct strbuf buf = STRBUF_INIT;
        unsigned char sha1[20];
 
-       const char *r = resolve_ref_unsafe(peer->name, sha1, 1, NULL);
+       const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
+                                          sha1, NULL);
        if (!r)
                return NULL;
 
@@ -1199,7 +1200,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
                unsigned char sha1[20];
                int flag;
 
-               dst_value = resolve_ref_unsafe(matched_src->name, sha1, 1, &flag);
+               dst_value = resolve_ref_unsafe(matched_src->name,
+                                              RESOLVE_REF_READING,
+                                              sha1, &flag);
                if (!dst_value ||
                    ((flag & REF_ISSYMREF) &&
                     !starts_with(dst_value, "refs/heads/")))
@@ -1673,7 +1676,7 @@ static int ignore_symref_update(const char *refname)
        unsigned char sha1[20];
        int flag;
 
-       if (!resolve_ref_unsafe(refname, sha1, 0, &flag))
+       if (!resolve_ref_unsafe(refname, 0, sha1, &flag))
                return 0; /* non-existing refs are OK */
        return (flag & REF_ISSYMREF);
 }
index 1b9a35e5875683c9bd6ae7dba8e849201fdc0a42..a03d4fa2521fbc119a8d6b471b9e3c1046610b84 100644 (file)
@@ -252,8 +252,8 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
        if (!transaction ||
            ref_transaction_update(transaction, "HEAD",
                                   to, unborn ? null_sha1 : from,
-                                  0, 1, &err) ||
-           ref_transaction_commit(transaction, sb.buf, &err)) {
+                                  0, 1, sb.buf, &err) ||
+           ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
                error("%s", err.buf);
                strbuf_release(&sb);
@@ -331,7 +331,7 @@ static int is_index_unchanged(void)
        unsigned char head_sha1[20];
        struct commit *head_commit;
 
-       if (!resolve_ref_unsafe("HEAD", head_sha1, 1, NULL))
+       if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
                return error(_("Could not resolve HEAD commit\n"));
 
        head_commit = lookup_commit(head_sha1);
@@ -871,7 +871,7 @@ static int rollback_single_pick(void)
        if (!file_exists(git_path("CHERRY_PICK_HEAD")) &&
            !file_exists(git_path("REVERT_HEAD")))
                return error(_("no cherry-pick or revert in progress"));
-       if (read_ref_full("HEAD", head_sha1, 0, NULL))
+       if (read_ref_full("HEAD", 0, head_sha1, NULL))
                return error(_("cannot resolve HEAD"));
        if (is_null_sha1(head_sha1))
                return error(_("cannot abort from a branch yet to be born"));
index 52c77ae936d9cb3ecc4ff42a2c4667fca4373577..9952261299e62c88d04954a2a8e738cd6a2adb30 100644 (file)
--- a/t/README
+++ b/t/README
@@ -82,6 +82,12 @@ appropriately before running "make".
        numbers matching <pattern>.  The number matched against is
        simply the running count of the test within the file.
 
+-x::
+       Turn on shell tracing (i.e., `set -x`) during the tests
+       themselves. Implies `--verbose`. Note that this can cause
+       failures in some tests which redirect and test the
+       output of shell functions. Use with caution.
+
 -d::
 --debug::
        This may help the person who is developing a new test.
index ea0bce2dc64b6fe3cac3e00f48b7a17a341af647..91235b76ba76f7e7e9338e37da7106eb550969e6 100755 (executable)
@@ -23,7 +23,7 @@ check_config () {
 }
 
 test_expect_success 'setup default config' '
-       cat >.git/config <<\EOF
+       cat >.git/config <<-\EOF
        [case]
                penguin = very blue
                Movie = BadPhysics
@@ -195,7 +195,7 @@ test_expect_success 'proper error on error in default config files' '
        cp .git/config .git/config.old &&
        test_when_finished "mv .git/config.old .git/config" &&
        echo "[" >>.git/config &&
-       echo "fatal: bad config file line 35 in .git/config" >expect &&
+       echo "fatal: bad config file line 34 in .git/config" >expect &&
        test_expect_code 128 test-config get_value foo.bar 2>actual &&
        test_cmp expect actual
 '
index 0218e96366ddd8659d5a78b42ffcfd415013114c..7b4707b776f493ad4b2df9877926dd420e94ca81 100755 (executable)
@@ -110,6 +110,32 @@ test_expect_success "delete symref without dereference when the referred ref is
 cp -f .git/HEAD.orig .git/HEAD
 git update-ref -d $m
 
+test_expect_success 'update-ref -d is not confused by self-reference' '
+       git symbolic-ref refs/heads/self refs/heads/self &&
+       test_when_finished "rm -f .git/refs/heads/self" &&
+       test_path_is_file .git/refs/heads/self &&
+       test_must_fail git update-ref -d refs/heads/self &&
+       test_path_is_file .git/refs/heads/self
+'
+
+test_expect_success 'update-ref --no-deref -d can delete self-reference' '
+       git symbolic-ref refs/heads/self refs/heads/self &&
+       test_when_finished "rm -f .git/refs/heads/self" &&
+       test_path_is_file .git/refs/heads/self &&
+       git update-ref --no-deref -d refs/heads/self &&
+       test_path_is_missing .git/refs/heads/self
+'
+
+test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
+       >.git/refs/heads/bad &&
+       test_when_finished "rm -f .git/refs/heads/bad" &&
+       git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
+       test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
+       test_path_is_file .git/refs/heads/ref-to-bad &&
+       git update-ref --no-deref -d refs/heads/ref-to-bad &&
+       test_path_is_missing .git/refs/heads/ref-to-bad
+'
+
 test_expect_success '(not) create HEAD with old sha1' "
        test_must_fail git update-ref HEAD $A $B
 "
@@ -374,12 +400,6 @@ test_expect_success 'stdin fails create with no ref' '
        grep "fatal: create: missing <ref>" err
 '
 
-test_expect_success 'stdin fails create with bad ref name' '
-       echo "create ~a $m" >stdin &&
-       test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: invalid ref format: ~a" err
-'
-
 test_expect_success 'stdin fails create with no new value' '
        echo "create $a" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -398,12 +418,6 @@ test_expect_success 'stdin fails update with no ref' '
        grep "fatal: update: missing <ref>" err
 '
 
-test_expect_success 'stdin fails update with bad ref name' '
-       echo "update ~a $m" >stdin &&
-       test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: invalid ref format: ~a" err
-'
-
 test_expect_success 'stdin fails update with no new value' '
        echo "update $a" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -422,12 +436,6 @@ test_expect_success 'stdin fails delete with no ref' '
        grep "fatal: delete: missing <ref>" err
 '
 
-test_expect_success 'stdin fails delete with bad ref name' '
-       echo "delete ~a $m" >stdin &&
-       test_must_fail git update-ref --stdin <stdin 2>err &&
-       grep "fatal: invalid ref format: ~a" err
-'
-
 test_expect_success 'stdin fails delete with too many arguments' '
        echo "delete $a $m $m" >stdin &&
        test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -700,12 +708,6 @@ test_expect_success 'stdin -z fails create with no ref' '
        grep "fatal: create: missing <ref>" err
 '
 
-test_expect_success 'stdin -z fails create with bad ref name' '
-       printf $F "create ~a " "$m" >stdin &&
-       test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: invalid ref format: ~a " err
-'
-
 test_expect_success 'stdin -z fails create with no new value' '
        printf $F "create $a" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
@@ -730,12 +732,6 @@ test_expect_success 'stdin -z fails update with too few args' '
        grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
 '
 
-test_expect_success 'stdin -z fails update with bad ref name' '
-       printf $F "update ~a" "$m" "" >stdin &&
-       test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: invalid ref format: ~a" err
-'
-
 test_expect_success 'stdin -z emits warning with empty new value' '
        git update-ref $a $m &&
        printf $F "update $a" "" "" >stdin &&
@@ -768,12 +764,6 @@ test_expect_success 'stdin -z fails delete with no ref' '
        grep "fatal: delete: missing <ref>" err
 '
 
-test_expect_success 'stdin -z fails delete with bad ref name' '
-       printf $F "delete ~a" "$m" >stdin &&
-       test_must_fail git update-ref -z --stdin <stdin 2>err &&
-       grep "fatal: invalid ref format: ~a" err
-'
-
 test_expect_success 'stdin -z fails delete with no old value' '
        printf $F "delete $a" >stdin &&
        test_must_fail git update-ref -z --stdin <stdin 2>err &&
diff --git a/t/t1413-reflog-detach.sh b/t/t1413-reflog-detach.sh
new file mode 100755 (executable)
index 0000000..c730600
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='Test reflog interaction with detached HEAD'
+. ./test-lib.sh
+
+reset_state () {
+       git checkout master &&
+       cp saved_reflog .git/logs/HEAD
+}
+
+test_expect_success setup '
+       test_tick &&
+       git commit --allow-empty -m initial &&
+       git branch side &&
+       test_tick &&
+       git commit --allow-empty -m second &&
+       cat .git/logs/HEAD >saved_reflog
+'
+
+test_expect_success baseline '
+       reset_state &&
+       git rev-parse master master^ >expect &&
+       git log -g --format=%H >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'switch to branch' '
+       reset_state &&
+       git rev-parse side master master^ >expect &&
+       git checkout side &&
+       git log -g --format=%H >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'detach to other' '
+       reset_state &&
+       git rev-parse master side master master^ >expect &&
+       git checkout side &&
+       git checkout master^0 &&
+       git log -g --format=%H >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'detach to self' '
+       reset_state &&
+       git rev-parse master master master^ >expect &&
+       git checkout master^0 &&
+       git log -g --format=%H >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'attach to self' '
+       reset_state &&
+       git rev-parse master master master master^ >expect &&
+       git checkout master^0 &&
+       git checkout master &&
+       git log -g --format=%H >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'attach to other' '
+       reset_state &&
+       git rev-parse side master master master^ >expect &&
+       git checkout master^0 &&
+       git checkout side &&
+       git log -g --format=%H >actual &&
+       test_cmp expect actual
+'
+
+test_done
diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh
new file mode 100755 (executable)
index 0000000..468e856
--- /dev/null
@@ -0,0 +1,207 @@
+#!/bin/sh
+
+test_description='Test handling of ref names that check-ref-format rejects'
+. ./test-lib.sh
+
+test_expect_success setup '
+       test_commit one &&
+       test_commit two
+'
+
+test_expect_success 'fast-import: fail on invalid branch name ".badbranchname"' '
+       test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
+       cat >input <<-INPUT_END &&
+               commit .badbranchname
+               committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+               data <<COMMIT
+               corrupt
+               COMMIT
+
+               from refs/heads/master
+
+       INPUT_END
+       test_must_fail git fast-import <input
+'
+
+test_expect_success 'fast-import: fail on invalid branch name "bad[branch]name"' '
+       test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
+       cat >input <<-INPUT_END &&
+               commit bad[branch]name
+               committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+               data <<COMMIT
+               corrupt
+               COMMIT
+
+               from refs/heads/master
+
+       INPUT_END
+       test_must_fail git fast-import <input
+'
+
+test_expect_success 'git branch shows badly named ref' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git branch >output &&
+       grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'branch -d can delete badly named ref' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git branch -d broken...ref &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'branch -D can delete badly named ref' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git branch -D broken...ref &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'branch -D cannot delete non-ref in .git dir' '
+       echo precious >.git/my-private-file &&
+       echo precious >expect &&
+       test_must_fail git branch -D ../../my-private-file &&
+       test_cmp expect .git/my-private-file
+'
+
+test_expect_success 'branch -D cannot delete absolute path' '
+       git branch -f extra &&
+       test_must_fail git branch -D "$(pwd)/.git/refs/heads/extra" &&
+       test_cmp_rev HEAD extra
+'
+
+test_expect_success 'git branch cannot create a badly named ref' '
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       test_must_fail git branch broken...ref &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'branch -m cannot rename to a bad ref name' '
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       test_might_fail git branch -D goodref &&
+       git branch goodref &&
+       test_must_fail git branch -m goodref broken...ref &&
+       test_cmp_rev master goodref &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_failure 'branch -m can rename from a bad ref name' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git branch -m broken...ref renamed &&
+       test_cmp_rev master renamed &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'push cannot create a badly named ref' '
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       test_must_fail git push "file://$(pwd)" HEAD:refs/heads/broken...ref &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_failure 'push --mirror can delete badly named ref' '
+       top=$(pwd) &&
+       git init src &&
+       git init dest &&
+
+       (
+               cd src &&
+               test_commit one
+       ) &&
+       (
+               cd dest &&
+               test_commit two &&
+               git checkout --detach &&
+               cp .git/refs/heads/master .git/refs/heads/broken...ref
+       ) &&
+       git -C src push --mirror "file://$top/dest" &&
+       git -C dest branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'rev-parse skips symref pointing to broken name' '
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git branch shadow one &&
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       git symbolic-ref refs/tags/shadow refs/heads/broken...ref &&
+
+       git rev-parse --verify one >expect &&
+       git rev-parse --verify shadow >actual 2>err &&
+       test_cmp expect actual &&
+       test_i18ngrep "ignoring.*refs/tags/shadow" err
+'
+
+test_expect_success 'update-ref --no-deref -d can delete reference to broken name' '
+       git symbolic-ref refs/heads/badname refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/badname" &&
+       test_path_is_file .git/refs/heads/badname &&
+       git update-ref --no-deref -d refs/heads/badname &&
+       test_path_is_missing .git/refs/heads/badname
+'
+
+test_expect_success 'update-ref -d can delete broken name' '
+       cp .git/refs/heads/master .git/refs/heads/broken...ref &&
+       test_when_finished "rm -f .git/refs/heads/broken...ref" &&
+       git update-ref -d refs/heads/broken...ref &&
+       git branch >output &&
+       ! grep -e "broken\.\.\.ref" output
+'
+
+test_expect_success 'update-ref -d cannot delete non-ref in .git dir' '
+       echo precious >.git/my-private-file &&
+       echo precious >expect &&
+       test_must_fail git update-ref -d my-private-file &&
+       test_cmp expect .git/my-private-file
+'
+
+test_expect_success 'update-ref -d cannot delete absolute path' '
+       git branch -f extra &&
+       test_must_fail git update-ref -d "$(pwd)/.git/refs/heads/extra" &&
+       test_cmp_rev HEAD extra
+'
+
+test_expect_success 'update-ref --stdin fails create with bad ref name' '
+       echo "create ~a refs/heads/master" >stdin &&
+       test_must_fail git update-ref --stdin <stdin 2>err &&
+       grep "fatal: invalid ref format: ~a" err
+'
+
+test_expect_success 'update-ref --stdin fails update with bad ref name' '
+       echo "update ~a refs/heads/master" >stdin &&
+       test_must_fail git update-ref --stdin <stdin 2>err &&
+       grep "fatal: invalid ref format: ~a" err
+'
+
+test_expect_success 'update-ref --stdin fails delete with bad ref name' '
+       echo "delete ~a refs/heads/master" >stdin &&
+       test_must_fail git update-ref --stdin <stdin 2>err &&
+       grep "fatal: invalid ref format: ~a" err
+'
+
+test_expect_success 'update-ref --stdin -z fails create with bad ref name' '
+       printf "%s\0" "create ~a " refs/heads/master >stdin &&
+       test_must_fail git update-ref -z --stdin <stdin 2>err &&
+       grep "fatal: invalid ref format: ~a " err
+'
+
+test_expect_success 'update-ref --stdin -z fails update with bad ref name' '
+       printf "%s\0" "update ~a" refs/heads/master "" >stdin &&
+       test_must_fail git update-ref -z --stdin <stdin 2>err &&
+       grep "fatal: invalid ref format: ~a" err
+'
+
+test_expect_success 'update-ref --stdin -z fails delete with bad ref name' '
+       printf "%s\0" "delete ~a" refs/heads/master >stdin &&
+       test_must_fail git update-ref -z --stdin <stdin 2>err &&
+       grep "fatal: invalid ref format: ~a" err
+'
+
+test_done
index ac31b711f29139470308d9062fea33259cf004ab..432921b6b81684313c6b0041a288749c30fdee8e 100755 (executable)
@@ -285,6 +285,15 @@ test_expect_success 'deleting a dangling symref' '
        test_i18ncmp expect actual
 '
 
+test_expect_success 'deleting a self-referential symref' '
+       git symbolic-ref refs/heads/self-reference refs/heads/self-reference &&
+       test_path_is_file .git/refs/heads/self-reference &&
+       echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect &&
+       git branch -d self-reference >actual &&
+       test_path_is_missing .git/refs/heads/self-reference &&
+       test_i18ncmp expect actual
+'
+
 test_expect_success 'renaming a symref is not allowed' '
        git symbolic-ref refs/heads/master2 refs/heads/master &&
        test_must_fail git branch -m master2 master3 &&
index 83d20c4ba9640fff27777917da0342940c33e0e3..305bcac6b765111106887d4d24d99657c0554b5b 100755 (executable)
@@ -113,9 +113,4 @@ test_expect_success 'archive empty subtree by direct pathspec' '
        check_dir extract sub
 '
 
-test_expect_success 'archive applies umask even for pax headers' '
-       git archive --format=tar HEAD >archive.tar &&
-       ! grep 0666 archive.tar
-'
-
 test_done
index 01c6a3fc1dc3ef028cfdaad749e9e68955f00226..e32e46dee10e96a0b0e51df0eeefd343373f662e 100755 (executable)
@@ -13,8 +13,8 @@ add_blob() {
        before=$(git count-objects | sed "s/ .*//") &&
        BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
        BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
-       test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
-       test -f $BLOB_FILE &&
+       verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
+       test_path_is_file $BLOB_FILE &&
        test-chmtime =+0 $BLOB_FILE
 }
 
@@ -35,9 +35,9 @@ test_expect_success 'prune stale packs' '
        : > .git/objects/tmp_2.pack &&
        test-chmtime =-86501 .git/objects/tmp_1.pack &&
        git prune --expire 1.day &&
-       test -f $orig_pack &&
-       test -f .git/objects/tmp_2.pack &&
-       ! test -f .git/objects/tmp_1.pack
+       test_path_is_file $orig_pack &&
+       test_path_is_file .git/objects/tmp_2.pack &&
+       test_path_is_missing .git/objects/tmp_1.pack
 
 '
 
@@ -45,12 +45,12 @@ test_expect_success 'prune --expire' '
 
        add_blob &&
        git prune --expire=1.hour.ago &&
-       test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
-       test -f $BLOB_FILE &&
+       verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
+       test_path_is_file $BLOB_FILE &&
        test-chmtime =-86500 $BLOB_FILE &&
        git prune --expire 1.day &&
-       test $before = $(git count-objects | sed "s/ .*//") &&
-       ! test -f $BLOB_FILE
+       verbose test $before = $(git count-objects | sed "s/ .*//") &&
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -59,12 +59,12 @@ test_expect_success 'gc: implicit prune --expire' '
        add_blob &&
        test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
        git gc &&
-       test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
-       test -f $BLOB_FILE &&
+       verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
+       test_path_is_file $BLOB_FILE &&
        test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
        git gc &&
-       test $before = $(git count-objects | sed "s/ .*//") &&
-       ! test -f $BLOB_FILE
+       verbose test $before = $(git count-objects | sed "s/ .*//") &&
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -110,7 +110,7 @@ test_expect_success 'prune: do not prune detached HEAD with no reflog' '
        git commit --allow-empty -m "detached commit" &&
        # verify that there is no reflogs
        # (should be removed and disabled by previous test)
-       test ! -e .git/logs &&
+       test_path_is_missing .git/logs &&
        git prune -n >prune_actual &&
        : >prune_expected &&
        test_cmp prune_actual prune_expected
@@ -144,8 +144,8 @@ test_expect_success 'gc --no-prune' '
        test-chmtime =-$((5001*$day)) $BLOB_FILE &&
        git config gc.pruneExpire 2.days.ago &&
        git gc --no-prune &&
-       test 1 = $(git count-objects | sed "s/ .*//") &&
-       test -f $BLOB_FILE
+       verbose test 1 = $(git count-objects | sed "s/ .*//") &&
+       test_path_is_file $BLOB_FILE
 
 '
 
@@ -153,10 +153,10 @@ test_expect_success 'gc respects gc.pruneExpire' '
 
        git config gc.pruneExpire 5002.days.ago &&
        git gc &&
-       test -f $BLOB_FILE &&
+       test_path_is_file $BLOB_FILE &&
        git config gc.pruneExpire 5000.days.ago &&
        git gc &&
-       test ! -f $BLOB_FILE
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -165,9 +165,9 @@ test_expect_success 'gc --prune=<date>' '
        add_blob &&
        test-chmtime =-$((5001*$day)) $BLOB_FILE &&
        git gc --prune=5002.days.ago &&
-       test -f $BLOB_FILE &&
+       test_path_is_file $BLOB_FILE &&
        git gc --prune=5000.days.ago &&
-       test ! -f $BLOB_FILE
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -175,9 +175,9 @@ test_expect_success 'gc --prune=never' '
 
        add_blob &&
        git gc --prune=never &&
-       test -f $BLOB_FILE &&
+       test_path_is_file $BLOB_FILE &&
        git gc --prune=now &&
-       test ! -f $BLOB_FILE
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -186,10 +186,10 @@ test_expect_success 'gc respects gc.pruneExpire=never' '
        git config gc.pruneExpire never &&
        add_blob &&
        git gc &&
-       test -f $BLOB_FILE &&
+       test_path_is_file $BLOB_FILE &&
        git config gc.pruneExpire now &&
        git gc &&
-       test ! -f $BLOB_FILE
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -197,9 +197,9 @@ test_expect_success 'prune --expire=never' '
 
        add_blob &&
        git prune --expire=never &&
-       test -f $BLOB_FILE &&
+       test_path_is_file $BLOB_FILE &&
        git prune &&
-       test ! -f $BLOB_FILE
+       test_path_is_missing $BLOB_FILE
 
 '
 
@@ -209,11 +209,11 @@ test_expect_success 'gc: prune old objects after local clone' '
        git clone --no-hardlinks . aclone &&
        (
                cd aclone &&
-               test 1 = $(git count-objects | sed "s/ .*//") &&
-               test -f $BLOB_FILE &&
+               verbose test 1 = $(git count-objects | sed "s/ .*//") &&
+               test_path_is_file $BLOB_FILE &&
                git gc --prune &&
-               test 0 = $(git count-objects | sed "s/ .*//") &&
-               ! test -f $BLOB_FILE
+               verbose test 0 = $(git count-objects | sed "s/ .*//") &&
+               test_path_is_missing $BLOB_FILE
        )
 '
 
@@ -250,7 +250,7 @@ test_expect_success 'prune .git/shallow' '
        grep $SHA1 .git/shallow &&
        grep $SHA1 out &&
        git prune &&
-       ! test -f .git/shallow
+       test_path_is_missing .git/shallow
 '
 
 test_done
index 54d78079e83d7d02f69035d3bf3999084f61834a..69f11bd40d56cb945023ee0d299acd6d6f4a5fed 100755 (executable)
@@ -350,10 +350,11 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu
 '
 
 test_expect_success 'git mv moves a submodule with gitfile' '
-       rm -rf mod/sub &&
+       rm -rf mod &&
        git reset --hard &&
        git submodule update &&
        entry="$(git ls-files --stage sub | cut -f 1)" &&
+       mkdir mod &&
        (
                cd mod &&
                git mv ../sub/ .
@@ -372,11 +373,12 @@ test_expect_success 'git mv moves a submodule with gitfile' '
 '
 
 test_expect_success 'mv does not complain when no .gitmodules file is found' '
-       rm -rf mod/sub &&
+       rm -rf mod &&
        git reset --hard &&
        git submodule update &&
        git rm .gitmodules &&
        entry="$(git ls-files --stage sub | cut -f 1)" &&
+       mkdir mod &&
        git mv sub mod/sub 2>actual.err &&
        ! test -s actual.err &&
        ! test -e sub &&
@@ -390,11 +392,12 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' '
 '
 
 test_expect_success 'mv will error out on a modified .gitmodules file unless staged' '
-       rm -rf mod/sub &&
+       rm -rf mod &&
        git reset --hard &&
        git submodule update &&
        git config -f .gitmodules foo.bar true &&
        entry="$(git ls-files --stage sub | cut -f 1)" &&
+       mkdir mod &&
        test_must_fail git mv sub mod/sub 2>actual.err &&
        test -s actual.err &&
        test -e sub &&
@@ -413,13 +416,14 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta
 '
 
 test_expect_success 'mv issues a warning when section is not found in .gitmodules' '
-       rm -rf mod/sub &&
+       rm -rf mod &&
        git reset --hard &&
        git submodule update &&
        git config -f .gitmodules --remove-section submodule.sub &&
        git add .gitmodules &&
        entry="$(git ls-files --stage sub | cut -f 1)" &&
        echo "warning: Could not find section in .gitmodules where path=sub" >expect.err &&
+       mkdir mod &&
        git mv sub mod/sub 2>actual.err &&
        test_i18ncmp expect.err actual.err &&
        ! test -e sub &&
@@ -433,9 +437,10 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule
 '
 
 test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' '
-       rm -rf mod/sub &&
+       rm -rf mod &&
        git reset --hard &&
        git submodule update &&
+       mkdir mod &&
        git mv -n sub mod/sub 2>actual.err &&
        test -f sub/.git &&
        git diff-index --exit-code HEAD &&
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
new file mode 100755 (executable)
index 0000000..1efb880
--- /dev/null
@@ -0,0 +1,863 @@
+#!/bin/sh
+#
+# Copyright (c) 2013, 2014 Christian Couder
+#
+
+test_description='git interpret-trailers'
+
+. ./test-lib.sh
+
+# When we want one trailing space at the end of each line, let's use sed
+# to make sure that these spaces are not removed by any automatic tool.
+
+test_expect_success 'setup' '
+       : >empty &&
+       cat >basic_message <<-\EOF &&
+               subject
+
+               body
+       EOF
+       cat >complex_message_body <<-\EOF &&
+               my subject
+
+               my body which is long
+               and contains some special
+               chars like : = ? !
+
+       EOF
+       sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF &&
+               Fixes: Z
+               Acked-by: Z
+               Reviewed-by: Z
+               Signed-off-by: Z
+       EOF
+       cat >basic_patch <<-\EOF
+               ---
+                foo.txt | 2 +-
+                1 file changed, 1 insertion(+), 1 deletion(-)
+
+               diff --git a/foo.txt b/foo.txt
+               index 0353767..1d91aa1 100644
+               --- a/foo.txt
+               +++ b/foo.txt
+               @@ -1,3 +1,3 @@
+
+               -bar
+               +baz
+
+               --
+               1.9.rc0.11.ga562ddc
+
+       EOF
+'
+
+test_expect_success 'without config' '
+       sed -e "s/ Z\$/ /" >expected <<-\EOF &&
+
+               ack: Peff
+               Reviewed-by: Z
+               Acked-by: Johan
+       EOF
+       git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \
+               --trailer "Acked-by: Johan" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'without config in another order' '
+       sed -e "s/ Z\$/ /" >expected <<-\EOF &&
+
+               Acked-by: Johan
+               Reviewed-by: Z
+               ack: Peff
+       EOF
+       git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \
+               --trailer "ack = Peff" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success '--trim-empty without config' '
+       cat >expected <<-\EOF &&
+
+               ack: Peff
+               Acked-by: Johan
+       EOF
+       git interpret-trailers --trim-empty --trailer ack=Peff \
+               --trailer "Reviewed-by" --trailer "Acked-by: Johan" \
+               --trailer "sob:" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with config option on the command line' '
+       cat >expected <<-\EOF &&
+
+               Acked-by: Johan
+               Reviewed-by: Peff
+       EOF
+       echo "Acked-by: Johan" |
+       git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
+               --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with config setup' '
+       git config trailer.ack.key "Acked-by: " &&
+       cat >expected <<-\EOF &&
+
+               Acked-by: Peff
+       EOF
+       git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
+       test_cmp expected actual &&
+       git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual &&
+       test_cmp expected actual &&
+       git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with config setup and ":=" as separators' '
+       git config trailer.separators ":=" &&
+       git config trailer.ack.key "Acked-by= " &&
+       cat >expected <<-\EOF &&
+
+               Acked-by= Peff
+       EOF
+       git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual &&
+       test_cmp expected actual &&
+       git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual &&
+       test_cmp expected actual &&
+       git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with config setup and "%" as separators' '
+       git config trailer.separators "%" &&
+       cat >expected <<-\EOF &&
+
+               bug% 42
+               count% 10
+               bug% 422
+       EOF
+       git interpret-trailers --trim-empty --trailer "bug = 42" \
+               --trailer count%10 --trailer "test: stuff" \
+               --trailer "bug % 422" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with "%" as separators and a message with trailers' '
+       cat >special_message <<-\EOF &&
+               Special Message
+
+               bug% 42
+               count% 10
+               bug% 422
+       EOF
+       cat >expected <<-\EOF &&
+               Special Message
+
+               bug% 42
+               count% 10
+               bug% 422
+               count% 100
+       EOF
+       git interpret-trailers --trailer count%100 \
+               special_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with config setup and ":=#" as separators' '
+       git config trailer.separators ":=#" &&
+       git config trailer.bug.key "Bug #" &&
+       cat >expected <<-\EOF &&
+
+               Bug #42
+       EOF
+       git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with commit basic message' '
+       cat basic_message >expected &&
+       echo >>expected &&
+       git interpret-trailers <basic_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with basic patch' '
+       cat basic_message >input &&
+       cat basic_patch >>input &&
+       cat basic_message >expected &&
+       echo >>expected &&
+       cat basic_patch >>expected &&
+       git interpret-trailers <input >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with commit complex message as argument' '
+       cat complex_message_body complex_message_trailers >complex_message &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by: Z
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with 2 files arguments' '
+       cat basic_message >>expected &&
+       echo >>expected &&
+       cat basic_patch >>expected &&
+       git interpret-trailers complex_message input >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with message that has comments' '
+       cat basic_message >>message_with_comments &&
+       sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
+               # comment
+
+               # other comment
+               Cc: Z
+               # yet another comment
+               Reviewed-by: Johan
+               Reviewed-by: Z
+               # last comment
+
+       EOF
+       cat basic_patch >>message_with_comments &&
+       cat basic_message >expected &&
+       cat >>expected <<-\EOF &&
+               # comment
+
+               Reviewed-by: Johan
+               Cc: Peff
+       EOF
+       cat basic_patch >>expected &&
+       git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with commit complex message and trailer args' '
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by: Z
+               Signed-off-by: Z
+               Acked-by= Peff
+               Bug #42
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "bug: 42" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with complex patch, args and --trim-empty' '
+       cat complex_message >complex_patch &&
+       cat basic_patch >>complex_patch &&
+       cat complex_message_body >expected &&
+       cat >>expected <<-\EOF &&
+               Acked-by= Peff
+               Bug #42
+       EOF
+       cat basic_patch >>expected &&
+       git interpret-trailers --trim-empty --trailer "ack: Peff" \
+               --trailer "bug: 42" <complex_patch >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "where = before"' '
+       git config trailer.bug.where "before" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by: Z
+               Signed-off-by: Z
+               Acked-by= Peff
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "bug: 42" complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "where = after"' '
+       git config trailer.ack.where "after" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Reviewed-by: Z
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "bug: 42" complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "where = end"' '
+       git config trailer.review.key "Reviewed-by" &&
+       git config trailer.review.where "end" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Reviewed-by: Z
+               Signed-off-by: Z
+               Reviewed-by: Junio
+               Reviewed-by: Johannes
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
+               complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "where = start"' '
+       git config trailer.review.key "Reviewed-by" &&
+       git config trailer.review.where "start" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Reviewed-by: Johannes
+               Reviewed-by: Junio
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Reviewed-by: Z
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \
+               complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "where = before" for a token in the middle of the message' '
+       git config trailer.review.key "Reviewed-by:" &&
+       git config trailer.review.where "before" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Reviewed-by:Johan
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \
+               --trailer "review: Johan" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "where = before" and --trim-empty' '
+       cat complex_message_body >expected &&
+       cat >>expected <<-\EOF &&
+               Bug #46
+               Bug #42
+               Acked-by= Peff
+               Reviewed-by:Johan
+       EOF
+       git interpret-trailers --trim-empty --trailer "ack: Peff" \
+               --trailer "bug: 42" --trailer "review: Johan" \
+               --trailer "Bug: 46" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' '
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
+               --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
+               --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'default "ifExists" is now "addIfDifferent"' '
+       git config trailer.ifexists "addIfDifferent" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Acked-by= Junio
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
+               --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \
+               --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' '
+       git config trailer.ack.ifExists "addIfDifferent" &&
+       git config trailer.ack.where "end" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Acked-by= Peff
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
+               --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' '
+       git config trailer.ack.ifExists "addIfDifferent" &&
+       git config trailer.ack.where "before" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Peff
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
+               --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' '
+       git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
+       git config trailer.ack.where "end" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Acked-by= Peff
+               Acked-by= Junio
+               Tested-by: Jakub
+               Acked-by= Junio
+               Acked-by= Peff
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
+               --trailer "ack: Junio" --trailer "bug: 42" \
+               --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
+               --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = addIfDifferentNeighbor"  with "where = after"' '
+       git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
+       git config trailer.ack.where "after" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+               Tested-by: Jakub
+       EOF
+       git interpret-trailers --trailer "ack: Peff" --trailer "review:" \
+               --trailer "ack: Junio" --trailer "bug: 42" \
+               --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
+               --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' '
+       git config trailer.ack.ifExists "addIfDifferentNeighbor" &&
+       cat complex_message_body >expected &&
+       cat >>expected <<-\EOF &&
+               Bug #42
+               Acked-by= Peff
+               Acked-by= Junio
+               Acked-by= Peff
+       EOF
+       git interpret-trailers --trim-empty --trailer "ack: Peff" \
+               --trailer "Acked-by= Peff" --trailer "review:" \
+               --trailer "ack: Junio" --trailer "bug: 42" \
+               --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = add" with "where = end"' '
+       git config trailer.ack.ifExists "add" &&
+       git config trailer.ack.where "end" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Acked-by= Peff
+               Acked-by= Peff
+               Tested-by: Jakub
+               Acked-by= Junio
+               Tested-by: Johannes
+               Acked-by= Peff
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "Acked-by= Peff" --trailer "review:" \
+               --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
+               --trailer "bug: 42" --trailer "Tested-by: Johannes" \
+               --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = add" with "where = after"' '
+       git config trailer.ack.ifExists "add" &&
+       git config trailer.ack.where "after" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Acked-by= Peff
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "Acked-by= Peff" --trailer "review:" \
+               --trailer "ack: Junio" --trailer "bug: 42" \
+               --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = replace"' '
+       git config trailer.fix.key "Fixes: " &&
+       git config trailer.fix.ifExists "replace" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+               Fixes: 22
+       EOF
+       git interpret-trailers --trailer "review:" \
+               --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
+               --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = replace" with "where = after"' '
+       git config trailer.fix.where "after" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: 22
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "review:" \
+               --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \
+               --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifExists = doNothing"' '
+       git config trailer.fix.ifExists "doNothing" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=53" \
+               --trailer "ack: Junio" --trailer "fix=22" \
+               --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'the default is "ifMissing = add"' '
+       git config trailer.cc.key "Cc: " &&
+       git config trailer.cc.where "before" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Cc: Linus
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=53" \
+               --trailer "cc=Linus" --trailer "ack: Junio" \
+               --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'when default "ifMissing" is "doNothing"' '
+       git config trailer.ifmissing "doNothing" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=53" \
+               --trailer "cc=Linus" --trailer "ack: Junio" \
+               --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual &&
+       git config trailer.ifmissing "add"
+'
+
+test_expect_success 'using "ifMissing = add" with "where = end"' '
+       git config trailer.cc.key "Cc: " &&
+       git config trailer.cc.where "end" &&
+       git config trailer.cc.ifMissing "add" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+               Cc: Linus
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=53" \
+               --trailer "ack: Junio" --trailer "fix=22" \
+               --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifMissing = add" with "where = before"' '
+       git config trailer.cc.key "Cc: " &&
+       git config trailer.cc.where "before" &&
+       git config trailer.cc.ifMissing "add" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Cc: Linus
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=53" \
+               --trailer "ack: Junio" --trailer "fix=22" \
+               --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'using "ifMissing = doNothing"' '
+       git config trailer.cc.ifMissing "doNothing" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=53" \
+               --trailer "cc=Linus" --trailer "ack: Junio" \
+               --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'default "where" is now "after"' '
+       git config trailer.where "after" &&
+       git config --unset trailer.ack.where &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Bug #42
+               Fixes: Z
+               Acked-by= Z
+               Acked-by= Peff
+               Acked-by= Peff
+               Acked-by= Junio
+               Acked-by= Peff
+               Reviewed-by:
+               Signed-off-by: Z
+               Tested-by: Jakub
+               Tested-by: Johannes
+       EOF
+       git interpret-trailers --trailer "ack: Peff" \
+               --trailer "Acked-by= Peff" --trailer "review:" \
+               --trailer "Tested-by: Jakub" --trailer "ack: Junio" \
+               --trailer "bug: 42" --trailer "Tested-by: Johannes" \
+               --trailer "ack: Peff" <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with simple command' '
+       git config trailer.sign.key "Signed-off-by: " &&
+       git config trailer.sign.where "after" &&
+       git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
+       git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Signed-off-by: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=22" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with command using commiter information' '
+       git config trailer.sign.ifExists "addIfDifferent" &&
+       git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Signed-off-by: C O Mitter <committer@example.com>
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=22" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with command using author information' '
+       git config trailer.sign.key "Signed-off-by: " &&
+       git config trailer.sign.where "after" &&
+       git config trailer.sign.ifExists "addIfDifferentNeighbor" &&
+       git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-\EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Signed-off-by: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=22" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'setup a commit' '
+       echo "Content of the first commit." > a.txt &&
+       git add a.txt &&
+       git commit -m "Add file a.txt"
+'
+
+test_expect_success 'with command using $ARG' '
+       git config trailer.fix.ifExists "replace" &&
+       git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" &&
+       FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-EOF &&
+               Fixes: $FIXED
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Signed-off-by: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with failing command using $ARG' '
+       git config trailer.fix.ifExists "replace" &&
+       git config trailer.fix.command "false \$ARG" &&
+       cat complex_message_body >expected &&
+       sed -e "s/ Z\$/ /" >>expected <<-EOF &&
+               Fixes: Z
+               Acked-by= Z
+               Reviewed-by:
+               Signed-off-by: Z
+               Signed-off-by: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \
+               <complex_message >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'with empty tokens' '
+       git config --unset trailer.fix.command &&
+       cat >expected <<-EOF &&
+
+               Signed-off-by: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF &&
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'with command but no key' '
+       git config --unset trailer.sign.key &&
+       cat >expected <<-EOF &&
+
+               sign: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers >actual <<-EOF &&
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'with no command and no key' '
+       git config --unset trailer.review.key &&
+       cat >expected <<-EOF &&
+
+               review: Junio
+               sign: A U Thor <author@example.com>
+       EOF
+       git interpret-trailers --trailer "review:Junio" >actual <<-EOF &&
+       EOF
+       test_cmp expected actual
+'
+
+test_done
index 05d9db090d7813d231a397c190603f4a3615a8d0..7eeb207b32b48041037488f42e645b8b12742690 100755 (executable)
@@ -14,512 +14,527 @@ Testing basic merge tool invocation'
 # running mergetool
 
 test_expect_success 'setup' '
-    git config rerere.enabled true &&
-    echo master >file1 &&
-    echo master spaced >"spaced name" &&
-    echo master file11 >file11 &&
-    echo master file12 >file12 &&
-    echo master file13 >file13 &&
-    echo master file14 >file14 &&
-    mkdir subdir &&
-    echo master sub >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 "spaced name" 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 spaced >"spaced name" &&
-    echo branch1 both added >both &&
-    echo branch1 change file11 >file11 &&
-    echo branch1 change file13 >file13 &&
-    echo branch1 sub >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 "spaced name" file11 file13 file2 subdir/file3 submod &&
-    git add both &&
-    git rm file12 &&
-    git commit -m "branch1 changes" &&
-
-    git checkout -b stash1 master &&
-    echo stash1 change file11 >file11 &&
-    git add file11 &&
-    git commit -m "stash1 changes" &&
-
-    git checkout -b stash2 master &&
-    echo stash2 change file11 >file11 &&
-    git add file11 &&
-    git commit -m "stash2 changes" &&
-
-    git checkout master &&
-    git submodule update -N &&
-    echo master updated >file1 &&
-    echo master new >file2 &&
-    echo master updated spaced >"spaced name" &&
-    echo master both added >both &&
-    echo master updated file12 >file12 &&
-    echo master updated file14 >file14 &&
-    echo master new sub >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 "spaced name" file12 file14 file2 subdir/file3 submod &&
-    git add both &&
-    git rm file11 &&
-    git commit -m "master updates" &&
-
-    git config merge.tool mytool &&
-    git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
-    git config mergetool.mytool.trustExitCode true &&
-    git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
-    git config mergetool.mybase.trustExitCode true
+       test_config rerere.enabled true &&
+       echo master >file1 &&
+       echo master spaced >"spaced name" &&
+       echo master file11 >file11 &&
+       echo master file12 >file12 &&
+       echo master file13 >file13 &&
+       echo master file14 >file14 &&
+       mkdir subdir &&
+       echo master sub >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 "spaced name" 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 spaced >"spaced name" &&
+       echo branch1 both added >both &&
+       echo branch1 change file11 >file11 &&
+       echo branch1 change file13 >file13 &&
+       echo branch1 sub >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 "spaced name" file11 file13 file2 subdir/file3 submod &&
+       git add both &&
+       git rm file12 &&
+       git commit -m "branch1 changes" &&
+
+       git checkout -b stash1 master &&
+       echo stash1 change file11 >file11 &&
+       git add file11 &&
+       git commit -m "stash1 changes" &&
+
+       git checkout -b stash2 master &&
+       echo stash2 change file11 >file11 &&
+       git add file11 &&
+       git commit -m "stash2 changes" &&
+
+       git checkout master &&
+       git submodule update -N &&
+       echo master updated >file1 &&
+       echo master new >file2 &&
+       echo master updated spaced >"spaced name" &&
+       echo master both added >both &&
+       echo master updated file12 >file12 &&
+       echo master updated file14 >file14 &&
+       echo master new sub >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 "spaced name" file12 file14 file2 subdir/file3 submod &&
+       git add both &&
+       git rm file11 &&
+       git commit -m "master updates" &&
+
+       git config merge.tool mytool &&
+       git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
+       git config mergetool.mytool.trustExitCode true &&
+       git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" &&
+       git config mergetool.mybase.trustExitCode true
 '
 
 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 both >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool file1 file1 ) &&
-    ( yes "" | git mergetool file2 "spaced name" >/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"
+       git checkout -b test1 branch1 &&
+       git submodule update -N &&
+       test_must_fail git merge master >/dev/null 2>&1 &&
+       ( yes "" | git mergetool both >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool file1 file1 ) &&
+       ( yes "" | git mergetool file2 "spaced name" >/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"
 '
 
 test_expect_success 'mergetool crlf' '
-    git config core.autocrlf true &&
-    git checkout -b test2 branch1 &&
-    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 "spaced name" >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 "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
+       test_config core.autocrlf true &&
+       git checkout -b test2 branch1 &&
+       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 "spaced name" >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 "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" &&
+       test_config core.autocrlf false &&
+       git reset --hard
 '
 
 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 &&
-       ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
-       test "$(cat file3)" = "master new sub"
-    )
+       git checkout -b test3 branch1 &&
+       git submodule update -N &&
+       (
+               cd subdir &&
+               test_must_fail git merge master >/dev/null 2>&1 &&
+               ( yes "" | git mergetool file3 >/dev/null 2>&1 ) &&
+               test "$(cat file3)" = "master new sub"
+       )
 '
 
 test_expect_success 'mergetool on file in parent dir' '
-    (
-       cd subdir &&
-       ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
-       ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
-       ( yes "" | git mergetool ../both >/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"
-    )
+       (
+               cd subdir &&
+               ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) &&
+               ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) &&
+               ( yes "" | git mergetool ../both >/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
+       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
 '
 
 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"
-    )
+       (
+               cd subdir &&
+               test_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"
+       )
 '
 
 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_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 'conflicted stash sets up rerere'  '
-    git config rerere.enabled true &&
-    git checkout stash1 &&
-    echo "Conflicting stash content" >file11 &&
-    git stash &&
-
-    git checkout --detach stash2 &&
-    test_must_fail git stash apply &&
-
-    test -n "$(git ls-files -u)" &&
-    conflicts="$(git rerere remaining)" &&
-    test "$conflicts" = "file11" &&
-    output="$(git mergetool --no-prompt)" &&
-    test "$output" != "No files need merging" &&
-
-    git commit -am "save the stash resolution" &&
-
-    git reset --hard stash2 &&
-    test_must_fail git stash apply &&
-
-    test -n "$(git ls-files -u)" &&
-    conflicts="$(git rerere remaining)" &&
-    test -z "$conflicts" &&
-    output="$(git mergetool --no-prompt)" &&
-    test "$output" = "No files need merging"
+       test_config rerere.enabled true &&
+       git checkout stash1 &&
+       echo "Conflicting stash content" >file11 &&
+       git stash &&
+
+       git checkout --detach stash2 &&
+       test_must_fail git stash apply &&
+
+       test -n "$(git ls-files -u)" &&
+       conflicts="$(git rerere remaining)" &&
+       test "$conflicts" = "file11" &&
+       output="$(git mergetool --no-prompt)" &&
+       test "$output" != "No files need merging" &&
+
+       git commit -am "save the stash resolution" &&
+
+       git reset --hard stash2 &&
+       test_must_fail git stash apply &&
+
+       test -n "$(git ls-files -u)" &&
+       conflicts="$(git rerere remaining)" &&
+       test -z "$conflicts" &&
+       output="$(git mergetool --no-prompt)" &&
+       test "$output" = "No files need merging"
 '
 
 test_expect_success 'mergetool takes partial path' '
-    git reset --hard
-    git config rerere.enabled false &&
-    git checkout -b test12 branch1 &&
-    git submodule update -N &&
-    test_must_fail git merge master &&
-
-    #should not need these lines
-    #( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
-    #( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
-    #( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
-    #( yes "" | git mergetool file1 file2 >/dev/null 2>&1 ) &&
-
-    ( yes "" | git mergetool subdir ) &&
-
-    test "$(cat subdir/file3)" = "master new sub" &&
-    git reset --hard
+       git reset --hard &&
+       test_config rerere.enabled false &&
+       git checkout -b test12 branch1 &&
+       git submodule update -N &&
+       test_must_fail git merge master &&
+
+       ( yes "" | git mergetool subdir ) &&
+
+       test "$(cat subdir/file3)" = "master new sub" &&
+       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 --cached 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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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
+       git checkout -b test6 branch1 &&
+       git submodule update -N &&
+       mv submod submod-movedaside &&
+       git rm --cached 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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 --cached 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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
-    ( yes "" | git mergetool both>/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 checkout -b test7 branch1 &&
+       git submodule update -N &&
+       mv submod submod-movedaside &&
+       git rm --cached 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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both >/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 spaced\ name subdir/file3 >/dev/null 2>&1 ) &&
+       ( yes "" | git mergetool both>/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 &&
+       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_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
+               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 --cached 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 >/dev/null 2>&1 &&
-    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 >/dev/null 2>&1 && 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 >/dev/null 2>&1 &&
-    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 >/dev/null 2>&1 &&
-    ( cd submod && git clean -f && git reset --hard ) &&
-    git submodule update -N
+       git checkout -b test11 branch1 &&
+       mv submod submod-movedaside &&
+       git rm --cached 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 >/dev/null 2>&1 &&
+       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 >/dev/null 2>&1 && 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 >/dev/null 2>&1 &&
+       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 >/dev/null 2>&1 &&
+       ( cd submod && git clean -f && git reset --hard ) &&
+       git submodule update -N
 '
 
 test_expect_success 'file with no base' '
-    git checkout -b test13 branch1 &&
-    test_must_fail git merge master &&
-    git mergetool --no-prompt --tool mybase -- both &&
-    >expected &&
-    test_cmp both expected &&
-    git reset --hard master >/dev/null 2>&1
+       git checkout -b test13 branch1 &&
+       test_must_fail git merge master &&
+       git mergetool --no-prompt --tool mybase -- both &&
+       >expected &&
+       test_cmp both expected &&
+       git reset --hard master >/dev/null 2>&1
 '
 
 test_expect_success 'custom commands override built-ins' '
-    git checkout -b test14 branch1 &&
-    git config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
-    git config mergetool.defaults.trustExitCode true &&
-    test_must_fail git merge master &&
-    git mergetool --no-prompt --tool defaults -- both &&
-    echo master both added >expected &&
-    test_cmp both expected &&
-    git config --unset mergetool.defaults.cmd &&
-    git config --unset mergetool.defaults.trustExitCode &&
-    git reset --hard master >/dev/null 2>&1
+       git checkout -b test14 branch1 &&
+       test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" &&
+       test_config mergetool.defaults.trustExitCode true &&
+       test_must_fail git merge master &&
+       git mergetool --no-prompt --tool defaults -- both &&
+       echo master both added >expected &&
+       test_cmp both expected &&
+       git reset --hard master >/dev/null 2>&1
+'
+
+test_expect_success 'filenames seen by tools start with ./' '
+       git checkout -b test15 branch1 &&
+       test_config mergetool.writeToTemp false &&
+       test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
+       test_config mergetool.myecho.trustExitCode true &&
+       test_must_fail git merge master &&
+       git mergetool --no-prompt --tool myecho -- both >actual &&
+       grep ^\./both_LOCAL_ actual >/dev/null &&
+       git reset --hard master >/dev/null 2>&1
+'
+
+test_expect_success 'temporary filenames are used with mergetool.writeToTemp' '
+       git checkout -b test16 branch1 &&
+       test_config mergetool.writeToTemp true &&
+       test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
+       test_config mergetool.myecho.trustExitCode true &&
+       test_must_fail git merge master &&
+       git mergetool --no-prompt --tool myecho -- both >actual &&
+       test_must_fail grep ^\./both_LOCAL_ actual >/dev/null &&
+       grep /both_LOCAL_ actual >/dev/null &&
+       git reset --hard master >/dev/null 2>&1
 '
 
 test_done
index 8df0445a84f86d9097406478ee0b08be7eeda74b..37c2d633f0d2fefdb530266b8b250ef59e8704d3 100755 (executable)
@@ -346,36 +346,6 @@ test_expect_success 'B: fail on invalid blob sha1' '
 '
 rm -f .git/objects/pack_* .git/objects/index_*
 
-cat >input <<INPUT_END
-commit .badbranchname
-committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-data <<COMMIT
-corrupt
-COMMIT
-
-from refs/heads/master
-
-INPUT_END
-test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
-    test_must_fail git fast-import <input
-'
-rm -f .git/objects/pack_* .git/objects/index_*
-
-cat >input <<INPUT_END
-commit bad[branch]name
-committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-data <<COMMIT
-corrupt
-COMMIT
-
-from refs/heads/master
-
-INPUT_END
-test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
-    test_must_fail git fast-import <input
-'
-rm -f .git/objects/pack_* .git/objects/index_*
-
 cat >input <<INPUT_END
 commit TEMP_TAG
 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
index dafd6ad21a92bac48155af39ebb9a4baaf3c4970..0d93e33de4759bff71739c19be803cac981f0770 100644 (file)
@@ -413,7 +413,7 @@ test_external () {
                # test_run_, but keep its stdout on our stdout even in
                # non-verbose mode.
                "$@" 2>&4
-               if [ "$?" = 0 ]
+               if test "$?" = 0
                then
                        if test $test_external_has_tap -eq 0; then
                                test_ok_ "$descr"
@@ -440,11 +440,12 @@ test_external_without_stderr () {
        tmp=${TMPDIR:-/tmp}
        stderr="$tmp/git-external-stderr.$$.tmp"
        test_external "$@" 4> "$stderr"
-       [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
+       test -f "$stderr" || error "Internal error: $stderr disappeared."
        descr="no stderr: $1"
        shift
        say >&3 "# expecting no stderr from previous command"
-       if [ ! -s "$stderr" ]; then
+       if test ! -s "$stderr"
+       then
                rm "$stderr"
 
                if test $test_external_has_tap -eq 0; then
@@ -454,8 +455,9 @@ test_external_without_stderr () {
                        test_success=$(($test_success + 1))
                fi
        else
-               if [ "$verbose" = t ]; then
-                       output=`echo; echo "# Stderr is:"; cat "$stderr"`
+               if test "$verbose" = t
+               then
+                       output=$(echo; echo "# Stderr is:"; cat "$stderr")
                else
                        output=
                fi
@@ -474,7 +476,7 @@ test_external_without_stderr () {
 # The commands test the existence or non-existence of $1. $2 can be
 # given to provide a more precise diagnosis.
 test_path_is_file () {
-       if ! [ -f "$1" ]
+       if ! test -f "$1"
        then
                echo "File $1 doesn't exist. $*"
                false
@@ -482,7 +484,7 @@ test_path_is_file () {
 }
 
 test_path_is_dir () {
-       if ! [ -d "$1" ]
+       if ! test -d "$1"
        then
                echo "Directory $1 doesn't exist. $*"
                false
@@ -501,11 +503,12 @@ test_dir_is_empty () {
 }
 
 test_path_is_missing () {
-       if [ -e "$1" ]
+       if test -e "$1"
        then
                echo "Path exists:"
                ls -ld "$1"
-               if [ $# -ge 1 ]; then
+               if test $# -ge 1
+               then
                        echo "$*"
                fi
                false
@@ -634,6 +637,15 @@ test_cmp_bin() {
        cmp "$@"
 }
 
+# Call any command "$@" but be more verbose about its
+# failure. This is handy for commands like "test" which do
+# not output anything when they fail.
+verbose () {
+       "$@" && return 0
+       echo >&2 "command failed: $(git rev-parse --sq-quote "$@")"
+       return 1
+}
+
 # Check if the file expected to be empty is indeed empty, and barfs
 # otherwise.
 
@@ -657,9 +669,12 @@ test_cmp_rev () {
 # similar to GNU seq(1), but the latter might not be available
 # everywhere (and does not do letters).  It may be used like:
 #
-#      for i in `test_seq 100`; do
-#              for j in `test_seq 10 20`; do
-#                      for k in `test_seq a z`; do
+#      for i in $(test_seq 100)
+#      do
+#              for j in $(test_seq 10 20)
+#              do
+#                      for k in $(test_seq a z)
+#                      do
 #                              echo $i-$j-$k
 #                      done
 #              done
index 0f4a67bfc63a989883007911f889ba5aed1c0aac..cf19339ccebd0ee5f55822ebe11386101f358f41 100644 (file)
@@ -233,6 +233,10 @@ do
        --root=*)
                root=$(expr "z$1" : 'z[^=]*=\(.*\)')
                shift ;;
+       -x)
+               trace=t
+               verbose=t
+               shift ;;
        *)
                echo "error: unknown test option '$1'" >&2; exit 1 ;;
        esac
@@ -517,10 +521,39 @@ maybe_setup_valgrind () {
        fi
 }
 
+# This is a separate function because some tests use
+# "return" to end a test_expect_success block early
+# (and we want to make sure we run any cleanup like
+# "set +x").
+test_eval_inner_ () {
+       # Do not add anything extra (including LF) after '$*'
+       eval "
+               test \"$trace\" = t && set -x
+               $*"
+}
+
 test_eval_ () {
-       # This is a separate function because some tests use
-       # "return" to end a test_expect_success block early.
-       eval </dev/null >&3 2>&4 "$*"
+       # We run this block with stderr redirected to avoid extra cruft
+       # during a "-x" trace. Once in "set -x" mode, we cannot prevent
+       # the shell from printing the "set +x" to turn it off (nor the saving
+       # of $? before that). But we can make sure that the output goes to
+       # /dev/null.
+       #
+       # The test itself is run with stderr put back to &4 (so either to
+       # /dev/null, or to the original stderr if --verbose was used).
+       {
+               test_eval_inner_ "$@" </dev/null >&3 2>&4
+               test_eval_ret_=$?
+               if test "$trace" = t
+               then
+                       set +x
+                       if test "$test_eval_ret_" != 0
+                       then
+                               say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
+                       fi
+               fi
+       } 2>/dev/null
+       return $test_eval_ret_
 }
 
 test_run_ () {
@@ -531,7 +564,8 @@ test_run_ () {
        eval_ret=$?
        teardown_malloc_check
 
-       if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
+       if test -z "$immediate" || test $eval_ret = 0 ||
+          test -n "$expecting_failure" && test "$test_cleanup" != ":"
        then
                setup_malloc_check
                test_eval_ "$test_cleanup"
diff --git a/trace.c b/trace.c
index b6f25a23fdf8b6eec64181b5d6b56909bbe4ae7b..477860894196e32d7db990459cef47175277c441 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -385,7 +385,7 @@ static inline uint64_t gettimeofday_nanos(void)
  * Returns nanoseconds since the epoch (01/01/1970), for performance tracing
  * (i.e. favoring high precision over wall clock time accuracy).
  */
-inline uint64_t getnanotime(void)
+uint64_t getnanotime(void)
 {
        static uint64_t offset;
        if (offset > 1) {
diff --git a/trailer.c b/trailer.c
new file mode 100644 (file)
index 0000000..8514566
--- /dev/null
+++ b/trailer.c
@@ -0,0 +1,851 @@
+#include "cache.h"
+#include "string-list.h"
+#include "run-command.h"
+#include "string-list.h"
+#include "trailer.h"
+/*
+ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org>
+ */
+
+enum action_where { WHERE_END, WHERE_AFTER, WHERE_BEFORE, WHERE_START };
+enum action_if_exists { EXISTS_ADD_IF_DIFFERENT_NEIGHBOR, EXISTS_ADD_IF_DIFFERENT,
+                       EXISTS_ADD, EXISTS_REPLACE, EXISTS_DO_NOTHING };
+enum action_if_missing { MISSING_ADD, MISSING_DO_NOTHING };
+
+struct conf_info {
+       char *name;
+       char *key;
+       char *command;
+       enum action_where where;
+       enum action_if_exists if_exists;
+       enum action_if_missing if_missing;
+};
+
+static struct conf_info default_conf_info;
+
+struct trailer_item {
+       struct trailer_item *previous;
+       struct trailer_item *next;
+       const char *token;
+       const char *value;
+       struct conf_info conf;
+};
+
+static struct trailer_item *first_conf_item;
+
+static char *separators = ":";
+
+#define TRAILER_ARG_STRING "$ARG"
+
+static int after_or_end(enum action_where where)
+{
+       return (where == WHERE_AFTER) || (where == WHERE_END);
+}
+
+/*
+ * Return the length of the string not including any final
+ * punctuation. E.g., the input "Signed-off-by:" would return
+ * 13, stripping the trailing punctuation but retaining
+ * internal punctuation.
+ */
+static size_t token_len_without_separator(const char *token, size_t len)
+{
+       while (len > 0 && !isalnum(token[len - 1]))
+               len--;
+       return len;
+}
+
+static int same_token(struct trailer_item *a, struct trailer_item *b)
+{
+       size_t a_len = token_len_without_separator(a->token, strlen(a->token));
+       size_t b_len = token_len_without_separator(b->token, strlen(b->token));
+       size_t min_len = (a_len > b_len) ? b_len : a_len;
+
+       return !strncasecmp(a->token, b->token, min_len);
+}
+
+static int same_value(struct trailer_item *a, struct trailer_item *b)
+{
+       return !strcasecmp(a->value, b->value);
+}
+
+static int same_trailer(struct trailer_item *a, struct trailer_item *b)
+{
+       return same_token(a, b) && same_value(a, b);
+}
+
+static inline int contains_only_spaces(const char *str)
+{
+       const char *s = str;
+       while (*s && isspace(*s))
+               s++;
+       return !*s;
+}
+
+static inline void strbuf_replace(struct strbuf *sb, const char *a, const char *b)
+{
+       const char *ptr = strstr(sb->buf, a);
+       if (ptr)
+               strbuf_splice(sb, ptr - sb->buf, strlen(a), b, strlen(b));
+}
+
+static void free_trailer_item(struct trailer_item *item)
+{
+       free(item->conf.name);
+       free(item->conf.key);
+       free(item->conf.command);
+       free((char *)item->token);
+       free((char *)item->value);
+       free(item);
+}
+
+static char last_non_space_char(const char *s)
+{
+       int i;
+       for (i = strlen(s) - 1; i >= 0; i--)
+               if (!isspace(s[i]))
+                       return s[i];
+       return '\0';
+}
+
+static void print_tok_val(const char *tok, const char *val)
+{
+       char c = last_non_space_char(tok);
+       if (!c)
+               return;
+       if (strchr(separators, c))
+               printf("%s%s\n", tok, val);
+       else
+               printf("%s%c %s\n", tok, separators[0], val);
+}
+
+static void print_all(struct trailer_item *first, int trim_empty)
+{
+       struct trailer_item *item;
+       for (item = first; item; item = item->next) {
+               if (!trim_empty || strlen(item->value) > 0)
+                       print_tok_val(item->token, item->value);
+       }
+}
+
+static void update_last(struct trailer_item **last)
+{
+       if (*last)
+               while ((*last)->next != NULL)
+                       *last = (*last)->next;
+}
+
+static void update_first(struct trailer_item **first)
+{
+       if (*first)
+               while ((*first)->previous != NULL)
+                       *first = (*first)->previous;
+}
+
+static void add_arg_to_input_list(struct trailer_item *on_tok,
+                                 struct trailer_item *arg_tok,
+                                 struct trailer_item **first,
+                                 struct trailer_item **last)
+{
+       if (after_or_end(arg_tok->conf.where)) {
+               arg_tok->next = on_tok->next;
+               on_tok->next = arg_tok;
+               arg_tok->previous = on_tok;
+               if (arg_tok->next)
+                       arg_tok->next->previous = arg_tok;
+               update_last(last);
+       } else {
+               arg_tok->previous = on_tok->previous;
+               on_tok->previous = arg_tok;
+               arg_tok->next = on_tok;
+               if (arg_tok->previous)
+                       arg_tok->previous->next = arg_tok;
+               update_first(first);
+       }
+}
+
+static int check_if_different(struct trailer_item *in_tok,
+                             struct trailer_item *arg_tok,
+                             int check_all)
+{
+       enum action_where where = arg_tok->conf.where;
+       do {
+               if (!in_tok)
+                       return 1;
+               if (same_trailer(in_tok, arg_tok))
+                       return 0;
+               /*
+                * if we want to add a trailer after another one,
+                * we have to check those before this one
+                */
+               in_tok = after_or_end(where) ? in_tok->previous : in_tok->next;
+       } while (check_all);
+       return 1;
+}
+
+static void remove_from_list(struct trailer_item *item,
+                            struct trailer_item **first,
+                            struct trailer_item **last)
+{
+       struct trailer_item *next = item->next;
+       struct trailer_item *previous = item->previous;
+
+       if (next) {
+               item->next->previous = previous;
+               item->next = NULL;
+       } else if (last)
+               *last = previous;
+
+       if (previous) {
+               item->previous->next = next;
+               item->previous = NULL;
+       } else if (first)
+               *first = next;
+}
+
+static struct trailer_item *remove_first(struct trailer_item **first)
+{
+       struct trailer_item *item = *first;
+       *first = item->next;
+       if (item->next) {
+               item->next->previous = NULL;
+               item->next = NULL;
+       }
+       return item;
+}
+
+static int read_from_command(struct child_process *cp, struct strbuf *buf)
+{
+       if (run_command(cp))
+               return error("running trailer command '%s' failed", cp->argv[0]);
+       if (strbuf_read(buf, cp->out, 1024) < 1)
+               return error("reading from trailer command '%s' failed", cp->argv[0]);
+       strbuf_trim(buf);
+       return 0;
+}
+
+static const char *apply_command(const char *command, const char *arg)
+{
+       struct strbuf cmd = STRBUF_INIT;
+       struct strbuf buf = STRBUF_INIT;
+       struct child_process cp;
+       const char *argv[] = {NULL, NULL};
+       const char *result;
+
+       strbuf_addstr(&cmd, command);
+       if (arg)
+               strbuf_replace(&cmd, TRAILER_ARG_STRING, arg);
+
+       argv[0] = cmd.buf;
+       memset(&cp, 0, sizeof(cp));
+       cp.argv = argv;
+       cp.env = local_repo_env;
+       cp.no_stdin = 1;
+       cp.out = -1;
+       cp.use_shell = 1;
+
+       if (read_from_command(&cp, &buf)) {
+               strbuf_release(&buf);
+               result = xstrdup("");
+       } else
+               result = strbuf_detach(&buf, NULL);
+
+       strbuf_release(&cmd);
+       return result;
+}
+
+static void apply_item_command(struct trailer_item *in_tok, struct trailer_item *arg_tok)
+{
+       if (arg_tok->conf.command) {
+               const char *arg;
+               if (arg_tok->value && arg_tok->value[0]) {
+                       arg = arg_tok->value;
+               } else {
+                       if (in_tok && in_tok->value)
+                               arg = xstrdup(in_tok->value);
+                       else
+                               arg = xstrdup("");
+               }
+               arg_tok->value = apply_command(arg_tok->conf.command, arg);
+               free((char *)arg);
+       }
+}
+
+static void apply_arg_if_exists(struct trailer_item *in_tok,
+                               struct trailer_item *arg_tok,
+                               struct trailer_item *on_tok,
+                               struct trailer_item **in_tok_first,
+                               struct trailer_item **in_tok_last)
+{
+       switch (arg_tok->conf.if_exists) {
+       case EXISTS_DO_NOTHING:
+               free_trailer_item(arg_tok);
+               break;
+       case EXISTS_REPLACE:
+               apply_item_command(in_tok, arg_tok);
+               add_arg_to_input_list(on_tok, arg_tok,
+                                     in_tok_first, in_tok_last);
+               remove_from_list(in_tok, in_tok_first, in_tok_last);
+               free_trailer_item(in_tok);
+               break;
+       case EXISTS_ADD:
+               apply_item_command(in_tok, arg_tok);
+               add_arg_to_input_list(on_tok, arg_tok,
+                                     in_tok_first, in_tok_last);
+               break;
+       case EXISTS_ADD_IF_DIFFERENT:
+               apply_item_command(in_tok, arg_tok);
+               if (check_if_different(in_tok, arg_tok, 1))
+                       add_arg_to_input_list(on_tok, arg_tok,
+                                             in_tok_first, in_tok_last);
+               else
+                       free_trailer_item(arg_tok);
+               break;
+       case EXISTS_ADD_IF_DIFFERENT_NEIGHBOR:
+               apply_item_command(in_tok, arg_tok);
+               if (check_if_different(on_tok, arg_tok, 0))
+                       add_arg_to_input_list(on_tok, arg_tok,
+                                             in_tok_first, in_tok_last);
+               else
+                       free_trailer_item(arg_tok);
+               break;
+       }
+}
+
+static void apply_arg_if_missing(struct trailer_item **in_tok_first,
+                                struct trailer_item **in_tok_last,
+                                struct trailer_item *arg_tok)
+{
+       struct trailer_item **in_tok;
+       enum action_where where;
+
+       switch (arg_tok->conf.if_missing) {
+       case MISSING_DO_NOTHING:
+               free_trailer_item(arg_tok);
+               break;
+       case MISSING_ADD:
+               where = arg_tok->conf.where;
+               in_tok = after_or_end(where) ? in_tok_last : in_tok_first;
+               apply_item_command(NULL, arg_tok);
+               if (*in_tok) {
+                       add_arg_to_input_list(*in_tok, arg_tok,
+                                             in_tok_first, in_tok_last);
+               } else {
+                       *in_tok_first = arg_tok;
+                       *in_tok_last = arg_tok;
+               }
+               break;
+       }
+}
+
+static int find_same_and_apply_arg(struct trailer_item **in_tok_first,
+                                  struct trailer_item **in_tok_last,
+                                  struct trailer_item *arg_tok)
+{
+       struct trailer_item *in_tok;
+       struct trailer_item *on_tok;
+       struct trailer_item *following_tok;
+
+       enum action_where where = arg_tok->conf.where;
+       int middle = (where == WHERE_AFTER) || (where == WHERE_BEFORE);
+       int backwards = after_or_end(where);
+       struct trailer_item *start_tok = backwards ? *in_tok_last : *in_tok_first;
+
+       for (in_tok = start_tok; in_tok; in_tok = following_tok) {
+               following_tok = backwards ? in_tok->previous : in_tok->next;
+               if (!same_token(in_tok, arg_tok))
+                       continue;
+               on_tok = middle ? in_tok : start_tok;
+               apply_arg_if_exists(in_tok, arg_tok, on_tok,
+                                   in_tok_first, in_tok_last);
+               return 1;
+       }
+       return 0;
+}
+
+static void process_trailers_lists(struct trailer_item **in_tok_first,
+                                  struct trailer_item **in_tok_last,
+                                  struct trailer_item **arg_tok_first)
+{
+       struct trailer_item *arg_tok;
+       struct trailer_item *next_arg;
+
+       if (!*arg_tok_first)
+               return;
+
+       for (arg_tok = *arg_tok_first; arg_tok; arg_tok = next_arg) {
+               int applied = 0;
+
+               next_arg = arg_tok->next;
+               remove_from_list(arg_tok, arg_tok_first, NULL);
+
+               applied = find_same_and_apply_arg(in_tok_first,
+                                                 in_tok_last,
+                                                 arg_tok);
+
+               if (!applied)
+                       apply_arg_if_missing(in_tok_first,
+                                            in_tok_last,
+                                            arg_tok);
+       }
+}
+
+static int set_where(struct conf_info *item, const char *value)
+{
+       if (!strcasecmp("after", value))
+               item->where = WHERE_AFTER;
+       else if (!strcasecmp("before", value))
+               item->where = WHERE_BEFORE;
+       else if (!strcasecmp("end", value))
+               item->where = WHERE_END;
+       else if (!strcasecmp("start", value))
+               item->where = WHERE_START;
+       else
+               return -1;
+       return 0;
+}
+
+static int set_if_exists(struct conf_info *item, const char *value)
+{
+       if (!strcasecmp("addIfDifferent", value))
+               item->if_exists = EXISTS_ADD_IF_DIFFERENT;
+       else if (!strcasecmp("addIfDifferentNeighbor", value))
+               item->if_exists = EXISTS_ADD_IF_DIFFERENT_NEIGHBOR;
+       else if (!strcasecmp("add", value))
+               item->if_exists = EXISTS_ADD;
+       else if (!strcasecmp("replace", value))
+               item->if_exists = EXISTS_REPLACE;
+       else if (!strcasecmp("doNothing", value))
+               item->if_exists = EXISTS_DO_NOTHING;
+       else
+               return -1;
+       return 0;
+}
+
+static int set_if_missing(struct conf_info *item, const char *value)
+{
+       if (!strcasecmp("doNothing", value))
+               item->if_missing = MISSING_DO_NOTHING;
+       else if (!strcasecmp("add", value))
+               item->if_missing = MISSING_ADD;
+       else
+               return -1;
+       return 0;
+}
+
+static void duplicate_conf(struct conf_info *dst, struct conf_info *src)
+{
+       *dst = *src;
+       if (src->name)
+               dst->name = xstrdup(src->name);
+       if (src->key)
+               dst->key = xstrdup(src->key);
+       if (src->command)
+               dst->command = xstrdup(src->command);
+}
+
+static struct trailer_item *get_conf_item(const char *name)
+{
+       struct trailer_item *item;
+       struct trailer_item *previous;
+
+       /* Look up item with same name */
+       for (previous = NULL, item = first_conf_item;
+            item;
+            previous = item, item = item->next) {
+               if (!strcasecmp(item->conf.name, name))
+                       return item;
+       }
+
+       /* Item does not already exists, create it */
+       item = xcalloc(sizeof(struct trailer_item), 1);
+       duplicate_conf(&item->conf, &default_conf_info);
+       item->conf.name = xstrdup(name);
+
+       if (!previous)
+               first_conf_item = item;
+       else {
+               previous->next = item;
+               item->previous = previous;
+       }
+
+       return item;
+}
+
+enum trailer_info_type { TRAILER_KEY, TRAILER_COMMAND, TRAILER_WHERE,
+                        TRAILER_IF_EXISTS, TRAILER_IF_MISSING };
+
+static struct {
+       const char *name;
+       enum trailer_info_type type;
+} trailer_config_items[] = {
+       { "key", TRAILER_KEY },
+       { "command", TRAILER_COMMAND },
+       { "where", TRAILER_WHERE },
+       { "ifexists", TRAILER_IF_EXISTS },
+       { "ifmissing", TRAILER_IF_MISSING }
+};
+
+static int git_trailer_default_config(const char *conf_key, const char *value, void *cb)
+{
+       const char *trailer_item, *variable_name;
+
+       if (!skip_prefix(conf_key, "trailer.", &trailer_item))
+               return 0;
+
+       variable_name = strrchr(trailer_item, '.');
+       if (!variable_name) {
+               if (!strcmp(trailer_item, "where")) {
+                       if (set_where(&default_conf_info, value) < 0)
+                               warning(_("unknown value '%s' for key '%s'"),
+                                       value, conf_key);
+               } else if (!strcmp(trailer_item, "ifexists")) {
+                       if (set_if_exists(&default_conf_info, value) < 0)
+                               warning(_("unknown value '%s' for key '%s'"),
+                                       value, conf_key);
+               } else if (!strcmp(trailer_item, "ifmissing")) {
+                       if (set_if_missing(&default_conf_info, value) < 0)
+                               warning(_("unknown value '%s' for key '%s'"),
+                                       value, conf_key);
+               } else if (!strcmp(trailer_item, "separators")) {
+                       separators = xstrdup(value);
+               }
+       }
+       return 0;
+}
+
+static int git_trailer_config(const char *conf_key, const char *value, void *cb)
+{
+       const char *trailer_item, *variable_name;
+       struct trailer_item *item;
+       struct conf_info *conf;
+       char *name = NULL;
+       enum trailer_info_type type;
+       int i;
+
+       if (!skip_prefix(conf_key, "trailer.", &trailer_item))
+               return 0;
+
+       variable_name = strrchr(trailer_item, '.');
+       if (!variable_name)
+               return 0;
+
+       variable_name++;
+       for (i = 0; i < ARRAY_SIZE(trailer_config_items); i++) {
+               if (strcmp(trailer_config_items[i].name, variable_name))
+                       continue;
+               name = xstrndup(trailer_item,  variable_name - trailer_item - 1);
+               type = trailer_config_items[i].type;
+               break;
+       }
+
+       if (!name)
+               return 0;
+
+       item = get_conf_item(name);
+       conf = &item->conf;
+       free(name);
+
+       switch (type) {
+       case TRAILER_KEY:
+               if (conf->key)
+                       warning(_("more than one %s"), conf_key);
+               conf->key = xstrdup(value);
+               break;
+       case TRAILER_COMMAND:
+               if (conf->command)
+                       warning(_("more than one %s"), conf_key);
+               conf->command = xstrdup(value);
+               break;
+       case TRAILER_WHERE:
+               if (set_where(conf, value))
+                       warning(_("unknown value '%s' for key '%s'"), value, conf_key);
+               break;
+       case TRAILER_IF_EXISTS:
+               if (set_if_exists(conf, value))
+                       warning(_("unknown value '%s' for key '%s'"), value, conf_key);
+               break;
+       case TRAILER_IF_MISSING:
+               if (set_if_missing(conf, value))
+                       warning(_("unknown value '%s' for key '%s'"), value, conf_key);
+               break;
+       default:
+               die("internal bug in trailer.c");
+       }
+       return 0;
+}
+
+static int parse_trailer(struct strbuf *tok, struct strbuf *val, const char *trailer)
+{
+       size_t len;
+       struct strbuf seps = STRBUF_INIT;
+       strbuf_addstr(&seps, separators);
+       strbuf_addch(&seps, '=');
+       len = strcspn(trailer, seps.buf);
+       strbuf_release(&seps);
+       if (len == 0)
+               return error(_("empty trailer token in trailer '%s'"), trailer);
+       if (len < strlen(trailer)) {
+               strbuf_add(tok, trailer, len);
+               strbuf_trim(tok);
+               strbuf_addstr(val, trailer + len + 1);
+               strbuf_trim(val);
+       } else {
+               strbuf_addstr(tok, trailer);
+               strbuf_trim(tok);
+       }
+       return 0;
+}
+
+static const char *token_from_item(struct trailer_item *item, char *tok)
+{
+       if (item->conf.key)
+               return item->conf.key;
+       if (tok)
+               return tok;
+       return item->conf.name;
+}
+
+static struct trailer_item *new_trailer_item(struct trailer_item *conf_item,
+                                            char *tok, char *val)
+{
+       struct trailer_item *new = xcalloc(sizeof(*new), 1);
+       new->value = val ? val : xstrdup("");
+
+       if (conf_item) {
+               duplicate_conf(&new->conf, &conf_item->conf);
+               new->token = xstrdup(token_from_item(conf_item, tok));
+               free(tok);
+       } else {
+               duplicate_conf(&new->conf, &default_conf_info);
+               new->token = tok;
+       }
+
+       return new;
+}
+
+static int token_matches_item(const char *tok, struct trailer_item *item, int tok_len)
+{
+       if (!strncasecmp(tok, item->conf.name, tok_len))
+               return 1;
+       return item->conf.key ? !strncasecmp(tok, item->conf.key, tok_len) : 0;
+}
+
+static struct trailer_item *create_trailer_item(const char *string)
+{
+       struct strbuf tok = STRBUF_INIT;
+       struct strbuf val = STRBUF_INIT;
+       struct trailer_item *item;
+       int tok_len;
+
+       if (parse_trailer(&tok, &val, string))
+               return NULL;
+
+       tok_len = token_len_without_separator(tok.buf, tok.len);
+
+       /* Lookup if the token matches something in the config */
+       for (item = first_conf_item; item; item = item->next) {
+               if (token_matches_item(tok.buf, item, tok_len))
+                       return new_trailer_item(item,
+                                               strbuf_detach(&tok, NULL),
+                                               strbuf_detach(&val, NULL));
+       }
+
+       return new_trailer_item(NULL,
+                               strbuf_detach(&tok, NULL),
+                               strbuf_detach(&val, NULL));
+}
+
+static void add_trailer_item(struct trailer_item **first,
+                            struct trailer_item **last,
+                            struct trailer_item *new)
+{
+       if (!new)
+               return;
+       if (!*last) {
+               *first = new;
+               *last = new;
+       } else {
+               (*last)->next = new;
+               new->previous = *last;
+               *last = new;
+       }
+}
+
+static struct trailer_item *process_command_line_args(struct string_list *trailers)
+{
+       struct trailer_item *arg_tok_first = NULL;
+       struct trailer_item *arg_tok_last = NULL;
+       struct string_list_item *tr;
+       struct trailer_item *item;
+
+       /* Add a trailer item for each configured trailer with a command */
+       for (item = first_conf_item; item; item = item->next) {
+               if (item->conf.command) {
+                       struct trailer_item *new = new_trailer_item(item, NULL, NULL);
+                       add_trailer_item(&arg_tok_first, &arg_tok_last, new);
+               }
+       }
+
+       /* Add a trailer item for each trailer on the command line */
+       for_each_string_list_item(tr, trailers) {
+               struct trailer_item *new = create_trailer_item(tr->string);
+               add_trailer_item(&arg_tok_first, &arg_tok_last, new);
+       }
+
+       return arg_tok_first;
+}
+
+static struct strbuf **read_input_file(const char *file)
+{
+       struct strbuf **lines;
+       struct strbuf sb = STRBUF_INIT;
+
+       if (file) {
+               if (strbuf_read_file(&sb, file, 0) < 0)
+                       die_errno(_("could not read input file '%s'"), file);
+       } else {
+               if (strbuf_read(&sb, fileno(stdin), 0) < 0)
+                       die_errno(_("could not read from stdin"));
+       }
+
+       lines = strbuf_split(&sb, '\n');
+
+       strbuf_release(&sb);
+
+       return lines;
+}
+
+/*
+ * Return the (0 based) index of the start of the patch or the line
+ * count if there is no patch in the message.
+ */
+static int find_patch_start(struct strbuf **lines, int count)
+{
+       int i;
+
+       /* Get the start of the patch part if any */
+       for (i = 0; i < count; i++) {
+               if (starts_with(lines[i]->buf, "---"))
+                       return i;
+       }
+
+       return count;
+}
+
+/*
+ * Return the (0 based) index of the first trailer line or count if
+ * there are no trailers. Trailers are searched only in the lines from
+ * index (count - 1) down to index 0.
+ */
+static int find_trailer_start(struct strbuf **lines, int count)
+{
+       int start, only_spaces = 1;
+
+       /*
+        * Get the start of the trailers by looking starting from the end
+        * for a line with only spaces before lines with one separator.
+        */
+       for (start = count - 1; start >= 0; start--) {
+               if (lines[start]->buf[0] == comment_line_char)
+                       continue;
+               if (contains_only_spaces(lines[start]->buf)) {
+                       if (only_spaces)
+                               continue;
+                       return start + 1;
+               }
+               if (strcspn(lines[start]->buf, separators) < lines[start]->len) {
+                       if (only_spaces)
+                               only_spaces = 0;
+                       continue;
+               }
+               return count;
+       }
+
+       return only_spaces ? count : 0;
+}
+
+static int has_blank_line_before(struct strbuf **lines, int start)
+{
+       for (;start >= 0; start--) {
+               if (lines[start]->buf[0] == comment_line_char)
+                       continue;
+               return contains_only_spaces(lines[start]->buf);
+       }
+       return 0;
+}
+
+static void print_lines(struct strbuf **lines, int start, int end)
+{
+       int i;
+       for (i = start; lines[i] && i < end; i++)
+               printf("%s", lines[i]->buf);
+}
+
+static int process_input_file(struct strbuf **lines,
+                             struct trailer_item **in_tok_first,
+                             struct trailer_item **in_tok_last)
+{
+       int count = 0;
+       int patch_start, trailer_start, i;
+
+       /* Get the line count */
+       while (lines[count])
+               count++;
+
+       patch_start = find_patch_start(lines, count);
+       trailer_start = find_trailer_start(lines, patch_start);
+
+       /* Print lines before the trailers as is */
+       print_lines(lines, 0, trailer_start);
+
+       if (!has_blank_line_before(lines, trailer_start - 1))
+               printf("\n");
+
+       /* Parse trailer lines */
+       for (i = trailer_start; i < patch_start; i++) {
+               struct trailer_item *new = create_trailer_item(lines[i]->buf);
+               add_trailer_item(in_tok_first, in_tok_last, new);
+       }
+
+       return patch_start;
+}
+
+static void free_all(struct trailer_item **first)
+{
+       while (*first) {
+               struct trailer_item *item = remove_first(first);
+               free_trailer_item(item);
+       }
+}
+
+void process_trailers(const char *file, int trim_empty, struct string_list *trailers)
+{
+       struct trailer_item *in_tok_first = NULL;
+       struct trailer_item *in_tok_last = NULL;
+       struct trailer_item *arg_tok_first;
+       struct strbuf **lines;
+       int patch_start;
+
+       /* Default config must be setup first */
+       git_config(git_trailer_default_config, NULL);
+       git_config(git_trailer_config, NULL);
+
+       lines = read_input_file(file);
+
+       /* Print the lines before the trailers */
+       patch_start = process_input_file(lines, &in_tok_first, &in_tok_last);
+
+       arg_tok_first = process_command_line_args(trailers);
+
+       process_trailers_lists(&in_tok_first, &in_tok_last, &arg_tok_first);
+
+       print_all(in_tok_first, trim_empty);
+
+       free_all(&in_tok_first);
+
+       /* Print the lines after the trailers as is */
+       print_lines(lines, patch_start, INT_MAX);
+
+       strbuf_list_free(lines);
+}
diff --git a/trailer.h b/trailer.h
new file mode 100644 (file)
index 0000000..8eb25d5
--- /dev/null
+++ b/trailer.h
@@ -0,0 +1,6 @@
+#ifndef TRAILER_H
+#define TRAILER_H
+
+void process_trailers(const char *file, int trim_empty, struct string_list *trailers);
+
+#endif /* TRAILER_H */
index 2b24d51a24adb9dfc885591ceb1653ace65f198a..9b2962041b573b6aa7880b87ce57fd8ddbd4cb11 100644 (file)
@@ -897,7 +897,10 @@ static int push_refs_with_export(struct transport *transport,
                                        int flag;
 
                                        /* Follow symbolic refs (mainly for HEAD). */
-                                       name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag);
+                                       name = resolve_ref_unsafe(
+                                                ref->peer_ref->name,
+                                                RESOLVE_REF_READING,
+                                                sha1, &flag);
                                        if (!name || !(flag & REF_ISSYMREF))
                                                name = ref->peer_ref->name;
 
index 055d2a27d945de69f20a890d5e184b7bd09f93d9..b56620ed7f63aa12716e5168d817722716e6d89d 100644 (file)
@@ -168,7 +168,8 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
                /* Follow symbolic refs (mainly for HEAD). */
                localname = ref->peer_ref->name;
                remotename = ref->name;
-               tmp = resolve_ref_unsafe(localname, sha, 1, &flag);
+               tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING,
+                                        sha, &flag);
                if (tmp && flag & REF_ISSYMREF &&
                        starts_with(tmp, "refs/heads/"))
                        localname = tmp;
@@ -743,7 +744,7 @@ void transport_print_push_status(const char *dest, struct ref *refs,
        unsigned char head_sha1[20];
        char *head;
 
-       head = resolve_refdup("HEAD", head_sha1, 1, NULL);
+       head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
 
        if (verbose) {
                for (ref = refs; ref; ref = ref->next)
index c789ec00507696b4e52b081b66cc0e7c8cba42f9..ac9ac1592d818da5ae90ec065581e3bf218ffc39 100644 (file)
@@ -744,7 +744,7 @@ static int find_symref(const char *refname, const unsigned char *sha1, int flag,
 
        if ((flag & REF_ISSYMREF) == 0)
                return 0;
-       symref_target = resolve_ref_unsafe(refname, unused, 0, &flag);
+       symref_target = resolve_ref_unsafe(refname, 0, unused, &flag);
        if (!symref_target || (flag & REF_ISSYMREF) == 0)
                die("'%s' is a symref but it is not?", refname);
        item = string_list_append(cb_data, refname);
index 18a67d33cb55b799f7784e52ceac214cf76e5d3e..f149371e71ebdcdbd12336aace15b0fc20f74569 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -300,14 +300,13 @@ int walker_fetch(struct walker *walker, int targets, char **target,
                strbuf_addf(&refname, "refs/%s", write_ref[i]);
                if (ref_transaction_update(transaction, refname.buf,
                                           &sha1[20 * i], NULL, 0, 0,
+                                          msg ? msg : "fetch (unknown)",
                                           &err)) {
                        error("%s", err.buf);
                        goto done;
                }
        }
-       if (ref_transaction_commit(transaction,
-                                  msg ? msg : "fetch (unknown)",
-                                  &err)) {
+       if (ref_transaction_commit(transaction, &err)) {
                error("%s", err.buf);
                goto done;
        }
index 5b77d2a1aecd494ea4bb5eb1e6f31afc9c96f82e..007ec0d8eac529579cc00b14f9baaddb7ac68487 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -466,17 +466,29 @@ int xmkstemp_mode(char *template, int mode)
 
 static int warn_if_unremovable(const char *op, const char *file, int rc)
 {
-       if (rc < 0) {
-               int err = errno;
-               if (ENOENT != err) {
-                       warning("unable to %s %s: %s",
-                               op, file, strerror(errno));
-                       errno = err;
-               }
-       }
+       int err;
+       if (!rc || errno == ENOENT)
+               return 0;
+       err = errno;
+       warning("unable to %s %s: %s", op, file, strerror(errno));
+       errno = err;
        return rc;
 }
 
+int unlink_or_msg(const char *file, struct strbuf *err)
+{
+       int rc = unlink(file);
+
+       assert(err);
+
+       if (!rc || errno == ENOENT)
+               return 0;
+
+       strbuf_addf(err, "unable to unlink %s: %s",
+                   file, strerror(errno));
+       return -1;
+}
+
 int unlink_or_warn(const char *file)
 {
        return warn_if_unremovable("unlink", file, unlink(file));
index 1bf5d725453f726f6a6179f9706a50f3c8c9dbb5..f367066f9214791908e761d1120d1a6d809015fa 100644 (file)
@@ -128,7 +128,7 @@ void wt_status_prepare(struct wt_status *s)
        s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
        s->use_color = -1;
        s->relative_paths = 1;
-       s->branch = resolve_refdup("HEAD", sha1, 0, NULL);
+       s->branch = resolve_refdup("HEAD", 0, sha1, NULL);
        s->reference = "HEAD";
        s->fp = stdout;
        s->index_file = get_index_file();