Commit 1c0b6a38bacb54de300d936338d4adb04a9b311f

Edward Thomson 2014-03-11T17:58:10

Remove fastforward / uptodate from `git_merge`

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
diff --git a/include/git2/merge.h b/include/git2/merge.h
index 1d30a5a..e20025b 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -274,35 +274,9 @@ GIT_EXTERN(int) git_merge_status(
 	const git_merge_head **their_heads,
 	size_t their_heads_len);
 
-/**
- * Option flags for `git_merge`.
- */
-typedef enum {
-	/**
-	 * The default behavior is to allow fast-forwards, returning
-	 * immediately with the commit ID to fast-forward to.
-	 */
-	GIT_MERGE_DEFAULT = 0,
-
-	/**
-	 * Do not fast-forward; perform a merge and prepare a merge result even
-	 * if the inputs are eligible for fast-forwarding.
-	 */
-	GIT_MERGE_NO_FASTFORWARD = 1,
-
-	/**
-	 * Ensure that the inputs are eligible for fast-forwarding, error if
-	 * a merge needs to be performed.
-	 */
-	GIT_MERGE_FASTFORWARD_ONLY = 2,
-} git_merge_flags_t;
-
 typedef struct {
 	unsigned int version;
 
-	/** Options for handling the commit-level merge. */
-	git_merge_flags_t merge_flags;
-
 	/** Options for handling the merges of individual files. */
 	git_merge_tree_opts merge_tree_opts;
 
@@ -311,7 +285,7 @@ typedef struct {
 } git_merge_opts;
 
 #define GIT_MERGE_OPTS_VERSION 1
-#define GIT_MERGE_OPTS_INIT {GIT_MERGE_OPTS_VERSION, 0, GIT_MERGE_TREE_OPTS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
+#define GIT_MERGE_OPTS_INIT {GIT_MERGE_OPTS_VERSION, GIT_MERGE_TREE_OPTS_INIT, GIT_CHECKOUT_OPTIONS_INIT}
 
 /**
  * Initializes a `git_merge_opts` with default values. Equivalent to creating
diff --git a/src/merge.c b/src/merge.c
index cdc1921..b7f043a 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1774,31 +1774,20 @@ cleanup:
 	return error;
 }
 
-static int write_merge_mode(git_repository *repo, unsigned int flags)
+static int write_merge_mode(git_repository *repo)
 {
 	git_filebuf file = GIT_FILEBUF_INIT;
 	git_buf file_path = GIT_BUF_INIT;
 	int error = 0;
 
-	/* For future expansion */
-	GIT_UNUSED(flags);
-
 	assert(repo);
 
 	if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MODE_FILE)) < 0 ||
 		(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0)
 		goto cleanup;
 
-	/*
-	 * no-ff is the only thing allowed here at present.  One would
-	 * presume they would be space-delimited when there are more, but
-	 * this needs to be revisited.
-	 */
-
-	if (flags & GIT_MERGE_NO_FASTFORWARD) {
-		if ((error = git_filebuf_write(&file, "no-ff", 5)) < 0)
-			goto cleanup;
-	}
+	if ((error = git_filebuf_write(&file, "no-ff", 5)) < 0)
+		goto cleanup;
 
 	error = git_filebuf_commit(&file);
 
@@ -2114,6 +2103,25 @@ cleanup:
 	return error;
 }
 
+int git_merge__setup(
+	git_repository *repo,
+	const git_merge_head *our_head,
+	const git_merge_head *heads[],
+	size_t heads_len)
+{
+	int error = 0;
+
+	assert (repo && our_head && heads);
+
+	if ((error = write_orig_head(repo, our_head)) == 0 &&
+		(error = write_merge_head(repo, heads, heads_len)) == 0 &&
+		(error = write_merge_mode(repo)) == 0) {
+		error = write_merge_msg(repo, heads, heads_len);
+	}
+
+	return error;
+}
+
 /* Merge branches */
 
 static int merge_ancestor_head(
@@ -2147,37 +2155,6 @@ on_error:
 	return error;
 }
 
