Junio C Hamano wrote: > Also you would want to see if the thing is bare. > > Unfortunately, git-sh-setup's is_bare_repository does a wrong > thing because receive-pack already runs GIT_DIR set to '.' after > chdir to it. Matthias's long set of patches currently parked in > 'pu' is supposed to clarify the semantics of bare/non-bare, so > it may help though (it has "rev-parse --is-bare-repository). > > I think 80% of the time (because other 20% of bare repositories > are initialized, following an often repeated incorrect procedure > of making a worktree-full repository and moving its .git/ to > another place, $name.git --- that is wrong for at least three > reasons), if $GIT_DIR/index exists, you can treat it as a > non-bare repository. > Great, well in lieu of that, Matthias suggests a reasonable extra heuristic of whether or not the pathname ends in "/.git" (or "\.git"). Which falls into the "why didn't I think of that" category ;-). No doubt with those patches the hook can be simplified, especially if it sets GIT_WORK_TREE. >> cd .. >> success= >> if git-diff-files >> then >> > > I would suggest running update-index --refresh before running > diff-files. The user may have cache-dirty file and only that. > Ah yes, is that what git-status does that checks the filestamps in the index and updates them... Handy to know. >> git-diff-index -z -R --name-status HEAD | perl -n0 -le \ >> 'if ($z^=1) { >> $status=$_; >> } >> else { >> $filename=$_; >> printf STDERR "$status\t$filename\n"; >> if($status eq "D"){ >> unlink($filename) >> or die("unlink($filename) failed; $!") >> } >> }' && >> > > With "--name-only --diff-filter=D" you would not have to do most > of the above ;-) Use --diff-filter=A without -R, perhaps, to > make it even shorter. > You're right, it was right there! I think it's a good thing to echo back to the user the output of the --name-status command, so they can see the changes that were made. >> git-reset --hard HEAD && success=1 >> fi >> > > Wouldn't "reset --hard HEAD" pretty much unconditionally nuke > your local changes, including added files to the index? For > example, if I do this: > > $ >foo && git add foo && git reset --hard HEAD > > it would remove the newly added 'foo' from both the index and > the working tree. So I am not quite sure what you are trying to > achieve with "diff-index | perl" magic. > Right, but we've already checked using diff-files that there weren't any local changes. So all we're saying is "remove all files which won't be written by git reset --hard, then checkout new versions of files". Actually there is a slight deficiency in the above script - empty directories will not be removed, so replacing a directory with a file will be broken. > I'll cook up an alternative patch perhaps tomorrow. > Cool! I'm sure bzr and darcs users will thank you :-) Sam. - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html