summaryrefslogtreecommitdiff
path: root/builtin/replace.c
diff options
context:
space:
mode:
authorLibravatar Johannes Schindelin <johannes.schindelin@gmx.de>2018-04-29 00:44:32 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-04-30 11:12:29 +0900
commit041c98e22d88d963a92f1bac6ab348a0d4c6d228 (patch)
treedd10d466a47000738c132770f6607e39c0583fd4 /builtin/replace.c
parentreplace: "libify" create_graft() and callees (diff)
downloadtgif-041c98e22d88d963a92f1bac6ab348a0d4c6d228.tar.xz
replace: prepare create_graft() for converting graft files wholesale
When converting all grafts in a graft file to replace refs, and one of them happens to leave the original commit's parents unchanged, we do not want to error out. Instead, we would like to issue a warning. Prepare the create_graft() function for such a use case by adding a `gentle` parameter. If set, we do not return an error when the replace ref is unchanged, but a mere warning. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/replace.c')
-rw-r--r--builtin/replace.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/builtin/replace.c b/builtin/replace.c
index e57d3d187e..64f5811270 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -428,7 +428,7 @@ static int check_mergetags(struct commit *commit, int argc, const char **argv)
return for_each_mergetag(check_one_mergetag, commit, &mergetag_data);
}
-static int create_graft(int argc, const char **argv, int force)
+static int create_graft(int argc, const char **argv, int force, int gentle)
{
struct object_id old_oid, new_oid;
const char *old_ref = argv[0];
@@ -470,8 +470,13 @@ static int create_graft(int argc, const char **argv, int force)
strbuf_release(&buf);
- if (!oidcmp(&old_oid, &new_oid))
+ if (!oidcmp(&old_oid, &new_oid)) {
+ if (gentle) {
+ warning("graft for '%s' unnecessary", oid_to_hex(&old_oid));
+ return 0;
+ }
return error("new commit is the same as the old one: '%s'", oid_to_hex(&old_oid));
+ }
return replace_object_oid(old_ref, &old_oid, "replacement", &new_oid, force);
}
@@ -547,7 +552,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
if (argc < 1)
usage_msg_opt("-g needs at least one argument",
git_replace_usage, options);
- return create_graft(argc, argv, force);
+ return create_graft(argc, argv, force, 0);
case MODE_LIST:
if (argc > 1)