git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 5/5] reset: disallow "reset --keep" outside a work tree

From
Christian Couder <chriscool@tuxfamily.org>
Date
Jan 2, 2010, 05:39 UTC
Message-ID
<20100102053934.30066.20988.chriscool@tuxfamily.org>
In-Reply-To
<20100102053303.30066.26391.chriscool@tuxfamily.org>

It is safer and consistent with "--merge" and "--hard" resets to disallow "git reset --keep" outside a work tree.

So let's just do that and add some tests while at it.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin-reset.c       |    2 +-
 t/t7103-reset-bare.sh |   25 +++++++++++++++++--------
 2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/builtin-reset.c b/builtin-reset.c
index da61f20..52584af 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -319,7 +319,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 	if (reset_type == NONE)
 		reset_type = MIXED; /* by default */
 
-	if (reset_type == HARD || reset_type == MERGE)
+	if (reset_type != SOFT && reset_type != MIXED)
 		setup_work_tree();
 
 	if (reset_type == MIXED && is_bare_repository())
diff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh
index afb55b3..1eef93c 100755
--- a/t/t7103-reset-bare.sh
+++ b/t/t7103-reset-bare.sh
@@ -11,21 +11,26 @@ test_expect_success 'setup non-bare' '
 	git commit -a -m two
 '
 
-test_expect_success 'hard reset requires a worktree' '
+test_expect_success '"hard" reset requires a worktree' '
 	(cd .git &&
 	 test_must_fail git reset --hard)
 '
 
-test_expect_success 'merge reset requires a worktree' '
+test_expect_success '"merge" reset requires a worktree' '
 	(cd .git &&
 	 test_must_fail git reset --merge)
 '
 
-test_expect_success 'mixed reset is ok' '
+test_expect_success '"keep" reset requires a worktree' '
+	(cd .git &&
+	 test_must_fail git reset --keep)
+'
+
+test_expect_success '"mixed" reset is ok' '
 	(cd .git && git reset)
 '
 
-test_expect_success 'soft reset is ok' '
+test_expect_success '"soft" reset is ok' '
 	(cd .git && git reset --soft)
 '
 
@@ -40,19 +45,23 @@ test_expect_success 'setup bare' '
 	cd bare.git
 '
 
-test_expect_success 'hard reset is not allowed in bare' '
+test_expect_success '"hard" reset is not allowed in bare' '
 	test_must_fail git reset --hard HEAD^
 '
 
-test_expect_success 'merge reset is not allowed in bare' '
+test_expect_success '"merge" reset is not allowed in bare' '
 	test_must_fail git reset --merge HEAD^
 '
 
-test_expect_success 'mixed reset is not allowed in bare' '
+test_expect_success '"keep" reset is not allowed in bare' '
+	test_must_fail git reset --keep HEAD^
+'
+
+test_expect_success '"mixed" reset is not allowed in bare' '
 	test_must_fail git reset --mixed HEAD^
 '
 
-test_expect_success 'soft reset is allowed in bare' '
+test_expect_success '"soft" reset is allowed in bare' '
 	git reset --soft HEAD^ &&
 	test "`git show --pretty=format:%s | head -n 1`" = "one"
 '
-- 
1.6.6.rc2.5.g49666
Previous: Christian Couder
Message 12 of 12 in “add "--keep" option to "git reset"”
  1. 0/5 add "--keep" option to "git reset"Christian Couder, Jan 2, 2010
  2. 1/5 reset: make "reset --merge" discard work tree changes on unmerged entriesChristian Couder, Jan 2, 2010
  3. Junio C HamanoJan 2, 2010
  4. 2/5 reset: add option "--keep" to "git reset"Christian Couder, Jan 2, 2010
  5. Junio C HamanoJan 2, 2010
  6. Christian CouderJan 19, 2010
  7. 3/5 reset: add test cases for "--keep" optionChristian Couder, Jan 2, 2010
  8. 4/5 Documentation: reset: describe new "--keep" optionChristian Couder, Jan 2, 2010
  9. Andreas SchwabJan 2, 2010
  10. Daniel ConvissorJan 2, 2010
  11. Christian CouderJan 19, 2010
  12. 5/5 reset: disallow "reset --keep" outside a work treeChristian Couder, Jan 2, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.