threads / patch / 6776

patchFix cg-commit -p to not touch the working tree

Subject: [PATCH] Fix cg-commit -p to not touch the working tree

## tl;dr

4 messages between Feb 12, 2007 and Feb 12, 2007. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Sam Vilain· Feb 12, 2007, 03:14 UTC · lore
Previously, the working tree state was modified with `patch', which
was a fragile operation.  Do everything with `git-apply --cached
--index' instead.
---
 cg-commit |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)
Show changes to cg-commit +17 −16
diff --git a/cg-commit b/cg-commit
index 360d5e6..f676e1f 100755
--- a/cg-commit
+++ b/cg-commit
@@ -575,22 +575,6 @@ else
 fi
 rm "$LOGMSG2"
 
-if [ "$review" ]; then
-	if ! cmp -s "$PATCH" "$PATCH2"; then
-		echo "Reverting the original patch..."
-		if ! cg-patch -R < "$PATCH"; then
-			die "unable to revert the original patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in ten minutes, have a nice day"
-		fi
-		echo "Applying the edited patch..."
-		if ! cg-patch < "$PATCH2"; then
-			# FIXME: Do something better to alleviate this situation.
-			# At least restore the tree to the original state.
-			die "unable to apply the edited patch; the original patch is available in $PATCH, your edited patch is available in $PATCH2, your log message is in $LOGMSG, your working copy is in undefined state now and the world is about to end in five minutes, have a nice day"
-		fi
-	fi
-fi
-
-
 precommit_update()
 {
 	queueN=(); queueD=(); queueM=();
@@ -620,6 +604,23 @@ if [ ! "$ignorecache" ]; then
 	precommit_update "${commitfiles[@]}" || die "update-cache failed"
 fi
 
+if [ "$review" ]; then
+	if ! cmp -s "$PATCH" "$PATCH2"; then
+		git-read-tree HEAD
+		while ! git-apply --check --cached --index "$PATCH2"
+		do
+			echo "patch tried was:"
+			cat $PATCH2
+			echo "your patch does not apply cleanly, re-edit it!"
+			echo -n "sleeping 5s..."
+			sleep 4
+			echo "get it right this time OK?"
+			sleep 1
+			${EDITOR:-vi} "$PATCH2"
+		done
+		git-apply --cached --index "$PATCH2"
+	fi
+fi
 
 oldhead=
 oldheadname="$(git-symbolic-ref HEAD)"
-- 
1.5.0.rc2.g84cf66-dirty
Junio C Hamano· Feb 12, 2007, 04:25 UTC · re: Sam Vilain · lore

Re: [PATCH] Fix cg-commit -p to not touch the working tree

Sam Vilain <sam.vilain@catalyst.net.nz> writes:
> Previously, the working tree state was modified with `patch', which
> was a fragile operation.  Do everything with `git-apply --cached
> --index' instead.

I do not use Cogito so I do not know what behaviour is wanted here, but '--cached --index' is same as saying just '--cached' as far as I know. It will patch against the index and should not touch working tree. If the original used 'patch' to apply, I suspect it wanted to touch the working tree (and possibly, it wanted to leave the index alone?), so --cached might be completely wrong thing to use here?

Sam Vilain· Feb 12, 2007, 20:22 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fix cg-commit -p to not touch the working tree

Junio C Hamano wrote:
Show 12 quoted lines
>> Previously, the working tree state was modified with `patch', which
>> was a fragile operation.  Do everything with `git-apply --cached
>> --index' instead.
>>     
> I do not use Cogito so I do not know what behaviour is wanted
> here, but '--cached --index' is same as saying just '--cached'
> as far as I know.  It will patch against the index and should
> not touch working tree.  If the original used 'patch' to apply,
> I suspect it wanted to touch the working tree (and possibly, it
> wanted to leave the index alone?), so --cached might be
> completely wrong thing to use here?
>   

The context is that "cg-commit -p", a kind of poor man's interactive commit that lets you preview changes that are to be committed in 'diff' form, and edit the patch to be applied. Many users expect this command to behave this way; they're quite surprised and sometimes even miffed when the changes they deleted from the patch are gone from their working copy.

Sam.
Junio C Hamano· Feb 12, 2007, 22:01 UTC · re: Sam Vilain · lore

Re: [PATCH] Fix cg-commit -p to not touch the working tree

Sam Vilain <sam@vilain.net> writes:
Show 20 quoted lines
> Junio C Hamano wrote:
>>> Previously, the working tree state was modified with `patch', which
>>> was a fragile operation.  Do everything with `git-apply --cached
>>> --index' instead.
>>>     
>> I do not use Cogito so I do not know what behaviour is wanted
>> here, but '--cached --index' is same as saying just '--cached'
>> as far as I know.  It will patch against the index and should
>> not touch working tree.  If the original used 'patch' to apply,
>> I suspect it wanted to touch the working tree (and possibly, it
>> wanted to leave the index alone?), so --cached might be
>> completely wrong thing to use here?
>>   
>
> The context is that "cg-commit -p", a kind of poor man's interactive
> commit that lets you preview changes that are to be committed in 'diff'
> form, and edit the patch to be applied. Many users expect this command
> to behave this way; they're quite surprised and sometimes even miffed
> when the changes they deleted from the patch are gone from their working
> copy.

Ah, I see that's why you do want to leave the working tree untouched. I think '--cached' alone is the right way to spell it (strictly speaking, giving --index and --cached should error out, although the current implementation does not).

← back to recent threads