Skip to content

Commit

Permalink
fix: additional check for git repo exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Artawower committed Feb 14, 2023
1 parent 600eab5 commit 0c77177
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions file-info.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Artur Yaroshenko <[email protected]>
;; URL: https://github.com/artawower/file-info.el
;; Package-Requires: ((emacs "28.1") (hydra "0.15.0") (browse-at-remote "0.15.0"))
;; Version: 0.5.2
;; Version: 0.5.3

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -209,9 +209,13 @@
(defvar-local file-info--cache '()
"Cache for file info.")

(defvar-local file-info--git-p nil
"Is buffer inside git repository.")

(defun file-info--get-first-commit-info ()
"Get first commit hash and user name via VC."
(when-let ((file-name (buffer-file-name)))
(when-let ((git-p file-info--git-p)
(file-name (buffer-file-name)))
(with-temp-buffer
(vc-git-command
t
Expand All @@ -226,7 +230,8 @@

(defun file-info--get-last-commit-info ()
"Get last commit hash and user name via VC."
(when-let ((file-name (buffer-file-name)))
(when-let ((git-p file-info--git-p)
(file-name (buffer-file-name)))
(with-temp-buffer
(vc-git-command
t 0 file-name "log" "--pretty=format|%H|%an|%cr" "-n" "1")
Expand Down Expand Up @@ -269,13 +274,15 @@

(defun file-info--get-current-branch ()
"Return current branch via VC."
(when-let ((file-name (buffer-file-name))
(when-let ((git-p file-info--git-p)
(file-name (buffer-file-name))
(root (file-info--get-project-root)))
(vc-git--symbolic-ref (file-info--get-file-name))))

(defun file-info--get-git-file-changes ()
"Get count of modified and removed lines of code from VC."
(when-let ((file-name (buffer-file-name))
(when-let ((git-p file-info--git-p)
(file-name (buffer-file-name))
(root (file-info--get-project-root)))
(with-temp-buffer
(vc-git-command t 0 file-name "diff" "--numstat")
Expand Down Expand Up @@ -388,7 +395,8 @@

(defun file-info--get-all-file-contributors ()
"Return list of all file contributers sorted by commits count via VC."
(when-let ((file-name (buffer-file-name))
(when-let ((git-p file-info--git-p)
(file-name (buffer-file-name))
(root (file-info--get-project-root)))
(with-temp-buffer
(vc-git-command t 0 file-name "log" "--pretty=%ae")
Expand Down Expand Up @@ -514,6 +522,7 @@

(defun file-info--get-pretty-information ()
"Get pretty information about file."
(file-info--prepare-data)
(concat
"\n\n"
(string-join
Expand Down Expand Up @@ -561,6 +570,11 @@
file-info-handlers))
"\n"))

(defun file-info--prepare-data ()
"Prepare local buffer data with caching."
(when (and (buffer-file-name) (not file-info--git-p))
(setq file-info--git-p (vc-git-root (buffer-file-name)))))

(defun file-info--get-hydra-bindings ()
"Get hydra bindings."
(let ((binding-functions '()))
Expand Down Expand Up @@ -605,12 +619,12 @@
(call-interactively
(eval
`(defhydra
file-name--hydra-menu
(:hint nil :exit t)
,(file-info--get-pretty-information)
,@
(file-info--get-hydra-bindings)
("q" posframe-hide-all :color blue)))))
file-name--hydra-menu
(:hint nil :exit t)
,(file-info--get-pretty-information)
,@
(file-info--get-hydra-bindings)
("q" posframe-hide-all :color blue)))))

;;;###autoload
(defun file-info-show ()
Expand Down

0 comments on commit 0c77177

Please sign in to comment.