emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/projectile 9de18b77b4 2/3: Don't add duplicate commands to


From: ELPA Syncer
Subject: [nongnu] elpa/projectile 9de18b77b4 2/3: Don't add duplicate commands to command history
Date: Sun, 22 May 2022 03:58:40 -0400 (EDT)

branch: elpa/projectile
commit 9de18b77b4ee7a1f5d27f15efd6216b62abfe20e
Author: lWarne <laurencewarne@gmail.com>
Commit: Bozhidar Batsov <bozhidar@batsov.dev>

    Don't add duplicate commands to command history
---
 projectile.el           |  4 +++-
 test/projectile-test.el | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/projectile.el b/projectile.el
index a871a55b2c..ff859a8ba2 100644
--- a/projectile.el
+++ b/projectile.el
@@ -4865,7 +4865,9 @@ The command actually run is returned."
          compilation-save-buffers-predicate)
     (when command-map
       (puthash default-directory command command-map)
-      (ring-insert (projectile--get-command-history project-root) command))
+      (let ((hist (projectile--get-command-history project-root)))
+        (unless (string= (car-safe (ring-elements hist)) command)
+          (ring-insert hist command))))
     (when save-buffers
       (save-some-buffers (not compilation-ask-about-save)
                          (lambda ()
diff --git a/test/projectile-test.el b/test/projectile-test.el
index e3d5a7feef..55570bf2ce 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -1988,6 +1988,27 @@ projectile-process-current-project-buffers-current to 
have similar behaviour"
       (funcall-interactively 'projectile-run-async-shell-command-in-root "cmd")
       (expect 'async-shell-command :to-have-been-called-with "cmd" nil nil))))
 
+(describe "projectile--run-project-cmd"
+  (it "command history is not duplicated"
+    (spy-on 'projectile-run-compilation)
+    (spy-on 'projectile-maybe-read-command :and-call-fake
+            (lambda (arg default-cmd prompt) default-cmd))
+    ;; Stops projectile--run-project-cmd from creating a new directory for
+    ;; the compilation dir
+    (spy-on 'file-directory-p :and-return-value t)
+    (let ((command-map (make-hash-table :test 'equal))
+          ;; history is based on the project root, so we set it to a random
+          ;; path to ensure there are no existing commands in history
+          (projectile-project-root "/a/random/path"))
+      (projectile--run-project-cmd "foo" command-map)
+      (projectile--run-project-cmd "foo" command-map)
+      (projectile--run-project-cmd "foo" command-map)
+      (projectile--run-project-cmd "bar" command-map)
+      (expect 'projectile-run-compilation :to-have-been-called-times 4)
+      (expect (ring-elements
+               (projectile--get-command-history projectile-project-root))
+              :to-equal '("bar" "foo")))))
+
 ;; A bunch of tests that make sure Projectile commands handle
 ;; gracefully the case of being run outside of a project.
 (assert-friendly-error-when-no-project projectile-project-info)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]