From: Junio C Hamano Date: Wed, 8 May 2019 15:37:24 +0000 (+0900) Subject: Merge branch 'cc/replace-graft-peel-tags' X-Git-Tag: v2.22.0-rc0~26 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ce2a18f2b1dd71966c00109f3da42df64bb836dd?ds=inline;hp=-c Merge branch 'cc/replace-graft-peel-tags' When given a tag that points at a commit-ish, "git replace --graft" failed to peel the tag before writing a replace ref, which did not make sense because the old graft mechanism the feature wants to mimick only allowed to replace one commit object with another. This has been fixed. * cc/replace-graft-peel-tags: replace: peel tag when passing a tag first to --graft replace: peel tag when passing a tag as parent to --graft t6050: redirect expected error output to a file t6050: use test_line_count instead of wc -l --- ce2a18f2b1dd71966c00109f3da42df64bb836dd diff --combined builtin/replace.c index f5701629a8,a06dc2b501..644b21ca8d --- a/builtin/replace.c +++ b/builtin/replace.c @@@ -82,10 -82,6 +82,10 @@@ static int list_replace_refs(const cha data.format = REPLACE_FORMAT_MEDIUM; else if (!strcmp(format, "long")) data.format = REPLACE_FORMAT_LONG; + /* + * Please update _git_replace() in git-completion.bash when + * you add new format + */ else return error(_("invalid replace format '%s'\n" "valid formats are 'short', 'medium' and 'long'"), @@@ -370,16 -366,19 +370,19 @@@ static int replace_parents(struct strbu /* prepare new parents */ for (i = 0; i < argc; i++) { struct object_id oid; + struct commit *commit; + if (get_oid(argv[i], &oid) < 0) { strbuf_release(&new_parents); return error(_("not a valid object name: '%s'"), argv[i]); } - if (!lookup_commit_reference(the_repository, &oid)) { + commit = lookup_commit_reference(the_repository, &oid); + if (!commit) { strbuf_release(&new_parents); - return error(_("could not parse %s"), argv[i]); + return error(_("could not parse %s as a commit"), argv[i]); } - strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid)); + strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&commit->object.oid)); } /* replace existing parents with new ones */ @@@ -478,15 -477,18 +481,18 @@@ static int create_graft(int argc, cons strbuf_release(&buf); - if (oideq(&old_oid, &new_oid)) { + if (oideq(&commit->object.oid, &new_oid)) { if (gentle) { - warning(_("graft for '%s' unnecessary"), oid_to_hex(&old_oid)); + warning(_("graft for '%s' unnecessary"), + oid_to_hex(&commit->object.oid)); return 0; } - return error(_("new commit is the same as the old one: '%s'"), oid_to_hex(&old_oid)); + return error(_("new commit is the same as the old one: '%s'"), + oid_to_hex(&commit->object.oid)); } - return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force); + return replace_object_oid(old_ref, &commit->object.oid, + "replacement", &new_oid, force); } static int convert_graft_file(int force)