Skip to content

Commit e3b825f

Browse files
authored
Merge pull request #313 from nickanderson/ENT-14170/master
ENT-14170: Fixed updating to a pinned module version
2 parents c9af4ad + ffe3e04 commit e3b825f

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

cfbs/commands.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,14 @@ def update_command(to_update):
712712
log.debug("Module '%s' has no version attribute." % old_module["name"])
713713
continue
714714

715-
index_info = index.get_module_object(update.name)
715+
if update.version and not index.exists(update):
716+
log.warning(
717+
"Module '%s' version '%s' is not present in the index,"
718+
" cannot update it." % (old_module["name"], update.version)
719+
)
720+
continue
721+
722+
index_info = index.get_module_object(update)
716723
if not index_info:
717724
log.warning(
718725
"Module '%s' not present in the index, cannot update it."

cfbs/index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ def get_module_object(
245245
}
246246
object.update(specifics)
247247
object["version"] = version
248+
# The version index stores an empty "subdirectory" for
249+
# modules without one; an empty subdirectory is invalid, so
250+
# drop it (matches how 'cfbs add' cleans the module up).
251+
if object.get("subdirectory") == "":
252+
del object["subdirectory"]
248253

249254
assert object is not None
250255
module.update(object)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set -x
4+
cd tests/
5+
mkdir -p ./tmp/
6+
cd ./tmp/
7+
touch cfbs.json && rm cfbs.json
8+
rm -rf .git
9+
10+
# Inspect the masterfiles module specifically, rather than grepping the whole
11+
# file (which could match a field belonging to a different module).
12+
mf() { jq -r --arg k "$1" '.build[] | select(.name == "masterfiles") | .[$k]' cfbs.json; }
13+
mf_has() { jq -r --arg k "$1" '.build[] | select(.name == "masterfiles") | has($k)' cfbs.json; }
14+
15+
# Start on an old version of masterfiles.
16+
cfbs --non-interactive init --masterfiles=3.24.1
17+
[ "$(mf version)" = "3.24.1" ]
18+
[ "$(mf commit)" = "1171e2e50a229d78e2fdd4357a5d07ecc19bdbf4" ]
19+
20+
# Update to a specific intermediate version (not the latest). This must pin to
21+
# exactly 3.24.4, not jump to the newest release in the index.
22+
cfbs --non-interactive update masterfiles@3.24.4
23+
[ "$(mf version)" = "3.24.4" ]
24+
[ "$(mf commit)" = "ed4628805e352fd68d7d72664c859df5a4bb0715" ]
25+
# Why we assert on "subdirectory" here: pinning an update to a version now routes
26+
# through index.get_module_object() *with that version*, which reads the
27+
# per-version index. That index stores an empty "subdirectory" ("") for modules
28+
# that don't have one, and an empty subdirectory is invalid and breaks validation
29+
# and build. So get_module_object() now has to drop it (matching how 'cfbs add'
30+
# cleans the module up). This asserts it does not leak into cfbs.json, and the
31+
# following 'cfbs validate' confirms the resulting module is actually valid.
32+
[ "$(mf_has subdirectory)" = "false" ]
33+
cfbs validate
34+
35+
# Asking again for the same version is a no-op.
36+
cfbs --non-interactive update masterfiles@3.24.4
37+
[ "$(mf version)" = "3.24.4" ]
38+
39+
# Asking for an older version than the current one must not downgrade.
40+
cfbs --non-interactive update masterfiles@3.24.1
41+
[ "$(mf version)" = "3.24.4" ]
42+
43+
# A plain update (no @version) still moves to a strictly newer version than the
44+
# pin. Checking "!= 3.24.4" alone would also pass on a downgrade, so verify that
45+
# 3.24.4 sorts before the new version (i.e. the new version is the greater one).
46+
cfbs --non-interactive update masterfiles
47+
new_ver="$(mf version)"
48+
[ "$new_ver" != "3.24.4" ]
49+
[ "$(printf '%s\n%s\n' "3.24.4" "$new_ver" | sort -V | tail -1)" = "$new_ver" ]
50+
51+
cfbs build

tests/shell/all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ run_test tests/shell/046_update_from_url_branch.sh
9393
run_test tests/shell/047_absolute_path_modules.sh
9494
run_test tests/shell/048_remove_with_dependencies.sh
9595
run_test tests/shell/049_remove_with_circular_dependencies.sh
96+
run_test tests/shell/050_update_masterfiles_specific_version.sh
9697

9798
# Summary
9899
_suite_end=$(date +%s)

0 commit comments

Comments
 (0)