From 2519e69fc89722114036f067a0cdb9c34c824b19 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 4 Jul 2022 14:37:58 +0300 Subject: [PATCH] Scripts for syncing the state of the vendor forlder with the workspace --- scripts/lib/git-helpers | 14 ++++++++++++++ scripts/sync-vendor-revisions-to-workspace | 22 ++++++++++++++++++++++ scripts/sync-workspace-revisions-to-vendor | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 scripts/lib/git-helpers create mode 100755 scripts/sync-vendor-revisions-to-workspace create mode 100755 scripts/sync-workspace-revisions-to-vendor diff --git a/scripts/lib/git-helpers b/scripts/lib/git-helpers new file mode 100644 index 0000000..c23e6cf --- /dev/null +++ b/scripts/lib/git-helpers @@ -0,0 +1,14 @@ +function copy_revision { + if [ -d "$1" ] && [ -d "$2" ]; then + pushd "$1" > /dev/null + COMMIT="$(git rev-parse HEAD)" + echo Switching "$(basename "$2")" to $COMMIT + popd > /dev/null + + pushd "$2" + git checkout "$COMMIT" + popd > /dev/null + else + echo "Usage: copy_revision " + fi +} diff --git a/scripts/sync-vendor-revisions-to-workspace b/scripts/sync-vendor-revisions-to-workspace new file mode 100755 index 0000000..3dd89c8 --- /dev/null +++ b/scripts/sync-vendor-revisions-to-workspace @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +shopt -s nocaseglob + +GIR_PROJECT_DIR=$(git rev-parse --show-toplevel) + +cd "$GIT_PROJECT_DIR" + +if [ ! -d vendor ]; then + SCRIPT_NAME=$(basename "$0") + echo "${SCRIPT_NAME} must be executed within a git repo, holding a 'vendor' folder" + exit 1 +fi + +source ../scripts/lib/git-helpers + +for submodule in vendor/*/; do + WORKSPACE_DIR="../$(basename "$submodule")" + if [ -d "$WORKSPACE_DIR" ]; then + copy_revision "$WORKSPACE_DIR" "$submodule" + fi +done diff --git a/scripts/sync-workspace-revisions-to-vendor b/scripts/sync-workspace-revisions-to-vendor new file mode 100755 index 0000000..2cd18dd --- /dev/null +++ b/scripts/sync-workspace-revisions-to-vendor @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +shopt -s nocaseglob + +GIR_PROJECT_DIR=$(git rev-parse --show-toplevel) + +cd "$GIT_PROJECT_DIR" + +if [ ! -d vendor ]; then + SCRIPT_NAME=$(basename "$0") + echo "${SCRIPT_NAME} must be executed within a git repo, holding a 'vendor' folder" + exit 1 +fi + +source ../scripts/lib/git-helpers + +for submodule in vendor/*/; do + WORKSPACE_DIR="../$(basename "$submodule")" + if [ -d "$WORKSPACE_DIR" ]; then + copy_revision "$submodule" "$WORKSPACE_DIR" + fi +done