# HG changeset patch # User alys # Date 2018-10-15 16:14:49 # Node ID 1e95425d64989f811f6def37b2c49a3f7d83c1da # Parent 9845f3c63181b7112027743a2da3c2c5f51ef572 Add git support. diff --git a/project.clj b/project.clj --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject project-checkup "0.1.2-SNAPSHOT" +(defproject project-checkup "0.1.3-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" diff --git a/src/project_checkup/core.clj b/src/project_checkup/core.clj --- a/src/project_checkup/core.clj +++ b/src/project_checkup/core.clj @@ -10,16 +10,33 @@ people are used to seeing extensions in." (re-find #"\.[a-zA-Z0-9]+$" path)) +(defn gather-untracked + [vcs-systems] + "Gather untracked files in Git or Mercurial." + (reduce into [ + (if (contains? vcs-systems ".hg") + (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n")) + (if (contains? vcs-systems ".git") + (string/split (:out (shell/sh "git" "ls-files" "--others" + "--exclude-standard")) #"\n"))] + + ) + ) + (defn gather-project-info - "Creates a dictionary of project information" + "Creates a dictionary of project information." [] (let [all-files (map str (file-seq (clojure.java.io/file "."))) ; files (string/split (:out (shell/sh "hg" "st" "-m" "-a" "-r" "-d" "-c" "-n" )) #"\n") - files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) ] + + files (map #(clojure.string/replace % #"./(.*)" "$1") all-files ) + ;note that using some here means that if both are present, hg is + ;ignored: + vcs-systems (set (vector (some #{".git" ".hg"} files))) ] {:files files :extensions (frequencies (map get-extension files )) :path (System/getProperty "user.dir") - :untracked-files (string/split (:out (shell/sh "chg" "st" "-u" "-n")) #"\n") + :untracked-files (gather-untracked vcs-systems) :readme (if-let [filename (some #{"README.md" "README.txt" "README.mkd"} files)] (slurp filename) "") }) ) @@ -70,7 +87,7 @@ :description "" :function check-untracked :level :warning - :follow-up "Commit or ignore files from 'hg st -u'." } + :follow-up "Commit or ignore files from 'hg st -u' or 'git ls-files --others --exclude-standard'." } {:name "No Todo" :function check-taskpaper :description "" @@ -108,8 +125,9 @@ "Run checks." [& args] (try - (doseq [check checks] - (println (:output (perform-check check (gather-project-info) )))) + (let [project-info (gather-project-info)] + (doseq [check checks] + (println (:output (perform-check check project-info ))))) (catch Exception ex (.printStackTrace ex) (str "caught exception: " (.getMessage ex)))