Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions git-join-repos
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ self_name="$(basename $0)"
sed="sed"

if [ -z "$1" ]; then
echo "usage: $self_name filename (where filename is in format \"name url(\n)name url\")"
echo "usage: $self_name filename [branchname]"
echo " filename - where filename is in format \"name url(\n)name url\""
echo " branchname - name of branch to merge (default \"master\")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just set the default to main :-)

exit 99
fi

Expand All @@ -23,6 +25,7 @@ fi

data_file="$1"
name_urls="$(cat $data_file)"
branch_name="${2:-master}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default main

repo_name=
repo_url=

Expand All @@ -40,7 +43,7 @@ function split_line {
repo_url="${a#* }"
}

function repo_master_to_subdir {
function repo_branch_to_subdir {
git filter-branch -f --index-filter \
"git ls-files -s | ${sed} \"s|\t\\\"*|&${repo_name}/|\" |
GIT_INDEX_FILE=\$GIT_INDEX_FILE.new git update-index --index-info &&
Expand All @@ -59,12 +62,12 @@ for a in $name_urls; do
git rm -qrf --ignore-unmatch .
git remote add "$repo_name" "$repo_url"
git fetch "$repo_name"
git merge "$repo_name/master"
repo_master_to_subdir
git merge "$repo_name/$branch_name"
repo_branch_to_subdir
git remote remove "$repo_name"
done

git checkout --orphan master
git checkout --orphan $branch_name
git rm -qrf --ignore-unmatch .

for a in $name_urls; do
Expand Down