diff --git a/extensions/legit/legit.lisp b/extensions/legit/legit.lisp index 89fccfa33..082019af2 100644 --- a/extensions/legit/legit.lisp +++ b/extensions/legit/legit.lisp @@ -27,6 +27,7 @@ Done: - basic Fossil support (current branch, add change, commit) - basic Mercurial support - show the commits log, with pagination +- view stashes, stash push, stash pop Ongoing: @@ -168,6 +169,16 @@ Currently Git-only. Concretely, this calls Git with the -w option.") (setf (buffer-read-only-p buffer) t) (move-to-line (buffer-point buffer) 1))) +(defun make-stash-show-function (stash) + (lambda () + (with-current-project (vcs) + (cond + ((and (numberp stash) + (not (minusp stash))) + (show-diff (lem/porcelain:stash-show vcs :position stash))) + (t + (show-diff (format nil "=== this stash reference is not valid: ~s" stash))))))) + (defun make-diff-function (file &key cached type) (lambda () (with-current-project (vcs) @@ -516,8 +527,12 @@ Currently Git-only. Concretely, this calls Git with the -w option.") (let ((stashes (lem/porcelain:stash-list vcs))) (collector-insert (format nil "Stashes (~a)" (length stashes)) :header t) (when *show-stashes* - (loop for line in stashes - do (collector-insert line)))) + (loop :for line :in stashes + :for position := 0 :then (incf position) + :do (with-appending-source + (point :move-function (make-stash-show-function position)) + (insert-string point line + :attribute 'filename-attribute :read-only t))))) ;; Unstaged changes (collector-insert "") diff --git a/extensions/legit/porcelain-git.lisp b/extensions/legit/porcelain-git.lisp index 7241218ea..137133664 100644 --- a/extensions/legit/porcelain-git.lisp +++ b/extensions/legit/porcelain-git.lisp @@ -455,3 +455,12 @@ I am stopping in case you still have something valuable there.")) ;; just display them. (str:lines (run-git (list "stash" "list")))) + +(defmethod stash-show ((vcs vcs-git) &key position) + (if (and (numberp position) + (not (minusp position))) + (run-git (list "stash" + "show" + "-p" ;; view as patch = view diff + (princ-to-string position))) + (format nil "Invalid stash reference: ~s. We expect a positive number." position))) diff --git a/extensions/legit/porcelain.lisp b/extensions/legit/porcelain.lisp index fd4fe6f2a..1943c16ee 100644 --- a/extensions/legit/porcelain.lisp +++ b/extensions/legit/porcelain.lisp @@ -31,6 +31,7 @@ :stash-list :stash-pop :stash-push + :stash-show :*diff-context-lines* :commits-log :*commits-log-page-size* @@ -281,3 +282,9 @@ M src/ext/porcelain.lisp (declare (ignorable position)) (values)) (:documentation "List stashes")) + +(defgeneric stash-show (vcs &key position) + (:method (vcs &key position) + (declare (ignorable position)) + (porcelain-error "lem/porcelain:stash-show not implement for vcs ~a" (vcs-name vcs))) + (:documentation "Show this stash, as a diff. Return text."))