-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_latest
44 lines (32 loc) · 1.12 KB
/
fetch_latest
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
#!/usr/bin/env ruby
def run_git_command(command,capture_ouptut = false)
full_command = "git #{command}"
if (capture_ouptut)
`#{full_command}`
else
system(full_command)
end
end
def get_latest_remote_branch_name(remote_name)
branch_pattern = /^\d*$/
branches = run_git_command("fetch #{remote_name}")
latest_branch = Dir.entries(File.join('.git','refs','remotes',remote_name)).select{|folder| branch_pattern =~ folder}.sort{|first,second| second <=> first}.first
end
def get_all_available_non_origin_remotes
run_git_command("remote",true).split("\n").select{|remote| /origin/ !~ remote}
end
def choose_remote(remotes)
remotes.each_with_index do|remote,index|
puts "#{index + 1} - #{remote}\n"
end
"Choose remote:"
index = gets.chomp.to_i
index == 0 ? "": remotes[index-1]
end
def update_to_latest_branch_on(remote_name)
`gitrb commit`
`gitrb checkout master`
`gitrb pull #{remote_name} #{get_latest_remote_branch_name(remote_name)} true`
end
remote_name = choose_remote(get_all_available_non_origin_remotes)
update_to_latest_branch_on(remote_name) unless remote_name.empty?