Skip to content

Commit

Permalink
Check Git version before copying local config
Browse files Browse the repository at this point in the history
  • Loading branch information
biscuitvile committed Oct 2, 2012
1 parent fa568a4 commit c46bbdb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
9 changes: 2 additions & 7 deletions .gitconfig
Expand Up @@ -24,10 +24,10 @@
excludesfile = ~/.cvsignore
editor = vim
whitespace = warn
[github]
user = hashrocketeer
[help]
autocorrect = 10
[include]
path = ~/.gitconfig.local
[interactive]
singlekey = true
[merge]
Expand All @@ -52,8 +52,3 @@
default = tracking
[rebase]
autosquash = true
[user]
email = dev@hashrocket.com
name = "Hashrocket Workstation"
[include]
path = .gitconfig.local
5 changes: 5 additions & 0 deletions .gitconfig.local
@@ -0,0 +1,5 @@
[github]
user = hashrocketeer
[user]
email = dev@hashrocket.com
name = "Hashrocket Workstation"
44 changes: 44 additions & 0 deletions bin/git_configuration_handler.rb
@@ -0,0 +1,44 @@
class GitConfigurationHandler

LocalGitConfigCopiedMessage = "\nGeneric Hashrocket Git credentials \
have been configured in ~/.gitconfig.local.\nReplace this with your \
own info if this is a personal machine.\n\n"

UnsupportedGitVersionMessage = "\nYour Git version does not support \
local configuration files. We highly recommend updating to the latest \
version.\n\n"

def initialize(home)
@home = home
if system_git_version_supports_local_config?
apply_local_gitconfig unless local_git_config_present?
else
puts UnsupportedGitVersionMessage
end
end

def target_git_version
Gem::Version.new('1.7.10')
end

def system_git_version
Gem::Version.new(extracted_version_number)
end

def extracted_version_number
`git --version`.scan(/\d+/).join('.')
end

def system_git_version_supports_local_config?
system_git_version >= target_git_version
end

def local_git_config_present?
File.exist?(@home + '/.gitconfig.local')
end

def apply_local_gitconfig
FileUtils.cp '.gitconfig.local', @home + '/.gitconfig.local'
puts LocalGitConfigCopiedMessage
end
end
7 changes: 6 additions & 1 deletion bin/hlink
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
require 'fileutils'
require_relative 'git_configuration_handler'

EXCLUDES = %w(bin custom . .. .git README.md)
EXCLUDES = %w(bin custom . .. .git README.md .gitconfig.local)

def cwd
@cwd ||= File.expand_path(File.dirname(__FILE__))
Expand Down Expand Up @@ -80,3 +81,7 @@ directories_at(File.join(root,'custom')).each do |custom|
install(file,dest_dir)
end
end

# install a .gitconfig.local if Git version
# is compatible and file not already present
GitConfigurationHandler.new(@home)

0 comments on commit c46bbdb

Please sign in to comment.