From: Junio C Hamano Date: Sat, 17 Sep 2011 04:48:10 +0000 (-0700) Subject: Merge branch 'ci/forbid-unwanted-current-branch-update' X-Git-Tag: v1.7.7-rc2~1 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/c103e9529c8a95b5acf4747cfe06b2f6adedab71?ds=inline;hp=-c Merge branch 'ci/forbid-unwanted-current-branch-update' * ci/forbid-unwanted-current-branch-update: branch --set-upstream: regression fix --- c103e9529c8a95b5acf4747cfe06b2f6adedab71 diff --combined branch.c index 478d82567d,4338a90b39..fecedd3b46 --- a/branch.c +++ b/branch.c @@@ -135,23 -135,25 +135,25 @@@ static int setup_tracking(const char *n return 0; } - int validate_new_branchname(const char *name, struct strbuf *ref, int force) + int validate_new_branchname(const char *name, struct strbuf *ref, + int force, int attr_only) { - const char *head; - unsigned char sha1[20]; - if (strbuf_check_branch_ref(ref, name)) die("'%s' is not a valid branch name.", name); if (!ref_exists(ref->buf)) return 0; - else if (!force) + else if (!force && !attr_only) die("A branch named '%s' already exists.", ref->buf + strlen("refs/heads/")); - head = resolve_ref("HEAD", sha1, 0, NULL); - if (!is_bare_repository() && head && !strcmp(head, ref->buf)) - die("Cannot force update the current branch."); + if (!attr_only) { + const char *head; + unsigned char sha1[20]; + head = resolve_ref("HEAD", sha1, 0, NULL); + if (!is_bare_repository() && head && !strcmp(head, ref->buf)) + die("Cannot force update the current branch."); + } return 1; } @@@ -171,7 -173,8 +173,8 @@@ void create_branch(const char *head if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE) explicit_tracking = 1; - if (validate_new_branchname(name, &ref, force || track == BRANCH_TRACK_OVERRIDE)) { + if (validate_new_branchname(name, &ref, force, + track == BRANCH_TRACK_OVERRIDE)) { if (!force) dont_change_ref = 1; else @@@ -224,7 -227,7 +227,7 @@@ start_name); if (real_ref && track) - setup_tracking(name, real_ref, track); + setup_tracking(ref.buf+11, real_ref, track); if (!dont_change_ref) if (write_ref_sha1(lock, sha1, msg) < 0) diff --combined builtin/branch.c index aa705a0fb0,5fb3d85ad3..f49596f826 --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -71,7 -71,7 +71,7 @@@ static int parse_branch_color_slot(cons static int git_branch_config(const char *var, const char *value, void *cb) { if (!strcmp(var, "color.branch")) { - branch_use_color = git_config_colorbool(var, value, -1); + branch_use_color = git_config_colorbool(var, value); return 0; } if (!prefixcmp(var, "color.branch.")) { @@@ -88,7 -88,7 +88,7 @@@ static const char *branch_get_color(enum color_branch ix) { - if (branch_use_color > 0) + if (want_color(branch_use_color)) return branch_colors[ix]; return ""; } @@@ -566,7 -566,7 +566,7 @@@ static void rename_branch(const char *o die(_("Invalid branch name: '%s'"), oldname); } - validate_new_branchname(newname, &newref, force); + validate_new_branchname(newname, &newref, force, 0); strbuf_addf(&logmsg, "Branch: renamed %s to %s", oldref.buf, newref.buf); @@@ -609,7 -609,7 +609,7 @@@ static int opt_parse_merge_filter(cons int cmd_branch(int argc, const char **argv, const char *prefix) { int delete = 0, rename = 0, force_create = 0; - int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0; + int verbose = 0, abbrev = -1, detached = 0; int reflog = 0; enum branch_track track; int kinds = REF_LOCAL_BRANCH; @@@ -669,6 -669,9 +669,6 @@@ git_config(git_branch_config, NULL); - if (branch_use_color == -1) - branch_use_color = git_use_color_default; - track = git_branch_track; head = resolve_ref("HEAD", head_sha1, 0, NULL); @@@ -689,9 -692,6 +689,9 @@@ if (!!delete + !!rename + !!force_create > 1) usage_with_options(builtin_branch_usage, options); + if (abbrev == -1) + abbrev = DEFAULT_ABBREV; + if (delete) return delete_branches(argc, argv, delete > 1, kinds); else if (argc == 0) diff --combined builtin/checkout.c index 3bb652591b,909a334627..5e356a6c61 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -201,7 -201,7 +201,7 @@@ static int checkout_merged(int pos, str } static int checkout_paths(struct tree *source_tree, const char **pathspec, - struct checkout_opts *opts) + const char *prefix, struct checkout_opts *opts) { int pos; struct checkout state; @@@ -231,7 -231,7 +231,7 @@@ match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched); } - if (report_path_error(ps_matched, pathspec, 0)) + if (report_path_error(ps_matched, pathspec, prefix)) return 1; /* "checkout -m path" to recreate conflicted state */ @@@ -657,25 -657,24 +657,25 @@@ static void suggest_reattach(struct com "Warning: you are leaving %d commit behind, " "not connected to\n" "any of your branches:\n\n" - "%s\n" - "If you want to keep it by creating a new branch, " - "this may be a good time\nto do so with:\n\n" - " git branch new_branch_name %s\n\n", + "%s\n", /* The plural version */ "Warning: you are leaving %d commits behind, " "not connected to\n" "any of your branches:\n\n" - "%s\n" - "If you want to keep them by creating a new branch, " - "this may be a good time\nto do so with:\n\n" - " git branch new_branch_name %s\n\n", + "%s\n", /* Give ngettext() the count */ lost), lost, - sb.buf, - sha1_to_hex(commit->object.sha1)); + sb.buf); strbuf_release(&sb); + + if (advice_detached_head) + fprintf(stderr, + _( + "If you want to keep them by creating a new branch, " + "this may be a good time\nto do so with:\n\n" + " git branch new_branch_name %s\n\n"), + sha1_to_hex(commit->object.sha1)); } /* @@@ -1064,7 -1063,7 +1064,7 @@@ int cmd_checkout(int argc, const char * if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge) die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\nchecking out of the index.")); - return checkout_paths(source_tree, pathspec, &opts); + return checkout_paths(source_tree, pathspec, prefix, &opts); } if (patch_mode) @@@ -1073,7 -1072,8 +1073,8 @@@ if (opts.new_branch) { struct strbuf buf = STRBUF_INIT; - opts.branch_exists = validate_new_branchname(opts.new_branch, &buf, !!opts.new_branch_force); + opts.branch_exists = validate_new_branchname(opts.new_branch, &buf, + !!opts.new_branch_force, 0); strbuf_release(&buf); }