-GIT_INLINE(bool) merge_check_uptodate(
-	git_merge_result *result,
-	const git_merge_head *ancestor_head,
-	const git_merge_head *their_head)
-{
-	if (git_oid_cmp(&ancestor_head->oid, &their_head->oid) == 0) {
-		result->is_uptodate = 1;
-		return true;
-	}
-
-	return false;
-}
-
-GIT_INLINE(bool) merge_check_fastforward(
-	git_merge_result *result,
-	const git_merge_head *ancestor_head,
-	const git_merge_head *our_head,
-	const git_merge_head *their_head,
-	unsigned int flags)
-{
-	if ((flags & GIT_MERGE_NO_FASTFORWARD) == 0 &&
-		git_oid_cmp(&ancestor_head->oid, &our_head->oid) == 0) {
-		result->is_fastforward = 1;
-		git_oid_cpy(&result->fastforward_oid, &their_head->oid);
-
-		return true;
-	}
-
-	return false;
-}
-
 const char *merge_their_label(const char *branchname)
 {
 	const char *slash;
@@ -2609,24 +2586,8 @@ int git_merge(
 	if ((error = merge_normalize_opts(repo, &opts, given_opts, ancestor_head, our_head, their_heads_len, their_heads)) < 0)
 		goto on_error;
 
-	if (their_heads_len == 1 &&
-		ancestor_head != NULL &&
-		(merge_check_uptodate(result, ancestor_head, their_heads[0]) ||
-		merge_check_fastforward(result, ancestor_head, our_head, their_heads[0], opts.merge_flags))) {
-		*out = result;
-		goto done;
-	}
-
-	/* If FASTFORWARD_ONLY is specified, fail. */
-	if ((opts.merge_flags & GIT_MERGE_FASTFORWARD_ONLY) ==
-		GIT_MERGE_FASTFORWARD_ONLY) {
-		giterr_set(GITERR_MERGE, "Not a fast-forward.");
-		error = GIT_ENONFASTFORWARD;
-		goto on_error;
-	}
-
 	/* Write the merge files to the repository. */
-	if ((error = git_merge__setup(repo, our_head, their_heads, their_heads_len, opts.merge_flags)) < 0)
+	if ((error = git_merge__setup(repo, our_head, their_heads, their_heads_len)) < 0)
 		goto on_error;
 
 	if (ancestor_head != NULL &&
@@ -2679,26 +2640,6 @@ done:
 	return error;
 }
 
-int git_merge__setup(
-	git_repository *repo,
-	const git_merge_head *our_head,
-	const git_merge_head *heads[],
-	size_t heads_len,
-	unsigned int flags)
-{
-	int error = 0;
-
-	assert (repo && our_head && heads);
-
-	if ((error = write_orig_head(repo, our_head)) == 0 &&
-		(error = write_merge_head(repo, heads, heads_len)) == 0 &&
-		(error = write_merge_mode(repo, flags)) == 0) {
-		error = write_merge_msg(repo, heads, heads_len);
-	}
-
-	return error;
-}
-
 /* Merge result data */
 
 int git_merge_result_is_uptodate(git_merge_result *merge_result)
diff --git a/src/merge.h b/src/merge.h
index dda0235..1bd2020 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -156,9 +156,8 @@ void git_merge_diff_list__free(git_merge_diff_list *diff_list);
 int git_merge__setup(
 	git_repository *repo,
 	const git_merge_head *our_head,
-	const git_merge_head *their_heads[],
-	size_t their_heads_len,
-	unsigned int flags);
+	const git_merge_head *heads[],
+	size_t heads_len);
 
 int git_merge__indexes(git_repository *repo, git_index *index_new);
 
diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c
index 05f994e..d23e454 100644
--- a/tests/merge/workdir/setup.c
+++ b/tests/merge/workdir/setup.c
@@ -71,7 +71,7 @@ static void write_file_contents(const char *filename, const char *output)
 	git_buf_free(&file_path_buf);
 }
 
