From 3ff7621984727c89da84f9155e0eb598717a3551 Mon Sep 17 00:00:00 2001
From: contradict <contradict@gmail.com>
Date: Sun, 27 Jan 2013 19:53:22 -0800
Subject: [PATCH 1/2] __git respects --owner and --group, add --mode

After checkout, chown and chmod as specified. If already present, but
not possessing correct permissions, run chown and chmod as needed.
---
 cdist/conf/type/__git/explorer/group     |  5 +++++
 cdist/conf/type/__git/explorer/owner     |  5 +++++
 cdist/conf/type/__git/gencode-remote     | 27 ++++++++++++++++++++++--
 cdist/conf/type/__git/manifest           |  3 ---
 cdist/conf/type/__git/parameter/optional |  1 +
 5 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 cdist/conf/type/__git/explorer/group
 create mode 100644 cdist/conf/type/__git/explorer/owner

diff --git a/cdist/conf/type/__git/explorer/group b/cdist/conf/type/__git/explorer/group
new file mode 100644
index 00000000..4be8c1a6
--- /dev/null
+++ b/cdist/conf/type/__git/explorer/group
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+destination="/$__object_id/.git"
+
+stat --print "%G" ${destination} 2>/dev/null
diff --git a/cdist/conf/type/__git/explorer/owner b/cdist/conf/type/__git/explorer/owner
new file mode 100644
index 00000000..1f3c80e6
--- /dev/null
+++ b/cdist/conf/type/__git/explorer/owner
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+destination="/$__object_id/.git"
+
+stat --print "%U" ${destination} 2>/dev/null
diff --git a/cdist/conf/type/__git/gencode-remote b/cdist/conf/type/__git/gencode-remote
index 0f665d59..bc0c66cc 100644
--- a/cdist/conf/type/__git/gencode-remote
+++ b/cdist/conf/type/__git/gencode-remote
@@ -20,6 +20,9 @@
 #
 
 state_is="$(cat "$__object/explorer/state")"
+owner_is="$(cat "$__object/explorer/owner")"
+group_is="$(cat "$__object/explorer/group")"
+
 state_should=present
 [ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
 
@@ -30,11 +33,31 @@ source="$(cat "$__object/parameter/source")"
 
 destination="/$__object_id"
 
-[ "$state_should" = "$state_is" ] && exit 0
+owner=""
+[ -f "$__object/parameter/owner" ] && owner="$(cat "$__object/parameter/owner")"
+group=""
+[ -f "$__object/parameter/group" ] && group="$(cat "$__object/parameter/group")"
+mode=""
+[ -f "$__object/parameter/mode" ] && mode="$(cat "$__object/parameter/mode")"
+
+[  "$state_should" = "$state_is" -a \
+   "$owner" = "$owner_is" -a \
+   "$group" = "$group_is" -a \
+   -n "$mode" ] && exit 0
 
 case $state_should in
     present)
-        echo git clone --quiet --branch "$branch" "$source" "$destination"
+
+        if [ "$state_should" != "$state_is" ]; then
+            echo git clone --quiet --branch "$branch" "$source" "$destination"
+        fi
+        if [ \( -n ${owner} -a "$owner_is" != "$owner" \) -o \
+             \( -n ${group} -a "$group_is" != "$group" \) ]; then
+            echo chown -R ${owner}:${group} ${destination}
+        fi
+        if [ -n ${mode} ]; then
+            echo chmod -R ${mode} ${destination}
+        fi
     ;;
     # Handled in manifest
     absent)
diff --git a/cdist/conf/type/__git/manifest b/cdist/conf/type/__git/manifest
index 3b52ad2d..8d6a29e4 100644
--- a/cdist/conf/type/__git/manifest
+++ b/cdist/conf/type/__git/manifest
@@ -26,9 +26,6 @@ __package git --state present
 state_should=present
 [ -f "$__object/parameter/state" ] && state_should="$(cat "$__object/parameter/state")"
 
-[ -f "$__object/parameter/owner" ] && dirparams="$dirparams --owner $(cat "$__object/parameter/owner")"
-[ -f "$__object/parameter/group" ] && dirparams="$dirparams --group $(cat "$__object/parameter/group")"
-
 # Let __directory handle removal of git repos
 
 case "$state_should" in
diff --git a/cdist/conf/type/__git/parameter/optional b/cdist/conf/type/__git/parameter/optional
index d9684aaa..3c409162 100644
--- a/cdist/conf/type/__git/parameter/optional
+++ b/cdist/conf/type/__git/parameter/optional
@@ -2,3 +2,4 @@ state
 branch
 group
 owner
+mode

From b772e09d532385ec66bb2e2061ab28b92d848a16 Mon Sep 17 00:00:00 2001
From: contradict <contradict@gmail.com>
Date: Wed, 30 Jan 2013 00:48:08 -0800
Subject: [PATCH 2/2] Exit with no error if directory absent

Explorers need to handle the case of no directory.
---
 cdist/conf/type/__git/explorer/group | 2 +-
 cdist/conf/type/__git/explorer/owner | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/cdist/conf/type/__git/explorer/group b/cdist/conf/type/__git/explorer/group
index 4be8c1a6..1308c710 100644
--- a/cdist/conf/type/__git/explorer/group
+++ b/cdist/conf/type/__git/explorer/group
@@ -2,4 +2,4 @@
 
 destination="/$__object_id/.git"
 
-stat --print "%G" ${destination} 2>/dev/null
+stat --print "%G" ${destination} 2>/dev/null || exit 0
diff --git a/cdist/conf/type/__git/explorer/owner b/cdist/conf/type/__git/explorer/owner
index 1f3c80e6..8c36b035 100644
--- a/cdist/conf/type/__git/explorer/owner
+++ b/cdist/conf/type/__git/explorer/owner
@@ -2,4 +2,4 @@
 
 destination="/$__object_id/.git"
 
-stat --print "%U" ${destination} 2>/dev/null
+stat --print "%U" ${destination} 2>/dev/null || exit 0