git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] make git-prune-script actually work
@ 2005-04-24 13:58 James Bottomley
  2005-04-24 17:35 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: James Bottomley @ 2005-04-24 13:58 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

I find this script very useful to get back to where I started from after
test merges, and also for cloning trees from a non-current base.  The
functionality is altered so it now takes an optional commit argument
(and a -q flag to make it be quiet).

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

--- a/git-prune-script
+++ b/git-prune-script
@@ -1,2 +1,23 @@
 #!/bin/sh
-fsck-cache --unreachable $(cat .git/HEAD ) | grep unreachable | cut -d' ' -f3 | sed 's:^\(..\):.git/objects/\1/:' | xargs rm
+verbose=true
+case $1 in 
+	-q)	verbose=false
+		shift;;
+esac
+head=$1
+if [ -z "$head" ]; then
+	head=$(cat .git/HEAD)
+fi
+f=$(fsck-cache --unreachable $head | awk '/^unreachable /{print $3}'| sed 's:^\(..\):.git/objects/\1/:')
+if [ -z "$f" ]; then
+	echo "Nothing to remove"
+	exit 0
+fi
+
+for g in $f; do
+	if $verbose; then
+		echo $g
+	fi
+	rm -f $g
+done
+echo $head > .git/HEAD



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

* Re: [PATCH] make git-prune-script actually work
  2005-04-24 13:58 [PATCH] make git-prune-script actually work James Bottomley
@ 2005-04-24 17:35 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2005-04-24 17:35 UTC (permalink / raw)
  To: James Bottomley; +Cc: git



On Sun, 24 Apr 2005, James Bottomley wrote:
>
> I find this script very useful to get back to where I started from after
> test merges, and also for cloning trees from a non-current base.  The
> functionality is altered so it now takes an optional commit argument
> (and a -q flag to make it be quiet).

Hmm.. You should probably rename it to "git-reset-script" or something, 
and any time you reset the head, you should also amke sure to reset the 
index, because otherwise your index file may actually be referencing 
objects that no longer even exist, and that's going to be very very 
painful.

So

> +echo $head > .git/HEAD

should probably be followed by

	read-tree -m $head
	update-cache --refresh

which will also tell the user what files he has that are now "dirty" (and 
he can decide whether he wants to commit his changes, or whether he wants 
to do a "checkout-cache -f -a" to just get rid of it all).

		Linus

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

end of thread, other threads:[~2005-04-24 17:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-24 13:58 [PATCH] make git-prune-script actually work James Bottomley
2005-04-24 17:35 ` Linus Torvalds

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).