-/* git merge octo1 */
+/* git merge --no-ff octo1 */
 void test_merge_workdir_setup__one_branch(void)
 {
 	git_oid our_oid;
@@ -84,33 +84,7 @@ void test_merge_workdir_setup__one_branch(void)
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
-
-	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
-	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
-	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
-
-	git_reference_free(octo1_ref);
-	
-	git_merge_head_free(our_head);
-	git_merge_head_free(their_heads[0]);
-}
-
-/* git merge --no-ff octo1 */
-void test_merge_workdir_setup__no_fastforward(void)
-{
-	git_oid our_oid;
-	git_reference *octo1_ref;
-	git_merge_head *our_head, *their_heads[1];
-
-	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
-	cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
-
-	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
-	cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
-
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, GIT_MERGE_NO_FASTFORWARD));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
@@ -118,12 +92,12 @@ void test_merge_workdir_setup__no_fastforward(void)
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
 
 	git_reference_free(octo1_ref);
-
+	
 	git_merge_head_free(our_head);
 	git_merge_head_free(their_heads[0]);
 }
 
-/* git merge  16f825815cfd20a07a75c71554e82d8eede0b061 */
+/* git merge --no-ff 16f825815cfd20a07a75c71554e82d8eede0b061 */
 void test_merge_workdir_setup__one_oid(void)
 {
 	git_oid our_oid;
@@ -136,11 +110,11 @@ void test_merge_workdir_setup__one_oid(void)
 	cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
 	cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &octo1_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'\n"));
 
 	git_merge_head_free(our_head);
@@ -164,11 +138,11 @@ void test_merge_workdir_setup__two_branches(void)
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -200,11 +174,11 @@ void test_merge_workdir_setup__three_branches(void)
 	cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[2], repo, octo3_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -238,11 +212,11 @@ void test_merge_workdir_setup__three_oids(void)
 	cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
 	cl_git_pass(git_merge_head_from_id(&their_heads[2], repo, &octo3_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO2_OID "'; commit '" OCTO3_OID "'\n"));
 	
 	git_merge_head_free(our_head);
@@ -268,11 +242,11 @@ void test_merge_workdir_setup__branches_and_oids_1(void)
 	cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
 	cl_git_pass(git_merge_head_from_id(&their_heads[1], repo, &octo2_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'; commit '" OCTO2_OID "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -307,11 +281,11 @@ void test_merge_workdir_setup__branches_and_oids_2(void)
 	cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
 	cl_git_pass(git_merge_head_from_id(&their_heads[3], repo, &octo4_oid));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "'; commit '" OCTO2_OID "'; commit '" OCTO4_OID "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -349,11 +323,11 @@ void test_merge_workdir_setup__branches_and_oids_3(void)
 	cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[3], repo, octo4_ref));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "'; commit '" OCTO3_OID "'\n"));
 	
 	git_reference_free(octo2_ref);
@@ -395,11 +369,11 @@ void test_merge_workdir_setup__branches_and_oids_4(void)
 	cl_git_pass(git_reference_lookup(&octo5_ref, repo, GIT_REFS_HEADS_DIR OCTO5_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[4], repo, octo5_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 5, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 5));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n" OCTO5_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "', '" OCTO4_BRANCH "' and '" OCTO5_BRANCH "'; commit '" OCTO3_OID "'\n"));
 	
 	git_reference_free(octo2_ref);
@@ -435,11 +409,11 @@ void test_merge_workdir_setup__three_same_branches(void)
 	cl_git_pass(git_reference_lookup(&octo1_3_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[2], repo, octo1_3_ref));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO1_BRANCH "' and '" OCTO1_BRANCH "'\n"));
 	
 	git_reference_free(octo1_1_ref);
