diff options
Diffstat (limited to 'scripts/git.clj')
| -rwxr-xr-x | scripts/git.clj | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/scripts/git.clj b/scripts/git.clj index a721b3a..b7fabc2 100755 --- a/scripts/git.clj +++ b/scripts/git.clj @@ -46,33 +46,36 @@ (when (not-empty (git dir "branch" "-r" "--contains" commit)) commit))) -#_ (todo add branch?) -#_ (defn git-current-branch [dir] ) +#_(todo add branch?) +#_(defn git-current-branch [dir]) (defn git-base-branch [dir] - (some->> (git dir "rev-parse" "--abbrev-ref" "origin/HEAD") :out - not-empty - (sh "basename") :out - not-empty)) + #_(todo handle non-clone set head (git remote set-head origin --auto)) + (or (some->> (git dir "rev-parse" "--abbrev-ref" "origin/HEAD") :out + not-empty + (sh "basename") :out + not-empty) "main")) (defn git-remote-url [dir file-path revision line-start line-end] (some-> (or (git-remote-origin dir) (git-first-remote dir)) (prepare-link revision file-path line-start line-end))) -(defn git-root [path] +(defn git-root [& [path]] (let [file-dir (if (empty? path) "." (dirname path))] (some->> (git file-dir "rev-parse" "--absolute-git-dir") dirname))) (defn cmd-link [[file-path line-start line-end rev]] (let [dir (git-root file-path) - revision (or rev (git-current-rev dir) (git-base-branch dir) "main") + revision (or rev (git-current-rev dir) (git-base-branch dir)) relative-file-path (str/trim (:out (sh "realpath" "--relative-to" dir file-path))) remote-url (git-remote-url dir relative-file-path revision line-start line-end)] (println remote-url))) +(defn cmd-base-branch [[]] (println (git-base-branch (git-root)))) + (def commands - {"link" cmd-link}) + {"link" cmd-link, "base-branch" cmd-base-branch}) (let [[cmd & args] *command-line-args*] (if-let [command-fn (commands cmd)] |
