| 1 |
package main |
| 2 |
|
| 3 |
const helpLongMsg = ` |
| 4 |
NAME: |
| 5 |
%_COMMAND_NAME_% - Lists the best common ancestors of the two passed commit revisions |
| 6 |
|
| 7 |
SYNOPSIS: |
| 8 |
usage: %_COMMAND_NAME_% <path> <commitRev> <commitRev> |
| 9 |
or: %_COMMAND_NAME_% <path> --independent <commitRev>... |
| 10 |
or: %_COMMAND_NAME_% <path> --is-ancestor <commitRev> <commitRev> |
| 11 |
|
| 12 |
params: |
| 13 |
<path> Path to the git repository |
| 14 |
<commitRev> Git revision as supported by go-git |
| 15 |
|
| 16 |
DESCRIPTION: |
| 17 |
%_COMMAND_NAME_% finds the best common ancestor(s) between two commits. One common ancestor is better than another common ancestor if the latter is an ancestor of the former. |
| 18 |
A common ancestor that does not have any better common ancestor is a best common ancestor, i.e. a merge base. Note that there can be more than one merge base for a pair of commits. |
| 19 |
Commits that does not share a common history has no common ancestors. |
| 20 |
|
| 21 |
OPTIONS: |
| 22 |
As the most common special case, specifying only two commits on the command line means computing the merge base between the given two commits. |
| 23 |
If there is no shared history between the passed commits, there won't be a merge-base, and the command will exit with status 1. |
| 24 |
|
| 25 |
--independent |
| 26 |
List the subgroup from the passed commits, that cannot be reached from any other of the passed ones. In other words, it prints a minimal subset of the supplied commits with the same ancestors. |
| 27 |
|
| 28 |
--is-ancestor |
| 29 |
Check if the first commit is an ancestor of the second one, and exit with status 0 if true, or with status 1 if not. Errors are signaled by a non-zero status that is not 1. |
| 30 |
|
| 31 |
DISCUSSION: |
| 32 |
Given two commits A and B, %_COMMAND_NAME_% A B will output a commit which is the best common ancestor of both, what means that is reachable from both A and B through the parent relationship. |
| 33 |
|
| 34 |
For example, with this topology: |
| 35 |
|
| 36 |
o---o---o---o---B |
| 37 |
/ / |
| 38 |
---3---2---o---1---o---A |
| 39 |
|
| 40 |
the merge base between A and B is 1. |
| 41 |
|
| 42 |
With the given topology 2 and 3 are also common ancestors of A and B, but they are not the best ones because they can be also reached from 1. |
| 43 |
|
| 44 |
When the history involves cross-cross merges, there can be more than one best common ancestor for two commits. For example, with this topology: |
| 45 |
|
| 46 |
---1---o---A |
| 47 |
\ / |
| 48 |
X |
| 49 |
/ \ |
| 50 |
---2---o---o---B |
| 51 |
|
| 52 |
When the history involves feature branches depending on other feature branches there can be also more than one common ancestor. For example: |
| 53 |
|
| 54 |
|
| 55 |
o---o---o |
| 56 |
/ \ |
| 57 |
1---o---A \ |
| 58 |
/ / \ |
| 59 |
---o---o---2---o---o---B |
| 60 |
|
| 61 |
In both examples, both 1 and 2 are merge-bases of A and B for each situation. |
| 62 |
Neither one is better than the other (both are best merge bases) because 1 cannot be reached from 2, nor the opposite. |
| 63 |
` |