Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gitconfig and gitignore parameters (Git) #10

Merged
merged 10 commits into from
Oct 23, 2017
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ fixtures:
repositories:
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
apt: "https://github.com/puppetlabs/puppetlabs-apt.git"
vcsrepo: "https://github.com/puppetlabs/puppetlabs-vcsrepo.git"
symlinks:
software: "#{source_dir}"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ classes:
- software::editors::atom
- software::entertainment::vlc
- software::social::skype
- software::vcsscm::git

software::browsers::chrome::channel: stable

Expand All @@ -119,6 +120,13 @@ software::editors::atom::packages:
software::editors::atom::themes:
twilight-syntax: {}
software::editors::atom::user: username

software::vcsscm::git:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classes above needs the git class added also...

gui: true
bash_completion: true
bash_prompt: true
gitconfig: true
gitignore: puppet:///modules/custom/user/gitignore
```

## Reference
Expand Down
4 changes: 4 additions & 0 deletions files/vcsscm/git/system-gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# System-global Git configuration. https://git-scm.com/docs/git-config#FILES

[alias]
undo-commit = reset --soft HEAD^
1 change: 1 addition & 0 deletions files/vcsscm/git/user-gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# User-global Git configuration. See /etc/gitconfig for system-global settings.
58 changes: 58 additions & 0 deletions files/vcsscm/git/user-gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Global Git Ignore. https://git-scm.com/docs/gitignore

# Special files and folder of various OSes
.AppleDesktop
.AppleDB
.AppleDouble
.apdisk
.com.apple.timemachine.donotpresent
Desktop.ini
.directory
*.DS_Store
.fseventsd
.fuse_hidden*
.LSOverride
Network Trash Folder
.nfs*
$RECYCLE.BIN/
.Spotlight-V100
.TemporaryItems
Temporary Items
.Trash-*
.Trashes
.VolumeIcon.icns

# Various cache files and folders
.cache
.eggs/
*.egg-info/
.eslintcache
Thumbs.db
webassets-cache

# Build files and folders
**/material-design-icons/*/ios/*.imageset/Contents.json
**/material-design-icons/sprites/
**/material-design-icons/iconfont/
**/material-design-icons/*/drawable-anydpi-v21/*.xml
**/material-design-icons/**/*.png
**/material-design-icons/*/svg/design/*.svg
__pycache__/
*.py[cod]
*$py.class

# Editor and IDE files and folders
.idea
*.stTheme.cache
*.sublime-project
*.sublime-workspace
*.tmlanguage.cache
*.tmPreferences.cache
GitHub.sublime-settings

# Environments
.env
.venv
env/
venv/
ENV/
86 changes: 85 additions & 1 deletion manifests/vcsscm/git.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# git.pp
# Install git cli
# Install git cli, optional tab completion, config and ignore files
#

class software::vcsscm::git (
$ensure = $software::params::software_ensure,
$gui = false,
$bash_completion = false,
$bash_prompt = false,
$gitconfig = false,
$gitignore = false,
) inherits software::params {

validate_string($ensure)
Expand All @@ -30,6 +32,7 @@
}

if $bash_prompt {

vcsrepo { '/opt/bash-git-prompt/':
ensure => present,
provider => git,
Expand All @@ -45,6 +48,87 @@
source => 'puppet:///modules/software/vcsscm/git/bash-git-prompt',
}
}

if $gitconfig or $gitignore {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we only need this if $gitconfig_user or $gitignore_user.

I'm thinking of some other way to order this that may make it easier...


if !defined(File['/etc/skel/.config']) {
file { '/etc/skel/.config':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
}

if !defined(File['/etc/skel/.config/git']) {
file { '/etc/skel/.config/git':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
}
}

if $gitconfig {

$gitconfig_system = $gitconfig ? {
Boolean => 'puppet:///modules/software/vcsscm/git/system-gitconfig',
String => false, # a string will only set user config
Hash => $gitconfig['system'],
default => fail('$gitconfig must be one of (Boolean, String, Hash)'),
}

if $gitconfig_system {

file { '/etc/gitconfig':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => $gitconfig_system,
}
}

$gitconfig_user = $gitconfig ? {
Boolean => 'puppet:///modules/software/vcsscm/git/user-gitconfig',
String => $gitconfig,
Hash => $gitconfig['user'],
default => fail('$gitconfig must be one of (Boolean, String, Hash)'),
}

if $gitconfig_user {

file { '/etc/skel/.config/git/config':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => $gitconfig_user,
}
}
}

if $gitignore {

$gitignore_user = $gitignore ? {
Boolean => 'puppet:///modules/software/vcsscm/git/user-gitignore',
String => $gitignore,
Hash => $gitignore['user'],
default => fail('$gitignore must be one of (Boolean, String, Hash)'),
}

if $gitignore_user {

file { '/etc/skel/.config/git/ignore':
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
source => $gitignore_user,
}
}
}
}
'windows': {
package { 'git':
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{"name": "puppetlabs/stdlib", "version_requirement": ">= 4.2.0 < 5.0.0"},
{"name": "puppetlabs/apt", "version_requirement": ">= 2.1.1 < 3.0.0"},
{"name": "puppetlabs/chocolatey", "version_requirement": ">= 0.8.0 < 2.0.0"},
{"name": "puppetlabs/vcsrepo", "version_requirement": ">= 2.0.0 < 3.0.0"},
{"name": "puppetlabs/vcsrepo", "version_requirement": ">= 1.3.1 < 3.0.0"},
{"name": "thekevjames/homebrew", "version_requirement": ">= 1.5.0 < 2.0.0"},
{"name": "unibet/vagrant", "version_requirement": ">= 0.2.1 < 1.0.0"}
],
Expand Down
128 changes: 128 additions & 0 deletions spec/classes/software_vcsscm_git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,134 @@
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git') }
it { is_expected.not_to contain_package('gitk') }
it { is_expected.not_to contain_package('git-gui') }
it { is_expected.not_to contain_package('bash-completion') }
it { is_expected.not_to contain_vcsrepo('/opt/bash-git-prompt/') }
it { is_expected.not_to contain_file('/etc/bash_completion.d/bash-git-prompt') }
it { is_expected.not_to contain_file('/etc/gitconfig') }
it { is_expected.not_to contain_file('/etc/skel/.config/git/config') }
it { is_expected.not_to contain_file('/etc/skel/.config/git/ignore') }
end
end

context 'with gui' do
let :params do
{
:gui => true
}
end
if facts[:operatingsystem] == 'Darwin'
it { is_expected.to compile.and_raise_error(/is not supported on Darwin./) }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git') }
it { is_expected.to contain_package('gitk') }
it { is_expected.to contain_package('git-gui') }
end
end

context 'with bash completion and prompt' do
let :params do
{
:bash_completion => true,
:bash_prompt => true
}
end
if facts[:operatingsystem] == 'Darwin'
it { is_expected.to compile.and_raise_error(/is not supported on Darwin./) }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git') }
it { is_expected.to contain_package('bash-completion') }
it { is_expected.to contain_vcsrepo('/opt/bash-git-prompt/') }
it {
is_expected.to contain_file('/etc/bash_completion.d/bash-git-prompt')
.with_source('puppet:///modules/software/vcsscm/git/bash-git-prompt')
}
end
end

context 'with booleans for gitconfig and gitignore' do
let :params do
{
:gitconfig => true,
:gitignore => true
}
end
if facts[:operatingsystem] == 'Darwin'
it { is_expected.to compile.and_raise_error(/is not supported on Darwin./) }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git') }
it {
is_expected.to contain_file('/etc/gitconfig')
.with_source('puppet:///modules/software/vcsscm/git/system-gitconfig')
}
it {
is_expected.to contain_file('/etc/skel/.config/git/config')
.with_source('puppet:///modules/software/vcsscm/git/user-gitconfig')
}
it {
is_expected.to contain_file('/etc/skel/.config/git/ignore')
.with_source('puppet:///modules/software/vcsscm/git/user-gitignore')
}
end
end

context 'with strings for gitconfig and gitignore' do
let :params do
{
:gitconfig => 'puppet:///modules/user-supplied/custom/user-gitconfig',
:gitignore => 'puppet:///modules/user-supplied/custom/user-gitignore'
}
end
if facts[:operatingsystem] == 'Darwin'
it { is_expected.to compile.and_raise_error(/is not supported on Darwin./) }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git') }
it { is_expected.not_to contain_file('/etc/gitconfig') }
it {
is_expected.to contain_file('/etc/skel/.config/git/config')
.with_source('puppet:///modules/user-supplied/custom/user-gitconfig')
}
it {
is_expected.to contain_file('/etc/skel/.config/git/ignore')
.with_source('puppet:///modules/user-supplied/custom/user-gitignore')
}
end
end

context 'with hashes for gitconfig and gitignore' do
let :params do
{
:gitconfig => {
:system => 'puppet:///modules/user-supplied/custom/system-gitconfig',
:user => 'puppet:///modules/user-supplied/custom/user-gitconfig'
},
:gitignore => {
:user => 'puppet:///modules/user-supplied/custom/user-gitignore'
}
}
end
if facts[:operatingsystem] == 'Darwin'
it { is_expected.to compile.and_raise_error(/is not supported on Darwin./) }
else
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('git') }
it {
is_expected.to contain_file('/etc/gitconfig')
.with_source('puppet:///modules/user-supplied/custom/system-gitconfig')
}
it {
is_expected.to contain_file('/etc/skel/.config/git/config')
.with_source('puppet:///modules/user-supplied/custom/user-gitconfig')
}
it {
is_expected.to contain_file('/etc/skel/.config/git/ignore')
.with_source('puppet:///modules/user-supplied/custom/user-gitignore')
}
end
end
end
Expand Down