git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
@ 2009-12-29  6:47 Fyn Fynn
  2009-12-29  8:12 ` Tay Ray Chuan
  2009-12-29  8:38 ` Nguyen Thai Ngoc Duy
  0 siblings, 2 replies; 9+ messages in thread
From: Fyn Fynn @ 2009-12-29  6:47 UTC (permalink / raw)
  To: git

The exact same git reset command that works in 1.6.4, fails to work
under 1.6.6:

$ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
/usr/local/git-1.6.6/bin/git reset --hard
fatal: hard reset requires a work tree
$ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
/usr/local/git-1.6.4/bin/git reset --hard
HEAD is now at 77ec73f...

What gives?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
  2009-12-29  6:47 Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE Fyn Fynn
@ 2009-12-29  8:12 ` Tay Ray Chuan
  2009-12-29  8:38 ` Nguyen Thai Ngoc Duy
  1 sibling, 0 replies; 9+ messages in thread
From: Tay Ray Chuan @ 2009-12-29  8:12 UTC (permalink / raw)
  To: Fyn Fynn; +Cc: git

Hi,

On Tue, Dec 29, 2009 at 2:47 PM, Fyn Fynn <fynfynn@gmail.com> wrote:
> The exact same git reset command that works in 1.6.4, fails to work
> under 1.6.6:
>
> $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
> /usr/local/git-1.6.6/bin/git reset --hard
> fatal: hard reset requires a work tree
> $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
> /usr/local/git-1.6.4/bin/git reset --hard
> HEAD is now at 77ec73f...
>
> What gives?

perhaps you should also specify the --exec-path option or
GIT_EXEC_PATH environment variable.

Assuming a full installation in /usr/local/git-1.6.6/ and thus that
the git commands are installed at
/usr/local/git-1.6.6/libexec/git-core/, the reset for 1.6.6 would look
like this:

$ GIT_WORK_TREE=$HOME/rawdata/ \
GIT_DIR=$HOME/rawdata/.git \
GIT_EXEC_PATH=/usr/local/git-1.6.6/libexec/git-core/ \
/usr/local/git-1.6.6/bin/git reset --hard

-- 
Cheers,
Ray Chuan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
  2009-12-29  6:47 Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE Fyn Fynn
  2009-12-29  8:12 ` Tay Ray Chuan
@ 2009-12-29  8:38 ` Nguyen Thai Ngoc Duy
  2009-12-29 11:04   ` Nanako Shiraishi
  1 sibling, 1 reply; 9+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2009-12-29  8:38 UTC (permalink / raw)
  To: Fyn Fynn; +Cc: git, Jeff King

On 12/29/09, Fyn Fynn <fynfynn@gmail.com> wrote:
> The exact same git reset command that works in 1.6.4, fails to work
>  under 1.6.6:
>
>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>  /usr/local/git-1.6.6/bin/git reset --hard
>  fatal: hard reset requires a work tree
>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>  /usr/local/git-1.6.4/bin/git reset --hard
>  HEAD is now at 77ec73f...
>
>  What gives?

A recent patch by Jeff (952dfc6 (reset: improve worktree safety valves
- 2009-12-04)) makes sure that "git reset --hard" will not work
outside worktree (which is right). Where was your current directory,
inside $GIT_WORK_TREE or outside?
-- 
Duy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
  2009-12-29  8:38 ` Nguyen Thai Ngoc Duy
@ 2009-12-29 11:04   ` Nanako Shiraishi
  2009-12-29 11:36     ` Nguyen Thai Ngoc Duy
  0 siblings, 1 reply; 9+ messages in thread
From: Nanako Shiraishi @ 2009-12-29 11:04 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: Fyn Fynn, git, Jeff King

Quoting Nguyen Thai Ngoc Duy <pclouds@gmail.com>:

> On 12/29/09, Fyn Fynn <fynfynn@gmail.com> wrote:
>> The exact same git reset command that works in 1.6.4, fails to work
>>  under 1.6.6:
>>
>>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>>  /usr/local/git-1.6.6/bin/git reset --hard
>>  fatal: hard reset requires a work tree
>>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>>  /usr/local/git-1.6.4/bin/git reset --hard
>>  HEAD is now at 77ec73f...
>>
>>  What gives?
>
> A recent patch by Jeff (952dfc6 (reset: improve worktree safety valves
> - 2009-12-04)) makes sure that "git reset --hard" will not work
> outside worktree (which is right).

Sorry, but I don't understand why it is *right*. Isn't 'git reset --hard' supposed to make all the files in the working tree match the HEAD, no matter where you start from?

Jeff's commit message says:

        make sure we are in a worktree. Otherwise, we can end up
	munging files inside of '.git'

