@matheusbsbs / matheus-bagliano / commits / 17bcdad3b7
Fork 0

git-merge: make it usable as the first class UI

This teaches the oft-requested syntax git merge $commit to implement merging the named commit to the current branch. This hopefully would make "git merge" usable as the first class UI instead of being a mere backend for "git pull". Most notably, $commit above can be any committish, so you can say for example: git merge js/shortlog~2 to merge early part of a topic branch without merging the rest of it. A custom merge message can be given with the new --message=<msg> parameter. The message is prepended in front of the usual "Merge ..." message autogenerated with fmt-merge-message. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 20, 2006 at 01:06 UTC 17bcdad3b7baa3b12c662663372f1e3cd560dd8e
2 files changed +67 -12
Documentation/git-merge.txt
+13 -5
@@ -8,12 +8,14 @@ git-merge - Grand Unified Merge Driver
8
9 SYNOPSIS
10 --------
11 -'git-merge' [-n] [--no-commit] [-s <strategy>]... <msg> <head> <remote> <remote>...
12 -
11 +[verse]
12 +'git-merge' [-n] [--no-commit] [--squash] [-s <strategy>]...
13 + [--reflog-action=<action>]
14 + -m=<msg> <remote> <remote>...
15
16 DESCRIPTION
17 -----------
16 -This is the top-level user interface to the merge machinery
18 +This is the top-level interface to the merge machinery
19 which drives multiple merge strategy scripts.
20
21
@@ -27,13 +29,19 @@ include::merge-options.txt[]
29 to give a good default for automated `git-merge` invocations.
30
31 <head>::
30 - our branch head commit.
32 + Our branch head commit. This has to be `HEAD`, so new
33 + syntax does not require it
34
35 <remote>::
33 - other branch head merged into our branch. You need at
36 + Other branch head merged into our branch. You need at
37 least one <remote>. Specifying more than one <remote>
38 obviously means you are trying an Octopus.
39
40 +--reflog-action=<action>::
41 + This is used internally when `git-pull` calls this command
42 + to record that the merge was created by `pull` command
43 + in the `ref-log` entry that results from the merge.
44 +
45 include::merge-strategies.txt[]
46
47
git-merge.sh
+54 -7
@@ -3,7 +3,8 @@
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 -USAGE='[-n] [--no-commit] [--squash] [-s <strategy>]... <merge-message> <head> <remote>+'
6 +USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [--reflog-action=<action>] [-m=<merge-message>] <commit>+'
7 +
8 . git-sh-setup
9
10 LF='
@@ -92,7 +93,7 @@ finish () {
93
94 case "$#" in 0) usage ;; esac
95
95 -rloga=
96 +rloga= have_message=
97 while case "$#" in 0) break ;; esac
98 do
99 case "$1" in
@@ -125,17 +126,63 @@ do
126 --reflog-action=*)
127 rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
128 ;;
129 + -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
130 + merge_msg=`expr "z$1" : 'z-[^=]*=\(.*\)'`
131 + have_message=t
132 + ;;
133 + -m|--m|--me|--mes|--mess|--messa|--messag|--message)
134 + shift
135 + case "$#" in
136 + 1) usage ;;
137 + esac
138 + merge_msg="$1"
139 + have_message=t
140 + ;;
141 -*) usage ;;
142 *) break ;;
143 esac
144 shift
145 done
146
134 -merge_msg="$1"
135 -shift
136 -head_arg="$1"
137 -head=$(git-rev-parse --verify "$1"^0) || usage
138 -shift
147 +# This could be traditional "merge <msg> HEAD <commit>..." and the
148 +# way we can tell it is to see if the second token is HEAD, but some
149 +# people might have misused the interface and used a committish that
150 +# is the same as HEAD there instead. Traditional format never would
151 +# have "-m" so it is an additional safety measure to check for it.
152 +
153 +if test -z "$have_message" &&
154 + second_token=$(git-rev-parse --verify "$2^0" 2>/dev/null) &&
155 + head_commit=$(git-rev-parse --verify "HEAD" 2>/dev/null) &&
156 + test "$second_token" = "$head_commit"
157 +then
158 + merge_msg="$1"
159 + shift
160 + head_arg="$1"
161 + shift
162 +else
163 + # We are invoked directly as the first-class UI.
164 + head_arg=HEAD
165 +
166 + # All the rest are the commits being merged; prepare
167 + # the standard merge summary message to be appended to
168 + # the given message. If remote is invalid we will die
169 + # later in the common codepath so we discard the error
170 + # in this loop.
171 + merge_name=$(for remote
172 + do
173 + rh=$(git-rev-parse --verify "$remote"^0 2>/dev/null)
174 + if git show-ref -q --verify "refs/heads/$remote"
175 + then
176 + what=branch
177 + else
178 + what=commit
179 + fi
180 + echo "$rh $what '$remote'"
181 + done | git-fmt-merge-msg
182 + )
183 + merge_msg="${merge_msg:+$merge_msg$LF$LF}$merge_name"
184 +fi
185 +head=$(git-rev-parse --verify "$head_arg"^0) || usage
186
187 # All the rest are remote heads
188 test "$#" = 0 && usage ;# we need at least one remote head.