From ab59cb3d92938e794a1081f6a55b1ac898b52465 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 11 Jun 2024 09:52:39 +0000 Subject: [PATCH 1/7] chore(get-modified-packages): ensure base branch is fetched Signed-off-by: GitHub --- get-modified-packages/get-modified-packages.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index a9522dd8..c5a9e1b6 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -49,6 +49,9 @@ function find_package_dir() { return 1 } +# Ensure base branch is fetched +git fetch --depth=1 origin "$base_branch" + # Find modified files from base branch modified_files=$(git diff --name-only "$base_branch"...HEAD) From 74b8278121cb8b72bc3a74bc754ec99cac5a012c Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 11 Jun 2024 10:27:02 +0000 Subject: [PATCH 2/7] fix: fix errors on get-modified-packages.sh on shallow fetched repository Signed-off-by: Kotaro Yoshimoto --- get-modified-packages/get-modified-packages.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index c5a9e1b6..1df12c39 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -50,10 +50,10 @@ function find_package_dir() { } # Ensure base branch is fetched -git fetch --depth=1 origin "$base_branch" +git fetch --depth=1 origin "$base_branch":refs/remotes/origin/"$base_branch" # Find modified files from base branch -modified_files=$(git diff --name-only "$base_branch"...HEAD) +modified_files=$(git diff --name-only refs/remotes/origin/"$base_branch"...HEAD) # Find modified packages modified_package_dirs=() From 8fc9ddb61db0630982ec2b6bc375f2e2a17ceed9 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 11 Jun 2024 11:00:22 +0000 Subject: [PATCH 3/7] chore: change approach Signed-off-by: GitHub --- .../get-modified-packages.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index 1df12c39..7f57c5c0 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -49,11 +49,22 @@ function find_package_dir() { return 1 } -# Ensure base branch is fetched -git fetch --depth=1 origin "$base_branch":refs/remotes/origin/"$base_branch" +# Function to check if the base ref SHA is in the commit history +check_base_ref_in_history() { + git rev-list HEAD | grep -q "$(git rev-parse origin/"$base_branch")" +} + +# Fetch the initial shallow clone depth +depth=1 + +# Loop to deepen the fetch until the base ref SHA is included +while ! check_base_ref_in_history; do + depth=$((depth * 2)) + git fetch --deepen=$depth +done -# Find modified files from base branch -modified_files=$(git diff --name-only refs/remotes/origin/"$base_branch"...HEAD) +# Get the modified files between base ref and HEAD +modified_files=$(git diff --name-only origin/"$base_branch"...HEAD) # Find modified packages modified_package_dirs=() From 69274b77d4d5f90d586e6f91645da86c5801e458 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 11 Jun 2024 11:09:11 +0000 Subject: [PATCH 4/7] chore: remove origin Signed-off-by: GitHub --- get-modified-packages/get-modified-packages.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index 7f57c5c0..3bc8b4f2 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -51,7 +51,7 @@ function find_package_dir() { # Function to check if the base ref SHA is in the commit history check_base_ref_in_history() { - git rev-list HEAD | grep -q "$(git rev-parse origin/"$base_branch")" + git rev-list HEAD | grep -q "$(git rev-parse "$base_branch")" } # Fetch the initial shallow clone depth @@ -64,7 +64,7 @@ while ! check_base_ref_in_history; do done # Get the modified files between base ref and HEAD -modified_files=$(git diff --name-only origin/"$base_branch"...HEAD) +modified_files=$(git diff --name-only $base_branch"...HEAD) # Find modified packages modified_package_dirs=() From c523a710403156a731afbc8ee19f41ffa62d3842 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 11 Jun 2024 11:42:46 +0000 Subject: [PATCH 5/7] chore: add some note --- get-modified-packages/get-modified-packages.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index 3bc8b4f2..a89ba751 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -60,6 +60,10 @@ depth=1 # Loop to deepen the fetch until the base ref SHA is included while ! check_base_ref_in_history; do depth=$((depth * 2)) + # NOTE: need to specify the bese_branch + # OK: git fetch origin/main --deepen=1 + # NG: git fetch origin main --deepen=1 + # => $base_branch need to be transformed from "origin/main" to "origin main" git fetch --deepen=$depth done From 69ae74e0d5eed4a541bb1e88ece4654a5d6f6ce0 Mon Sep 17 00:00:00 2001 From: Kotaro Yoshimoto Date: Tue, 11 Jun 2024 11:47:07 +0000 Subject: [PATCH 6/7] doc: fix some note Signed-off-by: GitHub --- get-modified-packages/get-modified-packages.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index a89ba751..527e59f9 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -16,6 +16,7 @@ while [ "${1-}" != "" ]; do done base_branch="${args[0]}" +# base_branch is like "origin/main" # Check args if [ "$base_branch" = "" ]; then @@ -61,8 +62,8 @@ depth=1 while ! check_base_ref_in_history; do depth=$((depth * 2)) # NOTE: need to specify the bese_branch - # OK: git fetch origin/main --deepen=1 - # NG: git fetch origin main --deepen=1 + # NG: git fetch origin/main --deepen=1 + # OK: git fetch origin main --deepen=1 # => $base_branch need to be transformed from "origin/main" to "origin main" git fetch --deepen=$depth done From ab0d0f9ffddb18795e6ed437730ddfc028d16d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Fatih=20C=C4=B1r=C4=B1t?= Date: Tue, 11 Jun 2024 15:31:23 +0300 Subject: [PATCH 7/7] echo github.base_ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: M. Fatih Cırıt --- get-modified-packages/get-modified-packages.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/get-modified-packages/get-modified-packages.sh b/get-modified-packages/get-modified-packages.sh index 527e59f9..1c0d3599 100755 --- a/get-modified-packages/get-modified-packages.sh +++ b/get-modified-packages/get-modified-packages.sh @@ -15,8 +15,9 @@ while [ "${1-}" != "" ]; do shift done -base_branch="${args[0]}" # base_branch is like "origin/main" +base_branch="${args[0]}" +echo "base_branch: $base_branch" # Check args if [ "$base_branch" = "" ]; then