From 41c8572ad6a95aa9d5f772a683f3540a06784378 Mon Sep 17 00:00:00 2001 From: Michal Lula Date: Thu, 10 Oct 2019 16:50:02 +0200 Subject: [PATCH] :umbrella: add tests --- cmd/git-sync/main.go | 4 +- test_e2e.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index e73ef46..959044f 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -453,12 +453,12 @@ func addWorktreeAndSwap(ctx context.Context, gitRoot, dest, branch, rev string, log.V(0).Info("reset worktree to hash", "path", worktreePath, "hash", hash) // Update submodules - + // NOTICE: it works for repos with or without submodules _, err = runCommand(ctx, worktreePath, *flGitCmd, "submodule", "update", "--init", "--recursive") if err != nil { return err } - log.V(0).Info("updating submodules") + log.V(0).Info("updated submodules") if *flChmod != 0 { // set file permissions diff --git a/test_e2e.sh b/test_e2e.sh index d610145..d0f5d59 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -664,5 +664,103 @@ remove_sync_container wait pass +# Test submodule sync +testcase "submodule-sync" + +# Init submodule repo +SUBMODULE_REPO_NAME="sub" +SUBMODULE="$DIR/$SUBMODULE_REPO_NAME" +mkdir "$SUBMODULE" + +git -C "$SUBMODULE" init -q +echo "submodule" > "$SUBMODULE"/submodule +git -C "$SUBMODULE" add submodule +git -C "$SUBMODULE" commit -aqm "init submodule file" + +# Init nested submodule repo +NESTED_SUBMODULE_REPO_NAME="nested-sub" +NESTED_SUBMODULE="$DIR/$NESTED_SUBMODULE_REPO_NAME" +mkdir "$NESTED_SUBMODULE" + +git -C "$NESTED_SUBMODULE" init -q +echo "nested-submodule" > "$NESTED_SUBMODULE"/nested-submodule +git -C "$NESTED_SUBMODULE" add nested-submodule +git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule file" + +# Add submodule +git -C "$REPO" submodule add -q $SUBMODULE +git -C "$REPO" commit -aqm "add submodule" +GIT_SYNC \ + --logtostderr \ + --v=5 \ + --wait=0.1 \ + --repo="$REPO" \ + --branch=master \ + --rev=HEAD \ + --root="$ROOT" \ + --dest="link" > "$DIR"/log."$TESTCASE" 2>&1 & +sleep 3 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule +assert_file_eq "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule "submodule" +# Make change in submodule repo +echo "$TESTCASE 2" > "$SUBMODULE"/submodule +git -C "$SUBMODULE" commit -qam "$TESTCASE 2" +git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1 +git -C "$REPO" commit -qam "$TESTCASE 2" +sleep 3 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule +assert_file_eq "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule "$TESTCASE 2" +# Move backward in submodule repo +git -C "$SUBMODULE" reset -q --hard HEAD^ +git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1 +git -C "$REPO" commit -qam "$TESTCASE 3" +sleep 3 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule +assert_file_eq "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule "submodule" +# Add nested submodule to submodule repo +git -C "$SUBMODULE" submodule add -q $NESTED_SUBMODULE +git -C "$SUBMODULE" commit -aqm "add nested submodule" +git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1 +git -C "$REPO" commit -qam "$TESTCASE 4" +sleep 3 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule +assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule +assert_file_eq "$ROOT"/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule "nested-submodule" +# Remove nested submodule +git -C "$SUBMODULE" submodule deinit -q $NESTED_SUBMODULE_REPO_NAME +rm -rf "$SUBMODULE"/.git/modules/$NESTED_SUBMODULE_REPO_NAME +git -C "$SUBMODULE" rm -qf $NESTED_SUBMODULE_REPO_NAME +git -C "$SUBMODULE" commit -aqm "delete nested submodule" +git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1 +git -C "$REPO" commit -qam "$TESTCASE 5" +sleep 3 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_exists "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule +assert_file_absent "$ROOT"/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule +# Remove submodule +git -C "$REPO" submodule deinit -q $SUBMODULE_REPO_NAME +rm -rf "$REPO"/.git/modules/$SUBMODULE_REPO_NAME +git -C "$REPO" rm -qf $SUBMODULE_REPO_NAME +git -C "$REPO" commit -aqm "delete submodule" +sleep 3 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_absent "$ROOT"/link/$SUBMODULE_REPO_NAME/submodule +# Wrap up +rm -rf $SUBMODULE +rm -rf $NESTED_SUBMODULE +remove_sync_container +wait +pass + echo "cleaning up $DIR" rm -rf "$DIR"