Skip to content

Commit

Permalink
Merge pull request #46 from exload/master
Browse files Browse the repository at this point in the history
Add a repo-branch argument to with-git which gets the latest revision…
  • Loading branch information
flosell committed Sep 10, 2015
2 parents 2a264df + f6d5e87 commit b6dc8f4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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

0 comments on commit b6dc8f4

Please sign in to comment.