forked from intellisysmay2014/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_branch
40 lines (27 loc) · 1.21 KB
/
fetch_branch
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
#!/usr/bin/env ruby
require_relative 'git_utils.rb'
def get_specific_remote_branch_name_from(remote_name)
run_git_command("fetch #{remote_name}")
branches = run_git_command("branch --remote",true).split("\n").select{|item| %r/#{remote_name}/ =~ item}.map{|item| item.gsub(%r/#{remote_name}\//,"").strip}
pick_item_from(branches,"Choose Branch:")
end
def get_all_available_non_origin_remotes
run_git_command("remote",true).split("\n").select{|remote| /origin/ !~ remote}
end
def choose_remote(remotes)
pick_item_from(remotes,"Choose remote:")
end
def update_to_specific_branch_on(remote_name)
run_git_command("add -A")
run_git_command('commit -m "Updated"')
run_git_command("checkout clean")
specific_branch = get_specific_remote_branch_name_from(remote_name)
new_branch = "pull_#{remote_name}_#{specific_branch}"
run_git_command("checkout -b #{new_branch}")
run_git_command("checkout #{new_branch}")
run_git_command("pull #{remote_name} #{specific_branch}")
end
%w[master clean].each{|branch| exit_if_on_the_branch branch}
remote_name = ARGV.shift
remote_name = choose_remote(get_all_available_non_origin_remotes) if remote_name == nil
update_to_specific_branch_on(remote_name) unless remote_name.empty?