Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/107802


Change subject: Share Git module between Vagrant and Wikimedia Labs
......................................................................

Share Git module between Vagrant and Wikimedia Labs

This change extends the Vagrant Git module with the functionality
of the labs module while preserving the vagrant defaults.

Bug: 59864
Change-Id: I37769c73fbf9411e3ac7fa1b299c4afd95c59b38
---
M puppet/modules/git/manifests/clone.pp
1 file changed, 109 insertions(+), 32 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/02/107802/1

diff --git a/puppet/modules/git/manifests/clone.pp 
b/puppet/modules/git/manifests/clone.pp
index e1d5036..704c7f0 100644
--- a/puppet/modules/git/manifests/clone.pp
+++ b/puppet/modules/git/manifests/clone.pp
@@ -1,46 +1,123 @@
-# == Define: git::clone
+
+# Definition: git::clone
 #
-# Custom resource for cloning a remote git repository.
+# Creates a git clone of a specified origin into a top level directory.
 #
-# === Parameters
+# === Required parameters
 #
-# [*directory*]
-#   Name for target directory for repository content. It should not
-#   refer to an existing directory.
+# $+directory+:: path to clone the repository into.
 #
-# [*branch*]
-#   Name of branch to check out. Defaults to 'master'.
+# === Optional parameters
+# $+remote+:: Remote URL for the repository. If unspecified, the resource title
+#                      will be interpolated into $git::urlformat.
+# $+branch+:: Branch you would like to check out.
+# $+ensure+:: _absent_, _present_, or _latest_.  Defaults to _present_.
+#             - _present_ (default) will just clone once.
+#             - _latest_ will execute a git pull if there are any changes.
+#             - _absent_ will ensure the directory is deleted.
+# $+owner+:: Owner of $directory, default: _root_.  git commands will be run
+#  by this user.
+# $+group+:: Group owner of $directory, default: 'root'
+# $+mode+:: Permission mode of $directory, default: 0755
+# $+ssh+:: SSH command/wrapper to use when checking out, default: ''
+# $+timeout+:: Time out in seconds for the exec command, default: 300
 #
-# [*remote*]
-#   Remote URL for the repository. If unspecified, the resource title
-#   will be interpolated into $git::urlformat.
+# === Example usage
 #
-# === Examples
+#   git::clone{ 'my_clone_name':
+#       directory => '/path/to/clone/container',
+#       origin    => 'http://blabla.org/core.git',
+#       branch    => 'the_best_branch'
+#   }
 #
-#  Clone VisualEditor to MediaWiki extension path:
-#
-#  git::clone { 'extensions/VisualEditor':
-#      directory => '/vagrant/mediawiki/extensions/VisualEditor',
-#  }
-#
+# Will clone +http://blabla.org/core.git+ branch +the_best_branch+ at
+#  +/path/to/clone/container/core+
 define git::clone(
     $directory,
-    $branch = 'master',
-    $remote = undef,
-) {
+    $remote=undef,
+    $branch='',
+    $ssh='',
+    $ensure='present',
+    $owner='vagrant',
+    $group='www-data',
+    $timeout='0',
+    $depth='full',
+    $mode=0755) {
     include git
-
     $url = $remote ? {
-        undef   => sprintf($git::urlformat, $title),
-        default => $remote,
-    }
+               undef   => sprintf($git::urlformat, $title),
+               default => $remote,
+       }
 
-    exec { "git clone ${title}":
-        command     => "git clone --recursive --branch ${branch} ${url} 
${directory}",
-        creates     => "${directory}/.git",
-        require     => Package['git'],
-        user        => 'vagrant',
-        environment => 'HOME=/home/vagrant',
-        timeout     => 0,
+
+    case $ensure {
+        'absent': {
+            # make sure $directory does not exist
+            file { $directory:
+                ensure  => 'absent',
+                recurse => true,
+                force   => true,
+            }
+        }
+
+        # otherwise clone the repository
+        default: {
+            # if branch was specified
+            if $branch {
+                $brancharg = "-b $branch "
+            }
+            # else don't checkout a non-default branch
+            else {
+                $brancharg = ''
+            }
+            if $ssh {
+                $env = "GIT_SSH=$ssh"
+            }
+
+            $deptharg = $depth ?  {
+                'full'  => '',
+                default => " --depth=$depth"
+            }
+
+            # set PATH for following execs
+            Exec { path => '/usr/bin:/bin' }
+            # clone the repository
+            exec { "git_clone_${title}":
+                command     => "git clone ${brancharg}${url}${deptharg} 
$directory",
+                logoutput   => on_failure,
+                cwd         => '/tmp',
+                environment => $env,
+                creates     => "$directory/.git/config", #differenct to 
vagrant version but should be ok
+                user        => $owner,
+                group       => $group,
+                timeout     => $timeout,
+                require     => Package['git'], #change due to vagrant 
environment
+            }
+
+            if (!defined(File[$directory])) {
+                file { $directory:
+                    ensure  => 'directory',
+                    mode    => $mode,
+                    owner   => $owner,
+                    group   => $group,
+                    require => Exec["git_clone_${title}"],
+                }
+            }
+
+            # pull if $ensure == latest and if there are changes to merge in.
+            if $ensure == 'latest' {
+                exec { "git_pull_${title}":
+                    cwd       => $directory,
+                    command   => "git pull --quiet${deptharg}",
+                    logoutput => on_failure,
+                    # git diff --quiet will exit 1 (return false)
+                    #  if there are differences
+                    unless    => 'git fetch && git diff --quiet 
remotes/origin/HEAD',
+                    user      => $owner,
+                    group     => $group,
+                    require   => Exec["git_clone_${title}"],
+                }
+            }
+        }
     }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/107802
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37769c73fbf9411e3ac7fa1b299c4afd95c59b38
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to