mirror of
https://github.com/NinjaTrappeur/my-repo-pins.git
synced 2024-06-01 19:14:07 +02:00
get-code-root-projects: implement "naive" version
This function is meant to retrieve the projects repositories from the code-root. This first version is a bit naive in its approach: we consider a directory to be a git repository as soon as a .git directory is present. That might be a bit too naive.
This commit is contained in:
parent
ea6631f05a
commit
02109cec18
30
h-tests.el
30
h-tests.el
|
@ -29,9 +29,33 @@
|
|||
(require 'ert)
|
||||
(require 'h)
|
||||
|
||||
(ert-deftest h-dummy-test ()
|
||||
"Testing the project setup."
|
||||
(should (eq h-test 1)))
|
||||
; For reference: test-root-1 looks like this
|
||||
; test-root-1
|
||||
; ├── example1.tld
|
||||
; │ ├── user1
|
||||
; │ │ ├── proj1
|
||||
; │ │ └── proj2
|
||||
; │ └── user2
|
||||
; │ └── proj1
|
||||
; └── example2.tld
|
||||
; └── user1
|
||||
; └── proj1
|
||||
(ert-deftest h-get-code-root-projects-test ()
|
||||
"Testing the `h--get-code-root-projects with test-root-1 setup."
|
||||
(let
|
||||
(
|
||||
(results (h--get-code-root-projects "./test/fixtures/test-root-1")))
|
||||
(should (member "example1.tld/user1/proj1" results))
|
||||
(should (member "example1.tld/user1/proj2" results))
|
||||
(should (member "example1.tld/user2/proj1" results))
|
||||
(should (member "example2.tld/user1/proj1" results))
|
||||
(should (eq (length results) 4))
|
||||
))
|
||||
|
||||
(h--get-code-root-projects "./test/fixtures/test-root-1")
|
||||
|
||||
|
||||
|
||||
|
||||
(provide 'h-tests)
|
||||
;;; h-tests.el ends here
|
||||
|
|
49
h.el
49
h.el
|
@ -5,7 +5,7 @@
|
|||
;; Maintainer: Félix Baylac Jacqué <felix at alternativebit.fr>
|
||||
;; Version: 1.14.0
|
||||
;; Homepage: https://alternativebit.fr/TODO
|
||||
;; Package-Requires: ((emacs "24.1"))
|
||||
;; Package-Requires: ((emacs "25.1"))
|
||||
|
||||
;;; License:
|
||||
|
||||
|
@ -28,7 +28,52 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(defvar h-test 1)
|
||||
(defgroup h-group nil
|
||||
"Variables used to setup the h.el code folder manager."
|
||||
:group 'Communication)
|
||||
|
||||
|
||||
(defcustom h-code-root nil
|
||||
"Directory containing the git projects.
|
||||
h.el organise the git repos you'll checkout in a tree fashion.
|
||||
|
||||
All the code fetched using h.el will end up in this root directory. A
|
||||
tree of subdirectories will be created mirroring the remote URI.
|
||||
|
||||
For instance, after checking out
|
||||
https://git.savannah.gnu.org/git/emacs/org-mode.git, the source code
|
||||
will live in the h-code-root/git.savannah.gnu.org/git/emacs/org-mode/
|
||||
local directory"
|
||||
:type 'directory
|
||||
:group 'h-group)
|
||||
|
||||
(defun h--is-git-repo (dir)
|
||||
"Check if DIR is a git repo using a pretty weak heuristic."
|
||||
(file-directory-p (concat (file-name-as-directory dir) ".git")))
|
||||
|
||||
(defun h--get-code-root-projects (code-root)
|
||||
"Retrieve the projects contained in the CODE-ROOT directory.
|
||||
We're going to make some hard assumptions about how the `h-code-root`
|
||||
directory should look like. First of all, if a directory seem to be a
|
||||
git repository, it'll automatically be considered as a project root.
|
||||
|
||||
It means that after encountering a git repository, we won't recurse
|
||||
any further."
|
||||
(let*
|
||||
((is-not-git-repo (lambda (dir) (not (h--is-git-repo dir))))
|
||||
(remove-code-root-prefix
|
||||
(lambda (path) (string-remove-prefix (concat code-root "/") path)))
|
||||
;;; PERF: Using directory-files-recursively is pretty
|
||||
;;; inneficient. We have to list the dir content twice:
|
||||
;;; 1. when directory-files-recursively checks.
|
||||
;;; 2. when we filter the intermediate dirs from this list.
|
||||
(recursively-found-dirs
|
||||
(directory-files-recursively code-root "" t is-not-git-repo))
|
||||
(projects-absolute-path (seq-filter (lambda (e) (h--is-git-repo e)) recursively-found-dirs))
|
||||
(projects-relative-to-code-root
|
||||
(mapcar remove-code-root-prefix projects-absolute-path)))
|
||||
|
||||
projects-relative-to-code-root))
|
||||
|
||||
(provide 'h)
|
||||
;;; h.el ends here
|
||||
|
|
1
test/fixtures/test-root-1/example1.tld/user1/proj1
vendored
Submodule
1
test/fixtures/test-root-1/example1.tld/user1/proj1
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 6943ed79983734fe9ad628e2feefbda62a8130bb
|
1
test/fixtures/test-root-1/example1.tld/user1/proj2
vendored
Submodule
1
test/fixtures/test-root-1/example1.tld/user1/proj2
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 99929c82f82047e662aa5784dc99f6a380b45f19
|
1
test/fixtures/test-root-1/example1.tld/user2/proj1
vendored
Submodule
1
test/fixtures/test-root-1/example1.tld/user2/proj1
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 99929c82f82047e662aa5784dc99f6a380b45f19
|
1
test/fixtures/test-root-1/example2.tld/user1/proj1
vendored
Submodule
1
test/fixtures/test-root-1/example2.tld/user1/proj1
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit b4f7fc570ad41b68e772f15311df4ad93f468a23
|
Loading…
Reference in a new issue