branch: add a --copy (-c) option to go with --move (-m)
commit52d59cc6452ed1aeec91f4c168a853ea8d9d5496
authorSahil Dua <sahildua2305@gmail.com>
Sun, 18 Jun 2017 21:19:16 +0000 (18 23:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 19 Jun 2017 04:47:59 +0000 (18 21:47 -0700)
treec373ca88d5a0480912ff23aea032ab55389f9933
parentc8b2cec09e548df7c948e5f4453381f0a3b0f6a9
branch: add a --copy (-c) option to go with --move (-m)

Add the ability to --copy a branch and its reflog and configuration,
this uses the same underlying machinery as the --move (-m) option
except the reflog and configuration is copied instead of being moved.

This is useful for e.g. copying a topic branch to a new version,
e.g. work to work-2 after submitting the work topic to the list, while
preserving all the tracking info and other configuration that goes
with the branch, and unlike --move keeping the other already-submitted
branch around for reference.

Like --move, when the source branch is the currently checked out
branch the HEAD is moved to the destination branch. In the case of
--move we don't really have a choice (other than remaining on a
detached HEAD) and in order to keep the functionality consistent, we
are doing it in similar way for --copy too.

The most common usage of this feature is expected to be moving to a
new topic branch which is a copy of the current one, in that case
moving to the target branch is what the user wants, and doesn't
unexpectedly behave differently than --move would.

One outstanding caveat of this implementation is that:

    git checkout maint &&
    git checkout master &&
    git branch -c topic &&
    git checkout -

Will check out 'maint' instead of 'master'. This is because the @{-N}
feature (or its -1 shorthand "-") relies on HEAD reflogs created by
the checkout command, so in this case we'll checkout maint instead of
master, as the user might expect. What to do about that is left to a
future change.

Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-branch.txt
builtin/branch.c
cache.h
config.c
refs.c
refs.h
refs/files-backend.c
refs/refs-internal.h
t/t3200-branch.sh