Skip to content

Commit

Permalink
legit: view stash diff
Browse files Browse the repository at this point in the history
  • Loading branch information
vindarel committed Nov 20, 2024
1 parent 0b61dbb commit 612f3a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
19 changes: 17 additions & 2 deletions extensions/legit/legit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 "")
Expand Down
9 changes: 9 additions & 0 deletions extensions/legit/porcelain-git.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
7 changes: 7 additions & 0 deletions extensions/legit/porcelain.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:stash-list
:stash-pop
:stash-push
:stash-show
:*diff-context-lines*
:commits-log
:*commits-log-page-size*
Expand Down Expand Up @@ -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."))

0 comments on commit 612f3a7

Please sign in to comment.