-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38c1bbb
commit c785b59
Showing
34 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(ns k16.kmono.git.files-test | ||
(:require | ||
[babashka.fs :as fs] | ||
[clojure.test :refer [deftest is use-fixtures]] | ||
[k16.kmono.git.commit :as git.commit] | ||
[k16.kmono.git.files :as git.files] | ||
[k16.kmono.test.helpers.commit :refer [commit]] | ||
[k16.kmono.test.helpers.repo :refer [*repo* with-test-repo] :as helpers.repo])) | ||
|
||
(use-fixtures :each with-test-repo) | ||
|
||
(defn prepare-repo [] | ||
(let [root-commit (git.commit/get-current-commit *repo*) | ||
|
||
_ (fs/create-file (fs/file *repo* "packages/a/change-1")) | ||
_ (fs/create-file (fs/file *repo* "packages/b/change-1")) | ||
|
||
commit-1 (commit *repo* "change-1") | ||
|
||
_ (fs/create-file (fs/file *repo* "packages/a/change-2")) | ||
_ (fs/create-file (fs/file *repo* "packages/b/change-2")) | ||
|
||
_ (commit *repo* "change-2")] | ||
|
||
[root-commit commit-1])) | ||
|
||
(deftest query-ordered-tags | ||
(let [[root-commit commit-1] (prepare-repo) | ||
|
||
files-since-root | ||
(git.files/find-changed-files-since | ||
*repo* {:ref root-commit}) | ||
|
||
files-since-change-1 | ||
(git.files/find-changed-files-since | ||
*repo* {:ref commit-1})] | ||
|
||
(is (= ["packages/a/change-1" | ||
"packages/a/change-2" | ||
"packages/b/change-1" | ||
"packages/b/change-2"] | ||
files-since-root)) | ||
|
||
(is (= ["packages/a/change-2" | ||
"packages/b/change-2"] | ||
files-since-change-1)))) | ||
|
||
(deftest query-ordered-tags-in-subdir | ||
(let [[root-commit commit-1] (prepare-repo) | ||
|
||
files-since-root-a | ||
(git.files/find-changed-files-since | ||
*repo* {:ref root-commit | ||
:subdir "packages/a"}) | ||
|
||
files-since-change-1-b | ||
(git.files/find-changed-files-since | ||
*repo* {:ref commit-1 | ||
:subdir "packages/b"})] | ||
|
||
(is (= ["packages/a/change-1" | ||
"packages/a/change-2"] | ||
files-since-root-a)) | ||
|
||
(is (= ["packages/b/change-2"] | ||
files-since-change-1-b)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns k16.kmono.git.tag-test | ||
(:require | ||
[clojure.test :refer [deftest is use-fixtures]] | ||
[k16.kmono.git.command :as git] | ||
[k16.kmono.git.commit :as git.commit] | ||
[k16.kmono.git.tags :as git.tags] | ||
[k16.kmono.test.helpers.commit :refer [commit]] | ||
[k16.kmono.test.helpers.repo :refer [*repo* with-test-repo] :as helpers.repo])) | ||
|
||
(use-fixtures :each with-test-repo) | ||
|
||
(deftest query-ordered-tags | ||
(let [initial-commit (git.commit/get-current-commit *repo*)] | ||
|
||
(git.tags/create-tags *repo* {:ref initial-commit | ||
:tags ["a"]}) | ||
|
||
(commit *repo* "change-1") | ||
|
||
(git.tags/create-tags *repo* {:ref (git.commit/get-current-commit *repo*) | ||
:tags ["b-1"]}) | ||
|
||
(git/run-cmd! *repo* "git" "checkout" initial-commit) | ||
|
||
(commit *repo* "change-2") | ||
|
||
(git.tags/create-tags *repo* {:ref (git.commit/get-current-commit *repo*) | ||
:tags ["b-2"]}) | ||
|
||
(let [tags (git.tags/get-sorted-tags *repo* (git.commit/get-current-commit *repo*))] | ||
|
||
(is (= ["b-2" "a"] tags))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(ns k16.kmono.test.helpers.commit | ||
(:require | ||
[k16.kmono.git.commit :as git.commit] | ||
[k16.kmono.git.command :as git])) | ||
|
||
(defn commit | ||
([repo] (commit repo "commit")) | ||
([repo message] | ||
(git/run-cmd! repo "git add .") | ||
(git/run-cmd! repo "git commit --allow-empty" "-m" message) | ||
(git.commit/get-current-commit repo))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(ns k16.kmono.test.helpers.repo | ||
(:require | ||
[babashka.fs :as fs] | ||
[k16.kmono.git.command :as git])) | ||
|
||
(defn setup-multi-package-repo [] | ||
(let [uuid (str (random-uuid)) | ||
|
||
repo (fs/file (str "test/.repos/" uuid))] | ||
(fs/create-dirs repo) | ||
(fs/copy-tree (fs/file "test/templates/monorepo") | ||
repo) | ||
|
||
(git/run-cmd! repo "git" "init") | ||
(git/run-cmd! repo "git" "add" ".") | ||
(git/run-cmd! repo "git" "commit" "-m" "init") | ||
|
||
(git/run-cmd! repo "git config advice.detachedHead false") | ||
|
||
(.getAbsolutePath repo))) | ||
|
||
(def ^:dynamic *repo* nil) | ||
|
||
(defn with-test-repo [test] | ||
(let [repo (setup-multi-package-repo)] | ||
(try | ||
(binding [*repo* repo] | ||
(test)) | ||
(finally | ||
(fs/delete-tree repo))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:kmono/workspace {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:kmono/package {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:kmono/package {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |