Skip to content

Commit

Permalink
Add a soft reset action
Browse files Browse the repository at this point in the history
  • Loading branch information
thierryvolpiatto committed Oct 8, 2021
1 parent 11d9f8c commit f9a03f4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions helm-ls-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ See docstring of `helm-ls-git-ls-switches'.
("Format patches" . helm-ls-git-log-format-patch)
("Git am" . helm-ls-git-log-am)
("Git interactive rebase" . helm-ls-git-log-interactive-rebase)
("Hard reset" . helm-ls-git-log-reset)
("Hard reset" . helm-ls-git-log-hard-reset)
("Soft reset" . helm-ls-git-log-soft-reset)
("Git revert" . helm-ls-git-log-revert))
:candidate-transformer
(lambda (candidates)
Expand Down Expand Up @@ -705,15 +706,25 @@ See docstring of `helm-ls-git-ls-switches'.
nil t t))
(apply #'process-file "git" nil "*git format-patch*" nil switches)))))

(defun helm-ls-git-log-reset (_candidate)
(let ((rev (get-text-property 1 'rev (helm-get-selection nil 'withprop))))
(defun helm-ls-git-log-reset-1 (hard-or-soft)
(let ((rev (get-text-property 1 'rev (helm-get-selection nil 'withprop)))
(arg (cl-case hard-or-soft
(hard "--hard")
(soft "--soft"))))
(with-helm-default-directory (helm-ls-git-root-dir
(helm-default-directory))
(when (and (y-or-n-p (format "Hard reset to <%s>?" rev))
(= (process-file "git" nil nil nil "reset" "--hard" rev) 0))
(when (and (y-or-n-p (format "%s reset to <%s>?"
(capitalize (symbol-name hard-or-soft)) rev))
(= (process-file "git" nil nil nil "reset" arg rev) 0))
(message "Now at `%s'" (helm-ls-git-oneline-log
(helm-ls-git--branch)))))))

(defun helm-ls-git-log-hard-reset (_candidate)
(helm-ls-git-log-reset-1 'hard))

(defun helm-ls-git-log-soft-reset (_candidate)
(helm-ls-git-log-reset-1 'soft))

(defun helm-ls-git-log-revert (_candidate)
(let ((rev (get-text-property 1 'rev (helm-get-selection nil 'withprop))))
(helm-ls-git-with-editor "revert" rev)))
Expand Down

0 comments on commit f9a03f4

Please sign in to comment.