Skip to content

Commit

Permalink
add support for moving dir to root
Browse files Browse the repository at this point in the history
add support to use subdirectory as the root in the new repo, if only a single subdirectory is specified.

Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
  • Loading branch information
akhilerm committed Oct 6, 2023
1 parent b2ba2c7 commit 2747573
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions artifacts/scripts/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,20 @@ function filter-repo() {
local recursive_delete_pattern="${3}"
echo "Running git filter-branch ..."

# create the --path <subdir> commands for all the required subdirectories
# convert subdirectory to an array by splitting the : separated string
IFS=':' read -r -a subdirectories <<< "$subdirectories"
local path_filter_command=""
for dir in "${subdirectories[@]}"; do
path_filter_command+=" --path ${dir}"
done
if [[ "${subdirectories}" == *":"* ]]; then
# create the --path <subdir> commands for all the required subdirectories
# convert subdirectory to an array by splitting the : separated string
IFS=':' read -r -a subdirectories <<< "$subdirectories"
for dir in "${subdirectories[@]}"; do
path_filter_command+=" --path ${dir}"
done
else
# TODO (akhilerm): add a switch to decide, if single subdirectory should become root of the
# project, or be a subdirectory itself
# if there is only one subdirectory, that will be converted to the root of the project
path_filter_command+=" --subdirectory-filter=${subdirectories}"
fi

local index_filter=""
if [ -n "${recursive_delete_pattern}" ]; then
Expand All @@ -631,7 +638,6 @@ function filter-repo() {
fi

# TODO(akhilerm) make sure index filter is honored
# TODO(akhilerm) make sure if only a single directory needs to be published, the directory acts as the root
# TODO(akhilerm) nit if the commit message ends in a new line, we dont need new line here in commit callback, else add new line
# TODO(akhilerm) instead of doing the --refs partial filter, we can apply the filter and then cherry pick only from the needed branches
git filter-repo \
Expand Down

0 comments on commit 2747573

Please sign in to comment.