Skip to content

added --cached option to scan for cached git files, useful in pre-com…#19

Open
michaelr524 wants to merge 1 commit into
pesterhazy:masterfrom
XLucidity:master
Open

added --cached option to scan for cached git files, useful in pre-com…#19
michaelr524 wants to merge 1 commit into
pesterhazy:masterfrom
XLucidity:master

Conversation

@michaelr524

Copy link
Copy Markdown

…mit hooks

@pesterhazy pesterhazy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! This seems useful. A few suggestions below to make this more general and reliable.

Comment thread src/boot_fmt/core.clj
(defn find-files-git-cached
[]
(let [{:keys [exit out err]} (clojure.java.shell/sh "git" "diff"
"--cached" "--name-only")]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use the -z option here, as with ls-files?

Comment thread src/boot_fmt/core.clj
"--cached" "--name-only")]
(when (not= exit 0) (throw (ex-info "git diff --cached failed" {:err err})))
(->> (clojure.string/split out #"\n")
(filter #(re-matches #".*\.(clj|cljs|cljc|cljx|cljs\.hl|boot)$" %))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use git diff --cached --name-only "*.clj" "*.cljs" ...? This would make this very similar to find-files-git

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the duplication concerns me, you need to add new file extensions in two places

Comment thread src/boot_fmt/core.clj
source (clojure.set/union (find-files-source))
git (clojure.set/union (find-files-git)))]
git (clojure.set/union (find-files-git))
cached (clojure.set/union (find-files-git-cached)))]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think git diff would be useful as well as git diff --cached. Perhaps two options?

-D --git-diff Automatically scan for changed files using git diff

-C -git-diff-cached Automatically scan for changed files using git diff --cached

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants