Class: Billy::Util::Git
- Inherits:
-
Scm
- Object
- Scm
- Billy::Util::Git
show all
- Defined in:
- lib/billy/util/scm/git.rb
Constant Summary
collapse
- GIT_PATH =
".git"
Instance Method Summary
collapse
Methods inherited from Scm
configure!, register_scm, register_self!
Instance Method Details
9
10
11
12
13
|
# File 'lib/billy/util/scm/git.rb', line 9
def configure!( cap, config )
cap.set :scm, :git
cap.set :repository, config.repository || get_repository_path
cap.set :branch, config.branch || current_branch
end
|
#current_branch ⇒ Object
15
16
17
|
# File 'lib/billy/util/scm/git.rb', line 15
def current_branch
`git symbolic-ref HEAD 2> /dev/null`.strip.gsub(/^refs\/heads\//, '')
end
|
#get_config ⇒ Object
19
20
21
|
# File 'lib/billy/util/scm/git.rb', line 19
def get_config
File.read( File.expand_path( GIT_PATH + "/config" ) )
end
|
#get_remotes(config) ⇒ Object
31
32
33
|
# File 'lib/billy/util/scm/git.rb', line 31
def get_remotes( config )
config.gsub( /\n/, ';' ).scan /\[remote\s+\"([^"]+)\"\][^\[]+url\s*=\s*([^;]+)/
end
|
#get_repository_path ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/billy/util/scm/git.rb', line 39
def get_repository_path
if !local_repository_exists?
if !Billy::Util::UI.confirm?( "Git repository was not created. Do you want Billy to create it now?" )
Billy::Util::UI.err "Billy could not proceed without git repository."
exit 1
else
Billy::Util::UI.inform "Creating git repository."
init_git_repository
end
end
config = get_config
if !remote_repository_exists?( config )
Billy::Util::UI.err "Billy could not find remote repository for your project."
Billy::Util::UI.err "Please add some remote, e.g. git remote add [email protected]:myUsername/myProject.git."
exit 1
end
idx = 1
i = 0
match_data = get_remotes( config )
if match_data.length > 1
Billy::Util::UI.inform "Billy found several remotes in repository. Choose one to deploy from:"
match_data.each do |remote|
i += 1
Billy::Util::UI.inform "#{i}: #{remote[0]}\t\t#{remote[1]}"
end
while ( idx = Billy::Util::UI.input.to_i ) > match_data.length; end
end
match_data[ idx - 1 ][ 1 ]
end
|
#init_repository ⇒ Object
35
36
37
|
# File 'lib/billy/util/scm/git.rb', line 35
def init_repository
system "git init ."
end
|
#local_repository_exists? ⇒ Boolean
23
24
25
|
# File 'lib/billy/util/scm/git.rb', line 23
def local_repository_exists?
File.exists?( File.expand_path( GIT_PATH ) )
end
|
#remote_repository_exists?(config) ⇒ Boolean
27
28
29
|
# File 'lib/billy/util/scm/git.rb', line 27
def remote_repository_exists?( config )
get_remotes( config ).any?
end
|