But if you have ~/myproject/.git project, whose working tree is ~/myproject, and if you run

        % cd ~/myproject/.git
	% git reset --hard

the code mistakenly overwrote files in ~/myproject/.git directory before Jeff's patch, and I agree it was a bug.

But shouldn't the correct fix be to go to ~/myproject, the obvious root level of the working tree, and check out the files in that directory?

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
  2009-12-29 11:04   ` Nanako Shiraishi
@ 2009-12-29 11:36     ` Nguyen Thai Ngoc Duy
  2009-12-29 21:09       ` Fyn Fynn
  0 siblings, 1 reply; 9+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2009-12-29 11:36 UTC (permalink / raw)
  To: Nanako Shiraishi; +Cc: Fyn Fynn, git, Jeff King

On 12/29/09, Nanako Shiraishi <nanako3@lavabit.com> wrote:
> Quoting Nguyen Thai Ngoc Duy <pclouds@gmail.com>:
>
>  > On 12/29/09, Fyn Fynn <fynfynn@gmail.com> wrote:
>  >> The exact same git reset command that works in 1.6.4, fails to work
>  >>  under 1.6.6:
>  >>
>  >>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>  >>  /usr/local/git-1.6.6/bin/git reset --hard
>  >>  fatal: hard reset requires a work tree
>  >>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>  >>  /usr/local/git-1.6.4/bin/git reset --hard
>  >>  HEAD is now at 77ec73f...
>  >>
>  >>  What gives?
>  >
>  > A recent patch by Jeff (952dfc6 (reset: improve worktree safety valves
>  > - 2009-12-04)) makes sure that "git reset --hard" will not work
>  > outside worktree (which is right).
>
>
> Sorry, but I don't understand why it is *right*. Isn't 'git reset --hard' supposed to make all the files in the working tree match the HEAD, no matter where you start from?

It is generally "right" to work from inside worktree, the way Git
worked before GIT_WORK_TREE came. In case of "git reset --hard", yes
it'd be best if Git could just go to worktree and reset it. I forgot
that "git reset --hard" does not take pathspec. The situation may be a
bit more complicated with "git status" (which also handles worktree as
a whole) because you may need to represent the filename output to be
relative to current working directory, not the GIT_WORK_TREE. Using
GIT_WORK_TREE from outside worktree is imo stretching git to its
limits.
-- 
Duy

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
  2009-12-29 11:36     ` Nguyen Thai Ngoc Duy
@ 2009-12-29 21:09       ` Fyn Fynn
  2009-12-29 21:50         ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Fyn Fynn @ 2009-12-29 21:09 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: Nanako Shiraishi, git, Jeff King

I went over the 952dfc6 patch, and it seems like it was designed to
fix a specific bug - the one demonstrated by Nanako Shiraishi above.

Nowhere there do I see an intention to prevent the action described in
the original post. And even if there was such intention, it should
have been made explicit by providing a proper error message: the
current one simply ignores the fact that we provided GIT_WORK_TREE,
and is thus incorrect since the work tree can be found.

Moreover, if there is an intention to prevent resetting from outside
the worktree (why?), then probably "checkout -f" should be limited as
well.

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.

Thus, the current state should be considered a bug.

--

Fynn

On Tue, Dec 29, 2009 at 3:36 AM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> On 12/29/09, Nanako Shiraishi <nanako3@lavabit.com> wrote:
>> Quoting Nguyen Thai Ngoc Duy <pclouds@gmail.com>:
>>
>>  > On 12/29/09, Fyn Fynn <fynfynn@gmail.com> wrote:
>>  >> The exact same git reset command that works in 1.6.4, fails to work
>>  >>  under 1.6.6:
>>  >>
>>  >>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>>  >>  /usr/local/git-1.6.6/bin/git reset --hard
>>  >>  fatal: hard reset requires a work tree
>>  >>  $ GIT_WORK_TREE=$HOME/rawdata/ GIT_DIR=$HOME/rawdata/.git
>>  >>  /usr/local/git-1.6.4/bin/git reset --hard
>>  >>  HEAD is now at 77ec73f...
>>  >>
>>  >>  What gives?
>>  >
>>  > A recent patch by Jeff (952dfc6 (reset: improve worktree safety valves
>>  > - 2009-12-04)) makes sure that "git reset --hard" will not work
>>  > outside worktree (which is right).
>>
>>
>> Sorry, but I don't understand why it is *right*. Isn't 'git reset --hard' supposed to make all the files in the working tree match the HEAD, no matter where you start from?
>
> It is generally "right" to work from inside worktree, the way Git
> worked before GIT_WORK_TREE came. In case of "git reset --hard", yes
> it'd be best if Git could just go to worktree and reset it. I forgot
> that "git reset --hard" does not take pathspec. The situation may be a
> bit more complicated with "git status" (which also handles worktree as
> a whole) because you may need to represent the filename output to be
> relative to current working directory, not the GIT_WORK_TREE. Using
> GIT_WORK_TREE from outside worktree is imo stretching git to its
> limits.
> --
> Duy
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE
  2009-12-29 21:09       ` Fyn Fynn
