Skip to content

Commit

Permalink
Merge branch 'jl/submodule-tests'
Browse files Browse the repository at this point in the history
* jl/submodule-tests:
  revert: add t3513 for submodule updates
  stash: add t3906 for submodule updates
  am: add t4255 for submodule updates
  cherry-pick: add t3512 for submodule updates
  pull: add t5572 for submodule updates
  rebase: add t3426 for submodule updates
  merge: add t7613 for submodule updates
  bisect: add t6041 for submodule updates
  reset: add t7112 for submodule updates
  read-tree: add t1013 for submodule updates
  apply: add t4137 for submodule updates
  checkout: call the new submodule update test framework
  submodules: add the lib-submodule-update.sh test library
  test-lib: add test_dir_is_empty()
  • Loading branch information
Junio C Hamano committed Jul 21, 2014
2 parents 3b3b61c + 1621c99 commit ad25da0
Show file tree
Hide file tree
Showing 14 changed files with 974 additions and 0 deletions.
680 changes: 680 additions & 0 deletions t/lib-submodule-update.sh

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions t/t1013-read-tree-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

test_description='read-tree can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

test_submodule_switch "git read-tree -u -m"

test_submodule_forced_switch "git read-tree -u --reset"

test_done
5 changes: 5 additions & 0 deletions t/t2013-checkout-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
test_description='checkout can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

test_expect_success 'setup' '
mkdir submodule &&
Expand Down Expand Up @@ -62,4 +63,8 @@ test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/
! test -s actual
'

test_submodule_switch "git checkout"

test_submodule_forced_switch "git checkout -f"

test_done
46 changes: 46 additions & 0 deletions t/t3426-rebase-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

test_description='rebase can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh
. "$TEST_DIRECTORY"/lib-rebase.sh

git_rebase () {
git status -su >expect &&
ls -1pR * >>expect &&
git checkout -b ours HEAD &&
echo x >>file1 &&
git add file1 &&
git commit -m add_x &&
git revert HEAD &&
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
git rebase "$1"
}

test_submodule_switch "git_rebase"

git_rebase_interactive () {
git status -su >expect &&
ls -1pR * >>expect &&
git checkout -b ours HEAD &&
echo x >>file1 &&
git add file1 &&
git commit -m add_x &&
git revert HEAD &&
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
set_fake_editor &&
echo "fake-editor.sh" >.git/info/exclude &&
git rebase -i "$1"
}

KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
# The real reason "replace directory with submodule" fails is because a
# directory "sub1" exists, but we reuse the suppression added for merge here
test_submodule_switch "git_rebase_interactive"

test_done
13 changes: 13 additions & 0 deletions t/t3512-cherry-pick-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

test_description='cherry-pick can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "git cherry-pick"

test_done
32 changes: 32 additions & 0 deletions t/t3513-revert-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

test_description='revert can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

# Create a revert that moves from HEAD (including any test modifications to
# the work tree) to $1 by first checking out $1 and reverting it. Reverting
# the revert is the transition we test for. We tar the current work tree
# first so we can restore the work tree test setup after doing the checkout
# and revert. We test here that the restored work tree content is identical
# to that at the beginning. The last revert is then tested by the framework.
git_revert () {
git status -su >expect &&
ls -1pR * >>expect &&
tar czf "$TRASH_DIRECTORY/tmp.tgz" * &&
git checkout "$1" &&
git revert HEAD &&
rm -rf * &&
tar xzf "$TRASH_DIRECTORY/tmp.tgz" &&
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
git revert HEAD
}

KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
test_submodule_switch "git_revert"

test_done
24 changes: 24 additions & 0 deletions t/t3906-stash-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

test_description='stash apply can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

git_stash () {
git status -su >expect &&
ls -1pR * >>expect &&
git read-tree -u -m "$1" &&
git stash &&
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
git stash apply
}

KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1
KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
test_submodule_switch "git_stash"

test_done
20 changes: 20 additions & 0 deletions t/t4137-apply-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

test_description='git apply handling submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

apply_index () {
git diff --ignore-submodules=dirty "..$1" | git apply --index -
}

test_submodule_switch "apply_index"

apply_3way () {
git diff --ignore-submodules=dirty "..$1" | git apply --3way -
}

test_submodule_switch "apply_3way"

test_done
21 changes: 21 additions & 0 deletions t/t4255-am-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

test_description='git am handling submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

am () {
git format-patch --stdout --ignore-submodules=dirty "..$1" | git am -
}

test_submodule_switch "am"

am_3way () {
git format-patch --stdout --ignore-submodules=dirty "..$1" | git am --3way -
}

KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "am_3way"

test_done
45 changes: 45 additions & 0 deletions t/t5572-pull-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

test_description='pull can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

reset_branch_to_HEAD () {
git branch -D "$1" &&
git checkout -b "$1" HEAD &&
git branch --set-upstream-to="origin/$1" "$1"
}

git_pull () {
reset_branch_to_HEAD "$1" &&
git pull
}

# pulls without conflicts
test_submodule_switch "git_pull"

git_pull_ff () {
reset_branch_to_HEAD "$1" &&
git pull --ff
}

test_submodule_switch "git_pull_ff"

git_pull_ff_only () {
reset_branch_to_HEAD "$1" &&
git pull --ff-only
}

test_submodule_switch "git_pull_ff_only"

git_pull_noff () {
reset_branch_to_HEAD "$1" &&
git pull --no-ff
}

KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "git_pull_noff"

test_done
32 changes: 32 additions & 0 deletions t/t6041-bisect-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

test_description='bisect can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

git_bisect () {
git status -su >expect &&
ls -1pR * >>expect &&
tar czf "$TRASH_DIRECTORY/tmp.tgz" * &&
GOOD=$(git rev-parse --verify HEAD) &&
git checkout "$1" &&
echo "foo" >bar &&
git add bar &&
git commit -m "bisect bad" &&
BAD=$(git rev-parse --verify HEAD) &&
git reset --hard HEAD^^ &&
git submodule update &&
git bisect start &&
git bisect good $GOOD &&
rm -rf * &&
tar xzf "$TRASH_DIRECTORY/tmp.tgz" &&
git status -su >actual &&
ls -1pR * >>actual &&
test_cmp expect actual &&
git bisect bad $BAD
}

test_submodule_switch "git_bisect"

test_done
14 changes: 14 additions & 0 deletions t/t7112-reset-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

test_description='reset can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

test_submodule_switch "git reset --keep"

test_submodule_switch "git reset --merge"

test_submodule_forced_switch "git reset --hard"

test_done
19 changes: 19 additions & 0 deletions t/t7613-merge-submodule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

test_description='merge can handle submodules'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-submodule-update.sh

# merges without conflicts
test_submodule_switch "git merge"

test_submodule_switch "git merge --ff"

test_submodule_switch "git merge --ff-only"

KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
test_submodule_switch "git merge --no-ff"

test_done
11 changes: 11 additions & 0 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@ test_path_is_dir () {
fi
}

# Check if the directory exists and is empty as expected, barf otherwise.
test_dir_is_empty () {
test_path_is_dir "$1" &&
if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
then
echo "Directory '$1' is not empty, it contains:"
ls -la "$1"
return 1
fi
}

test_path_is_missing () {
if [ -e "$1" ]
then
Expand Down

0 comments on commit ad25da0

Please sign in to comment.