commit 5daea63d1de8d927743e028ab6f2c673d7f78a56 Author: Arpit Mohan Date: Tue Jun 30 09:21:54 2020 +0530 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000000..f553951a67 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# MonoRepo diff --git a/merge_repos.sh b/merge_repos.sh new file mode 100755 index 0000000000..2d6b1778f3 --- /dev/null +++ b/merge_repos.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# This script takes a remote repository and merges it into +# the current one as a subdirectory + +set -e + +if [ -z "$1" ] +then + echo "Usage:" + echo " ./merge_repos.sh [name]" + echo " remote repository to merge" + echo " [name] sub-directory name (optional)" + exit +fi + +REPO_REMOTE="$1" +REPO_NAME="$2" + +# infer a name if one is not provided +if [ -z "$REPO_NAME" ] +then + REPO_NAME="${REPO_REMOTE##*/}" + REPO_NAME="${REPO_NAME%.*}" +fi + +REPO_DIR_TMP=${REPO_NAME} + +mkdir -p /tmp/${REPO_DIR_TMP} + +# REPO_DIR_TMP="$(mktemp -d -t "${TMPDIR:-/tmp}${REPO_NAME}.XXXX")" + +echo "REPO REMOTE: $REPO_REMOTE" +echo "REPO NAME: $REPO_NAME" +echo "REPO TMP DIR: $REPO_DIR_TMP" +echo +read -p "Press to continue" + +# clone other repo +git clone "$REPO_REMOTE" "$REPO_DIR_TMP" + +# rewrite the entire history into sub-directory +export REPO_NAME +( + cd $REPO_DIR_TMP && + git filter-branch -f --prune-empty --tree-filter ' + mkdir -p "${REPO_NAME}_tmp" + git ls-tree --name-only $GIT_COMMIT | xargs -I{} mv {} "${REPO_NAME}_tmp" + mv "${REPO_NAME}_tmp" "$REPO_NAME" + ' +) + +# merge the rewritten repo +git remote add "$REPO_NAME" "$REPO_DIR_TMP" +git fetch "$REPO_NAME" +# if you're running an older version of git, remove --allow-unrelated-histories +git checkout -b release +git merge --allow-unrelated-histories "$REPO_NAME/release" + +# delete the rewritten repo +rm -rf "$REPO_DIR_TMP" +git remote rm "$REPO_NAME"