@@ -473,11 +447,11 @@ void test_merge_workdir_setup__three_same_oids(void)
 	cl_git_pass(git_oid_fromstr(&octo1_3_oid, OCTO1_OID));
 	cl_git_pass(git_merge_head_from_id(&their_heads[2], repo, &octo1_3_oid));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO1_OID "'; commit '" OCTO1_OID "'\n"));
 	
 	git_merge_head_free(our_head);
@@ -544,11 +518,11 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void)
 	cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
 
 	git_reference_free(octo1_ref);
@@ -577,11 +551,11 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void)
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "' and 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -617,11 +591,11 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void)
 	cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO3_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[2], repo, octo3_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "', 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO3_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -653,11 +627,11 @@ void test_merge_workdir_setup__normal_branch_and_remote_tracking_branch(void)
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -687,11 +661,11 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void)
 	cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[1], repo, octo2_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO2_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -730,11 +704,11 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche
 	cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO4_BRANCH));
 	cl_git_pass(git_merge_head_from_ref(&their_heads[3], repo, octo4_ref));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "', remote-tracking branches 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO4_BRANCH "'\n"));
 	
 	git_reference_free(octo1_ref);
@@ -762,11 +736,11 @@ void test_merge_workdir_setup__pull_one(void)
 	cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID));
 	cl_git_pass(git_merge_head_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_1_oid));
 	
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 1));
 	
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch 'octo1' of http://remote.url/repo.git\n"));
 	
 	git_merge_head_free(our_head);
@@ -790,11 +764,11 @@ void test_merge_workdir_setup__pull_two(void)
 	cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
 	cl_git_pass(git_merge_head_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.url/repo.git", &octo2_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 2));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "' of http://remote.url/repo.git\n"));
 	
 	git_merge_head_free(our_head);
@@ -823,11 +797,11 @@ void test_merge_workdir_setup__pull_three(void)
 	cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
 	cl_git_pass(git_merge_head_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.url/repo.git", &octo3_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.url/repo.git\n"));
 	
 	git_merge_head_free(our_head);
@@ -856,11 +830,11 @@ void test_merge_workdir_setup__three_remotes(void)
 	cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
 	cl_git_pass(git_merge_head_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.third/repo.git", &octo3_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 3));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "' of http://remote.first/repo.git, branch '" OCTO2_BRANCH "' of http://remote.second/repo.git, branch '" OCTO3_BRANCH "' of http://remote.third/repo.git\n"));
 	
 	git_merge_head_free(our_head);
@@ -893,11 +867,11 @@ void test_merge_workdir_setup__two_remotes(void)
 	cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
 	cl_git_pass(git_merge_head_from_fetchhead(&their_heads[3], repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH, "http://remote.second/repo.git", &octo4_oid));
 
-	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4, 0));
+	cl_git_pass(git_merge__setup(repo, our_head, (const git_merge_head **)their_heads, 4));
 
 	cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
 	cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
-	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, ""));
+	cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
 	cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.first/repo.git, branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "' of http://remote.second/repo.git\n"));
 	
 	git_merge_head_free(our_head);
@@ -996,10 +970,8 @@ void test_merge_workdir_setup__retained_after_success(void)
 	git_oid our_oid;
 	git_reference *octo1_ref;
 	git_merge_head *our_head, *their_heads[1];
-	git_merge_result *result;
 	git_merge_opts opts = GIT_MERGE_OPTS_INIT;
-
-	opts.merge_flags |= GIT_MERGE_NO_FASTFORWARD;
+	git_merge_result *result;
 
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
@@ -1030,8 +1002,6 @@ void test_merge_workdir_setup__removed_after_failure(void)
 	git_merge_result *result;
 	git_merge_opts opts = GIT_MERGE_OPTS_INIT;
 
-	opts.merge_flags |= GIT_MERGE_NO_FASTFORWARD;
-
 	cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
 	cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));