33
#include "sequencer.h"
34
#include "string-list.h"
35
#include "packfile.h"
36
+#include "tag.h"
37
38
#define DEFAULT_TWOHEAD (1<<0)
39
#define DEFAULT_OCTOPUS (1<<1)
1126
return remoteheads;
1127
}
1128
1129
+static int merging_a_throwaway_tag(struct commit *commit)
1130
+{
1131
+ char *tag_ref;
1132
+ struct object_id oid;
1133
+ int is_throwaway_tag = 0;
1134
+
1135
+ /* Are we merging a tag? */
1136
+ if (!merge_remote_util(commit) ||
1137
+ !merge_remote_util(commit)->obj ||
1138
+ merge_remote_util(commit)->obj->type != OBJ_TAG)
1139
+ return is_throwaway_tag;
1140
+
1141
+ /*
1142
+ * Now we know we are merging a tag object. Are we downstream
1143
+ * and following the tags from upstream? If so, we must have
1144
+ * the tag object pointed at by "refs/tags/$T" where $T is the
1145
+ * tagname recorded in the tag object. We want to allow such
1146
+ * a "just to catch up" merge to fast-forward.
1147
+ *
1148
+ * Otherwise, we are playing an integrator's role, making a
1149
+ * merge with a throw-away tag from a contributor with
1150
+ * something like "git pull $contributor $signed_tag".
1151
+ * We want to forbid such a merge from fast-forwarding
1152
+ * by default; otherwise we would not keep the signature
1153
+ * anywhere.
1154
+ */
1155
+ tag_ref = xstrfmt("refs/tags/%s",
1156
+ ((struct tag *)merge_remote_util(commit)->obj)->tag);
1157
+ if (!read_ref(tag_ref, &oid) &&
1158
+ !oidcmp(&oid, &merge_remote_util(commit)->obj->oid))
1159
+ is_throwaway_tag = 0;
1160
+ else
1161
+ is_throwaway_tag = 1;
1162
+ free(tag_ref);
1163
+ return is_throwaway_tag;
1164
+}
1165
+
1166
int cmd_merge(int argc, const char **argv, const char *prefix)
1167
{
1168
struct object_id result_tree, stash, head_oid;
1360
oid_to_hex(&commit->object.oid));
1361
setenv(buf.buf, merge_remote_util(commit)->name, 1);
1362
strbuf_reset(&buf);
1325
- if (fast_forward != FF_ONLY &&
1326
- merge_remote_util(commit) &&
1327
- merge_remote_util(commit)->obj &&
1328
- merge_remote_util(commit)->obj->type == OBJ_TAG)
1363
+ if (fast_forward != FF_ONLY && merging_a_throwaway_tag(commit))
1364
fast_forward = FF_NO;
1365
}
1366