All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Elijah Newren <newren@gmail.com>
Subject: [PATCH] rebase, cherry-pick, revert: only run from toplevel
Date: Tue, 31 Aug 2021 03:03:50 +0000	[thread overview]
Message-ID: <pull.1083.git.git.1630379030665.gitgitgadget@gmail.com> (raw)

From: Elijah Newren <newren@gmail.com>

Allowing rebase, cherry-pick and revert to run from subdirectories
inevitably leads to eventual user confusion.  For example, if they
are within a directory that was created by one of the patches being
rebased, then the rebase operation could hit a conflict before the
directory is restored leading the user to be running from a directory
that no longer exists.  Similarly with cherry-pick and revert, those
operations could result in the directory being removed.

Similar to bisect, simply require that these commands be run from the
toplevel to avoid such problems.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
    rebase, cherry-pick, revert: only run from toplevel
    
    Allowing rebase, cherry-pick and revert to run from subdirectories
    inevitably leads to eventual user confusion. For example, if they are
    within a directory that was created by one of the patches being rebased,
    then the rebase operation could hit a conflict before the directory is
    restored leading the user to be running from a directory that no longer
    exists. Similarly with cherry-pick and revert, those operations could
    result in the directory being removed.
    
    Similar to bisect, simply require that these commands be run from the
    toplevel to avoid such problems.
    
    Signed-off-by: Elijah Newren newren@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1083%2Fnewren%2Ftoplevel-sequencing-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1083/newren/toplevel-sequencing-v1
Pull-Request: https://github.com/git/git/pull/1083

 builtin/rebase.c              |  3 +++
 builtin/revert.c              |  6 ++++++
 t/t3404-rebase-interactive.sh | 22 ----------------------
 3 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index c284a7ace19..7100f0627f6 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1430,6 +1430,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		usage_with_options(builtin_rebase_usage,
 				   builtin_rebase_options);
 
+	if (prefix)
+		die(_("You need to run this command from the toplevel of the working tree."));
+
 	options.allow_empty_message = 1;
 	git_config(rebase_config, &options);
 	/* options.gpg_sign_opt will be either "-S" or NULL */
diff --git a/builtin/revert.c b/builtin/revert.c
index 237f2f18d4c..9a150dcbdaf 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -230,6 +230,9 @@ int cmd_revert(int argc, const char **argv, const char *prefix)
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int res;
 
+	if (prefix)
+		die(_("You need to run this command from the toplevel of the working tree."));
+
 	opts.action = REPLAY_REVERT;
 	sequencer_init_config(&opts);
 	res = run_sequencer(argc, argv, &opts);
@@ -243,6 +246,9 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int res;
 
+	if (prefix)
+		die(_("You need to run this command from the toplevel of the working tree."));
+
 	opts.action = REPLAY_PICK;
 	sequencer_init_config(&opts);
 	res = run_sequencer(argc, argv, &opts);
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 66bcbbf9528..dd1afb97fca 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -112,28 +112,6 @@ test_expect_success 'rebase -i with the exec command' '
 	rm -f touch-*
 '
 
-test_expect_success 'rebase -i with the exec command runs from tree root' '
-	git checkout primary &&
-	mkdir subdir && (cd subdir &&
-	set_fake_editor &&
-	FAKE_LINES="1 exec_>touch-subdir" \
-		git rebase -i HEAD^
-	) &&
-	test_path_is_file touch-subdir &&
-	rm -fr subdir
-'
-
-test_expect_success 'rebase -i with exec allows git commands in subdirs' '
-	test_when_finished "rm -rf subdir" &&
-	test_when_finished "git rebase --abort ||:" &&
-	git checkout primary &&
-	mkdir subdir && (cd subdir &&
-	set_fake_editor &&
-	FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
-		git rebase -i HEAD^
-	)
-'
-
 test_expect_success 'rebase -i sets work tree properly' '
 	test_when_finished "rm -rf subdir" &&
 	test_when_finished "test_might_fail git rebase --abort" &&

base-commit: 6c40894d2466d4e7fddc047a05116aa9d14712ee
-- 
gitgitgadget

             reply	other threads:[~2021-08-31  3:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31  3:03 Elijah Newren via GitGitGadget [this message]
2021-08-31  3:05 ` [PATCH] rebase, cherry-pick, revert: only run from toplevel Elijah Newren
2021-08-31  5:55 ` Johannes Sixt
2021-08-31  7:01 ` Jeff King
2021-08-31 20:14   ` Elijah Newren
2021-09-01  2:55     ` Taylor Blau
2021-09-01  4:43       ` Elijah Newren
2021-09-01  4:59         ` Taylor Blau
2021-09-01  6:48           ` Elijah Newren
2021-09-01  5:29     ` Junio C Hamano
2021-09-01  6:08       ` Elijah Newren
2021-09-01  6:30         ` Jeff King
2021-11-26  7:31 Leon Dingman

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=pull.1083.git.git.1630379030665.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=newren@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.