Skip to content

Commit 2b916ff

Browse files
committed
Merge branch 'jn/update-contrib-example-merge'
* jn/update-contrib-example-merge: (24 commits) merge script: learn --[no-]rerere-autoupdate merge script: notice @{-1} shorthand merge script: handle --no-ff --no-commit correctly merge script: --ff-only to disallow true merge merge script: handle many-way octopus merge script: handle -m --log correctly merge script: forbid merge -s index merge script: allow custom strategies merge script: merge -X<option> merge script: improve log message subject merge script: refuse to merge during merge merge script: tweak unmerged files message to match builtin merge script: --squash, --ff from unborn branch are errors fmt-merge-msg -m to override merge title merge-base --independent to print reduced parent list in a merge merge-base --octopus to mimic show-branch --merge-base Documentation: add a SEE ALSO section for merge-base t6200 (fmt-merge-msg): style nitpicks t6010 (merge-base): modernize style t7600 (merge): test merge from branch yet to be born ...
2 parents 8aed4a5 + fdc4408 commit 2b916ff

9 files changed

Lines changed: 701 additions & 562 deletions

File tree

Documentation/git-fmt-merge-msg.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ git-fmt-merge-msg - Produce a merge commit message
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git fmt-merge-msg' [--log | --no-log] <$GIT_DIR/FETCH_HEAD
13-
'git fmt-merge-msg' [--log | --no-log] -F <file>
12+
'git fmt-merge-msg' [-m <message>] [--log | --no-log] <$GIT_DIR/FETCH_HEAD
13+
'git fmt-merge-msg' [-m <message>] [--log | --no-log] -F <file>
1414

1515
DESCRIPTION
1616
-----------
@@ -38,6 +38,11 @@ OPTIONS
3838
Synonyms to --log and --no-log; these are deprecated and will be
3939
removed in the future.
4040

41+
-m <message>::
42+
--message <message>::
43+
Use <message> instead of the branch names for the first line
44+
of the log message. For use with `--log`.
45+
4146
-F <file>::
4247
--file <file>::
4348
Take the list of merged objects from <file> instead of

Documentation/git-merge-base.txt

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ git-merge-base - Find as good common ancestors as possible for a merge
88

99
SYNOPSIS
1010
--------
11-
'git merge-base' [-a|--all] <commit> <commit>...
11+
[verse]
12+
'git merge-base' [-a|--all] [--octopus] <commit> <commit>...
13+
'git merge-base' --independent <commit>...
1214

1315
DESCRIPTION
1416
-----------
@@ -20,12 +22,12 @@ that does not have any better common ancestor is a 'best common
2022
ancestor', i.e. a 'merge base'. Note that there can be more than one
2123
merge base for a pair of commits.
2224

23-
Among the two commits to compute the merge base from, one is specified by
24-
the first commit argument on the command line; the other commit is a
25-
(possibly hypothetical) commit that is a merge across all the remaining
26-
commits on the command line. As the most common special case, specifying only
27-
two commits on the command line means computing the merge base between
28-
the given two commits.
25+
Unless `--octopus` is given, among the two commits to compute the merge
26+
base from, one is specified by the first commit argument on the command
27+
line; the other commit is a (possibly hypothetical) commit that is a merge
28+
across all the remaining commits on the command line. As the most common
29+
special case, specifying only two commits on the command line means
30+
computing the merge base between the given two commits.
2931

3032
As a consequence, the 'merge base' is not necessarily contained in each of the
3133
commit arguments if more than two commits are specified. This is different
@@ -37,6 +39,18 @@ OPTIONS
3739
--all::
3840
Output all merge bases for the commits, instead of just one.
3941

42+
--octopus::
43+
Compute the best common ancestors of all supplied commits,
44+
in preparation for an n-way merge. This mimics the behavior
45+
of 'git show-branch --merge-base'.
46+
47+
--independent::
48+
Instead of printing merge bases, print a minimal subset of
49+
the supplied commits with the same ancestors. In other words,
50+
among the commits given, list those which cannot be reached
51+
from any other. This mimics the behavior of 'git show-branch
52+
--independent'.
53+
4054
DISCUSSION
4155
----------
4256

@@ -96,6 +110,12 @@ Documentation
96110
--------------
97111
Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>.
98112

113+
See also
114+
--------
115+
linkgit:git-rev-list[1],
116+
linkgit:git-show-branch[1],
117+
linkgit:git-merge[1]
118+
99119
GIT
100120
---
101121
Part of the linkgit:git[1] suite

builtin/fmt-merge-msg.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "string-list.h"
88

99
static const char * const fmt_merge_msg_usage[] = {
10-
"git fmt-merge-msg [--log|--no-log] [--file <file>]",
10+
"git fmt-merge-msg [-m <message>] [--log|--no-log] [--file <file>]",
1111
NULL
1212
};
1313

