Skip to content

Commit

Permalink
undo unstaged hunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Linh Dang committed Aug 22, 2008
1 parent 65d4571 commit 8ba8243
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions lgit.el
Expand Up @@ -775,15 +775,18 @@ success."
(prog1 (point)
(apply 'insert (current-time-string) "\n" strings)))))

(defun lgit-hunk-section-patch-index (pos file patch &optional reverse-p)
(defun lgit-hunk-section-patch-index (pos file patch mode)
(let ((default-directory (file-name-directory (lgit-git-dir)))
(args (if reverse-p
'("apply" "--cached" "--reverse")
'("apply" "--cached")))
output ret)
output ret args)
(setq file (expand-file-name file))
(setq output (lgit-log "git apply --cached"
(if reverse-p " --reverse" " ") "<REGION\n"))
(setq args (cond ((eq mode 'patch) '("apply" "--cached"))
((eq mode 'reverse) '("apply" "--cached" "--reverse"))
((eq mode 'checkout)
(list "apply" "--reverse" "--" file))
(t (error "Unknown mode: %s!" mode))))

(setq output (lgit-log "git" (mapconcat 'identity args " ")
"<REGION\n"))
(with-temp-buffer
(insert patch)
(setq ret
Expand All @@ -795,23 +798,33 @@ success."
(widen)
(narrow-to-region (cdr output) (point-max))
(display-buffer (current-buffer) t))
(lgit-update-status-buffer (lgit-get-status-buffer-create) t))))
(lgit-update-status-buffer (lgit-get-status-buffer-create) t)
(when (eq mode 'checkout)
(lgit-revert-visited-files file)))))

(defun lgit-hunk-section-cmd-stage (pos)
(interactive (list (point)))
(let ((patch (lgit-hunk-section-patch-string pos))
(file (car (get-text-property pos :diff))))
(unless (stringp file)
(error "No diff with file-name here!"))
(lgit-hunk-section-patch-index pos file patch)))
(lgit-hunk-section-patch-index pos file patch 'patch)))

(defun lgit-hunk-section-cmd-unstage (pos)
(interactive (list (point)))
(let ((patch (lgit-hunk-section-patch-string pos))
(file (car (get-text-property pos :diff))))
(unless (stringp file)
(error "No diff with file-name here!"))
(lgit-hunk-section-patch-index pos file patch 'reverse-p)))
(lgit-hunk-section-patch-index pos file patch 'reverse)))

(defun lgit-hunk-section-cmd-undo (pos)
(interactive (list (point)))
(let ((patch (lgit-hunk-section-patch-string pos))
(file (car (get-text-property pos :diff))))
(unless (stringp file)
(error "No diff with file-name here!"))
(lgit-hunk-section-patch-index pos file patch 'checkout)))

(defun lgit-diff-section-cmd-stage (pos)
(interactive (list (point)))
Expand Down

0 comments on commit 8ba8243

Please sign in to comment.