-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
executable file
·100 lines (77 loc) · 2.09 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/ruby
@defaults = <<DEFAULTS
[color]
diff = auto
status = auto
branch = auto
[alias]
st = status
co = checkout
br = branch
DEFAULTS
def initialize_data
remote_origin = IO.popen('git remote -v show -n origin').readlines
@origin_url = remote_origin[1].strip.scan(/Fetch\sURL:\s(.*)/).to_s
end
def config_remotes
ask "Queres agregar a tu configuracion los alias/colores standard? (Yes/[No]) :" do |answer|
config_git @defaults if answer.match /yes|y|s|si/i
end
ask "Queres configurar un remote para hacer push? ([Yes]/No) :" do |answer|
if answer.match /no|n/i
puts "Chau!";
exit 0
end
end
@remote_name = :review
ask "Nombre del remote [review] :" do |answer|
@remote_name = answer.to_sym unless answer.strip.empty?
end
@branch_name = :master
ask "Nombre del branch [master] :" do |answer|
@branch_name = answer.to_sym unless answer.strip.empty?
end
question = <<"QUEST"
Se va a configurar el remote para que puedas pushear de la siguiente forma:
$ git push #{@remote_name}
y tus cambios vayan al branch #{@branch_name} en el remote: #{@origin_url}
Esto esta bien? ([YES]/No):
QUEST
ask question do |answer|
if answer.match /no|n/i
puts "\nNo configuramos nada :("
config_remotes
else
puts "Configurando"
text = <<GIT
[remote \"#{@remote_name}\"]
url = #{@origin_url}
push = HEAD:refs/for/#{@branch_name}
GIT
config_git text
end
end
end
def config_git(text)
git_config = File.open ".git/config", "a"
git_config.write text
git_config.close
end
def ask(question, &block)
print question
answer = gets.chomp
block.call answer
end
def config_gerrit_hook
ask "Gerrit user?: " do |user|
@gerrit_user = user
end
command = "scp -p -P 8082 #{@gerrit_user.to_s + "@" unless @gerrit_user.strip.empty?}gerrit.teracode.com:hooks/commit-msg .git/hooks/"
puts command
IO.popen command
IO.popen "chmod +x .git/hooks/commit-msg"
end
config_gerrit_hook
initialize_data
puts "La url de el repositorio origin es: #{@origin_url}"
config_remotes