2024-12-21 10:58:10 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
## Sync the Git Commits from NuttX Mirror Repo to NuttX Update Repo
|
2024-12-21 14:04:14 +08:00
|
|
|
## We use Git Bundles to preserve the Commit Hash. (Git Diff and Git Format Patch won't preserve the Committer Info!)
|
|
|
|
## Based on https://stackoverflow.com/a/12884254
|
2024-12-21 10:58:10 +08:00
|
|
|
|
|
|
|
set -e ## Exit when any command fails
|
|
|
|
set -x ## Echo commands
|
|
|
|
|
|
|
|
## Checkout the Upstream and Downstream Repos
|
|
|
|
tmp_dir=/tmp/sync-mirror-to-update
|
|
|
|
rm -rf $tmp_dir
|
|
|
|
mkdir $tmp_dir
|
|
|
|
cd $tmp_dir
|
2024-12-21 12:56:19 +08:00
|
|
|
git clone git@nuttx-forge:nuttx/nuttx-mirror upstream
|
2024-12-21 12:32:44 +08:00
|
|
|
git clone git@nuttx-forge:nuttx/nuttx-update downstream
|
2024-12-21 10:58:10 +08:00
|
|
|
|
2024-12-21 12:37:33 +08:00
|
|
|
## Find the First Commit to Sync
|
2024-12-21 12:56:19 +08:00
|
|
|
set +x ; echo "**** Last Upstream Commit" ; set -x
|
2024-12-21 12:37:33 +08:00
|
|
|
pushd upstream
|
|
|
|
upstream_commit=$(git rev-parse HEAD)
|
2024-12-21 12:56:19 +08:00
|
|
|
git --no-pager log -1
|
|
|
|
popd
|
|
|
|
set +x ; echo "**** Last Downstream Commit" ; set -x
|
|
|
|
pushd downstream
|
|
|
|
downstream_commit=$(git rev-parse HEAD)
|
|
|
|
git --no-pager log -1
|
2024-12-21 12:37:33 +08:00
|
|
|
popd
|
|
|
|
|
|
|
|
## If no new Commits to Sync: Quit
|
|
|
|
if [[ "$downstream_commit" == "$upstream_commit" ]]; then
|
|
|
|
set +x ; echo "**** No New Commits to Sync" ; set -x
|
|
|
|
exit
|
|
|
|
fi
|
2024-12-21 10:58:10 +08:00
|
|
|
|
2024-12-21 14:04:14 +08:00
|
|
|
## Emit the Commit Bundle for Upstream Repo
|
2024-12-21 10:58:10 +08:00
|
|
|
pushd upstream
|
2024-12-21 14:04:14 +08:00
|
|
|
git bundle create \
|
|
|
|
$tmp_dir/commit.bundle \
|
|
|
|
--branches --tags
|
2024-12-21 10:58:10 +08:00
|
|
|
popd
|
|
|
|
|
2024-12-21 14:04:14 +08:00
|
|
|
## Apply the Commit Bundle to Downstream Repo
|
2024-12-21 10:58:10 +08:00
|
|
|
pushd downstream
|
2024-12-21 14:04:14 +08:00
|
|
|
git pull $tmp_dir/commit.bundle master
|
2024-12-21 12:32:44 +08:00
|
|
|
git status
|
2024-12-21 10:58:10 +08:00
|
|
|
popd
|
|
|
|
|
|
|
|
## Commit the Patched Downstream Repo
|
|
|
|
pushd downstream
|
2024-12-21 13:27:54 +08:00
|
|
|
git push -f
|
2024-12-21 10:58:10 +08:00
|
|
|
popd
|
|
|
|
|
2024-12-21 13:27:54 +08:00
|
|
|
## Verify that Upstream and Downstream Commits are identical
|
|
|
|
set +x ; echo "**** Updated Downstream Commit" ; set -x
|
|
|
|
pushd downstream
|
|
|
|
git pull
|
|
|
|
downstream_commit2=$(git rev-parse HEAD)
|
|
|
|
git --no-pager log -1
|
2024-12-21 10:58:10 +08:00
|
|
|
popd
|
|
|
|
|
2024-12-21 13:27:54 +08:00
|
|
|
## If Not Identical: We have a problem
|
|
|
|
if [[ "$downstream_commit2" != "$upstream_commit" ]]; then
|
|
|
|
set +x ; echo "**** Sync Failed: Upstream and Downstream Commits don't match!" ; set -x
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-12-21 14:04:14 +08:00
|
|
|
|
|
|
|
set +x ; echo "**** Done!" ; set -x
|