diff options
-rw-r--r-- | .sync.yml | 6 | ||||
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | README.markdown | 1226 | ||||
-rw-r--r-- | examples/git/shallow-clone-with-just-one-commit.pp | 7 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 36 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/svn.rb | 14 | ||||
-rw-r--r-- | lib/puppet/type/vcsrepo.rb | 10 | ||||
-rw-r--r-- | spec/acceptance/create_repo_spec.rb | 16 | ||||
-rw-r--r-- | spec/acceptance/modules_1800_spec.rb | 41 | ||||
-rw-r--r-- | spec/acceptance/modules_2326_spec.rb | 69 | ||||
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/git_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 30 |
13 files changed, 837 insertions, 633 deletions
@@ -1,11 +1,5 @@ --- .travis.yml: - script: "\"bundle exec rake spec SPEC_OPTS='--format documentation'\"" - extras: - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" Rakefile: unmanaged: true spec/spec_helper.rb: diff --git a/.travis.yml b/.travis.yml index 727f6e7..1155a2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,10 +16,6 @@ matrix: env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes" - rvm: 2.1.6 env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" allow_failures: - rvm: 2.1.6 env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes" @@ -16,6 +16,7 @@ group :development, :unit_tests do gem 'simplecov', :require => false gem 'puppet_facts', :require => false gem 'json', :require => false + gem 'pry', :require => false end group :system_tests do diff --git a/README.markdown b/README.markdown index badb1ce..e878891 100644 --- a/README.markdown +++ b/README.markdown @@ -1,608 +1,608 @@ -#vcsrepo
-
-####Table of Contents
-
-1. [Overview](#overview)
-2. [Module Description - What the module does and why it is useful](#module-description)
-3. [Setup - The basics of getting started with vcsrepo](#setup)
- * [Setup requirements](#setup-requirements)
- * [Beginning with vcsrepo](#beginning-with-vcsrepo)
-4. [Usage - Configuration options and additional functionality](#usage)
- * [Git](#git)
- * [Bazaar](#bazaar)
- * [CVS](#cvs)
- * [Mercurial](#mercurial)
- * [Perforce](#perforce)
- * [Subversion](#subversion)
-5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
- * [Type: vcsrepo](#type-vcsrepo)
- * [Providers](#providers)
- * [Features](#features)
- * [Parameters](#parameters)
-5. [Limitations - OS compatibility, etc.](#limitations)
-6. [Development - Guide for contributing to the module](#development)
-
-##Overview
-
-The vcsrepo module lets you use Puppet to easily deploy content from your version control system (VCS).
-
-##Module Description
-
-The vcsrepo module provides a single type with providers to support the following version control systems:
-
-* [Git](#git)
-* [Bazaar](#bazaar)
-* [CVS](#cvs)
-* [Mercurial](#mercurial)
-* [Perforce](#perforce)
-* [Subversion](#subversion)
-
-**Note:** `git` is the only vcs provider officially [supported by Puppet Labs](https://forge.puppetlabs.com/supported).
-
-##Setup
-
-###Setup Requirements
-
-The `vcsrepo` module does not install any VCS software for you. You must install a VCS before you can use this module.
-
-Like Puppet in general, the `vcsrepo` module does not automatically create parent directories for the files it manages. Make sure to set up any needed directory structures before you get started.
-
-###Beginning with vcsrepo
-
-To create and manage a blank repository, define the type `vcsrepo` with a path to your repository and supply the `provider` parameter based on the [VCS you're using](#usage).
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
-}
-~~~
-
-##Usage
-
-**Note:** `git` is the only vcsrepo provider officially [supported by Puppet Labs](https://forge.puppetlabs.com/supported).
-
-###Git
-
-####Create a blank repository
-
-To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
-}
-~~~
-
-If you're managing a central or official repository, you might want to make it a bare repository. To do this, set `ensure` to 'bare':
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => bare,
- provider => git,
-}
-~~~
-
-####Clone/pull a repository
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
- source => 'git://example.com/repo.git',
-}
-~~~
-
-By default, `vcsrepo` will use the HEAD of the source repository's master branch. To use another branch or a specific commit, set `revision` to either a branch name or a commit SHA or tag.
-
-Branch name:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
- source => 'git://example.com/repo.git',
- revision => 'development',
-}
-~~~
-
-SHA:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
- source => 'git://example.com/repo.git',
- revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
-}
-~~~
-
-Tag:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
- source => 'git://example.com/repo.git',
- revision => '1.1.2rc1',
-}
-~~~
-
-To check out a branch as a specific user, supply the `user` parameter:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
- source => 'git://example.com/repo.git',
- revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31',
- user => 'someUser',
-}
-~~~
-
-To keep the repository at the latest revision, set `ensure` to 'latest'.
-
-**WARNING:** this overwrites any local changes to the repository:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => git,
- source => 'git://example.com/repo.git',
- revision => 'master',
-}
-~~~
-
-To clone the repository but skip initializing submodules, set `submodules` to 'false':
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => git,
- source => 'git://example.com/repo.git',
- submodules => false,
-}
-~~~
-
-####Use multiple remotes with a repository
-In place of a single string, you can set `source` to a hash of one or more name => URL pairs:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => git,
- remote => 'origin'
- source => {
- 'origin' => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git',
- 'other_remote' => 'https://github.com/other_user/puppetlabs-vcsrepo.git'
- },
-}
-~~~
-
+#vcsrepo + +####Table of Contents + +1. [Overview](#overview) +2. [Module Description - What the module does and why it is useful](#module-description) +3. [Setup - The basics of getting started with vcsrepo](#setup) + * [Setup requirements](#setup-requirements) + * [Beginning with vcsrepo](#beginning-with-vcsrepo) +4. [Usage - Configuration options and additional functionality](#usage) + * [Git](#git) + * [Bazaar](#bazaar) + * [CVS](#cvs) + * [Mercurial](#mercurial) + * [Perforce](#perforce) + * [Subversion](#subversion) +5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) + * [Type: vcsrepo](#type-vcsrepo) + * [Providers](#providers) + * [Features](#features) + * [Parameters](#parameters) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) + +##Overview + +The vcsrepo module lets you use Puppet to easily deploy content from your version control system (VCS). + +##Module Description + +The vcsrepo module provides a single type with providers to support the following version control systems: + +* [Git](#git) +* [Bazaar](#bazaar) +* [CVS](#cvs) +* [Mercurial](#mercurial) +* [Perforce](#perforce) +* [Subversion](#subversion) + +**Note:** `git` is the only vcs provider officially [supported by Puppet Labs](https://forge.puppetlabs.com/supported). + +##Setup + +###Setup Requirements + +The `vcsrepo` module does not install any VCS software for you. You must install a VCS before you can use this module. + +Like Puppet in general, the `vcsrepo` module does not automatically create parent directories for the files it manages. Make sure to set up any needed directory structures before you get started. + +###Beginning with vcsrepo + +To create and manage a blank repository, define the type `vcsrepo` with a path to your repository and supply the `provider` parameter based on the [VCS you're using](#usage). + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, +} +~~~ + +##Usage + +**Note:** `git` is the only vcsrepo provider officially [supported by Puppet Labs](https://forge.puppetlabs.com/supported). + +###Git + +####Create a blank repository + +To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, +} +~~~ + +If you're managing a central or official repository, you might want to make it a bare repository. To do this, set `ensure` to 'bare': + +~~~ +vcsrepo { '/path/to/repo': + ensure => bare, + provider => git, +} +~~~ + +####Clone/pull a repository + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, + source => 'git://example.com/repo.git', +} +~~~ + +By default, `vcsrepo` will use the HEAD of the source repository's master branch. To use another branch or a specific commit, set `revision` to either a branch name or a commit SHA or tag. + +Branch name: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, + source => 'git://example.com/repo.git', + revision => 'development', +} +~~~ + +SHA: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, + source => 'git://example.com/repo.git', + revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31', +} +~~~ + +Tag: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, + source => 'git://example.com/repo.git', + revision => '1.1.2rc1', +} +~~~ + +To check out a branch as a specific user, supply the `user` parameter: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, + source => 'git://example.com/repo.git', + revision => '0c466b8a5a45f6cd7de82c08df2fb4ce1e920a31', + user => 'someUser', +} +~~~ + +To keep the repository at the latest revision, set `ensure` to 'latest'. + +**WARNING:** this overwrites any local changes to the repository: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => git, + source => 'git://example.com/repo.git', + revision => 'master', +} +~~~ + +To clone the repository but skip initializing submodules, set `submodules` to 'false': + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => git, + source => 'git://example.com/repo.git', + submodules => false, +} +~~~ + +####Use multiple remotes with a repository +In place of a single string, you can set `source` to a hash of one or more name => URL pairs: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => git, + remote => 'origin' + source => { + 'origin' => 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git', + 'other_remote' => 'https://github.com/other_user/puppetlabs-vcsrepo.git' + }, +} +~~~ + **Note:** if you set `source` to a hash, one of the names you specify must match the value of the `remote` parameter. That remote serves as the upstream of your managed repository. -
-####Connect via SSH
-
-To connect to your source repository via SSH (e.g., 'username@server:…'), we recommend managing your SSH keys with Puppet and using the [`require`](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter to make sure they are present before the `vcsrepo` resource is applied.
-
-To use SSH keys associated with a user, specify the username in the `user` parameter:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => git,
- source => 'git://username@example.com/repo.git',
- user => 'toto', #uses toto's $HOME/.ssh setup
- require => File['/home/toto/.ssh/id_rsa'],
-}
-~~~ -
-###Bazaar
-
-####Create a blank repository
-
-To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => bzr,
-}
-~~~
-
-####Branch from an existing repository
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => bzr,
- source => '/some/path',
-}
-~~~
-
-To branch from a specific revision, set `revision` to a valid [Bazaar revision spec](http://wiki.bazaar.canonical.com/BzrRevisionSpec):
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => bzr,
- source => '/some/path',
- revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x',
-}
-~~~
-
-####Connect via SSH
-
-To connect to your source repository via SSH (e.g., `'bzr+ssh://...'` or `'sftp://...,'`), we recommend using the [`require`](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter to make sure your SSH keys are present before the `vcsrepo` resource is applied:
- -~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => bzr,
- source => 'bzr+ssh://bzr.example.com/some/path',
- user => 'toto', #uses toto's $HOME/.ssh setup
- require => File['/home/toto/.ssh/id_rsa'],
-}
-~~~ -
-###CVS
-
-####Create a blank repository
-
-To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => cvs,
-}
-~~~
-
-####Checkout/update from a repository
-
-~~~
-vcsrepo { '/path/to/workspace':
- ensure => present,
- provider => cvs,
- source => ':pserver:anonymous@example.com:/sources/myproj',
-}
-~~~
-
-To get a specific module on the current mainline, supply the `module` parameter:
-
-~~~
-vcsrepo {'/vagrant/lockss-daemon-source':
- ensure => present,
- provider => cvs,
- source => ':pserver:anonymous@lockss.cvs.sourceforge.net:/cvsroot/lockss',
- module => 'lockss-daemon',
-}
-~~~
-
-To set the GZIP compression levels for your repository history, use the `compression` parameter:
-
-~~~
-vcsrepo { '/path/to/workspace':
- ensure => present,
- provider => cvs,
- compression => 3,
- source => ':pserver:anonymous@example.com:/sources/myproj',
-}
-~~~
-
-To get a specific revision, set `revision` to the revision number.
-
-~~~
-vcsrepo { '/path/to/workspace':
- ensure => present,
- provider => cvs,
- compression => 3,
- source => ':pserver:anonymous@example.com:/sources/myproj',
- revision => '1.2',
-}
-~~~ - -You can also set `revision` to a tag:
- -~~~
-vcsrepo { '/path/to/workspace':
- ensure => present,
- provider => cvs,
- compression => 3,
- source => ':pserver:anonymous@example.com:/sources/myproj',
- revision => 'SOMETAG',
-}
-~~~ -
-####Connect via SSH
-
-To connect to your source repository via SSH, we recommend using the [`require`](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter to make sure your SSH keys are present before the `vcsrepo` resource is applied:
- -~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => cvs,
- source => ':pserver:anonymous@example.com:/sources/myproj',
- user => 'toto', #uses toto's $HOME/.ssh setup
- require => File['/home/toto/.ssh/id_rsa'],
-}
-~~~
-
-###Mercurial
-
-####Create a blank repository
-
-To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => hg,
-}
-~~~
-
-####Clone/pull & update a repository
-
-To get the default branch tip:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => hg,
- source => 'http://hg.example.com/myrepo',
-}
-~~~
-
-For a specific changeset, use `revision`:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => hg,
- source => 'http://hg.example.com/myrepo',
- revision => '21ea4598c962',
-}
-~~~
-
-You can also set `revision` to a tag:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => hg,
- source => 'http://hg.example.com/myrepo',
- revision => '1.1.2',
-}
-~~~
-
-To check out as a specific user:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => hg,
- source => 'http://hg.example.com/myrepo',
- user => 'user',
-}
-~~~
-
-To specify an SSH identity key:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => hg,
- source => 'ssh://hg@hg.example.com/myrepo',
- identity => '/home/user/.ssh/id_dsa1,
-}
-~~~
-
-To specify a username and password for HTTP Basic authentication:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => hg,
- source => 'http://hg.example.com/myrepo',
- basic_auth_username => 'hgusername',
- basic_auth_password => 'hgpassword',
-}
-~~~
-
-####Connect via SSH
-
-To connect to your source repository via SSH (e.g., `'ssh://...'`), we recommend using the [`require` metaparameter](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) to make sure your SSH keys are present before the `vcsrepo` resource is applied:
- -~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => hg,
- source => 'ssh://hg.example.com//path/to/myrepo',
- user => 'toto', #uses toto's $HOME/.ssh setup
- require => File['/home/toto/.ssh/id_rsa'],
-}
-~~~
-
-###Perforce
+ +####Connect via SSH + +To connect to your source repository via SSH (e.g., 'username@server:…'), we recommend managing your SSH keys with Puppet and using the [`require`](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter to make sure they are present before the `vcsrepo` resource is applied. + +To use SSH keys associated with a user, specify the username in the `user` parameter: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => git, + source => 'git://username@example.com/repo.git', + user => 'toto', #uses toto's $HOME/.ssh setup + require => File['/home/toto/.ssh/id_rsa'], +} +~~~ + +###Bazaar + +####Create a blank repository + +To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => bzr, +} +~~~ + +####Branch from an existing repository + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => bzr, + source => '/some/path', +} +~~~ + +To branch from a specific revision, set `revision` to a valid [Bazaar revision spec](http://wiki.bazaar.canonical.com/BzrRevisionSpec): + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => bzr, + source => '/some/path', + revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x', +} +~~~ + +####Connect via SSH + +To connect to your source repository via SSH (e.g., `'bzr+ssh://...'` or `'sftp://...,'`), we recommend using the [`require`](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter to make sure your SSH keys are present before the `vcsrepo` resource is applied: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => bzr, + source => 'bzr+ssh://bzr.example.com/some/path', + user => 'toto', #uses toto's $HOME/.ssh setup + require => File['/home/toto/.ssh/id_rsa'], +} +~~~ + +###CVS + +####Create a blank repository + +To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => cvs, +} +~~~ + +####Checkout/update from a repository + +~~~ +vcsrepo { '/path/to/workspace': + ensure => present, + provider => cvs, + source => ':pserver:anonymous@example.com:/sources/myproj', +} +~~~ + +To get a specific module on the current mainline, supply the `module` parameter: + +~~~ +vcsrepo {'/vagrant/lockss-daemon-source': + ensure => present, + provider => cvs, + source => ':pserver:anonymous@lockss.cvs.sourceforge.net:/cvsroot/lockss', + module => 'lockss-daemon', +} +~~~ + +To set the GZIP compression levels for your repository history, use the `compression` parameter: + +~~~ +vcsrepo { '/path/to/workspace': + ensure => present, + provider => cvs, + compression => 3, + source => ':pserver:anonymous@example.com:/sources/myproj', +} +~~~ + +To get a specific revision, set `revision` to the revision number. + +~~~ +vcsrepo { '/path/to/workspace': + ensure => present, + provider => cvs, + compression => 3, + source => ':pserver:anonymous@example.com:/sources/myproj', + revision => '1.2', +} +~~~ + +You can also set `revision` to a tag: + +~~~ +vcsrepo { '/path/to/workspace': + ensure => present, + provider => cvs, + compression => 3, + source => ':pserver:anonymous@example.com:/sources/myproj', + revision => 'SOMETAG', +} +~~~ + +####Connect via SSH + +To connect to your source repository via SSH, we recommend using the [`require`](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter to make sure your SSH keys are present before the `vcsrepo` resource is applied: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => cvs, + source => ':pserver:anonymous@example.com:/sources/myproj', + user => 'toto', #uses toto's $HOME/.ssh setup + require => File['/home/toto/.ssh/id_rsa'], +} +~~~ + +###Mercurial + +####Create a blank repository + +To create a blank repository, suitable for use as a central repository, define `vcsrepo` without `source` or `revision`: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => hg, +} +~~~ + +####Clone/pull & update a repository + +To get the default branch tip: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => hg, + source => 'http://hg.example.com/myrepo', +} +~~~ + +For a specific changeset, use `revision`: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => hg, + source => 'http://hg.example.com/myrepo', + revision => '21ea4598c962', +} +~~~ + +You can also set `revision` to a tag: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => hg, + source => 'http://hg.example.com/myrepo', + revision => '1.1.2', +} +~~~ + +To check out as a specific user: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => hg, + source => 'http://hg.example.com/myrepo', + user => 'user', +} +~~~ + +To specify an SSH identity key: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => hg, + source => 'ssh://hg@hg.example.com/myrepo', + identity => '/home/user/.ssh/id_dsa1, +} +~~~ + +To specify a username and password for HTTP Basic authentication: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => hg, + source => 'http://hg.example.com/myrepo', + basic_auth_username => 'hgusername', + basic_auth_password => 'hgpassword', +} +~~~ + +####Connect via SSH + +To connect to your source repository via SSH (e.g., `'ssh://...'`), we recommend using the [`require` metaparameter](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) to make sure your SSH keys are present before the `vcsrepo` resource is applied: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => hg, + source => 'ssh://hg.example.com//path/to/myrepo', + user => 'toto', #uses toto's $HOME/.ssh setup + require => File['/home/toto/.ssh/id_rsa'], +} +~~~ + +###Perforce ####Create an empty workspace To set up the connection to your Perforce service, set `p4config` to the location of a valid Perforce [config file](http://www.perforce.com/perforce/doc.current/manuals/p4guide/chapter.configuration.html#configuration.settings.configfiles) stored on the node: -~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => p4,
- p4config => '/root/.p4config'
-}
-~~~
+~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => p4, + p4config => '/root/.p4config' +} +~~~ **Note:** If you don't include the `P4CLIENT` setting in your config file, the provider generates a workspace name based on the digest of `path` and the node's hostname (e.g., `puppet-91bc00640c4e5a17787286acbe2c021c`): -####Create/update and sync a Perforce workspace
-
-To sync a depot path to head, set `ensure` to 'latest':
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => p4,
- source => '//depot/branch/...'
-}
-~~~
-
-To sync to a specific changelist, specify its revision number with the `revision` parameter:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => p4,
- source => '//depot/branch/...',
- revision => '2341'
-}
-~~~
-
-You can also set `revision` to a label:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => p4,
- source => '//depot/branch/...',
- revision => 'my_label'
-}
-~~~
-
-###Subversion
-
-####Create a blank repository
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => svn,
-}
-~~~
-
-####Check out from an existing repository
-
-Provide a `source` pointing to the branch or tag you want to check out:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => svn,
- source => 'svn://svnrepo/hello/branches/foo',
-}
-~~~
-
-You can also designate a specific revision:
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => svn,
- source => 'svn://svnrepo/hello/branches/foo',
- revision => '1234',
-}
-~~~
-
-####Use a specific Subversion configuration directory
-
-Use the `configuration` parameter to designate the directory that contains your Subversion configuration files (typically, '/path/to/.subversion'):
-
-~~~
-vcsrepo { '/path/to/repo':
- ensure => present,
- provider => svn,
- source => 'svn://svnrepo/hello/branches/foo',
- configuration => '/path/to/.subversion',
-}
-~~~
-
-####Connect via SSH
-
-To connect to your source repository via SSH (e.g., `'svn+ssh://...'`), we recommend using the [`require` metaparameter](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) to make sure your SSH keys are present before the `vcsrepo` resource is applied:
- -~~~
-vcsrepo { '/path/to/repo':
- ensure => latest,
- provider => svn,
- source => 'svn+ssh://svnrepo/hello/branches/foo',
- user => 'toto', #uses toto's $HOME/.ssh setup
- require => File['/home/toto/.ssh/id_rsa'],
-}
-~~~
-
-##Reference
-
-###Type: vcsrepo
-
-The vcsrepo module adds only one type with several providers. Each provider abstracts a different VCS, and each provider includes a set of features according to its needs.
-
-####Providers
-
-**Note:** Not all features are available with all providers.
-
-#####`git` - Supports the Git VCS.
-
+####Create/update and sync a Perforce workspace + +To sync a depot path to head, set `ensure` to 'latest': + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => p4, + source => '//depot/branch/...' +} +~~~ + +To sync to a specific changelist, specify its revision number with the `revision` parameter: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => p4, + source => '//depot/branch/...', + revision => '2341' +} +~~~ + +You can also set `revision` to a label: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => p4, + source => '//depot/branch/...', + revision => 'my_label' +} +~~~ + +###Subversion + +####Create a blank repository + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => svn, +} +~~~ + +####Check out from an existing repository + +Provide a `source` pointing to the branch or tag you want to check out: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => svn, + source => 'svn://svnrepo/hello/branches/foo', +} +~~~ + +You can also designate a specific revision: + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => svn, + source => 'svn://svnrepo/hello/branches/foo', + revision => '1234', +} +~~~ + +####Use a specific Subversion configuration directory + +Use the `configuration` parameter to designate the directory that contains your Subversion configuration files (typically, '/path/to/.subversion'): + +~~~ +vcsrepo { '/path/to/repo': + ensure => present, + provider => svn, + source => 'svn://svnrepo/hello/branches/foo', + configuration => '/path/to/.subversion', +} +~~~ + +####Connect via SSH + +To connect to your source repository via SSH (e.g., `'svn+ssh://...'`), we recommend using the [`require` metaparameter](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) to make sure your SSH keys are present before the `vcsrepo` resource is applied: + +~~~ +vcsrepo { '/path/to/repo': + ensure => latest, + provider => svn, + source => 'svn+ssh://svnrepo/hello/branches/foo', + user => 'toto', #uses toto's $HOME/.ssh setup + require => File['/home/toto/.ssh/id_rsa'], +} +~~~ + +##Reference + +###Type: vcsrepo + +The vcsrepo module adds only one type with several providers. Each provider abstracts a different VCS, and each provider includes a set of features according to its needs. + +####Providers + +**Note:** Not all features are available with all providers. + +#####`git` - Supports the Git VCS. + Features: `bare_repositories`, `depth`, `multiple_remotes`, `reference_tracking`, `ssh_identity`, `submodules`, `user` -
-Parameters: `depth`, `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `remote`, `revision`, `source`, `user`
-
-#####`bzr` - Supports the Bazaar VCS.
-
-Features: `reference_tracking`
-
+ +Parameters: `depth`, `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `remote`, `revision`, `source`, `user` + +#####`bzr` - Supports the Bazaar VCS. + +Features: `reference_tracking` + Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `path`, `provider`, `revision`, `source` -
-#####`cvs` - Supports the CVS VCS.
-
-Features: `cvs_rsh`, `gzip_compression`, `modules`, `reference_tracking`, `user`
+ +#####`cvs` - Supports the CVS VCS. + +Features: `cvs_rsh`, `gzip_compression`, `modules`, `reference_tracking`, `user` Parameters: `compression`, `cvs_rsh`, `ensure`, `excludes`, `force`, `group`, `module`, `owner`, `path`, `provider` -
-#####`hg` - Supports the Mercurial VCS.
-
+ +#####`hg` - Supports the Mercurial VCS. + Features: `reference_tracking`, `ssh_identity`, `user` -
+ Parameters: `ensure`, `excludes`, `force`, `group`, `identity`, `owner`, `path`, `provider`, `revision`, `source`, `user` -
-#####`p4` - Supports the Perforce VCS.
-
+ +#####`p4` - Supports the Perforce VCS. + Features: `p4config`, `reference_tracking` -
+ Parameters: `ensure`, `excludes`, `force`, `group`, `owner`, `p4config`, `path`, `provider`, `revision`, `source` -
-#####`svn` - Supports the Subversion VCS.
-
-Features: `basic_auth`, `configuration`, `conflict`, `filesystem_types`, `reference_tracking` - -Parameters: `basic_auth_password`, `basic_auth_username`, `configuration`, `conflict`, `ensure`, `excludes`, `force`, `fstype`, `group`, `owner`, `path`, `provider`, `revision`, `source`
-
-####Features
-
-**Note:** Not all features are available with all providers.
-
-* `bare_repositories` - Differentiates between bare repositories and those with working copies. (Available with `git`.)
+ +#####`svn` - Supports the Subversion VCS. + +Features: `basic_auth`, `configuration`, `conflict`, `depth`, `filesystem_types`, `reference_tracking` + +Parameters: `basic_auth_password`, `basic_auth_username`, `configuration`, `conflict`, `ensure`, `excludes`, `force`, `fstype`, `group`, `owner`, `path`, `provider`, `revision`, `source`, `trust_server_cert` + +####Features + +**Note:** Not all features are available with all providers. + +* `bare_repositories` - Differentiates between bare repositories and those with working copies. (Available with `git`.) * `basic_auth` - Supports HTTP Basic authentication. (Available with `svn`.) -* `conflict` - Lets you decide how to resolve any conflicts between the source repository and your working copy. (Available with `svn`.)
-* `configuration` - Lets you specify the location of your configuration files. (Available with `svn`.)
-* `cvs_rsh` - Understands the `CVS_RSH` environment variable. (Available with `cvs`.)
-* `depth` - Supports shallow clones. (Available with `git`.)
-* `filesystem_types` - Supports multiple types of filesystem. (Available with `svn`.)
-* `gzip_compression` - Supports explicit GZip compression levels. (Available with `cvs`.)
-* `modules` - Lets you choose a specific repository module. (Available with `cvs`.)
-* `multiple_remotes` - Tracks multiple remote repositories. (Available with `git`.)
-* `reference_tracking` - Lets you track revision references that can change over time (e.g., some VCS tags and branch names). (Available with all providers)
-* `ssh_identity` - Lets you specify an SSH identity file. (Available with `git` and `hg`.)
-* `user` - Can run as a different user. (Available with `git`, `hg` and `cvs`.)
-* `p4config` - Supports setting the `P4CONFIG` environment. (Available with `p4`.)
-* `submodules` - Supports repository submodules which can be optionally initialized. (Available with `git`.)
-
-####Parameters
-
+* `conflict` - Lets you decide how to resolve any conflicts between the source repository and your working copy. (Available with `svn`.) +* `configuration` - Lets you specify the location of your configuration files. (Available with `svn`.) +* `cvs_rsh` - Understands the `CVS_RSH` environment variable. (Available with `cvs`.) +* `depth` - Supports shallow clones in `git` or sets scope limit in `svn`. (Available with `git` and `svn`.) +* `filesystem_types` - Supports multiple types of filesystem. (Available with `svn`.) +* `gzip_compression` - Supports explicit GZip compression levels. (Available with `cvs`.) +* `modules` - Lets you choose a specific repository module. (Available with `cvs`.) +* `multiple_remotes` - Tracks multiple remote repositories. (Available with `git`.) +* `reference_tracking` - Lets you track revision references that can change over time (e.g., some VCS tags and branch names). (Available with all providers) +* `ssh_identity` - Lets you specify an SSH identity file. (Available with `git` and `hg`.) +* `user` - Can run as a different user. (Available with `git`, `hg` and `cvs`.) +* `p4config` - Supports setting the `P4CONFIG` environment. (Available with `p4`.) +* `submodules` - Supports repository submodules which can be optionally initialized. (Available with `git`.) + +####Parameters + All parameters are optional, except where specified otherwise. ##### `basic_auth_password` @@ -631,7 +631,9 @@ Provides a value for the `CVS_RSH` environment variable. (Requires the `cvs_rsh` ##### `depth` -Sets the number of commits to include when creating a shallow clone. (Requires the `depth` feature.) Valid options: an integer. Default: none. +In `git` sets the number of commits to include when creating a shallow clone. (Requires the `depth` feature.) Valid options: an integer. Default: none. + +In `svn` instructs Subversion to limit the scope of an operation to a particular tree depth. (Requires the `depth` feature.) Valid options: 'empty', 'files', 'immediates', 'infinity'. Default: none. ##### `ensure` @@ -711,32 +713,36 @@ Default: none. Specifies whether to initialize and update each submodule in the repository. (Requires the `submodules` feature.) Valid options: 'true' and 'false'. Default: 'true'. +##### `trust_server_cert` + +Instructs Subversion to accept SSL server certificates issued by unknown certificate authorities. Valid options: 'true' and 'false'. Default: 'false'. + ##### `user` -Specifies the user to run as for repository operations. (Requires the `user` feature.) Valid options: a string containing a username or UID. Default: none.
-
-##Limitations
-
-Git is the only VCS provider officially [supported](https://forge.puppetlabs.com/supported) by Puppet Labs.
-
-This module has been tested with Puppet 2.7 and higher.
-
-The module has been tested on:
-
+Specifies the user to run as for repository operations. (Requires the `user` feature.) Valid options: a string containing a username or UID. Default: none. + +##Limitations + +Git is the only VCS provider officially [supported](https://forge.puppetlabs.com/supported) by Puppet Labs. + +This module has been tested with Puppet 2.7 and higher. + +The module has been tested on: + * CentOS 5/6/7 * Debian 6/7 -* Oracle 5/6/7
-* Red Hat Enterprise Linux 5/6/7
+* Oracle 5/6/7 +* Red Hat Enterprise Linux 5/6/7 * Scientific Linux 5/6/7 * SLES 10/11/12 -* Ubuntu 10.04/12.04/14.04
-
-Testing on other platforms has been light and cannot be guaranteed.
-
-##Development
-
-Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.
-
-We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
-
+* Ubuntu 10.04/12.04/14.04 + +Testing on other platforms has been light and cannot be guaranteed. + +##Development + +Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. + +We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. + You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) diff --git a/examples/git/shallow-clone-with-just-one-commit.pp b/examples/git/shallow-clone-with-just-one-commit.pp new file mode 100644 index 0000000..cd5a05d --- /dev/null +++ b/examples/git/shallow-clone-with-just-one-commit.pp @@ -0,0 +1,7 @@ +vcsrepo { '/tmp/git': + ensure => 'present', + provider => 'git', + source => 'https://github.com/git/git.git', + branch => 'v2.2.0', + depth => 1, +} diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index bf11f3d..3b20a83 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -3,7 +3,9 @@ require File.join(File.dirname(__FILE__), '..', 'vcsrepo') Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do desc "Supports Git repositories" - commands :git => 'git' + has_command(:git, 'git') do + environment({ 'HOME' => ENV['HOME'] }) + end has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes, :user, :depth, :branch, :submodules @@ -45,7 +47,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) # # @return [String] Returns the target sha/tag/branch def latest - @resource.value(:revision) + if not @resource.value(:revision) and branch = on_branch? + return branch + else + return @resource.value(:revision) + end end # Get the current revision of the repo (tag/branch/sha) @@ -72,7 +78,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) #updated and authoritative. #TODO might be worthwhile to have an allow_local_changes param to decide #whether to reset or pull when we're ensuring latest. - at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") } + if @resource.value(:source) + at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") } + else + at_path { git_with_identity('reset', '--hard', "#{desired}") } + end end #TODO Would this ever reach here if it is bare? if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true @@ -103,7 +113,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) def working_copy_exists? if @resource.value(:source) and File.exists?(File.join(@resource.value(:path), '.git', 'config')) - File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{default_url}/).any? + File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{Regexp.escape(default_url)}/).any? else File.directory?(File.join(@resource.value(:path), '.git')) end @@ -281,7 +291,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) # handle upstream branch changes # @!visibility private def checkout(revision = @resource.value(:revision)) - if !local_branch_revision? && remote_branch_revision? + if !local_branch_revision?(revision) && remote_branch_revision?(revision) #non-locally existant branches (perhaps switching to a branch that has never been checked out) at_path { git_with_identity('checkout', '--force', '-b', revision, '--track', "#{@resource.value(:remote)}/#{revision}") } else @@ -388,7 +398,17 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) # @return [String] Returns the tag/branch of the current repo if it's up to # date; otherwise returns the sha of the requested revision. def get_revision(rev = 'HEAD') - update_references + if @resource.value(:source) + update_references + else + status = at_path { git_with_identity('status')} + is_it_new = status =~ /Initial commit/ + if is_it_new + status =~ /On branch (.*)/ + branch = $1 + return branch + end + end current = at_path { git_with_identity('rev-parse', rev).strip } if @resource.value(:revision) if tag_revision? @@ -425,6 +445,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) if @resource.value(:identity) Tempfile.open('git-helper', Puppet[:statedir]) do |f| f.puts '#!/bin/sh' + f.puts 'export SSH_AUTH_SOCKET=' f.puts "exec ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -oConnectTimeout=120 -i #{@resource.value(:identity)} $*" f.close @@ -439,7 +460,8 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) return ret end elsif @resource.value(:user) and @resource.value(:user) != Facter['id'].value - Puppet::Util::Execution.execute("git #{args.join(' ')}", :uid => @resource.value(:user), :failonfail => true) + env = Etc.getpwnam(@resource.value(:user)) + Puppet::Util::Execution.execute("git #{args.join(' ')}", :uid => @resource.value(:user), :failonfail => true, :custom_environment => {'HOME' => env['dir']}) else git(*args) end diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb index 905d5ad..fccfaa5 100644 --- a/lib/puppet/provider/vcsrepo/svn.rb +++ b/lib/puppet/provider/vcsrepo/svn.rb @@ -7,7 +7,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) :svnadmin => 'svnadmin', :svnlook => 'svnlook' - has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration, :conflict + has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration, :conflict, :depth def create if !@resource.value(:source) @@ -15,7 +15,8 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) else checkout_repository(@resource.value(:source), @resource.value(:path), - @resource.value(:revision)) + @resource.value(:revision), + @resource.value(:depth)) end update_owner end @@ -62,6 +63,10 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) args.push('--config-dir', @resource.value(:configuration)) end + if @resource.value(:trust_server_cert) != :false + args.push('--trust-server-cert') + end + args end @@ -105,11 +110,14 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) private - def checkout_repository(source, path, revision) + def checkout_repository(source, path, revision, depth) args = buildargs.push('checkout') if revision args.push('-r', revision) end + if depth + args.push('--depth', depth) + end args.push(source, path) svn(*args) end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb index e5dfbb5..290bdad 100644 --- a/lib/puppet/type/vcsrepo.rb +++ b/lib/puppet/type/vcsrepo.rb @@ -38,7 +38,7 @@ Puppet::Type.newtype(:vcsrepo) do "The provider understands the CVS_RSH environment variable" feature :depth, - "The provider can do shallow clones" + "The provider can do shallow clones or set scope limit" feature :branch, "The name of the branch" @@ -227,8 +227,14 @@ Puppet::Type.newtype(:vcsrepo) do newparam :conflict do desc "The action to take if conflicts exist between repository and working copy" end + + newparam :trust_server_cert do + desc "Trust server certificate" + newvalues(:true, :false) + defaultto :false + end autorequire(:package) do - ['git', 'git-core'] + ['git', 'git-core', 'mercurial'] end end diff --git a/spec/acceptance/create_repo_spec.rb b/spec/acceptance/create_repo_spec.rb index db0cd29..53a93c9 100644 --- a/spec/acceptance/create_repo_spec.rb +++ b/spec/acceptance/create_repo_spec.rb @@ -30,6 +30,22 @@ describe 'create a repo' do end end + context 'no source but revision provided' do + it 'should not fail (MODULES-2125)' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/testrepo_blank_with_revision_repo": + ensure => present, + provider => git, + revision => 'master' + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + end + context 'bare repo' do it 'creates a bare repo' do pp = <<-EOS diff --git a/spec/acceptance/modules_1800_spec.rb b/spec/acceptance/modules_1800_spec.rb new file mode 100644 index 0000000..12415e8 --- /dev/null +++ b/spec/acceptance/modules_1800_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper_acceptance' + +tmpdir = default.tmpdir('vcsrepo') + +describe 'clones a remote repo' do + before(:all) do + my_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + shell("mkdir -p #{tmpdir}") # win test + end + + after(:all) do + shell("rm -rf #{tmpdir}/vcsrepo") + end + + context 'ensure latest with no revision' do + it 'clones from default remote' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/vcsrepo": + ensure => present, + provider => git, + source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git", + } + EOS + + apply_manifest(pp, :catch_failures => true) + shell("cd #{tmpdir}/vcsrepo; /usr/bin/git reset --hard HEAD~2") + end + + it 'updates' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/vcsrepo": + ensure => latest, + provider => git, + source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git", + } + EOS + + apply_manifest(pp, :catch_failures => true) + end + end +end diff --git a/spec/acceptance/modules_2326_spec.rb b/spec/acceptance/modules_2326_spec.rb new file mode 100644 index 0000000..601c6ff --- /dev/null +++ b/spec/acceptance/modules_2326_spec.rb @@ -0,0 +1,69 @@ +require 'spec_helper_acceptance' + +tmpdir = default.tmpdir('vcsrepo') + +describe 'clones with special characters' do + + before(:all) do + my_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + shell("mkdir -p #{tmpdir}") # win test + scp_to(default, "#{my_root}/acceptance/files/create_git_repo.sh", tmpdir) + shell("cd #{tmpdir} && ./create_git_repo.sh") + end + + after(:all) do + shell("rm -rf #{tmpdir}/testrepo.git") + end + + context 'as a user with ssh' do + before(:all) do + # create user + pp = <<-EOS + group { 'testuser-ssh': + ensure => present, + } + user { 'testuser-ssh': + ensure => present, + groups => 'testuser-ssh', + managehome => true, + } + EOS + apply_manifest(pp, :catch_failures => true) + + # create ssh keys + shell('mkdir -p /home/testuser-ssh/.ssh') + shell('echo -e \'y\n\'|ssh-keygen -q -t rsa -f /home/testuser-ssh/.ssh/id_rsa -N ""') + + # copy public key to authorized_keys + shell('cat /home/testuser-ssh/.ssh/id_rsa.pub > /home/testuser-ssh/.ssh/authorized_keys') + shell('echo -e "Host localhost\n\tStrictHostKeyChecking no\n" > /home/testuser-ssh/.ssh/config') + shell('chown -R testuser-ssh:testuser-ssh /home/testuser-ssh/.ssh') + shell("chown testuser-ssh:testuser-ssh #{tmpdir}") + end + + it 'applies the manifest' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/testrepo_user_ssh": + ensure => present, + provider => git, + source => "git+ssh://testuser-ssh@localhost#{tmpdir}/testrepo.git", + user => 'testuser-ssh', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + after(:all) do + pp = <<-EOS + user { 'testuser-ssh': + ensure => absent, + managehome => true, + } + EOS + apply_manifest(pp, :catch_failures => true) + end + end +end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index a240b50..87113fa 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -206,7 +206,7 @@ branches before do expects_chdir('/tmp/test') resource[:revision] = 'currentsha' - resource.delete(:source) + resource[:source] = 'http://example.com' provider.stubs(:git).with('config', 'remote.origin.url').returns('') provider.stubs(:git).with('fetch', 'origin') # FIXME provider.stubs(:git).with('fetch', '--tags', 'origin') @@ -272,6 +272,14 @@ branches end end + context "when there's no source" do + it 'should return the revision' do + resource.delete(:source) + provider.expects(:git).with('status') + provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') + expect(provider.revision).to eq(resource.value(:revision)) + end + end end context "setting the revision property" do diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 77f0e03..6a37c20 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -52,6 +52,36 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do provider.create end end + + context "with depth" do + it "should execute 'svn checkout' with a depth" do + resource[:source] = 'exists' + resource[:depth] = 'infinity' + provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'infinity', + resource.value(:source), + resource.value(:path)) + provider.create + end + end + + context "with trust_server_cert" do + it "should execute 'svn checkout' without a trust-server-cert" do + resource[:source] = 'exists' + resource[:trust_server_cert] = :false + provider.expects(:svn).with('--non-interactive', 'checkout', + resource.value(:source), + resource.value(:path)) + provider.create + end + it "should execute 'svn checkout' with a trust-server-cert" do + resource[:source] = 'exists' + resource[:trust_server_cert] = :true + provider.expects(:svn).with('--non-interactive', '--trust-server-cert', 'checkout', + resource.value(:source), + resource.value(:path)) + provider.create + end + end end describe 'destroying' do |