From a40025d8427cf225d47d932d80aaab9a8025f041 Mon Sep 17 00:00:00 2001 From: Evilham Date: Thu, 18 Jun 2020 00:47:16 +0200 Subject: [PATCH] [__git] Implement onchange triggers and messaging. Closes #820. --- cdist/conf/type/__git/gencode-remote | 18 +++++++++++++++++- cdist/conf/type/__git/man.rst | 15 +++++++++++++++ .../conf/type/__git/parameter/default/onchange | 0 cdist/conf/type/__git/parameter/optional | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 cdist/conf/type/__git/parameter/default/onchange diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote index d52d44e1..7e0118fc 100755 --- a/cdist/conf/type/__git/gencode-remote +++ b/cdist/conf/type/__git/gencode-remote @@ -71,16 +71,24 @@ EOF fi # Actually clone the repository su -m "$git_user" -c "git clone --quiet '$recursive' '$shallow' --branch '$branch' '$source' '$destination'" + echo create >> "$__messages_out" + repo_changed="YES" elif [ "$branch_should" != "$branch_is" ]; then # User has changed tag / branch, let's update that echo su -m "$git_user" -c "git checkout '$branch_should'" + echo "change $branch_is -> $branch_should" >> "$__messages_out" + repo_changed="YES" elif [ "$needs_update" = "YES" ]; then # The remote has newer information than our repository. # Fetch was done in the explorer, here we can just pull echo su -m "$git_user" -c "git -C '$destination' pull" + echo update >> "$__messages_out" + repo_changed="YES" fi if [ -n "$needs_chown" ]; then echo chown -R "${owner}:${group}" "$destination" + echo "chown -R '${owner}:${group}'" >> "$__messages_out" + repo_changed="YES" fi if [ -f "$__object/parameter/mode-recursive" ]; then mode_recursive="-R" @@ -91,7 +99,11 @@ EOF ;; absent) - # Handled in manifest + # Handled in manifest, except for the change triggers + if [ "$state_should" != "$state_is" ]; then + echo remove >> "$__messages_out" + repo_changed="YES" + fi ;; *) @@ -99,3 +111,7 @@ EOF exit 1 ;; esac + +if [ -n "$repo_changed" ]; then + cat "$__object/parameter/onchange" +fi diff --git a/cdist/conf/type/__git/man.rst b/cdist/conf/type/__git/man.rst index dfcbc0f6..2db4d548 100644 --- a/cdist/conf/type/__git/man.rst +++ b/cdist/conf/type/__git/man.rst @@ -35,6 +35,9 @@ mode By default it only applies to the top-level directory. See the mode-recursive parameter as well. +onchange + The code to run if the repository is first-cloned, changes or is removed. + owner User to chown to. @@ -50,6 +53,18 @@ recursive shallow Sets --depth=1 and --shallow-submodules for cloning repositories with big history. +MESSAGES +-------- +change -> + The directory tracks old_branch but should track new_branch, it will be changed +chown -R : + Changed ownership +create + Freshly created the directory with the repository clone +remove + The directory with the repository exists, but state is absent, it will be removed +update + The repository tracks a branch that has been updated on the remote EXAMPLES -------- diff --git a/cdist/conf/type/__git/parameter/default/onchange b/cdist/conf/type/__git/parameter/default/onchange new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__git/parameter/optional b/cdist/conf/type/__git/parameter/optional index 3c409162..13feb97e 100644 --- a/cdist/conf/type/__git/parameter/optional +++ b/cdist/conf/type/__git/parameter/optional @@ -1,5 +1,6 @@ state branch group +onchange owner mode