@ 2009-12-29 21:50         ` Jeff King
  2009-12-30  8:47           ` [PATCH] reset: unbreak hard resets with GIT_WORK_TREE Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2009-12-29 21:50 UTC (permalink / raw)
  To: Fyn Fynn; +Cc: Nguyen Thai Ngoc Duy, Nanako Shiraishi, git

On Tue, Dec 29, 2009 at 01:09:20PM -0800, Fyn Fynn wrote:

> 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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] reset: unbreak hard resets with GIT_WORK_TREE
  2009-12-29 21:50         ` Jeff King
@ 2009-12-30  8:47           ` Jeff King
  2009-12-30 17:54             ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2009-12-30  8:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Fyn Fynn, Nguyen Thai Ngoc Duy, Nanako Shiraishi, git

Commit 952dfc6 tried to tighten the safety valves for doing
a "reset --hard" in a bare repository or outside the work
tree, but accidentally broke the case for GIT_WORK_TREE.
This patch unbreaks it.

Most git commands which need a work tree simply use
NEED_WORK_TREE in git.c to die before they get to their
cmd_* function. Reset, however, only needs a work tree in
some cases, and so must handle the work tree itself. The
error that 952dfc6 made was to simply forbid certain
operations if the work tree was not set up; instead, we need
to do the same thing that NEED_WORK_TREE does, which is to
call setup_work_tree(). We no longer have to worry about dying
in the non-worktree case, as setup_work_tree handles that
for us.

Signed-off-by: Jeff King <peff@peff.net>
---
Junio, this should probably go onto maint. I based it directly on
952dfc6, which is in v1.6.6 and v1.6.5.5.

 builtin-reset.c       |    6 ++----
 t/t7103-reset-bare.sh |    6 ++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

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
diff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh
index 68041df..afb55b3 100755
--- a/t/t7103-reset-bare.sh
+++ b/t/t7103-reset-bare.sh
@@ -29,6 +29,12 @@ test_expect_success 'soft reset is ok' '
 	(cd .git && git reset --soft)
 '
 
+test_expect_success 'hard reset works with GIT_WORK_TREE' '
+	mkdir worktree &&
+	GIT_WORK_TREE=$PWD/worktree GIT_DIR=$PWD/.git git reset --hard &&
+	test_cmp file worktree/file
+'
+
 test_expect_success 'setup bare' '
 	git clone --bare . bare.git &&
 	cd bare.git
-- 
1.6.6.320.g7c9b3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] reset: unbreak hard resets with GIT_WORK_TREE
  2009-12-30  8:47           ` [PATCH] reset: unbreak hard resets with GIT_WORK_TREE Jeff King
@ 2009-12-30 17:54             ` Junio C Hamano
  0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2009-12-30 17:54 UTC (permalink / raw)
  To: Jeff King
  Cc: Junio C Hamano, Fyn Fynn, Nguyen Thai Ngoc Duy, Nanako Shiraishi,
	git

Jeff King <peff@peff.net> writes:

> Commit 952dfc6 tried to tighten the safety valves for doing
> a "reset --hard" in a bare repository or outside the work
> tree, but accidentally broke the case for GIT_WORK_TREE.
> This patch unbreaks it.
>
> Most git commands which need a work tree simply use
> NEED_WORK_TREE in git.c to die before they get to their
> cmd_* function. Reset, however, only needs a work tree in
> some cases, and so must handle the work tree itself. The
> error that 952dfc6 made was to simply forbid certain
> operations if the work tree was not set up; instead, we need
> to do the same thing that NEED_WORK_TREE does, which is to
> call setup_work_tree(). We no longer have to worry about dying
> in the non-worktree case, as setup_work_tree handles that
> for us.

Sounds very sane to me.  Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-12-30 17:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-29  6:47 Possible bug in 1.6.6 with reset --hard and $GIT_WORK_TREE Fyn Fynn
2009-12-29  8:12 ` Tay Ray Chuan
2009-12-29  8:38 ` Nguyen Thai Ngoc Duy
2009-12-29 11:04   ` Nanako Shiraishi
2009-12-29 11:36     ` Nguyen Thai Ngoc Duy
2009-12-29 21:09       ` Fyn Fynn
2009-12-29 21:50         ` Jeff King
2009-12-30  8:47           ` [PATCH] reset: unbreak hard resets with GIT_WORK_TREE Jeff King
2009-12-30 17:54             ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).