| 1 |
# |
| 2 |
# Tests for track_submodules with non-master default branches |
| 3 |
# |
| 4 |
# Verifies that get_submodule_branch() correctly reads the branch from |
| 5 |
# .gitmodules and falls back to remote HEAD, instead of hardcoding 'master'. |
| 6 |
# |
| 7 |
|
| 8 |
# --- Setup --- |
| 9 |
|
| 10 |
- name: TRACK-SUBMODULES-BRANCH | allow local file transport for submodule clones |
| 11 |
shell: git config --global protocol.file.allow always |
| 12 |
|
| 13 |
- name: TRACK-SUBMODULES-BRANCH | create local repo dirs |
| 14 |
file: |
| 15 |
path: "{{ item }}" |
| 16 |
state: directory |
| 17 |
loop: |
| 18 |
- "{{ repo_dir }}/track_sub_remote" |
| 19 |
- "{{ repo_dir }}/track_sub_parent" |
| 20 |
|
| 21 |
- name: TRACK-SUBMODULES-BRANCH | create a submodule repo with 'main' as default branch |
| 22 |
shell: | |
| 23 |
set -eEu |
| 24 |
git init |
| 25 |
echo "initial" > file1.txt |
| 26 |
git add file1.txt |
| 27 |
git commit -m "initial commit on main" |
| 28 |
args: |
| 29 |
chdir: "{{ repo_dir }}/track_sub_remote" |
| 30 |
|
| 31 |
- name: TRACK-SUBMODULES-BRANCH | create parent repo with submodule pointing to 'main' |
| 32 |
shell: | |
| 33 |
set -eEu |
| 34 |
git init |
| 35 |
echo "parent" > README.md |
| 36 |
git add README.md |
| 37 |
git commit -m "parent initial" |
| 38 |
|
| 39 |
git submodule add "{{ repo_dir }}/track_sub_remote" sub1 |
| 40 |
git commit -m "add submodule sub1" |
| 41 |
args: |
| 42 |
chdir: "{{ repo_dir }}/track_sub_parent" |
| 43 |
|
| 44 |
- name: TRACK-SUBMODULES-BRANCH | set explicit branch in .gitmodules |
| 45 |
shell: | |
| 46 |
set -eEu |
| 47 |
git config -f .gitmodules submodule.sub1.branch main |
| 48 |
git add .gitmodules |
| 49 |
git commit -m "set submodule branch to main" |
| 50 |
args: |
| 51 |
chdir: "{{ repo_dir }}/track_sub_parent" |
| 52 |
|
| 53 |
# --- Test 1: track_submodules detects updates on configured branch (main) --- |
| 54 |
|
| 55 |
- name: TRACK-SUBMODULES-BRANCH | clean checkout dir |
| 56 |
file: |
| 57 |
state: absent |
| 58 |
path: "{{ checkout_dir }}" |
| 59 |
|
| 60 |
- name: TRACK-SUBMODULES-BRANCH | clone parent with recursive submodules |
| 61 |
git: |
| 62 |
repo: "{{ repo_dir }}/track_sub_parent" |
| 63 |
dest: "{{ checkout_dir }}" |
| 64 |
recursive: yes |
| 65 |
track_submodules: yes |
| 66 |
|
| 67 |
- name: TRACK-SUBMODULES-BRANCH | record initial state (should not be changed) |
| 68 |
git: |
| 69 |
repo: "{{ repo_dir }}/track_sub_parent" |
| 70 |
dest: "{{ checkout_dir }}" |
| 71 |
recursive: yes |
| 72 |
track_submodules: yes |
| 73 |
register: track_initial |
| 74 |
|
| 75 |
- name: TRACK-SUBMODULES-BRANCH | assert no change on first re-run |
| 76 |
assert: |
| 77 |
that: |
| 78 |
- not track_initial.changed |
| 79 |
|
| 80 |
- name: TRACK-SUBMODULES-BRANCH | push a new commit to the submodule remote |
| 81 |
shell: | |
| 82 |
set -eEu |
| 83 |
echo "update" > file2.txt |
| 84 |
git add file2.txt |
| 85 |
git commit -m "second commit on main" |
| 86 |
args: |
| 87 |
chdir: "{{ repo_dir }}/track_sub_remote" |
| 88 |
|
| 89 |
- name: TRACK-SUBMODULES-BRANCH | re-run with track_submodules to detect remote update |
| 90 |
git: |
| 91 |
repo: "{{ repo_dir }}/track_sub_parent" |
| 92 |
dest: "{{ checkout_dir }}" |
| 93 |
recursive: yes |
| 94 |
track_submodules: yes |
| 95 |
register: track_after_update |
| 96 |
|
| 97 |
- name: TRACK-SUBMODULES-BRANCH | assert change detected after submodule remote was updated |
| 98 |
assert: |
| 99 |
that: |
| 100 |
- track_after_update.changed |
| 101 |
|
| 102 |
# --- Test 2: track_submodules works with remote HEAD fallback (no branch in .gitmodules) --- |
| 103 |
|
| 104 |
- name: TRACK-SUBMODULES-BRANCH | create dirs for fallback test |
| 105 |
file: |
| 106 |
path: "{{ item }}" |
| 107 |
state: directory |
| 108 |
loop: |
| 109 |
- "{{ repo_dir }}/track_sub_remote_fb" |
| 110 |
- "{{ repo_dir }}/track_sub_parent_fb" |
| 111 |
|
| 112 |
- name: TRACK-SUBMODULES-BRANCH | create submodule repo for fallback test |
| 113 |
shell: | |
| 114 |
set -eEu |
| 115 |
git init |
| 116 |
echo "initial" > file1.txt |
| 117 |
git add file1.txt |
| 118 |
git commit -m "initial commit" |
| 119 |
args: |
| 120 |
chdir: "{{ repo_dir }}/track_sub_remote_fb" |
| 121 |
|
| 122 |
- name: TRACK-SUBMODULES-BRANCH | create parent repo without explicit branch in .gitmodules |
| 123 |
shell: | |
| 124 |
set -eEu |
| 125 |
git init |
| 126 |
echo "parent" > README.md |
| 127 |
git add README.md |
| 128 |
git commit -m "parent initial" |
| 129 |
|
| 130 |
git submodule add "{{ repo_dir }}/track_sub_remote_fb" sub_fb |
| 131 |
git commit -m "add submodule sub_fb (no explicit branch)" |
| 132 |
args: |
| 133 |
chdir: "{{ repo_dir }}/track_sub_parent_fb" |
| 134 |
|
| 135 |
- name: TRACK-SUBMODULES-BRANCH | clean checkout dir for fallback test |
| 136 |
file: |
| 137 |
state: absent |
| 138 |
path: "{{ checkout_dir }}" |
| 139 |
|
| 140 |
- name: TRACK-SUBMODULES-BRANCH | clone parent (fallback test) |
| 141 |
git: |
| 142 |
repo: "{{ repo_dir }}/track_sub_parent_fb" |
| 143 |
dest: "{{ checkout_dir }}" |
| 144 |
recursive: yes |
| 145 |
track_submodules: yes |
| 146 |
|
| 147 |
- name: TRACK-SUBMODULES-BRANCH | push a new commit to fallback submodule remote |
| 148 |
shell: | |
| 149 |
set -eEu |
| 150 |
echo "new content" > file2.txt |
| 151 |
git add file2.txt |
| 152 |
git commit -m "second commit" |
| 153 |
args: |
| 154 |
chdir: "{{ repo_dir }}/track_sub_remote_fb" |
| 155 |
|
| 156 |
- name: TRACK-SUBMODULES-BRANCH | re-run track_submodules with fallback branch detection |
| 157 |
git: |
| 158 |
repo: "{{ repo_dir }}/track_sub_parent_fb" |
| 159 |
dest: "{{ checkout_dir }}" |
| 160 |
recursive: yes |
| 161 |
track_submodules: yes |
| 162 |
register: track_fallback_update |
| 163 |
|
| 164 |
- name: TRACK-SUBMODULES-BRANCH | assert change detected with fallback branch |
| 165 |
assert: |
| 166 |
that: |
| 167 |
- track_fallback_update.changed |
| 168 |
|
| 169 |
# --- Test 3: two submodules with different default branches --- |
| 170 |
|
| 171 |
- name: TRACK-SUBMODULES-BRANCH | create dirs for multi-branch test |
| 172 |
file: |
| 173 |
path: "{{ item }}" |
| 174 |
state: directory |
| 175 |
loop: |
| 176 |
- "{{ repo_dir }}/track_sub_remote_master" |
| 177 |
- "{{ repo_dir }}/track_sub_remote_main" |
| 178 |
- "{{ repo_dir }}/track_sub_parent_multi" |
| 179 |
|
| 180 |
- name: TRACK-SUBMODULES-BRANCH | create submodule repo with 'develop' branch |
| 181 |
shell: | |
| 182 |
set -eEu |
| 183 |
git init |
| 184 |
echo "initial" > file1.txt |
| 185 |
git add file1.txt |
| 186 |
git commit -m "initial on main" |
| 187 |
git checkout -b develop |
| 188 |
echo "dev" > file2.txt |
| 189 |
git add file2.txt |
| 190 |
git commit -m "initial on develop" |
| 191 |
args: |
| 192 |
chdir: "{{ repo_dir }}/track_sub_remote_master" |
| 193 |
|
| 194 |
- name: TRACK-SUBMODULES-BRANCH | create submodule repo using 'main' |
| 195 |
shell: | |
| 196 |
set -eEu |
| 197 |
git init |
| 198 |
echo "initial" > file1.txt |
| 199 |
git add file1.txt |
| 200 |
git commit -m "initial on main" |
| 201 |
args: |
| 202 |
chdir: "{{ repo_dir }}/track_sub_remote_main" |
| 203 |
|
| 204 |
- name: TRACK-SUBMODULES-BRANCH | create parent with two submodules on different branches |
| 205 |
shell: | |
| 206 |
set -eEu |
| 207 |
git init |
| 208 |
echo "parent" > README.md |
| 209 |
git add README.md |
| 210 |
git commit -m "parent initial" |
| 211 |
|
| 212 |
git submodule add -b develop "{{ repo_dir }}/track_sub_remote_master" sub_develop |
| 213 |
git submodule add "{{ repo_dir }}/track_sub_remote_main" sub_main |
| 214 |
git config -f .gitmodules submodule.sub_main.branch main |
| 215 |
git add .gitmodules |
| 216 |
git commit -m "add two submodules with different branches" |
| 217 |
args: |
| 218 |
chdir: "{{ repo_dir }}/track_sub_parent_multi" |
| 219 |
|
| 220 |
- name: TRACK-SUBMODULES-BRANCH | clean checkout dir for multi-branch test |
| 221 |
file: |
| 222 |
state: absent |
| 223 |
path: "{{ checkout_dir }}" |
| 224 |
|
| 225 |
- name: TRACK-SUBMODULES-BRANCH | clone parent with two submodules |
| 226 |
git: |
| 227 |
repo: "{{ repo_dir }}/track_sub_parent_multi" |
| 228 |
dest: "{{ checkout_dir }}" |
| 229 |
recursive: yes |
| 230 |
track_submodules: yes |
| 231 |
|
| 232 |
- name: TRACK-SUBMODULES-BRANCH | re-run should show no changes |
| 233 |
git: |
| 234 |
repo: "{{ repo_dir }}/track_sub_parent_multi" |
| 235 |
dest: "{{ checkout_dir }}" |
| 236 |
recursive: yes |
| 237 |
track_submodules: yes |
| 238 |
register: track_multi_initial |
| 239 |
|
| 240 |
- name: TRACK-SUBMODULES-BRANCH | assert no change on re-run with two submodules |
| 241 |
assert: |
| 242 |
that: |
| 243 |
- not track_multi_initial.changed |
| 244 |
|
| 245 |
- name: TRACK-SUBMODULES-BRANCH | push update to only the 'main' submodule |
| 246 |
shell: | |
| 247 |
set -eEu |
| 248 |
echo "update" > file2.txt |
| 249 |
git add file2.txt |
| 250 |
git commit -m "second commit on main" |
| 251 |
args: |
| 252 |
chdir: "{{ repo_dir }}/track_sub_remote_main" |
| 253 |
|
| 254 |
- name: TRACK-SUBMODULES-BRANCH | re-run should detect change in sub_main only |
| 255 |
git: |
| 256 |
repo: "{{ repo_dir }}/track_sub_parent_multi" |
| 257 |
dest: "{{ checkout_dir }}" |
| 258 |
recursive: yes |
| 259 |
track_submodules: yes |
| 260 |
register: track_multi_update |
| 261 |
|
| 262 |
- name: TRACK-SUBMODULES-BRANCH | assert change detected with mixed-branch submodules |
| 263 |
assert: |
| 264 |
that: |
| 265 |
- track_multi_update.changed |
| 266 |
|
| 267 |
# --- Cleanup --- |
| 268 |
|
| 269 |
- name: TRACK-SUBMODULES-BRANCH | clean checkout dir |
| 270 |
file: |
| 271 |
state: absent |
| 272 |
path: "{{ checkout_dir }}" |