diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-19 06:33:06 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-19 06:33:06 -0500 |
| commit | bdf3058542bbce298b435b301c7863b9d81d5bf4 (patch) | |
| tree | 4905253aa528d743ae7479be6ed0cbabe9b3b4b2 /tests/test-reconcile--git-directory.el | |
| parent | 5cd7ca13005680b3e7bdac48dedf9cfbbfbcaa59 (diff) | |
| download | dotemacs-bdf3058542bbce298b435b301c7863b9d81d5bf4.tar.gz dotemacs-bdf3058542bbce298b435b301c7863b9d81d5bf4.zip | |
refactor(reconcile): extract helpers, add recursive repo discovery and 28 tests
Extract should-skip-p, pull-clean, pull-dirty from 6-level nested
reconcile-git-directory. Make find-git-repos recurse into sub-repos.
Diffstat (limited to 'tests/test-reconcile--git-directory.el')
| -rw-r--r-- | tests/test-reconcile--git-directory.el | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/test-reconcile--git-directory.el b/tests/test-reconcile--git-directory.el new file mode 100644 index 00000000..ab4a6323 --- /dev/null +++ b/tests/test-reconcile--git-directory.el @@ -0,0 +1,94 @@ +;;; test-reconcile--git-directory.el --- Tests for cj/reconcile-git-directory -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for the top-level reconcile function that dispatches to skip/clean/dirty. + +;;; Code: + +(require 'ert) +(require 'testutil-reconcile-open-repos) +(require 'reconcile-open-repos) + +;;; Normal Cases + +(ert-deftest test-reconcile-git-directory-normal-clean-repo-pulls () + "Clean SSH repo calls pull-clean, not pull-dirty." + (reconcile-test-with-temp-dirs + ("repo/.git/") + (let ((dir (expand-file-name "repo" test-root)) + (clean-called nil) + (dirty-called nil)) + (reconcile-test-with-shell-mocks + (lambda (_cmd) 0) + (lambda (cmd) + (cond ((string-match-p "remote.origin.url" cmd) "git@host:repo.git") + ((string-match-p "status --porcelain" cmd) "") + (t ""))) + (cl-letf (((symbol-function 'cj/reconcile--pull-clean) + (lambda (_dir) (setq clean-called t))) + ((symbol-function 'cj/reconcile--pull-dirty) + (lambda (_dir) (setq dirty-called t))) + ((symbol-function 'message) (lambda (_fmt &rest _args)))) + (cj/reconcile-git-directory dir))) + (should clean-called) + (should-not dirty-called)))) + +(ert-deftest test-reconcile-git-directory-normal-dirty-repo-stashes () + "Dirty SSH repo calls pull-dirty, not pull-clean." + (reconcile-test-with-temp-dirs + ("repo/.git/") + (let ((dir (expand-file-name "repo" test-root)) + (clean-called nil) + (dirty-called nil)) + (reconcile-test-with-shell-mocks + (lambda (_cmd) 0) + (lambda (cmd) + (cond ((string-match-p "remote.origin.url" cmd) "git@host:repo.git") + ((string-match-p "status --porcelain" cmd) " M file.el\n") + (t ""))) + (cl-letf (((symbol-function 'cj/reconcile--pull-clean) + (lambda (_dir) (setq clean-called t))) + ((symbol-function 'cj/reconcile--pull-dirty) + (lambda (_dir) (setq dirty-called t))) + ((symbol-function 'message) (lambda (_fmt &rest _args)))) + (cj/reconcile-git-directory dir))) + (should-not clean-called) + (should dirty-called)))) + +(ert-deftest test-reconcile-git-directory-normal-skipped-repo-no-calls () + "HTTP repo is skipped entirely — neither pull-clean nor pull-dirty called." + (reconcile-test-with-temp-dirs + ("repo/.git/") + (let ((dir (expand-file-name "repo" test-root)) + (clean-called nil) + (dirty-called nil)) + (reconcile-test-with-shell-mocks + (lambda (_cmd) 0) + (lambda (cmd) + (if (string-match-p "remote.origin.url" cmd) + "https://github.com/user/repo.git" + "")) + (cl-letf (((symbol-function 'cj/reconcile--pull-clean) + (lambda (_dir) (setq clean-called t))) + ((symbol-function 'cj/reconcile--pull-dirty) + (lambda (_dir) (setq dirty-called t))) + ((symbol-function 'message) (lambda (_fmt &rest _args)))) + (cj/reconcile-git-directory dir))) + (should-not clean-called) + (should-not dirty-called)))) + +;;; Boundary Cases + +(ert-deftest test-reconcile-git-directory-boundary-emits-checking-message () + "Always emits 'checking: <dir>' message, even for skipped repos." + (reconcile-test-with-temp-dirs + ("repo/readme.txt") + (let ((dir (expand-file-name "repo" test-root)) + (messages nil)) + (cl-letf (((symbol-function 'message) + (lambda (fmt &rest args) (push (apply #'format fmt args) messages)))) + (cj/reconcile-git-directory dir)) + (should (cl-some (lambda (m) (string-match-p "checking:" m)) messages))))) + +(provide 'test-reconcile--git-directory) +;;; test-reconcile--git-directory.el ends here |
