summaryrefslogtreecommitdiff
path: root/refs.h
diff options
context:
space:
mode:
authorSahil Dua <sahildua2305@gmail.com>2017-06-18 21:19:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-19 04:47:59 (GMT)
commit52d59cc6452ed1aeec91f4c168a853ea8d9d5496 (patch)
treec373ca88d5a0480912ff23aea032ab55389f9933 /refs.h
parentc8b2cec09e548df7c948e5f4453381f0a3b0f6a9 (diff)
downloadgit-52d59cc6452ed1aeec91f4c168a853ea8d9d5496.zip
git-52d59cc6452ed1aeec91f4c168a853ea8d9d5496.tar.gz
git-52d59cc6452ed1aeec91f4c168a853ea8d9d5496.tar.bz2
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>
Diffstat (limited to 'refs.h')
-rw-r--r--refs.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/refs.h b/refs.h
index 4be14c4..00fce93 100644
--- a/refs.h
+++ b/refs.h
@@ -440,7 +440,14 @@ char *shorten_unambiguous_ref(const char *refname, int strict);
/** rename ref, return 0 on success **/
int refs_rename_ref(struct ref_store *refs, const char *oldref,
const char *newref, const char *logmsg);
-int rename_ref(const char *oldref, const char *newref, const char *logmsg);
+int rename_ref(const char *oldref, const char *newref,
+ const char *logmsg);
+
+/** copy ref, return 0 on success **/
+int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
+ const char *newref, const char *logmsg);
+int copy_existing_ref(const char *oldref, const char *newref,
+ const char *logmsg);
int refs_create_symref(struct ref_store *refs, const char *refname,
const char *target, const char *logmsg);