aboutsummaryrefslogtreecommitdiff
path: root/tests/test-reconcile--find-git-repos.el
blob: e065fca901dcc336c817ef34a86acc885735f666 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;; test-reconcile--find-git-repos.el --- Tests for cj/find-git-repos -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for recursive git repository discovery in cj/find-git-repos.
;; Uses real temporary directory trees with fake .git directories.

;;; Code:

(require 'ert)
(require 'testutil-reconcile-open-repos)
(require 'reconcile-open-repos)

;;; Normal Cases

(ert-deftest test-find-git-repos-normal-flat-repos ()
  "Finds multiple git repos at the same level."
  (reconcile-test-with-temp-dirs
   ("repo-a/.git/" "repo-b/.git/" "repo-c/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 3)))))

(ert-deftest test-find-git-repos-normal-nested-repo ()
  "Finds a repo nested inside a non-repo directory."
  (reconcile-test-with-temp-dirs
   ("parent/child/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 1))
     (should (string-suffix-p "child" (car repos))))))

(ert-deftest test-find-git-repos-normal-stops-at-repo-root-by-default ()
  "Finds a parent repo and does not descend into nested repos by default."
  (reconcile-test-with-temp-dirs
   ("deepsat/.git/" "deepsat/frontend/.git/" "deepsat/backend/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 1))
     (should (string-suffix-p "deepsat" (car repos))))))

(ert-deftest test-find-git-repos-normal-can-include-nested-subrepos ()
  "Finds nested repos when INCLUDE-NESTED is non-nil."
  (reconcile-test-with-temp-dirs
   ("deepsat/.git/" "deepsat/frontend/.git/" "deepsat/backend/.git/")
   (let ((repos (cj/find-git-repos test-root t)))
     (should (= (length repos) 3)))))

(ert-deftest test-find-git-repos-normal-mixed-repos-and-dirs ()
  "Finds repos while skipping plain directories."
  (reconcile-test-with-temp-dirs
   ("repo-a/.git/" "not-a-repo/readme.txt" "repo-b/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 2)))))

(ert-deftest test-find-git-repos-normal-deeply-nested ()
  "Finds a repo several levels deep."
  (reconcile-test-with-temp-dirs
   ("a/b/c/deep-repo/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 1))
     (should (string-suffix-p "deep-repo" (car repos))))))

;;; Boundary Cases

(ert-deftest test-find-git-repos-boundary-empty-directory ()
  "Returns empty list for directory with no children."
  (reconcile-test-with-temp-dirs
   ()
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 0)))))

(ert-deftest test-find-git-repos-boundary-no-git-repos ()
  "Returns empty list when no directories contain .git."
  (reconcile-test-with-temp-dirs
   ("dir-a/file.txt" "dir-b/file.txt")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 0)))))

(ert-deftest test-find-git-repos-boundary-hidden-dirs-skipped ()
  "Skips hidden directories (starting with dot) per the regex filter."
  (reconcile-test-with-temp-dirs
   (".hidden-repo/.git/" "visible-repo/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 1))
     (should (string-suffix-p "visible-repo" (car repos))))))

(ert-deftest test-find-git-repos-boundary-prunes-heavy-directories ()
  "Skips generated/heavy directories while discovering repos."
  (reconcile-test-with-temp-dirs
   ("project/node_modules/dependency/.git/"
    "project/.venv/tool/.git/"
    "project/src/repo/.git/")
   (let ((repos (cj/find-git-repos test-root)))
     (should (= (length repos) 1))
     (should (string-suffix-p "repo" (car repos))))))

(provide 'test-reconcile--find-git-repos)
;;; test-reconcile--find-git-repos.el ends here