git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] make cg-commit --review restore original tree state afterwards

From
Sam Vilain <sam@vilain.net>
Date
Oct 21, 2006, 01:11 UTC
Message-ID
<20061021014723.B8E9C13810D@magnus.utsl.gen.nz>
If you delete hunks from the patch that 'cg-commit -p' shows you, then
they are lost 'forever'.  Let's put back everything how it was
beforehand instead.
---
 cg-commit |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/cg-commit b/cg-commit
index 01a4eb7..81b3619 100755
--- a/cg-commit
+++ b/cg-commit
@@ -568,18 +568,16 @@ else
 fi
 rm "$LOGMSG2"
 
+pine_for_darcs() {
+	die "unable to revert the new 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"
+}
+
 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
+		cg-patch -R < "$PATCH" || pine_for_darcs
 		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
+		cg-patch < "$PATCH2" || pine_for_darcs
 	fi
 fi
 
@@ -625,6 +623,17 @@ if [ "$amend" ]; then
 fi
 
 treeid="$(git-write-tree ${missingok})"
+
+if [ "$review" ]; then
+        if ! cmp -s "$PATCH" "$PATCH2"; then
+                echo "Reverting the new patch..."
+                cg-patch -R < "$PATCH2" || pine_for_darcs
+                echo "Applying the old patch..."
+                cg-patch < "$PATCH" || pine_for_darcs
+        fi
+fi
+
+
 [ "$treeid" ] || die "git-write-tree failed"
 if [ ! "$force" ] && [ ! "$merging" ] && [ "$oldhead" ] &&
    [ "$treeid" = "$(cg-object-id -t)" ]; then
-- 
1.4.2.g0ea2
Next: Sam Vilain
Message 1 of 3 in “make cg-commit --review restore original tree state afterwards”
  1. make cg-commit --review restore original tree state afterwardsSam Vilain, Oct 21, 2006
  2. Sam VilainOct 21, 2006
  3. Petr BaudisOct 27, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.