Skip to content

Commit 6f08ca3

Browse files
authored
Merge pull request #441 from jkloetzke/fix-440
Properly support inline git SCM updates when enabling submodules
2 parents 562f995 + abe4fc4 commit 6f08ca3

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

pym/bob/scm/git.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,20 @@ async def __checkoutBranch(self, invoker, fetchCmd, switch):
219219
elif switch:
220220
# We're switching the ref. There we will actively change the branch which
221221
# is normally forbidden.
222-
assert not self.__submodules
223222
if await invoker.callCommand(["git", "show-ref", "-q", "--verify",
224223
"refs/heads/" + self.__branch]):
225224
# Branch does not exist. Create and checkout.
226225
await invoker.checkCommand(["git", "checkout", "--no-recurse-submodules",
227226
"-b", self.__branch, "remotes/origin/"+self.__branch], cwd=self.__dir)
227+
await self.__checkoutSubmodules(invoker)
228228
else:
229229
# Branch exists already. Checkout and fast forward...
230230
await invoker.checkCommand(["git", "checkout", "--no-recurse-submodules",
231231
self.__branch], cwd=self.__dir)
232+
preUpdate = await self.__updateSubmodulesPre(invoker)
232233
await invoker.checkCommand(["git", "-c", "submodule.recurse=0", "merge",
233234
"--ff-only", "refs/remotes/origin/"+self.__branch], cwd=self.__dir)
235+
await self.__updateSubmodulesPost(invoker, preUpdate)
234236
elif (await invoker.checkOutputCommand(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=self.__dir)) == self.__branch:
235237
# pull only if on original branch
236238
preUpdate = await self.__updateSubmodulesPre(invoker)

test/git-scm-switch/run.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,28 @@
77

88
git_dir1=$(mktemp -d)
99
git_dir2=$(mktemp -d)
10-
trap 'rm -rf "$git_dir1" "$git_dir2"' EXIT
10+
git_submod=$(mktemp -d)
11+
trap 'rm -rf "$git_dir1" "$git_dir2" "$git_submod"' EXIT
1112
cleanup
1213

1314
# Prepare git repositories
1415

16+
pushd "$git_submod"
17+
git init .
18+
git config user.email "bob@bob.bob"
19+
git config user.name test
20+
echo sub > sub.txt
21+
git add sub.txt
22+
git commit -m import
23+
popd
24+
1525
pushd "$git_dir1"
1626
git init .
1727
git config user.email "bob@bob.bob"
1828
git config user.name test
1929
echo "hello world" > test.txt
2030
git add test.txt
31+
git submodule add "$git_submod" submod
2132
git commit -m "first commit"
2233
git tag -a -m "First Tag" tag1
2334
git checkout -b foobar
@@ -54,9 +65,20 @@ run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="refs/heads/master" root
5465
expect_output "hello world" cat dev/src/root/1/workspace/test.txt
5566
expect_exist dev/src/root/1/workspace/canary.txt
5667

68+
# Enabling submodules on branch is ok
69+
run_bob dev -c submodules -DSCM_DIR="$git_dir1" -DSCM_REV="refs/heads/master" root
70+
expect_exist dev/src/root/1/workspace/canary.txt
71+
expect_exist dev/src/root/1/workspace/submod/sub.txt
72+
73+
# But disabling submodules on branch must trigger an attic move
74+
run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="refs/heads/master" root
75+
expect_not_exist dev/src/root/1/workspace/canary.txt
76+
expect_not_exist dev/src/root/1/workspace/submod/sub.txt
77+
5778
# Change repository but keep branch. This must move the dir into the attic
5879
# because they do not share a common history and the branch cannot be
5980
# forwarded.
81+
echo canary > dev/src/root/1/workspace/canary.txt
6082
run_bob dev -DSCM_DIR="$git_dir2" -DSCM_REV="refs/heads/master" root -j
6183
expect_not_exist dev/src/root/1/workspace/test.txt
6284
expect_output "hello bob" cat dev/src/root/1/workspace/bob.txt
@@ -71,13 +93,15 @@ expect_output "changed" cat dev/src/root/1/workspace/test.txt
7193
expect_not_exist dev/src/root/1/workspace/bob.txt
7294
expect_exist dev/src/root/1/workspace/canary.txt
7395

74-
# Enabling submodules is ok
96+
# Enabling submodules on tags is ok
7597
run_bob dev -c submodules -DSCM_DIR="$git_dir1" -DSCM_REV="refs/tags/tag2" root
7698
expect_exist dev/src/root/1/workspace/canary.txt
99+
expect_exist dev/src/root/1/workspace/submod/sub.txt
77100

78-
# But disabling submodules must trigger an attic move
101+
# But disabling submodules on tags must trigger an attic move
79102
run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="refs/tags/tag2" root
80103
expect_not_exist dev/src/root/1/workspace/canary.txt
104+
expect_not_exist dev/src/root/1/workspace/submod/sub.txt
81105

82106
# Trying to trigger an inline upgrade for dirty data will fail and move to attic.
83107
echo canary > dev/src/root/1/workspace/canary.txt

0 commit comments

Comments
 (0)