@matheusbsbs / matheus-bagliano / commits / db18a182a2
Fork 0

git.el: Fix git-amend-commit to support amending an initial commit.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>

Alexandre Julliard committed Aug 2, 2008 at 20:35 UTC db18a182a28f254fa514179dcd49ceb3d95cd9d8
1 file changed +7 -3
contrib/emacs/git.el
+7 -3
@@ -389,11 +389,12 @@ the process output as a string, or nil if the git command failed."
389 (defun git-update-ref (ref newval &optional oldval reason)
390 "Update a reference by calling git-update-ref."
391 (let ((args (and oldval (list oldval))))
392 - (push newval args)
392 + (when newval (push newval args))
393 (push ref args)
394 (when reason
395 (push reason args)
396 (push "-m" args))
397 + (unless newval (push "-d" args))
398 (apply 'git-call-process-display-error "update-ref" args)))
399
400 (defun git-read-tree (tree &optional index-file)
@@ -1329,7 +1330,7 @@ Return the list of files that haven't been handled."
1330 "Retrieve the list of files modified by COMMIT."
1331 (let (files)
1332 (with-temp-buffer
1332 - (git-call-process t "diff-tree" "-m" "-r" "-z" "--name-only" "--no-commit-id" commit)
1333 + (git-call-process t "diff-tree" "-m" "-r" "-z" "--name-only" "--no-commit-id" "--root" commit)
1334 (goto-char (point-min))
1335 (while (re-search-forward "\\([^\0]*\\)\0" nil t 1)
1336 (push (match-string 1) files)))
@@ -1343,7 +1344,10 @@ amended version of it."
1344 (when (git-empty-db-p) (error "No commit to amend."))
1345 (let* ((commit (git-rev-parse "HEAD"))
1346 (files (git-get-commit-files commit)))
1346 - (when (git-call-process-display-error "reset" "--soft" "HEAD^")
1347 + (when (if (git-rev-parse "HEAD^")
1348 + (git-call-process-display-error "reset" "--soft" "HEAD^")
1349 + (and (git-update-ref "ORIG_HEAD" commit)
1350 + (git-update-ref "HEAD" nil commit)))
1351 (git-update-status-files (copy-sequence files) 'uptodate)
1352 (git-mark-files git-status files)
1353 (git-refresh-files)