branch: master
commit 8cddc052528d7d8585ce75a948991c811a0e5f82
Author: nathan moreau <[email protected]>
Commit: Oleh Krehel <[email protected]>
Git worktree: Fix: avoid to trigger an error while walking the buffers.
Fixes #1115
---
counsel.el | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/counsel.el b/counsel.el
index 403eb3a..e024943 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1446,17 +1446,19 @@ TREE is the selected candidate."
(defun counsel-git-toplevel ()
"Return the base directory of the current git repository."
(let ((out (string-trim-right (shell-command-to-string "git rev-parse
--show-toplevel"))))
- (and (string-match-p "Not a git repository" out) (error "Not a git
repository!"))
- out))
+ (unless (string-match-p "Not a git repository" out) out)))
(defun counsel-git-close-worktree-files-action (root-dir)
"Close all buffers from the worktree located at ROOT-DIR."
+ (setq root-dir (counsel-git-worktree-parse-root root-dir))
(save-excursion
(dolist (buf (buffer-list))
(set-buffer buf)
- (and buffer-file-name
- (string= "." (file-relative-name root-dir (counsel-git-toplevel)))
- (kill-buffer buf)))))
+ (let (top)
+ (and buffer-file-name
+ (setq top (counsel-git-toplevel))
+ (string= "." (file-relative-name root-dir top))
+ (kill-buffer buf))))))
(ivy-set-actions
'counsel-git-change-worktree