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

Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE

From
Jeff King <peff@peff.net>
Date
Dec 29, 2009, 21:50 UTC
Message-ID
<20091229215015.GA1529@coredump.intra.peff.net>
In-Reply-To
<1a04eebf0912291309u7a222d9ch7e0926d30a5899b7@mail.gmail.com>
On Tue, Dec 29, 2009 at 01:09:20PM -0800, Fyn Fynn wrote:
Show 5 quoted lines
> But it is more likely that the breaking of the original action between
> 1.6.4 and 1.6.6 came about as an untended consequence of 952dfc6,
> which oversimplified by assuming that the worktree can only be found
> if we're inside it, ignoring the possibility that GIT_WORK_TREE was
> provided.

Yes, it is an unintended breakage. We discussed the possibility of automatically moving to the work tree when inside the repo, but decided it could be done later, as other builtins which use NEEDS_WORK_TREE (e.g., clean) already fail in that instance.

However, I did not take into account that those commands fail only with automatic repo detection; they _do_ work with GIT_WORK_TREE. So instead of just dying, we need to be emulating the code in git.c which sets up the work tree (and which will die itself if we run into an error).

So I think what we really want is this:
diff --git a/builtin-reset.c b/builtin-reset.c
index 11d1c6e..e4418bc 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -286,10 +286,8 @@ 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)
-	    && !is_inside_work_tree())
-		die("%s reset requires a work tree",
-		    reset_type_names[reset_type]);
+	if (reset_type == HARD || reset_type == MERGE)
+		setup_work_tree();
 
 	/* Soft reset does not touch the index file nor the working tree
 	 * at all, but requires them in a good order.  Other resets reset

I'll try to write a few tests and make sure that's sane.

-Peff
Previous: Fyn FynnNext: Jeff King
Message 7 of 9 in “Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE”
  1. Fyn FynnDec 29, 2009
  2. Tay Ray ChuanDec 29, 2009
  3. Nguyen Thai Ngoc DuyDec 29, 2009
  4. Nanako ShiraishiDec 29, 2009
  5. Nguyen Thai Ngoc DuyDec 29, 2009
  6. Fyn FynnDec 29, 2009
  7. Jeff KingDec 29, 2009
  8. reset: unbreak hard resets with GIT_WORK_TREEJeff King, Dec 30, 2009
  9. Junio C HamanoDec 30, 2009

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.