diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-12-19 11:33:57 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-12-19 11:33:57 -0800 |
commit | 66d3f19324ac9eeae8ef0d2ae2067ae7b18f8ac8 (patch) | |
tree | e94fa30407c0068170f6c19a94adadd66fcbeca7 /builtin/checkout.c | |
parent | 1974f4791af2b8720f2983149defe13e571b3884 (diff) | |
parent | e92445a73173cf21a11b8e79cb7be16485deec69 (diff) | |
download | git-66d3f19324ac9eeae8ef0d2ae2067ae7b18f8ac8.tar.gz |
Merge branch 'tg/worktree-create-tracking'
The way "git worktree add" determines what branch to create from
where and checkout in the new worktree has been updated a bit.
* tg/worktree-create-tracking:
add worktree.guessRemote config option
worktree: add --guess-remote flag to add subcommand
worktree: make add <path> <branch> dwim
worktree: add --[no-]track option to the add subcommand
worktree: add can be created from any commit-ish
checkout: factor out functions to new lib file
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r-- | builtin/checkout.c | 41 |
1 files changed, 1 insertions, 40 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index e1e157d205..9b886356bf 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1,5 +1,6 @@ #include "builtin.h" #include "config.h" +#include "checkout.h" #include "lockfile.h" #include "parse-options.h" #include "refs.h" @@ -872,46 +873,6 @@ static int git_checkout_config(const char *var, const char *value, void *cb) return git_xmerge_config(var, value, NULL); } -struct tracking_name_data { - /* const */ char *src_ref; - char *dst_ref; - struct object_id *dst_oid; - int unique; -}; - -static int check_tracking_name(struct remote *remote, void *cb_data) -{ - struct tracking_name_data *cb = cb_data; - struct refspec query; - memset(&query, 0, sizeof(struct refspec)); - query.src = cb->src_ref; - if (remote_find_tracking(remote, &query) || - get_oid(query.dst, cb->dst_oid)) { - free(query.dst); - return 0; - } - if (cb->dst_ref) { - free(query.dst); - cb->unique = 0; - return 0; - } - cb->dst_ref = query.dst; - return 0; -} - -static const char *unique_tracking_name(const char *name, struct object_id *oid) -{ - struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 }; - cb_data.src_ref = xstrfmt("refs/heads/%s", name); - cb_data.dst_oid = oid; - for_each_remote(check_tracking_name, &cb_data); - free(cb_data.src_ref); - if (cb_data.unique) - return cb_data.dst_ref; - free(cb_data.dst_ref); - return NULL; -} - static int parse_branchname_arg(int argc, const char **argv, int dwim_new_local_branch_ok, struct branch_info *new, |