From 05c639e3b7a8fc2501d375466d1a04bf4a4cee68 Mon Sep 17 00:00:00 2001 From: Evilham Date: Thu, 18 Jun 2020 00:12:02 +0200 Subject: [PATCH] [__git]: Don't generate code only because owner/group is absent This closes #821 and improves readability. --- cdist/conf/type/__git/gencode-remote | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote index 11bd0a00..edc25aae 100755 --- a/cdist/conf/type/__git/gencode-remote +++ b/cdist/conf/type/__git/gencode-remote @@ -38,9 +38,13 @@ mode=$(cat "$__object/parameter/mode") [ -f "$__object/parameter/recursive" ] && recursive='--recurse-submodules' || recursive='' [ -f "$__object/parameter/shallow" ] && shallow='--depth 1 --shallow-submodules' || shallow='' +if { [ -n "$owner" ] && [ "$owner_is" != "$owner" ]; } || \ + { [ -n "$group" ] && [ "$group_is" != "$group" ]; }; then + needs_chown="YES" +fi + [ "$state_should" = "$state_is" ] \ - && [ "$owner" = "$owner_is" ] \ - && [ "$group" = "$group_is" ] \ + && [ -z "$needs_chown" ] \ && [ -n "$mode" ] && exit 0 case $state_should in @@ -48,8 +52,7 @@ case $state_should in if [ "$state_should" != "$state_is" ]; then echo git clone --quiet "$recursive" "$shallow" --branch "$branch" "$source" "$destination" fi - if { [ -n "$owner" ] && [ "$owner_is" != "$owner" ]; } || \ - { [ -n "$group" ] && [ "$group_is" != "$group" ]; }; then + if [ -n "$needs_chown" ]; then echo chown -R "${owner}:${group}" "$destination" fi if [ -f "$__object/parameter/mode-recursive" ]; then