branch: elpa/magit
commit 78ffd1a38917d67f091dd5c26a67b6ef3e350634
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
Prefix names of shelved branches with the tip's committer date
Remove that prefix when unshelving, but keep supporting unshelving
branches that were shelved without adding such a prefix.
---
lisp/magit-branch.el | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/lisp/magit-branch.el b/lisp/magit-branch.el
index 03889aff85..532b9beace 100644
--- a/lisp/magit-branch.el
+++ b/lisp/magit-branch.el
@@ -812,11 +812,13 @@ the remote."
;;;###autoload
(defun magit-branch-shelve (branch)
"Shelve a BRANCH.
-Rename \"refs/heads/BRANCH\" to \"refs/shelved/BRANCH\",
+Rename \"refs/heads/BRANCH\" to \"refs/shelved/YYYY-MM-DD-BRANCH\",
and also rename the respective reflog file."
(interactive (list (magit-read-other-local-branch "Shelve branch")))
- (let ((old (concat "refs/heads/" branch))
- (new (concat "refs/shelved/" branch)))
+ (let ((old (concat "refs/heads/" branch))
+ (new (format "refs/shelved/%s-%s"
+ (magit-rev-format "%cs" branch)
+ branch)))
(magit-git "update-ref" new old "")
(magit--rename-reflog-file old new)
(magit-branch-unset-pushRemote branch)
@@ -825,8 +827,9 @@ and also rename the respective reflog file."
;;;###autoload
(defun magit-branch-unshelve (branch)
"Unshelve a BRANCH.
-Rename \"refs/shelved/BRANCH\" to \"refs/heads/BRANCH\",
-and also rename the respective reflog file."
+Rename \"refs/shelved/BRANCH\" to \"refs/heads/BRANCH\". If BRANCH
+is prefixed with \"YYYY-MM-DD\", then drop that part of the name.
+Also rename the respective reflog file."
(interactive
(list (magit-completing-read
"Unshelve branch"
@@ -834,7 +837,11 @@ and also rename the respective reflog file."
(magit-list-refnames "refs/shelved"))
nil t)))
(let ((old (concat "refs/shelved/" branch))
- (new (concat "refs/heads/" branch)))
+ (new (concat "refs/heads/"
+ (if (string-match-p
+ "\\`[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}-" branch)
+ (substring branch 11)
+ branch))))
(magit-git "update-ref" new old "")
(magit--rename-reflog-file old new)
(magit-run-git "update-ref" "-d" old)))