All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sam Vilain <sam@vilain.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Matthias Lederhofer <matled@gmx.net>
Subject: Re: post-update script to update wc - suggestions welcome
Date: Thu, 21 Jun 2007 08:14:46 +1200	[thread overview]
Message-ID: <46798AB6.6060403@vilain.net> (raw)
In-Reply-To: <7vr6o7uhwz.fsf@assigned-by-dhcp.pobox.com>

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.

  reply	other threads:[~2007-06-20 20:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-20  6:21 post-update script to update wc - suggestions welcome Sam Vilain
2007-06-20  7:03 ` Sam Vilain
2007-06-20  8:52 ` Junio C Hamano
2007-06-20 20:14   ` Sam Vilain [this message]
2007-06-20 21:02     ` Junio C Hamano
2007-06-20 22:28       ` Sam Vilain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46798AB6.6060403@vilain.net \
    --to=sam@vilain.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matled@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.