All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH 3/6] revert: don't let revert continue a cherry-pick
Date: Sun,  8 Jan 2012 17:57:30 +0530	[thread overview]
Message-ID: <1326025653-11922-4-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1326025653-11922-1-git-send-email-artagnon@gmail.com>

When we allow mixing "revert" and "pick" instructions in the same
sheet in the next patch, the following workflow would be perfectly
valid:

  $ git cherry-pick base..latercommit
  [conflict occurs]
  $ edit problematicfile
  $ git add problematicfile
  $ git revert --continue
  [finishes successfully]

This is confusing to the operator, because the sequencer is an
implementation detail hidden behind the 'git cherry-pick' and 'git
revert' builtins.  So, disallow this workflow by keeping track of the
builtin command executed (either "revert" or "cherry-pick") in
'.git/sequencer/cmd'.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/revert.c                |   57 +++++++++++++++++++++++++++++++++++++++
 sequencer.h                     |    1 +
 t/t3510-cherry-pick-sequence.sh |   11 +++++++
 3 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index 3ac6da0..52fa115 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -871,6 +871,50 @@ static int create_seq_dir(void)
 	return 0;
 }
 
+static enum replay_command read_cmd(void)
+{
+	const char *cmd_file = git_path(SEQ_CMD_FILE);
+	struct strbuf buf = STRBUF_INIT;
+	enum replay_command res;
+	int fd;
+
+	fd = open(cmd_file, O_RDONLY);
+	if (fd < 0)
+		die_errno(_("Could not open %s"), cmd_file);
+	if (strbuf_read(&buf, fd, 0) < 0) {
+		close(fd);
+		strbuf_release(&buf);
+		die(_("Could not read %s."), cmd_file);
+	}
+	close(fd);
+
+	if (!strcmp(buf.buf, "revert\n"))
+		res = REPLAY_CMD_REVERT;
+	else if (!strcmp(buf.buf, "cherry-pick\n"))
+		res = REPLAY_CMD_CHERRY_PICK;
+	else {
+		strbuf_release(&buf);
+		die(_("Malformed command file: %s"), cmd_file);
+	}
+	strbuf_release(&buf);
+	return res;
+}
+
+static void save_cmd(struct replay_opts *opts)
+{
+	const char *cmd_file = git_path(SEQ_CMD_FILE);
+	static struct lock_file cmd_lock;
+	struct strbuf buf = STRBUF_INIT;
+	int fd;
+
+	fd = hold_lock_file_for_update(&cmd_lock, cmd_file, LOCK_DIE_ON_ERROR);
+	strbuf_addf(&buf, "%s\n", command_name(opts));
+	if (write_in_full(fd, buf.buf, buf.len) < 0)
+		die_errno(_("Could not write to %s"), cmd_file);
+	if (commit_lock_file(&cmd_lock) < 0)
+		die(_("Error wrapping up %s."), cmd_file);
+}
+
 static void save_head(const char *head)
 {
 	const char *head_file = git_path(SEQ_HEAD_FILE);
@@ -1043,9 +1087,21 @@ static int continue_single_pick(void)
 static int sequencer_continue(struct replay_opts *opts)
 {
 	struct commit_list *todo_list = NULL;
+	enum replay_command cmd;
 
 	if (!file_exists(git_path(SEQ_TODO_FILE)))
 		return continue_single_pick();
+
+	/*
+	 * Disallow continuing a cherry-pick with 'git revert
+	 * --continue' and viceversa
+	 */
+	cmd = read_cmd();
+	if (cmd != opts->command)
+		return error(_("cannot %s: a %s is in progress."),
+			command_name(opts),
+			cmd == REPLAY_CMD_REVERT ? "revert" : "cherry-pick");
+
 	read_populate_opts(&opts);
 	read_populate_todo(&todo_list, opts);
 
@@ -1126,6 +1182,7 @@ static int pick_revisions(struct replay_opts *opts)
 			return error(_("Can't revert as initial commit"));
 		return error(_("Can't cherry-pick into empty head"));
 	}
+	save_cmd(opts);
 	save_head(sha1_to_hex(sha1));
 	save_opts(opts);
 	return pick_commits(todo_list, opts);
diff --git a/sequencer.h b/sequencer.h
index 07e0639..00ab685 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -2,6 +2,7 @@
 #define SEQUENCER_H
 
 #define SEQ_DIR		"sequencer"
+#define SEQ_CMD_FILE	"sequencer/cmd"
 #define SEQ_HEAD_FILE	"sequencer/head"
 #define SEQ_TODO_FILE	"sequencer/todo"
 #define SEQ_OPTS_FILE	"sequencer/opts"
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index 97f3710..73298cf 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -48,6 +48,7 @@ test_expect_success 'cherry-pick persists data on failure' '
 	pristine_detach initial &&
 	test_expect_code 1 git cherry-pick -s base..anotherpick &&
 	test_path_is_dir .git/sequencer &&
+	test_path_is_file .git/sequencer/cmd &&
 	test_path_is_file .git/sequencer/head &&
 	test_path_is_file .git/sequencer/todo &&
 	test_path_is_file .git/sequencer/opts
@@ -69,6 +70,7 @@ test_expect_success 'cherry-pick persists opts correctly' '
 	pristine_detach initial &&
 	test_expect_code 128 git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours initial..anotherpick &&
 	test_path_is_dir .git/sequencer &&
+	test_path_is_file .git/sequencer/cmd &&
 	test_path_is_file .git/sequencer/head &&
 	test_path_is_file .git/sequencer/todo &&
 	test_path_is_file .git/sequencer/opts &&
@@ -517,4 +519,13 @@ test_expect_success 'commit descriptions in insn sheet are optional' '
 	test_line_count = 4 commits
 '
 
+test_expect_success 'revert --continue refuses to follow cherry-pick' '
+       pristine_detach initial &&
+       test_expect_code 1 git cherry-pick base..anotherpick &&
+       echo "c" >foo &&
+       git add foo &&
+       git commit &&
+       test_expect_code 128 git revert --continue
+'
+
 test_done
-- 
1.7.8.2

  parent reply	other threads:[~2012-01-08 12:29 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-08 12:27 [PATCH 0/6] The move to sequencer.c Ramkumar Ramachandra
2012-01-08 12:27 ` [PATCH 1/6] revert: move replay_action, replay_subcommand to header Ramkumar Ramachandra
2012-01-08 19:31   ` Jonathan Nieder
2012-01-08 12:27 ` [PATCH 2/6] revert: decouple sequencer actions from builtin commands Ramkumar Ramachandra
2012-01-08 19:34   ` Jonathan Nieder
2012-01-08 19:53     ` Ramkumar Ramachandra
2012-01-08 20:09       ` Jonathan Nieder
2012-01-08 20:07         ` Ramkumar Ramachandra
2012-01-08 20:48           ` Jonathan Nieder
2012-01-08 12:27 ` Ramkumar Ramachandra [this message]
2012-01-08 19:37   ` [PATCH 3/6] revert: don't let revert continue a cherry-pick Jonathan Nieder
2012-01-08 20:03     ` Ramkumar Ramachandra
2012-01-08 20:22       ` Jonathan Nieder
2012-01-08 20:28         ` Ramkumar Ramachandra
2012-01-08 20:45           ` Jonathan Nieder
2012-01-08 12:27 ` [PATCH 4/6] revert: allow mixing "pick" and "revert" actions Ramkumar Ramachandra
2012-01-08 19:40   ` Jonathan Nieder
2012-01-08 20:17     ` Ramkumar Ramachandra
2012-01-08 21:40       ` Jonathan Nieder
2012-01-08 21:55         ` Jonathan Nieder
2012-01-10  3:40           ` Ramkumar Ramachandra
2012-01-08 12:27 ` [PATCH 5/6] revert: report fine-grained error messages from insn parser Ramkumar Ramachandra
2012-01-08 20:07   ` Jonathan Nieder
2012-01-08 20:16     ` Ramkumar Ramachandra
2012-01-08 21:33       ` Jonathan Nieder
2012-01-10 15:24         ` Ramkumar Ramachandra
2012-01-08 12:27 ` [PATCH 6/6] sequencer: factor code out of revert builtin Ramkumar Ramachandra
2012-01-08 20:38   ` Jonathan Nieder
2012-01-10 15:21     ` Ramkumar Ramachandra
2012-01-08 19:28 ` [PATCH 0/6] The move to sequencer.c Jonathan Nieder
2012-01-08 19:51   ` Ramkumar Ramachandra
2012-01-08 20:43     ` Jonathan Nieder
2012-01-10 16:13 ` [PATCH v2 0/8] " Ramkumar Ramachandra
2012-01-10 16:13   ` [PATCH 1/8] revert: prepare to move replay_action to header Ramkumar Ramachandra
2012-01-10 18:27     ` Jonathan Nieder
2012-01-10 16:13   ` [PATCH 2/8] revert: decouple sequencer actions from builtin commands Ramkumar Ramachandra
2012-01-10 18:38     ` Jonathan Nieder
2012-01-11  4:02       ` Ramkumar Ramachandra
2012-01-11  4:17         ` Ramkumar Ramachandra
2012-01-11  5:04           ` Jonathan Nieder
2012-01-11  5:14             ` Ramkumar Ramachandra
2012-01-11  5:26               ` Ramkumar Ramachandra
2012-01-11  5:49                 ` Jonathan Nieder
2012-01-11  9:19                   ` Ramkumar Ramachandra
2012-01-11  9:52                     ` Jonathan Nieder
2012-01-11 10:11                       ` Ramkumar Ramachandra
2012-01-11 13:40                         ` Jonathan Nieder
2012-01-11 13:18               ` Jonathan Nieder
2012-01-11 16:39                 ` Ramkumar Ramachandra
2012-01-11 16:47                   ` Jonathan Nieder
2012-01-11 16:52                     ` Ramkumar Ramachandra
2012-01-11 18:15                     ` [PATCH v3 0/2] The move to sequencer.c Ramkumar Ramachandra
2012-01-11 18:15                       ` [PATCH 1/2] revert: prepare to move replay_action to header Ramkumar Ramachandra
2012-01-11 18:15                       ` [PATCH 2/2] sequencer: factor code out of revert builtin Ramkumar Ramachandra
2012-01-11 18:40                       ` [PATCH v3 0/2] The move to sequencer.c Jonathan Nieder
2012-01-10 16:13   ` [PATCH 3/8] revert: allow mixing "pick" and "revert" actions Ramkumar Ramachandra
2012-01-10 16:13   ` [PATCH 4/8] revert: separate out parse errors logically Ramkumar Ramachandra
2012-01-10 19:03     ` Jonathan Nieder
2012-01-11 12:38       ` Ramkumar Ramachandra
2012-01-10 16:13   ` [PATCH 5/8] revert: report fine-grained errors from insn parser Ramkumar Ramachandra
2012-01-11 12:44     ` Jonathan Nieder
2012-01-10 16:13   ` [PATCH 6/8] sha1_name: introduce getn_sha1() to take length Ramkumar Ramachandra
2012-01-10 16:13   ` [PATCH 7/8] revert: use getn_sha1() to simplify insn parsing Ramkumar Ramachandra
2012-01-10 16:13   ` [PATCH 8/8] sequencer: factor code out of revert builtin Ramkumar Ramachandra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1326025653-11922-4-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.