From c7ce409128070a3d4b7abd2643565851a1a02dc9 Mon Sep 17 00:00:00 2001 From: Hoogervorst Date: Thu, 26 Sep 2019 12:03:10 +0200 Subject: [PATCH 1/2] limit commits to 1 if no range is given Signed-off-by: Hoogervorst --- assets/check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/check b/assets/check index b9d26e35..bfbacdeb 100755 --- a/assets/check +++ b/assets/check @@ -126,7 +126,7 @@ fi #if no range is selected just grab the last commit that fits the filter if [ -z "$log_range" ] then - list_command+=" -1" + list_command+="| git rev-list --stdin -1" fi if [ -n "$tag_filter" ]; then From 0d0e9f8903d64e7f4e661ba93744550fb375866f Mon Sep 17 00:00:00 2001 From: Hoogervorst Date: Mon, 30 Sep 2019 11:44:46 +0200 Subject: [PATCH 2/2] add testcase for path filtering on branch Signed-off-by: Hoogervorst --- test/check.sh | 17 +++++++++++++++++ test/helpers.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/test/check.sh b/test/check.sh index 36f7ff16..d87d0812 100755 --- a/test/check.sh +++ b/test/check.sh @@ -263,6 +263,22 @@ it_checks_given_paths() { " } +it_checks_given_paths_on_branch() { + local repo=$(init_repo) + local ref1=$(make_commit_to_file_on_branch_with_path $repo dummy file-b master) + echo $ref1 + local ref2=$(make_commit_to_file_on_branch_with_path $repo dummy file-b master) + echo $ref2 + local ref3=$(make_commit_to_file_on_branch_with_path $repo dummy file-b newbranch) + echo $ref3 + local result=$(check_uri_from_paths_with_branch $repo newbranch "dummy/*") + echo result + + check_uri_from_paths_with_branch $repo newbranch "dummy/*"| jq -e " + . == [{ref: $(echo $ref3 | jq -R .)}] + " +} + it_checks_given_glob_paths() { # issue gh-120 local repo=$(init_repo) mkdir -p $repo/a/b @@ -657,6 +673,7 @@ run it_can_check_from_a_first_commit_in_repo run it_can_check_from_a_bogus_sha run it_skips_ignored_paths run it_checks_given_paths +run it_checks_given_paths_on_branch run it_checks_given_glob_paths run it_checks_given_ignored_paths run it_can_check_when_not_ff diff --git a/test/helpers.sh b/test/helpers.sh index 359efbb3..9d7fc5a3 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -146,6 +146,34 @@ make_commit_to_file_on_branch() { git -C $repo rev-parse HEAD } +make_commit_to_file_on_branch_with_path() { + local repo=$1 + local path=$2 + local file=$3 + local branch=$4 + local msg=${5-} + + # ensure branch exists + if ! git -C $repo rev-parse --verify $branch >/dev/null; then + git -C $repo branch $branch master + fi + + # switch to branch + git -C $repo checkout -q $branch + + # modify file and commit + mkdir -p $repo/$path + echo x >> $repo/$path/$file + git -C $repo add $path/$file + git -C $repo \ + -c user.name='test' \ + -c user.email='test@example.com' \ + commit -q -m "commit $(wc -l $repo/$path/$file) $msg" + + # output resulting sha + git -C $repo rev-parse HEAD +} + make_commit_to_file() { make_commit_to_file_on_branch $1 $2 master "${3-}" } @@ -352,6 +380,22 @@ check_uri_from_paths() { }" | ${resource_dir}/check | tee /dev/stderr } +check_uri_from_paths_with_branch() { + local uri=$1 + local branch=$2 + + shift 2 + + jq -n "{ + source: { + uri: $(echo $uri | jq -R .), + paths: $(echo "$@" | jq -R '. | split(" ")'), + branch: $(echo $branch | jq -R .), + disable_ci_skip: true + }, + }" | ${resource_dir}/check | tee /dev/stderr +} + check_uri_from_paths_ignoring() { local uri=$1 local ref=$2