Subject: Re: git ate my home directory :-(

From: Richard Weinberger <[email-masked]>
Date: Tue, 26 Mar 2013 18:06:17 +0100

Am 26.03.2013 15:56, schrieb Jeff King:
> On Tue, Mar 26, 2013 at 02:07:44PM +0100, Richard Weinberger wrote:
>
>>> Should this important warning be part of the git(1) documentation on
>>> the environment variables (and possibly other places) given the
>>> consequences of this case? It wasn't something
>>> I'd appreciated from a simple reading.
>>
>> BTW: Can't we change git-clean such that it will not delete any files
>> if GIT_DIR is set and GIT_WORK_TREE is "."?s
>
> We could, but that would break the existing behavior for other people
> (and I assume you mean "when GIT_WORK_TREE is not set at all", as I
> would think GIT_WORK_TREE=. is explicit enough).

Is there a valid use case to call git-clean with GIT_DIR set but GIT_WORK_TREE
not (or to ."")?
It will delete "." ;)

> I am sympathetic to your data loss, but I wonder how common a problem it
> is in practice. Git-clean already does a dry-run by default; you have to
> give it `-f`. This is the first such report we've had. This seems more
> akin to "oops, I accidentally ran `rm -rf` in the wrong directory". Yes,
> it's catastrophic, but at some point you have to accept that deleting
> files is what rm (and git-clean) does; you can only put so many safety
> hoops in place.

The data loss was not too bad. I was able to restore anything within 2 hours.
But was kinda shocked that git-clean deletes files outside my git tree.
I'm aware of -d. But in my case it happened within a fully automated script.
I simply thought GIT_DIR=.. git-clean -f -d does the right thing...

> I don't know. It's an uncommon enough case that we could deprecate
> "GIT_WORK_TREE is implicitly `.`" entirely, but I think it would need a
> deprecation period, and a way to get the same behavior (e.g., allowing
> "GIT_WORK_TREE=.").

Yeah, this sounds sane.

Thanks,
//richard

P.s: I've told this story to some friends and co-workers which use git like me very day.
All of them were shocked about the behavior of git-clean and GIT_DIR.