Leo <[email protected]> writes:
> On a fresh repo, make a few commits and try to rewrite from the first
> commit (`r s').
>
> It generates the following backtrace for me on Emacs 23.0.93.
>
> Backtrace:
>
> Debugger entered--Lisp error: (error "Invalid use of `\\' in
> replacement text")
>   replace-match("'\\''" nil nil "'" nil)
>   replace-regexp-in-string("'" "'\\''" "fatal: ambiguous argument
> 'master~1^': unknown revision or path not in the working tree.\nUse
> '--' to separate paths from revisions\nmaster~1^")
>   magit-escape-for-shell("fatal: ambiguous argument 'master~1^':
> unknown revision or path not in the working tree.\nUse '--' to
> separate paths from revisions\nmaster~1^")
>   mapcar(magit-escape-for-shell ("fatal: ambiguous argument
> 'master~1^': unknown revision or path not in the working tree.\nUse
> '--' to separate paths from revisions\nmaster~1^"))
>   magit-format-shell-command("rev-list %s.." ("fatal: ambiguous
> argument 'master~1^': unknown revision or path not in the working tree.
> \nUse '--' to separate paths from revisions\nmaster~1^"))
>   magit-format-git-command("rev-list %s.." ("fatal: ambiguous argument
> 'master~1^': unknown revision or path not in the working tree.\nUse
> '--' to separate paths from revisions\nmaster~1^"))
>   magit-git-lines("rev-list %s.." "fatal: ambiguous argument
> 'master~1^': unknown revision or path not in the working tree.\nUse
> '--' to separate paths from revisions\nmaster~1^")
>   magit-rewrite-start("master~1")
>   call-interactively(magit-rewrite-start nil nil)

The attached patch should fix replace-regexp-in-string bug, but I still
have a backtrace when rewriting from the very first commit.  The second
patch tries to address this problem, but I'm not sure it's the correct
way: maybe it's more suitable to just throw an error when someone wants
to rewrite the initial commit?

m.

>From 5a0a969f3a9fe2a633ba88860aa6d9e8ec05b568 Mon Sep 17 00:00:00 2001
From: Marcin Bachry <[email protected]>
Date: Sun, 17 May 2009 16:58:37 +0200
Subject: [PATCH 1/2] Fix shell escaping.

* magit.el (magit-escape-for-shell): use literal argument to
replace-regexp-in-string function.
---
 magit.el |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/magit.el b/magit.el
index b4513a2..0e48b08 100644
--- a/magit.el
+++ b/magit.el
@@ -320,7 +320,7 @@ Many Magit faces inherit from this one by default."
 		     prop val))
 
 (defun magit-escape-for-shell (str)
-  (concat "'" (replace-regexp-in-string "'" "'\\''" str) "'"))
+  (concat "'" (replace-regexp-in-string "'" "'\\''" str t t) "'"))
 
 (defun magit-format-commit (commit format)
   (magit-git-string "log --max-count=1 --pretty=format:%s %s" format commit))
-- 
1.6.1.3

>From fb85f8856897f51b9ae4cbe4a51b9832e3efb083 Mon Sep 17 00:00:00 2001
From: Marcin Bachry <[email protected]>
Date: Sun, 17 May 2009 19:34:09 +0200
Subject: [PATCH 2/2] Allow rewriting history from the first commit.

* magit.el (magit-rewrite-start): use magit-commit-parents to find
base commit for rewrite
---
 magit.el |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/magit.el b/magit.el
index 0e48b08..a6a8644 100644
--- a/magit.el
+++ b/magit.el
@@ -2112,7 +2112,8 @@ in log buffer."
   (or (not (magit-read-rewrite-info))
       (error "Rewrite in progress."))
   (let* ((orig (magit-git-string "rev-parse HEAD"))
-	 (base (magit-git-string "rev-parse %s^" from))
+	 (base (or (car (magit-commit-parents from))
+                   from))
 	 (pending (magit-git-lines "rev-list %s.." base)))
     (magit-write-rewrite-info `((orig ,orig)
 				(pending ,@(mapcar #'list pending))))
-- 
1.6.1.3

Reply via email to