Skip to content

Commit

Permalink
Merge pull request #151 from larsewi/gitconfig
Browse files Browse the repository at this point in the history
Fixed bug where git options where ignored
  • Loading branch information
olehermanse authored Dec 20, 2022
2 parents 6b4132e + 960f96f commit 425734c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
22 changes: 11 additions & 11 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(self, message):
_MODULES_URL = "https://archive.build.cfengine.com/modules"

PLURAL_S = lambda args, _: "s" if len(args[0]) > 1 else ""
FIRST_ARG = lambda args, _: "'%s'" % args[0]
FIRST_ARG_SLIST = lambda args, _: ", ".join("'%s'" % module for module in args[0])

_commands = OrderedDict()
Expand Down Expand Up @@ -1037,6 +1038,7 @@ def input_command(args, input_from="cfbs input"):


@cfbs_command("set-input")
@commit_after_command("Set input for module %s", [FIRST_ARG])
def set_input_command(name, infile):
config = CFBSConfig.get_instance()
module = config.get_module_from_build(name)
Expand Down Expand Up @@ -1104,19 +1106,17 @@ def _compare_list(a, b):

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
changes_made = old_data != data

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],
if changes_made:
write_json(path, data)
log.debug(
"Input data for '%s' changed, writing json to file '%s'" % (name, path)
)
return 0
else:
log.debug("Input data for '%s' unchanged, nothing to write / commit" % name)

return Result(0, changes_made, None, [path])


@cfbs_command("get-input")
Expand Down
43 changes: 43 additions & 0 deletions tests/shell/034_git_user_name_git_user_email.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
rm -rf cfbs.json .git

# Check that the options '--git-user-name' and '--git-user-email' is not
# ignored by the 'set-input' command.

cfbs --non-interactive init
cfbs --non-interactive add delete-files@0.0.1

cat <<EOF | cfbs --git-user-name=foo --git-user-email=bar@baz set-input delete-files -
[
{
"type": "list",
"variable": "files",
"namespace": "delete_files",
"bundle": "delete_files",
"label": "Files",
"subtype": [
{
"key": "path",
"type": "string",
"label": "Path",
"question": "Path to file"
},
{
"key": "why",
"type": "string",
"label": "Why",
"question": "Why should this file be deleted?",
"default": "Unknown"
}
],
"while": "Specify another file you want deleted on your hosts?",
"response": [{"path": "/tmp/bogus", "why": "Because I say so"}]
}
]
EOF

git log -n1 | grep "Author: foo <bar@baz>"
1 change: 1 addition & 0 deletions tests/shell/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ bash tests/shell/030_get_set_input.sh
bash tests/shell/031_get_set_input_pipe.sh
bash tests/shell/032_set_input_unordered.sh
bash tests/shell/033_add_commits_local_files.sh
bash tests/shell/034_git_user_name_git_user_email.sh

echo "All cfbs shell tests completed successfully!"

0 comments on commit 425734c

Please sign in to comment.