commit | author | age
|
5cb5f7
|
1 |
;;; magit-reset.el --- reset fuctionality -*- lexical-binding: t -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2010-2018 The Magit Project Contributors |
|
4 |
;; |
|
5 |
;; You should have received a copy of the AUTHORS.md file which |
|
6 |
;; lists all contributors. If not, see http://magit.vc/authors. |
|
7 |
|
|
8 |
;; Author: Jonas Bernoulli <jonas@bernoul.li> |
|
9 |
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li> |
|
10 |
|
|
11 |
;; Magit is free software; you can redistribute it and/or modify it |
|
12 |
;; under the terms of the GNU General Public License as published by |
|
13 |
;; the Free Software Foundation; either version 3, or (at your option) |
|
14 |
;; any later version. |
|
15 |
;; |
|
16 |
;; Magit is distributed in the hope that it will be useful, but WITHOUT |
|
17 |
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
18 |
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
|
19 |
;; License for more details. |
|
20 |
;; |
|
21 |
;; You should have received a copy of the GNU General Public License |
|
22 |
;; along with Magit. If not, see http://www.gnu.org/licenses. |
|
23 |
|
|
24 |
;;; Commentary: |
|
25 |
|
|
26 |
;; This library implements reset commands. |
|
27 |
|
|
28 |
;;; Code: |
|
29 |
|
|
30 |
(require 'magit) |
|
31 |
|
|
32 |
;;;###autoload (autoload 'magit-reset-popup "magit" nil t) |
|
33 |
(magit-define-popup magit-reset-popup |
|
34 |
"Popup console for reset commands." |
|
35 |
:man-page "git-reset" |
|
36 |
:actions '((?m "reset mixed (HEAD and index)" magit-reset-mixed) |
|
37 |
(?s "reset soft (HEAD only)" magit-reset-soft) |
|
38 |
(?h "reset hard (HEAD, index, and files)" magit-reset-hard) |
|
39 |
(?i "reset index (only)" magit-reset-index) |
|
40 |
(?w "reset worktree (only)" magit-reset-worktree) |
|
41 |
nil |
|
42 |
(?f "reset a file" magit-file-checkout)) |
|
43 |
:max-action-columns 1) |
|
44 |
|
|
45 |
;;;###autoload |
|
46 |
(defun magit-reset-mixed (commit) |
|
47 |
"Reset the `HEAD' and index to COMMIT, but not the working tree. |
|
48 |
\n(git reset --mixed COMMIT)" |
|
49 |
(interactive (list (magit-reset-read-branch-or-commit "Reset %s to"))) |
|
50 |
(magit-reset-internal "--mixed" commit)) |
|
51 |
|
|
52 |
;;;###autoload |
|
53 |
(defun magit-reset-soft (commit) |
|
54 |
"Reset the `HEAD' to COMMIT, but not the index and working tree. |
|
55 |
\n(git reset --soft REVISION)" |
|
56 |
(interactive (list (magit-reset-read-branch-or-commit "Soft reset %s to"))) |
|
57 |
(magit-reset-internal "--soft" commit)) |
|
58 |
|
|
59 |
;;;###autoload |
|
60 |
(defun magit-reset-hard (commit) |
|
61 |
"Reset the `HEAD', index, and working tree to COMMIT. |
|
62 |
\n(git reset --hard REVISION)" |
|
63 |
(interactive (list (magit-reset-read-branch-or-commit |
|
64 |
(concat (propertize "Hard" 'face 'bold) |
|
65 |
" reset %s to")))) |
|
66 |
(magit-reset-internal "--hard" commit)) |
|
67 |
|
|
68 |
;;;###autoload |
|
69 |
(defun magit-reset-index (commit) |
|
70 |
"Reset the index to COMMIT. |
|
71 |
Keep the `HEAD' and working tree as-is, so if COMMIT refers to the |
|
72 |
head this effectively unstages all changes. |
|
73 |
\n(git reset COMMIT .)" |
|
74 |
(interactive (list (magit-read-branch-or-commit "Reset index to"))) |
|
75 |
(magit-reset-internal nil commit ".")) |
|
76 |
|
|
77 |
;;;###autoload |
|
78 |
(defun magit-reset-worktree (commit) |
|
79 |
"Reset the worktree to COMMIT. |
|
80 |
Keep the `HEAD' and index as-is." |
|
81 |
(interactive (list (magit-read-branch-or-commit "Reset worktree to"))) |
|
82 |
(magit-with-temp-index commit nil |
|
83 |
(magit-wip-commit-before-change nil " before reset") |
|
84 |
(magit-run-git "checkout-index" "--all" "--force") |
|
85 |
(magit-wip-commit-after-apply nil " after reset"))) |
|
86 |
|
|
87 |
;;;###autoload |
|
88 |
(defun magit-reset-quickly (commit &optional hard) |
|
89 |
"Reset the `HEAD' and index to COMMIT, and possibly the working tree. |
|
90 |
With a prefix argument reset the working tree otherwise don't. |
|
91 |
\n(git reset --mixed|--hard COMMIT)" |
|
92 |
(interactive (list (magit-reset-read-branch-or-commit |
|
93 |
(if current-prefix-arg |
|
94 |
(concat (propertize "Hard" 'face 'bold) |
|
95 |
" reset %s to") |
|
96 |
"Reset %s to")) |
|
97 |
current-prefix-arg)) |
|
98 |
(magit-reset-internal (if hard "--hard" "--mixed") commit)) |
|
99 |
|
|
100 |
(defun magit-reset-read-branch-or-commit (prompt) |
|
101 |
"Prompt for and return a ref to reset HEAD to. |
|
102 |
|
|
103 |
PROMPT is a format string, where either the current branch name |
|
104 |
or \"detached head\" will be substituted for %s." |
|
105 |
(magit-read-branch-or-commit |
|
106 |
(format prompt (or (magit-get-current-branch) "detached head")))) |
|
107 |
|
|
108 |
(defun magit-reset-internal (arg commit &optional path) |
|
109 |
(when (and (not (member arg '("--hard" nil))) |
|
110 |
(equal (magit-rev-parse commit) |
|
111 |
(magit-rev-parse "HEAD~"))) |
|
112 |
(with-temp-buffer |
|
113 |
(magit-git-insert "show" "-s" "--format=%B" "HEAD") |
|
114 |
(when git-commit-major-mode |
|
115 |
(funcall git-commit-major-mode)) |
|
116 |
(git-commit-setup-font-lock) |
|
117 |
(git-commit-save-message))) |
|
118 |
(let ((cmd (if (and (equal commit "HEAD") (not arg)) "unstage" "reset"))) |
|
119 |
(magit-wip-commit-before-change nil (concat " before " cmd)) |
|
120 |
(magit-run-git "reset" arg commit "--" path) |
|
121 |
(when (equal cmd "unstage") |
|
122 |
(magit-wip-commit-after-apply nil " after unstage")))) |
|
123 |
|
|
124 |
;;; _ |
|
125 |
(provide 'magit-reset) |
|
126 |
;;; magit-reset.el ends here |