com.palletops/git-crate

0.8.0-alpha.1


Pallet crate to install, configure and use java

dependencies

org.clojure/clojure
1.4.0
com.palletops/pallet
0.8.0-beta.1



(this space intentionally left almost blank)
 

Crate to install and use git.

(ns pallet.crate.git
  (:require
   [clojure.string :as string]
   [pallet.actions :refer [packages exec-script exec-checked-script]]
   [pallet.api :refer [server-spec plan-fn]]
   [pallet.crate :refer [defplan admin-user os-family]]
   [pallet.crate.package.epel :refer [add-epel]]))

Install git

(defplan install-git
  []
  (when (#{:amzn-linux :centos} (os-family))
   (add-epel :version "5-4"))
  (packages
   :yum ["git" "git-email"]
   :aptitude ["git-core" "git-email"]
   :pacman ["git"]))
(defn repo-name [repo-uri]
  "Find a repository name from a repo uri string"
  (-> (string/split repo-uri #"/") last (string/replace #"\..*$" )))

Which branch is checkout-dir currently using?

(defplan branch?
  [checkout-dir & {:keys [user] :as options}]
  (exec-script
   (pipe ("git" branch)
         ("head" "-1")
         ("xawk" "'{print $2}'"))))

Clone a repository from repo-uri, a uri string. By default the :checkout-dir option is found from the repo-uri. :args can be used to pass a sequence of arbitrary arguments to the clone command.

(defplan clone
  [repo-uri & {:keys [checkout-dir args]
               :or {checkout-dir (repo-name repo-uri)}
               :as options}]
  (exec-checked-script
   (str "Clone " repo-uri " into " checkout-dir)
   (if (not (file-exists? ~(str checkout-dir "/.git/config")))
     ("git" clone ~@(or (seq args) [""]) ~repo-uri ~checkout-dir))))

Pull :branch from the specified :remote name. The branch and remote are optional

(defplan pull
  [& {:keys [branch remote args] :as options}]
  (exec-checked-script
   (str "Pull"
        (if branch (str " " branch) "")
        (if remote (str " from " remote)))
   ("git" pull ~@(or (seq (concat args (remove nil? [remote branch]))) [""]))))

Checkout a branch. An optional :remote-branch may be specified, which is used to create the branch if it doesn't already exist.

(defplan checkout
  [branch & {:keys [remote-branch]}]
  (exec-checked-script
   (str "Checkout " branch (if remote-branch (str " from "  remote-branch) ""))
   (if ("git" "show-ref" "--verify" "--quiet" (str "refs/heads/" ~branch))
     ("git" checkout ~branch)
     ("git" checkout "-b" ~branch ~(or remote-branch branch)))))
(defn git
  [_]
  (server-spec
   :phases {:configure (plan-fn (install-git))}))
 

Crate to install git.

(ns pallet.crate.git
  (:use
   [clojure.java.io :only [file]]
   [pallet.api :only [server-spec plan-fn]]
   [pallet.actions :only [exec-checked-script packages]]
   [pallet.crate :only [defplan]])
  (:require
   [clojure.string :as string]))

Install git

(defplan install-git
  []
  (packages
   :yum ["git" "git-email"]
   :aptitude ["git-core" "git-email"]
   :apt ["git-core" "git-email"]
   :pacman ["git"]))
(defplan clone
  [repo & args]
  (let [repo-name
        (-> (java.net.URL. (string/replace repo "git:" "http:"))
            .getPath
            file
            .getName
            (string/replace #"\.git$" ))]
    (exec-checked-script
     (str "Clone " repo "into" repo-name)
     (if (not (file-exists? ~(str repo-name "/.git/config")))
       ("git" clone ~@(or (seq args) []) ~repo)))))
(defn git
  [_]
  (server-spec
   :phases {:configure (plan-fn (install-git))}))