From 23be3213d588c2afdf331f8592a48bf860d06615 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 22 Nov 2022 12:07:59 +0100 Subject: [PATCH 1/2] Adjusted test code to check that set-input commits changes Should fail until I fix the bug. Signed-off-by: Ole Herman Schumacher Elgesem --- tests/shell/031_get_set_input_pipe.sh | 20 +++++++++++++++++++ ...nordered.sh => 032_set_input_unordered.sh} | 9 +++++++++ tests/shell/all.sh | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) rename tests/shell/{032_get_set_input_unordered.sh => 032_set_input_unordered.sh} (76%) diff --git a/tests/shell/031_get_set_input_pipe.sh b/tests/shell/031_get_set_input_pipe.sh index 2d0b5deb..63e8ab9a 100644 --- a/tests/shell/031_get_set_input_pipe.sh +++ b/tests/shell/031_get_set_input_pipe.sh @@ -9,6 +9,9 @@ rm -rf delete-files cfbs --non-interactive init cfbs --non-interactive add delete-files@0.0.1 + +commit_a=$(git rev-parse HEAD) + echo '[ { "type": "list", @@ -39,4 +42,21 @@ echo '[ } ]' | cfbs set-input delete-files - +commit_b=$(git rev-parse HEAD) + +test "x$commit_a" != "x$commit_b" + cfbs get-input delete-files - | cfbs set-input delete-files - + +commit_c=$(git rev-parse HEAD) + +test "x$commit_b" = "x$commit_c" + +# Error if the file has never been added: +git ls-files --error-unmatch delete-files/input.json + +# Error if there are staged (added, not yet commited) +git diff --exit-code --staged + +# Error if there are uncommited changes (to tracked files): +git diff --exit-code diff --git a/tests/shell/032_get_set_input_unordered.sh b/tests/shell/032_set_input_unordered.sh similarity index 76% rename from tests/shell/032_get_set_input_unordered.sh rename to tests/shell/032_set_input_unordered.sh index d0e6d247..e4d1d481 100644 --- a/tests/shell/032_get_set_input_unordered.sh +++ b/tests/shell/032_set_input_unordered.sh @@ -40,3 +40,12 @@ echo '[ "while": "Specify another file you want deleted on your hosts?" } ]' | cfbs --log=debug set-input delete-files - + +# Error if the file has never been added: +git ls-files --error-unmatch delete-files/input.json + +# Error if there are staged (added, not yet commited) +git diff --exit-code --staged + +# Error if there are uncommited changes (to tracked files): +git diff --exit-code diff --git a/tests/shell/all.sh b/tests/shell/all.sh index 7ff7df11..c8d0c115 100644 --- a/tests/shell/all.sh +++ b/tests/shell/all.sh @@ -34,6 +34,6 @@ bash tests/shell/028_init_masterfiles_version_3.18.2.sh bash tests/shell/029_init_masterfiles_version_3.18.1-1.sh bash tests/shell/030_get_set_input.sh bash tests/shell/031_get_set_input_pipe.sh -bash tests/shell/032_get_set_input_unordered.sh +bash tests/shell/032_set_input_unordered.sh echo "All cfbs shell tests completed successfully!" From dcc075897610b87ddefda643b36861be6cd77c44 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Tue, 22 Nov 2022 12:52:04 +0100 Subject: [PATCH 2/2] Fixed commiting of changes made by set-input Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/commands.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cfbs/commands.py b/cfbs/commands.py index c2e85276..18323a7f 100644 --- a/cfbs/commands.py +++ b/cfbs/commands.py @@ -41,6 +41,7 @@ from cfbs.index import _VERSION_INDEX, Index from cfbs.git import ( is_git_repo, + git_commit, git_get_config, git_set_config, git_init, @@ -1067,9 +1068,21 @@ def _compare_list(a, b): return 1 path = os.path.join(name, "input.json") - log.debug("Writing json to file '%s'" % path) - write_json(path, data) + log.debug("Comparing with data already in file '%s'" % path) + old_data = read_json(path) + if old_data == data: + log.debug("Input data for '%s' unchanged, nothing to write / commit" % name) + return 0 + + log.debug("Input data for '%s' changed, writing json to file '%s'" % (name, path)) + write_json(path, data) + if config.get("git", False): + git_commit( + "Set the input for module '%s'" % name, + edit_commit_msg=False, + scope=[path], + ) return 0