[__git] Implement onchange triggers and messaging.

Closes #820.
This commit is contained in:
evilham 2020-06-18 00:47:16 +02:00
parent 852ac22b13
commit a40025d842
4 changed files with 33 additions and 1 deletions

View file

@ -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

View file

@ -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 <old_branch> -> <new_branch>
The directory tracks old_branch but should track new_branch, it will be changed
chown -R <owner>:<group>
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
--------

View file

@ -1,5 +1,6 @@
state
branch
group
onchange
owner
mode