Skip to content

Instantly share code, notes, and snippets.

@dextercd
Created August 18, 2022 20:48
Show Gist options
  • Save dextercd/c05d80256726e01a8c28a9e98e25eb83 to your computer and use it in GitHub Desktop.
Save dextercd/c05d80256726e01a8c28a9e98e25eb83 to your computer and use it in GitHub Desktop.
Script for merging two Git repositories
#!/bin/bash
set -e
base_commit=30b923863d1768121c1ffb95932977e4283eceea
config_tree=56ecfa52fa08335c44ebcc9a8749779b3b9a7ecc
make_tree() {
sway_config=$1
new_config="$( (
set -e
git ls-tree $config_tree &&
echo "040000 tree $sway_config sway"
) | git mktree)"
(
set -e
echo "040000 tree $new_config configs"
git ls-tree $base_commit | grep -v $config_tree
) | git mktree
}
current_commit="$(git rev-parse HEAD)"
result_commit="$(git rev-list --reverse sway/main | (while IFS=$'\n' read -r sway_commit; do
sway_tree="$(git rev-parse "$sway_commit^{tree}")"
merged_tree=$(make_tree "$sway_tree")
message="Sway: $(git show --format=%B --no-patch "$sway_commit")"
merged_commit="$(git commit-tree -p "$current_commit" -m "$message" "$merged_tree")"
current_commit=$merged_commit
done
echo "$current_commit")
)"
echo "$result_commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment