New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow defining specific files to check during overcommit --run
#677
Comments
Open to a pull request that adds support to the For example, if you want to compare the branch to git --no-pager diff --name-only origin/master | xargs overcommit --run Allowing the user to pass in the set of files makes this solution more flexible for different workflows/filtering methodologies. |
overcommit --run
My situation is exactly what @HarlemSquirrel is experiencing -- @sds your suggestion would be super useful. I have 0 Ruby experience (and am quite swamped with early stage startup life =), otherwise I'd love to create a PR. |
I've been using this bash script with pretty good success.
I had another thought about how this could work since overcommit already knows how to filter modified lines of files. A new
|
Yes, I really wish Fortunately, the One note on the script -- it has a small bug where if commit f747358719b718df8719749944dfc9744e9ab560
Author: Jonathan Mohrbacher <johnnymo87@gmail.com>
Date: Thu Aug 31 11:30:11 2023 -0400
Don't match lines that start with same line number
diff --git a/scripts/diff_filter.sh b/scripts/diff_filter.sh
index 861dcba1..9f9428b6 100755
--- a/scripts/diff_filter.sh
+++ b/scripts/diff_filter.sh
@@ -24,7 +24,7 @@ done
err_count=0
while read -r ln; do
for m in ${diff_list[@]}; do
- if [[ ${ln} =~ ^$m ]]; then
+ if [[ ${ln} =~ ^$m: ]]; then
echo $ln
err_count=$((err_count+1))
break
|
Ah shoot, there's actually a problem with this script. The script looks at As a solution, I threw out the diff --git c/scripts/diff_filter.sh i/scripts/diff_filter.sh
index 9f9428b6..30750175 100755
--- c/scripts/diff_filter.sh
+++ i/scripts/diff_filter.sh
@@ -10,16 +10,11 @@
BASE_REMOTE=origin
BASE_BRANCH=master
-diff_list=()
-commit_list=$(git --no-pager log --no-merges $BASE_REMOTE/$BASE_BRANCH...HEAD | grep -e '^commit' | sed -e "s/^commit \(.\{8\}\).*/\1/")
-for f in $(git --no-pager diff $BASE_REMOTE/$BASE_BRANCH...HEAD --name-only --diff-filter=AM); do
- for c in $commit_list; do
- diffs=$(git --no-pager blame --show-name -s $f | grep $c | sed -e "s/^[^ ]* *\([^ ]*\) *\([0-9]*\)*).*$/\1:\2/")
- for ln in $diffs; do
- diff_list+=( $ln )
- done
- done
-done
+# Get the directory of the current script
+DIR="$(dirname "$0")"
+
+# Directly assign the output to the array
+IFS=$'\n' read -r -d '' -a diff_list < <("$DIR/git-diff-changed-lines.sh" $BASE_REMOTE/$BASE_BRANCH...HEAD && printf '\0')
err_count=0
while read -r ln; do |
I know we can run pre-commit hooks on all files with https://github.com/sds/overcommit#continuous-integration
It would be great to be able to do this just on modified files and lines based on the commits ahead of the target branch in a pull request.
I'm working with some legacy code that was never linted and so this would help with incrementally improving the code base without needing to use a service like CodeFactor.
The text was updated successfully, but these errors were encountered: