Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a repo-branch argument to with-git which gets the latest revision… #46

Merged
merged 3 commits into from
Sep 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/clj/lambdacd/steps/git.clj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
(fn [args ctx]
(checkout-and-execute repo-uri (:revision args) args ctx steps)))

(defn with-git-branch
"creates a container-step that checks out the latest revision from a repository with the
given branch."
[repo-uri repo-branch steps]
(fn [args ctx]
(checkout-and-execute repo-uri repo-branch args ctx steps)))

(defn- parse-log-lines [l]
(let [[hash & msg-parts] (s/split l #" ")
msg (s/join " " msg-parts)]
Expand Down
38 changes: 38 additions & 0 deletions test/clj/lambdacd/steps/git_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
{:dir dir
:commits (git-commits dir)}))

(defn create-test-repo-with-branch []
(let [dir (util/create-temp-dir)]
(util/bash dir
"git init"
"echo \"hello\" > foo"
"git add -A"
"git commit -m \"some message\""
"git branch develop"
"git checkout develop"
"echo \"world\" > bar"
"git add -A"
"git commit -m \"some other message\"")
{:dir dir
:commits (git-commits dir)}))

(defn- commit-to
([git-dir]
(commit-to git-dir "new commit"))
Expand Down Expand Up @@ -141,6 +156,29 @@
(is (= :failure (:status with-git-result)))
(is (.contains (:out with-git-result) "some-unknown-uri" )))))

(deftest with-git-branch-test
(testing "that it checks out the head revision for a given branch and then returns, indicating the location of the checked out repo as :cwd value and that the cloned repo is in a directory named like the repo that was cloned"
(let [create-output (create-test-repo-with-branch)
git-src-dir (:dir create-output)
commits (:commits create-output)
lastest-commit (last commits)
with-git-function (with-git-branch (repo-uri-for git-src-dir) "develop" [step-that-returns-the-current-cwd-head])
with-git-result (with-git-function {} (some-ctx))]
(is (= lastest-commit (:current-head (get (:outputs with-git-result ) [1 42]))))
(is (.startsWith (:out with-git-result) "Cloning"))))
(testing "that it fails when it couldn't check out a repository"
(let [with-git-function (with-git-branch "some-unknown-uri" "some-unknown-branch" [])
with-git-result (with-git-function {} (some-ctx))]
(is (= :failure (:status with-git-result)))
(is (.contains (:out with-git-result) "some-unknown-uri" ))))
(testing "that it fails when it couldn't check out a branch"
(let [create-output (create-test-repo-with-branch)
git-src-dir (:dir create-output)
with-git-function (with-git-branch (repo-uri-for git-src-dir) "some-unknown-branch" [])
with-git-result (with-git-function {} (some-ctx))]
(is (= :failure (:status with-git-result)))
(is (.contains (:out with-git-result) "some-unknown-branch" )))))

(defn some-step-that-returns-42 [args ctx]
{:status :success :the-number 42})
(defn some-step-that-returns-21 [args ctx]
Expand Down