Skip to content

Commit

Permalink
wip: support monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mano-lis committed Nov 6, 2023
1 parent 3e75340 commit ea4c6cd
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions template-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ url=""
threshold=20
debug=false
commit=""
directory=""

while [ "$#" -gt 0 ]; do
case "$1" in
Expand All @@ -16,6 +17,9 @@ while [ "$#" -gt 0 ]; do
--commit=*)
commit="${1#*=}"
;;
--directory=*)
directory="${1#*=}"
;;
*)
if [ -z "$url" ]; then
url="$1"
Expand All @@ -38,6 +42,7 @@ project_dir=$(pwd)
temp_dir=$(mktemp -d)
cd "$temp_dir" || return

mkdir temp
mkdir template
mkdir project
mkdir template_modified
Expand Down Expand Up @@ -74,11 +79,19 @@ estimate_similarity_index() {
ratio_percent=$(printf "%.0f" "$(echo "$ratio * 100" | bc)")
}

git_template_sync clone "$url" template/

git_template_sync clone "$project_dir" project/

cd template/ || return
if [ -n "$directory" ]; then
git_template_sync clone "$url" temp/
cd temp/ || return
git_template_sync subtree split -P "$directory" -b branch/template
cd ../template/ || return
git_template_sync init
git_template_sync pull ../temp/ branch/template
else
git_template_sync clone "$url" template/
cd template/ || return
fi

if [ -n "$commit" ]; then
git_template_sync reset --hard "$commit"
Expand All @@ -105,6 +118,7 @@ do
done

ratioThreshold=$(echo "$ratioMax - ($ratioMax - $ratioMin) / 3" | bc)
echo "$ratioThreshold"

rm -rf ../template_modified/*

Expand All @@ -121,15 +135,18 @@ do
if [ $index -eq 0 ]; then
minSum=$sum
wantedSha=$sha
index=$((index + 1))
fi
echo "$minSum"
echo "$sum"
echo "$wantedSha"
if [ $sum -lt "$minSum" ] || [ $sum -eq "$minSum" ]; then
minSum=$sum
wantedSha=$sha
fi
fi

cd template/ || return
index=$((index + 1))
done

echo "The targeted commit in the template is :"
Expand Down

0 comments on commit ea4c6cd

Please sign in to comment.