clone: support atomic operation with --separate-git-dir

Since b57fb80a7d (init, clone: support --separate-git-dir for .git file)
git clone supports the --separate-git-dir option to create the git dir
outside the work tree. But when that option is used, the git dir won't be
deleted in case the clone fails like it would be without this option. This
makes clone lose its atomicity as in case of a failure a partly set up git
dir is left behind. A real world example where this leads to problems is
when "git submodule update" fails to clone a submodule and later calls to
"git submodule update" stumble over the partially set up git dir and try
to revive the submodule from there, which then fails with a not very user
friendly error message.

Fix that by updating the junk_git_dir variable (used to remember if and
what git dir should be removed in case of failure) to the new value given
with the --seperate-git-dir option. Also add a test for this to t5600 (and
while at it fix the former last test to not cd into a directory to test
for its existence but use "test -d" instead).

Reported-by: Manlio Perillo <manlio.perillo@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-tar: split long paths more carefully

The name field of a tar header has a size of 100 characters.  This limit
was extended long ago in a backward compatible way by providing the
additional prefix field, which can hold 155 additional characters.  The
actual path is constructed at extraction time by concatenating the prefix
field, a slash and the name field.

get_path_prefix() is used to determine which slash in the path is used as
the cutting point and thus which part of it is placed into the field
prefix and which into the field name.  It tries to cram as much into the
prefix field as possible.  (And only if we can't fit a path into the
provided 255 characters we use a pax extended header to store it.)

If a path is longer than 100 but shorter than 156 characters and ends
with a slash (i.e. is for a directory) then get_path_prefix() puts the
whole path in the prefix field and leaves the name field empty.  GNU tar
reconstructs the path without complaint, but the tar included with
NetBSD 6 does not: It reports the header to be invalid.

For compatibility with this version of tar, make sure to never leave the
name field empty.  In order to do that, trim the trailing slash from the
part considered as possible prefix, if it exists -- that way the last
path component (or more, but not less) will end up in the name field.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command: encode signal death as a positive integer

When a sub-command dies due to a signal, we encode the
signal number into the numeric exit status as "signal -
128". This is easy to identify (versus a regular positive
error code), and when cast to an unsigned integer (e.g., by
feeding it to exit), matches what a POSIX shell would return
when reporting a signal death in $? or through its own exit
code.

So we have a negative value inside the code, but once it
passes across an exit() barrier, it looks positive (and any
code we receive from a sub-shell will have the positive
form). E.g., death by SIGPIPE (signal 13) will look like
-115 to us in inside git, but will end up as 141 when we
call exit() with it. And a program killed by SIGPIPE but run
via the shell will come to us with an exit code of 141.

Unfortunately, this means that when the "use_shell" option
is set, we need to be on the lookout for _both_ forms. We
might or might not have actually invoked the shell (because
we optimize out some useless shell calls). If we didn't invoke
the shell, we will will see the sub-process's signal death
directly, and run-command converts it into a negative value.
But if we did invoke the shell, we will see the shell's
128+signal exit status. To be thorough, we would need to
check both, or cast the value to an unsigned char (after
checking that it is not -1, which is a magic error value).

Fortunately, most callsites do not care at all whether the
exit was from a code or from a signal; they merely check for
a non-zero status, and sometimes propagate the error via
exit(). But for the callers that do care, we can make life
slightly easier by just using the consistent positive form.

This actually fixes two minor bugs:

  1. In launch_editor, we check whether the editor died from
     SIGINT or SIGQUIT. But we checked only the negative
     form, meaning that we would fail to notice a signal
     death exit code which was propagated through the shell.

  2. In handle_alias, we assume that a negative return value
     from run_command means that errno tells us something
     interesting (like a fork failure, or ENOENT).
     Otherwise, we simply propagate the exit code. Negative
     signal death codes confuse us, and we print a useless
     "unable to run alias 'foo': Success" message. By
     encoding signal deaths using the positive form, the
     existing code just propagates it as it would a normal
     non-zero exit code.

The downside is that callers of run_command can no longer
differentiate between a signal received directly by the
sub-process, and one propagated. However, no caller
currently cares, and since we already optimize out some
calls to the shell under the hood, that distinction is not
something that should be relied upon by callers.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-fast-import(1): remove duplicate "--done" option

The "--done" option to git-fast-import is documented twice in its manual
page.  Combine the best bits of each description, keeping the location
of the instance that was added first.

Signed-off-by: John Keeping <john@keeping.me.uk>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'mz/oneway-merge-wo-u-no-lstat' into jch

Optimize "read-tree -m <tree-ish>" without "-u".

Will merge to 'master'.

* mz/oneway-merge-wo-u-no-lstat:
  oneway_merge(): only lstat() when told to update worktree
Merge branch 'jc/apply-trailing-blank-removal' into jch

Fix to update_pre_post_images() that did not take into account the
possibility that whitespace fix could shrink the preimage and
change the number of lines in it.

Will merge to 'master'.

* jc/apply-trailing-blank-removal:
  apply.c:update_pre_post_images(): the preimage can be truncated
Merge branch 'nd/wildmatch' into jch

