Forked from rnesytov/Example of usage git in clojure using shell
Created
March 18, 2023 01:08
-
-
Save asakasinsky/26d335230e6726881d542d18957ad648 to your computer and use it in GitHub Desktop.
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
(ns git-example | |
(:require [clojure.java.shell :as shell] | |
[clojure.string :as string])) | |
(defn run-command [command & {:keys [directory] :or {directory (System/getProperty "user.dir")}}] | |
(shell/with-sh-dir directory | |
(shell/sh "sh" "-c" command))) | |
(defn resolve-command [command & [args]] | |
(reduce | |
(fn [command arg-key] | |
(string/replace command (str "%" (name arg-key)) (arg-key args))) | |
command | |
(keys args))) | |
(defn wrapper [command] | |
(fn [path & [args]] | |
(let [result (run-command (resolve-command command args) :directory path)] | |
(if (zero? (:exit result)) | |
(:out result) | |
false)))) | |
(defmacro defgit [alias command] | |
`(def ~(symbol (str alias)) (wrapper ~command))) | |
(defgit pull "git pull") | |
(defgit commit "git commit -a -m %message") | |
(pull "/Path/To/My/Repo/") | |
(commit "/Path/To/My/Repo/" {:message "My commit message"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment