checkout: verify new branch name's validity early

If the new branch name to -b/-B happens to be missing, the next
argument may be mistaken as branch name and no longer recognized by
checkout as argument. This may lead to confusing error messages.

By checking branch name early and printing out the invalid name, users
may realize they forgot to specify branch name.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
[BROKEN] fetch/push: allow refs/*:refs/*

There are a handful of places where we call check_refname_format() on a
substring after "refs/" of a refname we are going to use, and filter out a
valid match with "refs/stash" with such a pathspec.  Not sending a stash
may arguably be a feature (as stash is inherently a local workflow
element), but the code in the transport layer is oblivious to this
filtering performed by the lower layer of the code, and complains that the
other side did not send all the objects that needs to complete refs/stash
at the end, even though the code will not write refs/stash out anyway, and
making the whole command fail.

This is an attempt to "fix" it by using check_refname_format() on the
whole "refs/....." string and allowing refs/stash to be also copied.

THIS IS BROKEN. A NEW SENDER MAY ATTEMPT A --MIRROR PUSH TO SEND
refs/stash AND AN OLD RECEIVER WILL BARF WITH "funny refname",
BREAKING THE ENTIRE "git push" SESSION. THE SAME ISSUE MAY EXIST IN
THE OPPOSITE DIRECTION. IT NEEDS TO BE PROTECTED WITH A NEW
CAPABILITY (E.G. FULL-MIRROR).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
get_fetch_map(): tighten checks on dest refs

The code to check the refname we store the fetched result locally did not
bother checking the first 5 bytes of it, presumably assuming that it
always begin with "refs/".  For a fetch refspec (or the result of applying
wildcard on one), we always want the RHS to map to something inside
"refs/" hierarchy, so let's spell that rule out in a more explicit way.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Merge branch 'jc/dotdot-is-parent-directory' into jch

"git log .." errored out saying it is both rev range and a path when
there is no disambiguating "--" is on the command line.  Update the
command line parser to interpret ".." as a path in such a case.

Will merge to 'next'.

* jc/dotdot-is-parent-directory:
  specifying ranges: we did not mean to make ".." an empty set

Conflicts:
	builtin/rev-parse.c
	revision.c
Merge branch 'jc/maint-mergetool-style-fix' into jch

As the title says.

Will merge to 'next'.

* jc/maint-mergetool-style-fix:
  mergetool: style fixes
Merge branch 'js/no-curl-easy-strerror-on-old-curl' into jch

Pieces to support compilation on __TANDEM.

Will merge to 'next'.

* js/no-curl-easy-strerror-on-old-curl:
  http.c: don't use curl_easy_strerror prior to curl-7.12.0
Merge branch 'js/compat-mkdir' into jch

Pieces to support compilation on __TANDEM.

Will merge to 'next'.

* js/compat-mkdir:
  compat: some mkdir() do not like a slash at the end
Merge branch 'js/use-sc-open-max' into jch

Pieces to support compilation on __TANDEM.

Will merge to 'next'.

* js/use-sc-open-max:
  sha1_file.c: introduce get_max_fd_limit() helper
Merge branch 'jc/apply-binary-p0' into jch

"git apply -p0" did not parse pathnames on "diff --git" line
correctly.  This caused patches that had pathnames in no other
places to be mistakenly rejected (most notably, binary patch that
does not rename nor change mode).  Textual patches, renames or
mode changes have preimage and postimage pathnames in different
places in a form that can be parsed unambiguously and did not suffer
from this problem.

Will merge to 'next'.

* jc/apply-binary-p0:
  apply: compute patch->def_name correctly under -p0

Conflicts:
	t/t4103-apply-binary.sh
Merge branch 'jc/maint-doc-checkout-b-always-takes-branch-name' into jch

The synopsis said "checkout [-B branch]" to make it clear the branch
name is a parameter to the option, but the heading for the option
description was "-B::", not "-B branch::", making the documentation
misleading.  There may be room in documentation pages of other
commands for similar improvements (hint, hint).

Will merge to 'next'.

* jc/maint-doc-checkout-b-always-takes-branch-name:
  doc: "git checkout -b/-B/--orphan" always takes a branch name
Merge branch 'er/doc-fast-import-done' into pu

Parked in 'pu' in case ESR responds with "Sorry, forgot to sign-off".

* er/doc-fast-import-done:
  fast-import: document the --done option
Merge branch 'nd/i18n-poison-test-updates' into pu

Updates to tests that can be broken with gettext-poison builds.
Queued with trivial fix-ups.

Will merge to 'next'.

* nd/i18n-poison-test-updates:
  Fix tests under GETTEXT_POISON on parseopt
  Fix tests under GETTEXT_POISON on git-remote
  Fix tests under GETTEXT_POISON on pack-object
  Fix tests under GETTEXT_POISON on git-apply
  Fix tests under GETTEXT_POISON on diffstat
  Fix tests under GETTEXT_POISON on git-stash
  Fix tests under GETTEXT_POISON on relative dates
Merge branch 'nd/branch-v-alignment' into pu

Output from "git branch -v" contains "(no branch)" that could be
localized, but the code to align it along with the names of branches
were counting in bytes, not in display columns.

Will merge to 'next'.

* nd/branch-v-alignment:
  branch -v: align even when branch names are in UTF-8
Merge branch 'jx/test-real-path' into pu

Running tests with the "trash" directory elsewhere with the "--root"
option did not work well if the directory was specified by a symbolic
link pointing at it.

Waiting for a Tested-by.

* jx/test-real-path:
  test: set the realpath of CWD as TRASH_DIRECTORY
Merge branch 'nd/checkout-branch-name-check' into pu

"git checkout -b --opt y" errors out saying that creating a new
branch to check it out and grabbing contents for paths out of a
commit are incompatible operations.  While it is technically correct
(the command line wants to create a new branch whose name is "--opt"
and check it out, and there shouldn't be anything else left on the
command line, but there is "y"), "--opt" is not a valid name of the
branch to begin with, so even without "y", the command will not
succeed.  Treat this case specially to complain that "--opt" is not
a valid branch name.

* nd/checkout-branch-name-check:
  checkout: verify new branch name's validity early
Merge branch 'js/compat-itimer' into pu

Pieces to support compilation on __TANDEM.

* js/compat-itimer:
  Support for setitimer() on platforms lacking it

Conflicts:
	git-compat-util.h
Merge branch 'jk/maint-http-half-auth-push' into pu

Pushing to smart HTTP server with recent Git fails without having
the username in the URL to force authentication, if the server is
configured to allow GET anonymously, while requiring authentication
for POST.

Will merge to 'next'.

* jk/maint-http-half-auth-push:
  http: prompt for credentials on failed POST
  http: factor out http error code handling
  t: test http access to "half-auth" repositories
  t: test basic smart-http authentication
  t/lib-httpd: recognize */smart/* repos as smart-http
  t/lib-httpd: only route auth/dumb to dumb repos
  t5550: factor out http auth setup
  t5550: put auth-required repo in auth/dumb

Conflicts:
	http.c
Merge branch 'jc/merge-bases' into pu

Optimises the "merge-base" computation a bit, and also updates its
users that do not need the full merge-base information to call a
cheaper subset.  The most important one is the second from the tip
done by Thomas.

Needs sign-off.

* jc/merge-bases:
  get_merge_bases_many(): walk from many tips in parallel
  in_merge_bases(): omit unnecessary redundant common ancestor reduction
  http-push: use in_merge_bases() for fast-forward check
  receive-pack: use in_merge_bases() for fast-forward check
  in_merge_bases(): support only one "other" commit
Merge branch 'jc/add-delete-default' into pu

"git add dir/" updated modified files and added new files, but does
not notice removed files, which may be "Huh?" to some users.  They
can of course use "git add -A dir/", but why should they?

Resurrected from graveyard, as I thought it was a worthwhile thing
to do in the longer term; waiting for comments.

* jc/add-delete-default:
  git add: notice removal of tracked paths by default
Merge branch 'tx/relative-in-the-future' into pu

Not my itch; rewritten an earlier submission by Tom Xue into
somewhat more maintainable form, though it breaks existing i18n.

Anybody interested in fixing it up?  Otherwise may discard.

* tx/relative-in-the-future:
  date: show relative dates in the future
  date: refactor the relative date logic from presentation