Skip to content

Commit

Permalink
e2e: Add test for submodule remote tracking sync
Browse files Browse the repository at this point in the history
  • Loading branch information
neutronth committed Sep 1, 2020
1 parent 27fe50d commit bec0339
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,111 @@ rm -rf $SUBMODULE
rm -rf $NESTED_SUBMODULE
pass

##############################################
# Test submodule remote tracking sync
##############################################
testcase "submodule-sync-remote-tracking"

# Init submodule repo
SUBMODULE1_REPO_NAME="sub1"
SUBMODULE1_NAME="submodule1-remote-tracking"
SUBMODULE1_BRANCH="branch1"

SUBMODULE2_REPO_NAME="sub2"
SUBMODULE2_NAME="submodule2-remote-tracking"

SUBMODULE3_REPO_NAME="sub3"
SUBMODULE3_NAME="submodule3-remote-tracking"

SUBMODULE1=$DIR/$SUBMODULE1_REPO_NAME
SUBMODULE2=$DIR/$SUBMODULE2_REPO_NAME
SUBMODULE3=$DIR/$SUBMODULE3_REPO_NAME

for i in $(seq 1 3); do
SUBMODULE=$(eval "echo \$SUBMODULE${i}")
SUBMODULE_NAME=$(eval "echo \$SUBMODULE${i}_NAME")

# Create submodule repo
mkdir "$SUBMODULE"
git -C "$SUBMODULE" init -q
echo "submodule${i}" > "$SUBMODULE"/submodule
git -C "$SUBMODULE" add submodule
git -C "$SUBMODULE" commit -aqm "init submodule${i} file"

# Add submodule
git -C "$REPO" submodule add -q --name $SUBMODULE_NAME file://$SUBMODULE
git -C "$REPO" commit -aqm "add submodule${i}"
done

GIT_SYNC \
--logtostderr \
--v=5 \
--wait=0.1 \
--repo="file://$REPO" \
--root="$ROOT" \
--dest="link" \
--submodules-remote-tracking="$SUBMODULE1_NAME,$SUBMODULE3_NAME" \
> "$DIR"/log."$TESTCASE" 2>&1 &
sleep 3
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule "submodule1"
assert_file_exists "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule "submodule2"
assert_file_exists "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule "submodule3"

## Make change in submodules repo listed in the remote tracking
echo "$TESTCASE 2" > "$SUBMODULE1"/submodule
git -C "$SUBMODULE1" commit -qam "$TESTCASE 2"
echo "$TESTCASE 2" > "$SUBMODULE3"/submodule
git -C "$SUBMODULE3" commit -qam "$TESTCASE 2"
sleep 3
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule "$TESTCASE 2"
assert_file_exists "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule "submodule2"
assert_file_exists "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule "$TESTCASE 2"

## Make change in submodules repo not listed in the remote tracking
git -C "$SUBMODULE1" reset -q --hard HEAD~1
git -C "$SUBMODULE3" reset -q --hard HEAD~1
echo "$TESTCASE 2" > "$SUBMODULE2"/submodule
git -C "$SUBMODULE2" commit -qam "$TESTCASE 3"
sleep 3
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule "submodule1"
assert_file_exists "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule "submodule2"
assert_file_exists "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule "submodule3"

## Remote tracking submodules branch
git -C "$SUBMODULE1" checkout -qb $SUBMODULE1_BRANCH
echo "$TESTCASE 4" > "$SUBMODULE1"/submodule
git -C "$SUBMODULE1" commit -qam "$TESTCASE 4"
git -C "$REPO" submodule -q set-branch --branch $SUBMODULE1_BRANCH -- $SUBMODULE1_NAME
git -C "$REPO" commit -aqm "submodule1 with branch"
sleep 3
assert_link_exists "$ROOT"/link
assert_file_exists "$ROOT"/link/file
assert_file_exists "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE1_REPO_NAME/submodule "$TESTCASE 4"
assert_file_exists "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE2_REPO_NAME/submodule "submodule2"
assert_file_exists "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule
assert_file_eq "$ROOT"/link/$SUBMODULE3_REPO_NAME/submodule "submodule3"

# Wrap up
rm -rf $SUBMODULE1 $SUBMODULE2 $SUBMODULE3
pass

##############################################
# Test SSH
##############################################
Expand Down

0 comments on commit bec0339

Please sign in to comment.