@@ -319,11 +319,14 @@ int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
319319
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
320320
{
321321
const char *inpath = NULL;
322+
const char *message = NULL;
322323
struct option options[] = {
323324
OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"),
324325
{ OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
325326
"alias for --log (deprecated)",
326327
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
328+
OPT_STRING('m', "message", &message, "text",
329+
"use <text> as start of message"),
327330
OPT_FILENAME('F', "file", &inpath, "file to read from"),
328331
OPT_END()
329332
};
@@ -337,6 +340,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
337340
0);
338341
if (argc > 0)
339342
usage_with_options(fmt_merge_msg_usage, options);
343+
if (message && !merge_summary) {
344+
char nl = '\n';
345+
write_in_full(STDOUT_FILENO, message, strlen(message));
346+
write_in_full(STDOUT_FILENO, &nl, 1);
347+
return 0;
348+
}
340349

341350
if (inpath && strcmp(inpath, "-")) {
342351
in = fopen(inpath, "r");
@@ -346,7 +355,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
346355

347356
if (strbuf_read(&input, fileno(in), 0) < 0)
348357
die_errno("could not read input file");
349-
ret = fmt_merge_msg(merge_summary, &input, &output);
358+
if (message) {
359+
strbuf_addstr(&output, message);
360+
ret = fmt_merge_msg_shortlog(&input, &output);
361+
} else {
362+
ret = fmt_merge_msg(merge_summary, &input, &output);
363+
}
350364
if (ret)
351365
return ret;
352366
write_in_full(STDOUT_FILENO, output.buf, output.len);

builtin/merge-base.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
2323
}
2424

2525
static const char * const merge_base_usage[] = {
26-
"git merge-base [-a|--all] <commit> <commit>...",
26+
"git merge-base [-a|--all] [--octopus] <commit> <commit>...",
27+
"git merge-base --independent <commit>...",
2728
NULL
2829
};
2930

@@ -41,21 +42,58 @@ static struct commit *get_commit_reference(const char *arg)
4142
return r;
4243
}
4344

45+
static int handle_octopus(int count, const char **args, int reduce, int show_all)
46+
{
47+
struct commit_list *revs = NULL;
48+
struct commit_list *result;
49+
int i;
50+
51+
if (reduce)
52+
show_all = 1;
53+
54+
for (i = count - 1; i >= 0; i--)
55+
commit_list_insert(get_commit_reference(args[i]), &revs);
56+
57+
result = reduce ? reduce_heads(revs) : get_octopus_merge_bases(revs);
58+
59+
if (!result)
60+
return 1;
61+
62+
while (result) {
63+
printf("%s\n", sha1_to_hex(result->item->object.sha1));
64+
if (!show_all)
65+
return 0;
66+
result = result->next;
67+
}
68+
69+
return 0;
70+
}
71+
4472
int cmd_merge_base(int argc, const char **argv, const char *prefix)
4573
{
4674
struct commit **rev;
4775
int rev_nr = 0;
4876
int show_all = 0;
77+
int octopus = 0;
78+
int reduce = 0;
4979

5080
struct option options[] = {
51-
OPT_BOOLEAN('a', "all", &show_all, "outputs all common ancestors"),
81+
OPT_BOOLEAN('a', "all", &show_all, "output all common ancestors"),
82+
OPT_BOOLEAN(0, "octopus", &octopus, "find ancestors for a single n-way merge"),
83+
OPT_BOOLEAN(0, "independent", &reduce, "list revs not reachable from others"),
5284
OPT_END()
5385
};
5486

5587
git_config(git_default_config, NULL);
5688
argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);
57-
if (argc < 2)
89+
if (!octopus && !reduce && argc < 2)
5890
usage_with_options(merge_base_usage, options);
91+
if (reduce && (show_all || octopus))
92+
die("--independent cannot be used with other options");
93+
94+
if (octopus || reduce)
95+
return handle_octopus(argc, argv, reduce, show_all);
96+
5997
rev = xmalloc(argc * sizeof(*rev));
6098
while (argc-- > 0)
6199
rev[rev_nr++] = get_commit_reference(*argv++);

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
438438
strbuf_addstr(&truname, "refs/heads/");
439439
strbuf_addstr(&truname, remote);
440440
strbuf_setlen(&truname, truname.len - len);
441-
if (resolve_ref(truname.buf, buf_sha, 0, NULL)) {
441+
if (resolve_ref(truname.buf, buf_sha, 1, NULL)) {
442442
strbuf_addf(msg,
443443
"%s\t\tbranch '%s'%s of .\n",
444444
sha1_to_hex(remote_head->sha1),

0 commit comments

Comments
 (0)