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

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

[elpa] externals/counsel 8a4d1fc 1/3: counsel.el (counsel-github-url-p):


From: Basil L. Contovounesios
Subject: [elpa] externals/counsel 8a4d1fc 1/3: counsel.el (counsel-github-url-p): Don't raise an error when no Git
Date: Fri, 23 Apr 2021 11:48:14 -0400 (EDT)

branch: externals/counsel
commit 8a4d1fc99c96a06e0b0b37c04ad7b9dd745d840d
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    counsel.el (counsel-github-url-p): Don't raise an error when no Git
---
 counsel.el | 58 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/counsel.el b/counsel.el
index 2d8bc01..e6c2c43 100644
--- a/counsel.el
+++ b/counsel.el
@@ -123,10 +123,11 @@ complex regexes."
       (executable-find command)))
   "Compatibility shim for `executable-find'.")
 
-(defun counsel-require-program (cmd)
+(defun counsel-require-program (cmd &optional noerror)
   "Check system for program used in CMD, printing error if not found.
 CMD is either a string or a list of strings.
-To skip the `executable-find' check, start the string with a space."
+To skip the `executable-find' check, start the string with a space.
+When NOERROR is non-nil, return nil instead of raising an error."
   (unless (and (stringp cmd) (string-prefix-p " " cmd))
     (let ((program (if (listp cmd)
                        (car cmd)
@@ -134,7 +135,8 @@ To skip the `executable-find' check, start the string with 
a space."
       (or (and (stringp program)
                (not (string= program ""))
                (counsel--executable-find program t))
-          (user-error "Required program \"%s\" not found in your path" 
program)))))
+          (unless noerror
+            (user-error "Required program \"%s\" not found in your path" 
program))))))
 
 (declare-function eshell-split-path "esh-util")
 
@@ -2210,34 +2212,34 @@ See variable `counsel-up-directory-level'."
 
 (defun counsel-github-url-p ()
   "Return a Github issue URL at point."
-  (counsel-require-program "git")
-  (let ((url (counsel-at-git-issue-p)))
-    (when url
-      (let ((origin (shell-command-to-string
-                     "git remote get-url origin"))
-            user repo)
-        (cond ((string-match "\\`git@github.com:\\([^/]+\\)/\\(.*\\)\\.git$"
-                             origin)
-               (setq user (match-string 1 origin))
-               (setq repo (match-string 2 origin)))
-              ((string-match "\\`https://github.com/\\([^/]+\\)/\\(.*\\)$"
-                             origin)
-               (setq user (match-string 1 origin))
-               (setq repo (match-string 2 origin))))
-        (when user
-          (setq url (format "https://github.com/%s/%s/issues/%s";
-                            user repo (substring url 1))))))))
+  (when (counsel-require-program "git" t)
+    (let ((url (counsel-at-git-issue-p)))
+      (when url
+        (let ((origin (shell-command-to-string
+                       "git remote get-url origin"))
+              user repo)
+          (cond ((string-match "\\`git@github.com:\\([^/]+\\)/\\(.*\\)\\.git$"
+                               origin)
+                 (setq user (match-string 1 origin))
+                 (setq repo (match-string 2 origin)))
+                ((string-match "\\`https://github.com/\\([^/]+\\)/\\(.*\\)$"
+                               origin)
+                 (setq user (match-string 1 origin))
+                 (setq repo (match-string 2 origin))))
+          (when user
+            (setq url (format "https://github.com/%s/%s/issues/%s";
+                              user repo (substring url 1)))))))))
 
 (defun counsel-emacs-url-p ()
   "Return a Debbugs issue URL at point."
-  (counsel-require-program "git")
-  (let ((url (counsel-at-git-issue-p)))
-    (when url
-      (let ((origin (shell-command-to-string
-                     "git remote get-url origin")))
-        (when (string-match "git.sv.gnu.org:/srv/git/emacs.git" origin)
-          (format "https://debbugs.gnu.org/cgi/bugreport.cgi?bug=%s";
-                  (substring url 1)))))))
+  (when (counsel-require-program "git" t)
+    (let ((url (counsel-at-git-issue-p)))
+      (when url
+        (let ((origin (shell-command-to-string
+                       "git remote get-url origin")))
+          (when (string-match "git.sv.gnu.org:/srv/git/emacs.git" origin)
+            (format "https://debbugs.gnu.org/cgi/bugreport.cgi?bug=%s";
+                    (substring url 1))))))))
 
 (defvar counsel-url-expansions-alist nil
   "Map of regular expressions to expansions.



reply via email to

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