@matheusbsbs / matheus-bagliano / commits / 9509af686b
Fork 0

Make git-revert & git-cherry-pick a builtin

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Mar 1, 2007 at 05:26 UTC 9509af686bffdbd7c3f17faf3c07d2034d480ffc
5 files changed +414 -204
Makefile
+4 -7
@@ -180,7 +180,7 @@ SCRIPT_SH = \
180 git-merge-one-file.sh git-parse-remote.sh \
181 git-pull.sh git-rebase.sh \
182 git-repack.sh git-request-pull.sh git-reset.sh \
183 - git-revert.sh git-sh-setup.sh \
183 + git-sh-setup.sh \
184 git-tag.sh git-verify-tag.sh \
185 git-applymbox.sh git-applypatch.sh git-am.sh \
186 git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
@@ -196,7 +196,7 @@ SCRIPT_PERL = \
196
197 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
198 $(patsubst %.perl,%,$(SCRIPT_PERL)) \
199 - git-cherry-pick git-status git-instaweb
199 + git-status git-instaweb
200
201 # ... and all the rest that could be moved out of bindir to gitexecdir
202 PROGRAMS = \
@@ -223,7 +223,7 @@ EXTRA_PROGRAMS =
223 BUILT_INS = \
224 git-format-patch$X git-show$X git-whatchanged$X git-cherry$X \
225 git-get-tar-commit-id$X git-init$X git-repo-config$X \
226 - git-fsck-objects$X \
226 + git-fsck-objects$X git-cherry-pick$X \
227 $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
228
229 # what 'all' will build and 'install' will install, in gitexecdir
@@ -315,6 +315,7 @@ BUILTIN_OBJS = \
315 builtin-rerere.o \
316 builtin-rev-list.o \
317 builtin-rev-parse.o \
318 + builtin-revert.o \
319 builtin-rm.o \
320 builtin-runstatus.o \
321 builtin-shortlog.o \
@@ -689,10 +690,6 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl
690 chmod +x $@+
691 mv $@+ $@
692
692 -git-cherry-pick: git-revert
693 - cp $< $@+
694 - mv $@+ $@
695 -
693 git-status: git-commit
694 cp $< $@+
695 mv $@+ $@
builtin-revert.c new
+406
@@ -0,0 +1,406 @@
1 +#include "cache.h"
2 +#include "builtin.h"
3 +#include "object.h"
4 +#include "commit.h"
5 +#include "tag.h"
6 +#include "wt-status.h"
7 +#include "run-command.h"
8 +#include "exec_cmd.h"
9 +#include "utf8.h"
10 +
11 +/*
12 + * This implements the builtins revert and cherry-pick.
13 + *
14 + * Copyright (c) 2007 Johannes E. Schindelin
15 + *
16 + * Based on git-revert.sh, which is
17 + *
18 + * Copyright (c) 2005 Linus Torvalds
19 + * Copyright (c) 2005 Junio C Hamano
20 + */
21 +
22 +static const char *revert_usage = "git-revert [--edit | --no-edit] [-n] <commit-ish>";
23 +
24 +static const char *cherry_pick_usage = "git-cherry-pick [--edit] [-n] [-r] [-x] <commit-ish>";
25 +
26 +static int edit;
27 +static int replay;
28 +enum { REVERT, CHERRY_PICK } action;
29 +static int no_commit;
30 +static struct commit *commit;
31 +static int needed_deref;
32 +
33 +static const char *me;
34 +
35 +#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
36 +
37 +static void parse_options(int argc, const char **argv)
38 +{
39 + const char *usage_str = action == REVERT ?
40 + revert_usage : cherry_pick_usage;
41 + unsigned char sha1[20];
42 + const char *arg;
43 + int i;
44 +
45 + if (argc < 2)
46 + usage(usage_str);
47 +
48 + for (i = 1; i < argc - 1; i++) {
49 + arg = argv[i];
50 + if (!strcmp(arg, "-n") || !strcmp(arg, "--no-commit"))
51 + no_commit = 1;
52 + else if (!strcmp(arg, "-e") || !strcmp(arg, "--edit"))
53 + edit = 1;
54 + else if (!strcmp(arg, "--no-edit"))
55 + edit = 0;
56 + else if (!strcmp(arg, "-x") || !strcmp(arg, "--i-really-want-"
57 + "to-expose-my-private-commit-object-name"))
58 + replay = 0;
59 + else if (strcmp(arg, "-r"))
60 + usage(usage_str);
61 + }
62 +
63 + arg = argv[argc - 1];
64 + if (get_sha1(arg, sha1))
65 + die ("Cannot find '%s'", arg);
66 + commit = (struct commit *)parse_object(sha1);
67 + if (!commit)
68 + die ("Could not find %s", sha1_to_hex(sha1));
69 + if (commit->object.type == OBJ_TAG) {
70 + commit = (struct commit *)
71 + deref_tag((struct object *)commit, arg, strlen(arg));
72 + needed_deref = 1;
73 + }
74 + if (commit->object.type != OBJ_COMMIT)
75 + die ("'%s' does not point to a commit", arg);
76 +}
77 +
78 +static char *get_oneline(const char *message)
79 +{
80 + char *result;
81 + const char *p = message, *abbrev, *eol;
82 + int abbrev_len, oneline_len;
83 +
84 + if (!p)
85 + die ("Could not read commit message of %s",
86 + sha1_to_hex(commit->object.sha1));
87 + while (*p && (*p != '\n' || p[1] != '\n'))
88 + p++;
89 +
90 + if (*p) {
91 + p += 2;
92 + for (eol = p + 1; *eol && *eol != '\n'; eol++)
93 + ; /* do nothing */
94 + } else
95 + eol = p;
96 + abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
97 + abbrev_len = strlen(abbrev);
98 + oneline_len = eol - p;
99 + result = xmalloc(abbrev_len + 5 + oneline_len);
100 + memcpy(result, abbrev, abbrev_len);
101 + memcpy(result + abbrev_len, "... ", 4);
102 + memcpy(result + abbrev_len + 4, p, oneline_len);
103 + result[abbrev_len + 4 + oneline_len] = '\0';
104 + return result;
105 +}
106 +
107 +char *get_encoding(const char *message)
108 +{
109 + const char *p = message, *eol;
110 +
111 + if (!p)
112 + die ("Could not read commit message of %s",
113 + sha1_to_hex(commit->object.sha1));
114 + while (*p && *p != '\n') {
115 + for (eol = p + 1; *eol && *eol != '\n'; eol++)
116 + ; /* do nothing */
117 + if (!prefixcmp(p, "encoding ")) {
118 + char *result = xmalloc(eol - 8 - p);
119 + strlcpy(result, p + 9, eol - 8 - p);
120 + return result;
121 + }
122 + p = eol;
123 + if (*p == '\n')
124 + p++;
125 + }
126 + return NULL;
127 +}
128 +
129 +struct lock_file msg_file;
130 +static int msg_fd;
131 +
132 +static void add_to_msg(const char *string)
133 +{
134 + int len = strlen(string);
135 + if (write_in_full(msg_fd, string, len) < 0)
136 + die ("Could not write to .msg");
137 +}
138 +
139 +static void add_message_to_msg(const char *message)
140 +{
141 + const char *p = message;
142 + while (*p && (*p != '\n' || p[1] != '\n'))
143 + p++;
144 +
145 + if (!*p)
146 + add_to_msg(sha1_to_hex(commit->object.sha1));
147 +
148 + p += 2;
149 + add_to_msg(p);
150 + return;
151 +}
152 +
153 +static void set_author_ident_env(const char *message)
154 +{
155 + const char *p = message;
156 + if (!p)
157 + die ("Could not read commit message of %s",
158 + sha1_to_hex(commit->object.sha1));
159 + while (*p && *p != '\n') {
160 + const char *eol;
161 +
162 + for (eol = p; *eol && *eol != '\n'; eol++)
163 + ; /* do nothing */
164 + if (!prefixcmp(p, "author ")) {
165 + char *line, *pend, *email, *timestamp;
166 +
167 + p += 7;
168 + line = xmalloc(eol + 1 - p);
169 + memcpy(line, p, eol - p);
170 + line[eol - p] = '\0';
171 + email = strchr(line, '<');
172 + if (!email)
173 + die ("Could not extract author email from %s",
174 + sha1_to_hex(commit->object.sha1));
175 + if (email == line)
176 + pend = line;
177 + else
178 + for (pend = email; pend != line + 1 &&
179 + isspace(pend[-1]); pend--);
180 + ; /* do nothing */
181 + *pend = '\0';
182 + email++;
183 + timestamp = strchr(email, '>');
184 + if (!timestamp)
185 + die ("Could not extract author email from %s",
186 + sha1_to_hex(commit->object.sha1));
187 + *timestamp = '\0';
188 + for (timestamp++; *timestamp && isspace(*timestamp);
189 + timestamp++)
190 + ; /* do nothing */
191 + setenv("GIT_AUTHOR_NAME", line, 1);
192 + setenv("GIT_AUTHOR_EMAIL", email, 1);
193 + setenv("GIT_AUTHOR_DATE", timestamp, 1);
194 + free(line);
195 + return;
196 + }
197 + p = eol;
198 + if (*p == '\n')
199 + p++;
200 + }
201 + die ("No author information found in %s",
202 + sha1_to_hex(commit->object.sha1));
203 +}
204 +
205 +static int merge_recursive(const char *base_sha1,
206 + const char *head_sha1, const char *head_name,
207 + const char *next_sha1, const char *next_name)
208 +{
209 + char buffer[256];
210 +
211 + sprintf(buffer, "GITHEAD_%s", head_sha1);
212 + setenv(buffer, head_name, 1);
213 + sprintf(buffer, "GITHEAD_%s", next_sha1);
214 + setenv(buffer, next_name, 1);
215 +
216 + /*
217 + * This three way merge is an interesting one. We are at
218 + * $head, and would want to apply the change between $commit
219 + * and $prev on top of us (when reverting), or the change between
220 + * $prev and $commit on top of us (when cherry-picking or replaying).
221 + */
222 +
223 + return run_command_opt(RUN_COMMAND_NO_STDIN | RUN_GIT_CMD,
224 + "merge-recursive", base_sha1, "--",
225 + head_sha1, next_sha1, NULL);
226 +}
227 +
228 +static int revert_or_cherry_pick(int argc, const char **argv)
229 +{
230 + unsigned char head[20];
231 + struct commit *base, *next;
232 + int i;
233 + char *oneline, *encoding, *reencoded_message = NULL;
234 + const char *message;
235 +
236 + git_config(git_default_config);
237 + me = action == REVERT ? "revert" : "cherry-pick";
238 + setenv(GIT_REFLOG_ACTION, me, 0);
239 + parse_options(argc, argv);
240 +
241 + /* this is copied from the shell script, but it's never triggered... */
242 + if (action == REVERT && replay)
243 + die("revert is incompatible with replay");
244 +
245 + if (no_commit) {
246 + /*
247 + * We do not intend to commit immediately. We just want to
248 + * merge the differences in.
249 + */
250 + if (write_tree(head, 0, NULL))
251 + die ("Your index file is unmerged.");
252 + } else {
253 + struct wt_status s;
254 +
255 + if (get_sha1("HEAD", head))
256 + die ("You do not have a valid HEAD");
257 + wt_status_prepare(&s);
258 + if (s.commitable || s.workdir_dirty)
259 + die ("Dirty index: cannot %s", me);
260 + discard_cache();
261 + }
262 +
263 + if (!commit->parents)
264 + die ("Cannot %s a root commit", me);
265 + if (commit->parents->next)
266 + die ("Cannot %s a multi-parent commit.", me);
267 + if (!(message = commit->buffer))
268 + die ("Cannot get commit message for %s",
269 + sha1_to_hex(commit->object.sha1));
270 +
271 + /*
272 + * "commit" is an existing commit. We would want to apply
273 + * the difference it introduces since its first parent "prev"
274 + * on top of the current HEAD if we are cherry-pick. Or the
275 + * reverse of it if we are revert.
276 + */
277 +
278 + msg_fd = hold_lock_file_for_update(&msg_file, ".msg", 1);
279 +
280 + encoding = get_encoding(message);
281 + if (!encoding)
282 + encoding = "utf-8";
283 + if (!git_commit_encoding)
284 + git_commit_encoding = "utf-8";
285 + if ((reencoded_message = reencode_string(message,
286 + git_commit_encoding, encoding)))
287 + message = reencoded_message;
288 +
289 + oneline = get_oneline(message);
290 +
291 + if (action == REVERT) {
292 + base = commit;
293 + next = commit->parents->item;
294 + add_to_msg("Revert ");
295 + add_to_msg(find_unique_abbrev(commit->object.sha1,
296 + DEFAULT_ABBREV));
297 + add_to_msg(oneline);
298 + add_to_msg("\nThis reverts commit ");
299 + add_to_msg(sha1_to_hex(commit->object.sha1));
300 + add_to_msg(".\n");
301 + } else {
302 + base = commit->parents->item;
303 + next = commit;
304 + set_author_ident_env(message);
305 + add_message_to_msg(message);
306 + if (replay) {
307 + add_to_msg("\n(cherry picked from commit ");
308 + add_to_msg(sha1_to_hex(commit->object.sha1));
309 + add_to_msg(")\n");
310 + }
311 + }
312 + if (needed_deref) {
313 + add_to_msg("(original 'git ");
314 + add_to_msg(me);
315 + add_to_msg("' arguments: ");
316 + for (i = 0; i < argc; i++) {
317 + if (i)
318 + add_to_msg(" ");
319 + add_to_msg(argv[i]);
320 + }
321 + add_to_msg(")\n");
322 + }
323 +
324 + if (merge_recursive(sha1_to_hex(base->object.sha1),
325 + sha1_to_hex(head), "HEAD",
326 + sha1_to_hex(next->object.sha1), oneline))
327 + exit(1);
328 + if (write_tree(head, 0, NULL)) {
329 + const char *target = git_path("MERGE_MSG");
330 + add_to_msg("\nConflicts:\n\n");
331 + read_cache();
332 + for (i = 0; i < active_nr;) {
333 + struct cache_entry *ce = active_cache[i++];
334 + if (ce_stage(ce)) {
335 + add_to_msg("\t");
336 + add_to_msg(ce->name);
337 + add_to_msg("\n");
338 + while (i < active_nr && !strcmp(ce->name,
339 + active_cache[i]->name))
340 + i++;
341 + }
342 + }
343 + if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
344 + die ("Error wrapping up .msg");
345 + unlink(target);
346 + if (rename(".msg", target))
347 + die ("Could not move .msg to %s", target);
348 + fprintf(stderr, "Automatic %s failed. "
349 + "After resolving the conflicts,\n"
350 + "mark the corrected paths with 'git-add <paths>'\n"
351 + "and commit the result.\n", me);
352 + if (action == CHERRY_PICK) {
353 + fprintf(stderr, "You may choose to use the following "
354 + "when making the commit:\n"
355 + "GIT_AUTHOR_NAME=\"%s\"\n",
356 + getenv("GIT_AUTHOR_NAME"));
357 + fprintf(stderr, "GIT_AUTHOR_EMAIL=\"%s\"\n",
358 + getenv("GIT_AUTHOR_EMAIL"));
359 + fprintf(stderr, "GIT_AUTHOR_DATE=\"%s\"\n"
360 + "export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL "
361 + "GIT_AUTHOR_DATE\n",
362 + getenv("GIT_AUTHOR_DATE"));
363 + }
364 + exit(1);
365 + }
366 + if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
367 + die ("Error wrapping up .msg");
368 + fprintf(stderr, "Finished one %s.\n", me);
369 +
370 + /*
371 + *
372 + * If we are cherry-pick, and if the merge did not result in
373 + * hand-editing, we will hit this commit and inherit the original
374 + * author date and name.
375 + * If we are revert, or if our cherry-pick results in a hand merge,
376 + * we had better say that the current user is responsible for that.
377 + */
378 +
379 + if (!no_commit) {
380 + if (edit)
381 + return execl_git_cmd("commit", "-n", "-F", ".msg",
382 + "-e", NULL);
383 + else
384 + return execl_git_cmd("commit", "-n", "-F", ".msg",
385 + NULL);
386 + }
387 + if (reencoded_message)
388 + free(reencoded_message);
389 +
390 + return 0;
391 +}
392 +
393 +int cmd_revert(int argc, const char **argv, const char *prefix)
394 +{
395 + if (isatty(0))
396 + edit = 1;
397 + action = REVERT;
398 + return revert_or_cherry_pick(argc, argv);
399 +}
400 +
401 +int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
402 +{
403 + replay = 1;
404 + action = CHERRY_PICK;
405 + return revert_or_cherry_pick(argc, argv);
406 +}
builtin.h
+2
@@ -24,6 +24,7 @@ extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
24 extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
25 extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
26 extern int cmd_cherry(int argc, const char **argv, const char *prefix);
27 +extern int cmd_cherry_pick(int argc, const char **argv, const char *prefix);
28 extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
29 extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
30 extern int cmd_describe(int argc, const char **argv, const char *prefix);
@@ -60,6 +61,7 @@ extern int cmd_config(int argc, const char **argv, const char *prefix);
61 extern int cmd_rerere(int argc, const char **argv, const char *prefix);
62 extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
63 extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
64 +extern int cmd_revert(int argc, const char **argv, const char *prefix);
65 extern int cmd_rm(int argc, const char **argv, const char *prefix);
66 extern int cmd_runstatus(int argc, const char **argv, const char *prefix);
67 extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
git-revert.sh deleted
-197
@@ -1,197 +0,0 @@
1 -#!/bin/sh
2 -#
3 -# Copyright (c) 2005 Linus Torvalds
4 -# Copyright (c) 2005 Junio C Hamano
5 -#
6 -
7 -case "$0" in
8 -*-revert* )
9 - test -t 0 && edit=-e
10 - replay=
11 - me=revert
12 - USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
13 -*-cherry-pick* )
14 - replay=t
15 - edit=
16 - me=cherry-pick
17 - USAGE='[--edit] [-n] [-r] [-x] <commit-ish>' ;;
18 -* )
19 - echo >&2 "What are you talking about?"
20 - exit 1 ;;
21 -esac
22 -
23 -SUBDIRECTORY_OK=Yes ;# we will cd up
24 -. git-sh-setup
25 -require_work_tree
26 -cd_to_toplevel
27 -
28 -no_commit=
29 -while case "$#" in 0) break ;; esac
30 -do
31 - case "$1" in
32 - -n|--n|--no|--no-|--no-c|--no-co|--no-com|--no-comm|\
33 - --no-commi|--no-commit)
34 - no_commit=t
35 - ;;
36 - -e|--e|--ed|--edi|--edit)
37 - edit=-e
38 - ;;
39 - --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit)
40 - edit=
41 - ;;
42 - -r)
43 - : no-op ;;
44 - -x|--i-really-want-to-expose-my-private-commit-object-name)
45 - replay=
46 - ;;
47 - -*)
48 - usage
49 - ;;
50 - *)
51 - break
52 - ;;
53 - esac
54 - shift
55 -done
56 -
57 -set_reflog_action "$me"
58 -
59 -test "$me,$replay" = "revert,t" && usage
60 -
61 -case "$no_commit" in
62 -t)
63 - # We do not intend to commit immediately. We just want to
64 - # merge the differences in.
65 - head=$(git-write-tree) ||
66 - die "Your index file is unmerged."
67 - ;;
68 -*)
69 - head=$(git-rev-parse --verify HEAD) ||
70 - die "You do not have a valid HEAD"
71 - files=$(git-diff-index --cached --name-only $head) || exit
72 - if [ "$files" ]; then
73 - die "Dirty index: cannot $me (dirty: $files)"
74 - fi
75 - ;;
76 -esac
77 -
78 -rev=$(git-rev-parse --verify "$@") &&
79 -commit=$(git-rev-parse --verify "$rev^0") ||
80 - die "Not a single commit $@"
81 -prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) ||
82 - die "Cannot run $me a root commit"
83 -git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
84 - die "Cannot run $me a multi-parent commit."
85 -
86 -encoding=$(git config i18n.commitencoding || echo UTF-8)
87 -
88 -# "commit" is an existing commit. We would want to apply
89 -# the difference it introduces since its first parent "prev"
90 -# on top of the current HEAD if we are cherry-pick. Or the
91 -# reverse of it if we are revert.
92 -
93 -case "$me" in
94 -revert)
95 - git show -s --pretty=oneline --encoding="$encoding" $commit |
96 - sed -e '
97 - s/^[^ ]* /Revert "/
98 - s/$/"/
99 - '
100 - echo
101 - echo "This reverts commit $commit."
102 - test "$rev" = "$commit" ||
103 - echo "(original 'git revert' arguments: $@)"
104 - base=$commit next=$prev
105 - ;;
106 -
107 -cherry-pick)
108 - pick_author_script='
109 - /^author /{
110 - s/'\''/'\''\\'\'\''/g
111 - h
112 - s/^author \([^<]*\) <[^>]*> .*$/\1/
113 - s/'\''/'\''\'\'\''/g
114 - s/.*/GIT_AUTHOR_NAME='\''&'\''/p
115 -
116 - g
117 - s/^author [^<]* <\([^>]*\)> .*$/\1/
118 - s/'\''/'\''\'\'\''/g
119 - s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
120 -
121 - g
122 - s/^author [^<]* <[^>]*> \(.*\)$/\1/
123 - s/'\''/'\''\'\'\''/g
124 - s/.*/GIT_AUTHOR_DATE='\''&'\''/p
125 -
126 - q
127 - }'
128 -
129 - logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"`
130 - set_author_env=`echo "$logmsg" |
131 - LANG=C LC_ALL=C sed -ne "$pick_author_script"`
132 - eval "$set_author_env"
133 - export GIT_AUTHOR_NAME
134 - export GIT_AUTHOR_EMAIL
135 - export GIT_AUTHOR_DATE
136 -
137 - echo "$logmsg" |
138 - sed -e '1,/^$/d' -e 's/^ //'
139 - case "$replay" in
140 - '')
141 - echo "(cherry picked from commit $commit)"
142 - test "$rev" = "$commit" ||
143 - echo "(original 'git cherry-pick' arguments: $@)"
144 - ;;
145 - esac
146 - base=$prev next=$commit
147 - ;;
148 -
149 -esac >.msg
150 -
151 -eval GITHEAD_$head=HEAD
152 -eval GITHEAD_$next='`git show -s \
153 - --pretty=oneline --encoding="$encoding" "$commit" |
154 - sed -e "s/^[^ ]* //"`'
155 -export GITHEAD_$head GITHEAD_$next
156 -
157 -# This three way merge is an interesting one. We are at
158 -# $head, and would want to apply the change between $commit
159 -# and $prev on top of us (when reverting), or the change between
160 -# $prev and $commit on top of us (when cherry-picking or replaying).
161 -
162 -git-merge-recursive $base -- $head $next &&
163 -result=$(git-write-tree 2>/dev/null) || {
164 - mv -f .msg "$GIT_DIR/MERGE_MSG"
165 - {
166 - echo '
167 -Conflicts:
168 -'
169 - git ls-files --unmerged |
170 - sed -e 's/^[^ ]* / /' |
171 - uniq
172 - } >>"$GIT_DIR/MERGE_MSG"
173 - echo >&2 "Automatic $me failed. After resolving the conflicts,"
174 - echo >&2 "mark the corrected paths with 'git-add <paths>'"
175 - echo >&2 "and commit the result."
176 - case "$me" in
177 - cherry-pick)
178 - echo >&2 "You may choose to use the following when making"
179 - echo >&2 "the commit:"
180 - echo >&2 "$set_author_env"
181 - esac
182 - exit 1
183 -}
184 -echo >&2 "Finished one $me."
185 -
186 -# If we are cherry-pick, and if the merge did not result in
187 -# hand-editing, we will hit this commit and inherit the original
188 -# author date and name.
189 -# If we are revert, or if our cherry-pick results in a hand merge,
190 -# we had better say that the current user is responsible for that.
191 -
192 -case "$no_commit" in
193 -'')
194 - git-commit -n -F .msg $edit
195 - rm -f .msg
196 - ;;
197 -esac
git.c
+2
@@ -234,6 +234,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
234 { "checkout-index", cmd_checkout_index, RUN_SETUP },
235 { "check-ref-format", cmd_check_ref_format },
236 { "cherry", cmd_cherry, RUN_SETUP },
237 + { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NOT_BARE },
238 { "commit-tree", cmd_commit_tree, RUN_SETUP },
239 { "config", cmd_config },
240 { "count-objects", cmd_count_objects, RUN_SETUP },
@@ -272,6 +273,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
273 { "rerere", cmd_rerere, RUN_SETUP },
274 { "rev-list", cmd_rev_list, RUN_SETUP },
275 { "rev-parse", cmd_rev_parse, RUN_SETUP },
276 + { "revert", cmd_revert, RUN_SETUP | NOT_BARE },
277 { "rm", cmd_rm, RUN_SETUP | NOT_BARE },
278 { "runstatus", cmd_runstatus, RUN_SETUP | NOT_BARE },
279 { "shortlog", cmd_shortlog, RUN_SETUP | USE_PAGER },