Allows pathname patterns in .gitignore and .gitattributes files
with double-asterisks "foo/**/bar" to match any number of directory
hierarchies.

* nd/wildmatch:
  wildmatch: replace variable 'special' with better named ones
  compat/fnmatch: respect NO_FNMATCH* even on glibc
  wildmatch: fix "**" special case
  t3070: Disable some failing fnmatch tests
  test-wildmatch: avoid Windows path mangling
  Support "**" wildcard in .gitignore and .gitattributes
  wildmatch: make /**/ match zero or more directories
  wildmatch: adjust "**" behavior
  wildmatch: fix case-insensitive matching
  wildmatch: remove static variable force_lower_case
  wildmatch: make wildmatch's return value compatible with fnmatch
  t3070: disable unreliable fnmatch tests
  Integrate wildmatch to git
  wildmatch: follow Git's coding convention
  wildmatch: remove unnecessary functions
  Import wildmatch from rsync
  ctype: support iscntrl, ispunct, isxdigit and isprint
  ctype: make sane_ctype[] const array

Conflicts:
	Makefile
Merge branch 'rc/maint-complete-git-p4' into jch

Comment from Pete will need to be addressed ($gmane/206172).

Will kick back to 'pu'.

* rc/maint-complete-git-p4:
  Teach git-completion about git p4
Merge branch 'jn/warn-on-inaccessible-loosen' into jch

Deal with a situation where .config/git is a file and we notice
.config/git/config is not readable due to ENOTDIR, not ENOENT.

Will merge to 'master'.

* jn/warn-on-inaccessible-loosen:
  config: exit on error accessing any config file
  doc: advertise GIT_CONFIG_NOSYSTEM
  config: treat user and xdg config permission problems as errors
  config, gitignore: failure to access with ENOTDIR is ok
Merge branch 'jl/submodule-deinit' into jch

There was no Porcelain way to say "I no longer am interested in
this submodule", once you express your interest in a submodule with
"submodule init".  "submodule deinit" is the way to do so.

But this does not yet do so (does not remove the checkout of the
submodule).  The design discussion petered out.

http://thread.gmane.org/gmane.comp.version-control.git/210867/focus=211456

Will kick back to 'pu'.

* jl/submodule-deinit:
  submodule: add 'deinit' command

Conflicts:
	Documentation/git-submodule.txt
	git-submodule.sh
Merge branch 'cc/no-gitk-build-dependency' into jch

Remove leftover bits from an earlier change to move gitk in its own
subdirectory.  Reimplementing the dependency tracking rules needs
to be done in gitk history separately.

Will merge to 'master'.

* cc/no-gitk-build-dependency:
  Makefile: replace "echo 1>..." with "echo >..."
  Makefile: detect when PYTHON_PATH changes
  Makefile: remove tracking of TCLTK_PATH
Merge branch 'jn/less-reconfigure' into jch

When autoconf is used, any build on a different commit always ran
"config.status --recheck" even when unnecessary.

Will merge to 'master'.

* jn/less-reconfigure:
  build: do not automatically reconfigure unless configure.ac changed
Merge branch 'aw/rebase-am-failure-detection' into jch

Save output from format-patch command in a temporary file, just in
case it aborts, to give a better failure-case behaviour.

* aw/rebase-am-failure-detection:
  rebase: Handle cases where format-patch fails
Merge branch 'mz/pick-unborn' into jch

Allows "git cherry-pick $commit" when you do not have any history
behind HEAD yet.

* mz/pick-unborn:
  learn to pick/revert into unborn branch
  tests: move test_cmp_rev to test-lib-functions
Merge branch 'ta/remove-stale-translated-tut' into jch

Remove a translation of a document that was left stale.

Will merge to 'master'.

* ta/remove-stale-translated-tut:
  Remove Documentation/pt_BR/gittutorial.txt
Merge branch 'er/stop-recommending-parsecvs' into jch

Stop recommending a defunct third-party software.

Will merge to 'master'.

* er/stop-recommending-parsecvs:
  Remove the suggestion to use parsecvs, which is currently broken.
Merge branch 'as/test-name-alias-uniquely' into jch

A few short-and-bland aliases used in the tests were interfering
with git-custom command in user's $PATH.

Will merge to 'master'.

* as/test-name-alias-uniquely:
  Use longer alias names in subdirectory tests
Merge branch 'jc/maint-fmt-merge-msg-no-edit-lose-credit' into jch

Stop spending cycles to compute information to be placed on
commented lines in "merge --no-edit".

Will merge to 'master'.

* jc/maint-fmt-merge-msg-no-edit-lose-credit:
  merge --no-edit: do not credit people involved in the side branch
Merge branch 'er/python-version-requirements' into jch

Some python scripts we ship cannot be run with old versions of the
interpreter.

Will merge to 'master'.

* er/python-version-requirements:
  Add checks to Python scripts for version dependencies.
Merge branch 'kb/maint-bundle-doc' into jch

Will merge to 'master'.

* kb/maint-bundle-doc:
  Documentation: full-ness of a bundle is significant for cloning
  Documentation: correct example restore from bundle