Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (37 sloc) 1.313 kb
a5e4df2 @developwithpassion Initial commit
developwithpassion authored
1 #!/usr/bin/env ruby
2
3 def run_git_command(command,capture_ouptut = false)
4 full_command = "git #{command}"
5 if (capture_ouptut)
6 `#{full_command}`
7 else
8 system(full_command)
9 end
10 end
11
12 def get_latest_remote_branch_name(remote_name)
13 branch_pattern = /^\d*$/
14 branches = run_git_command("fetch #{remote_name}")
15 latest_branch = Dir.entries(File.join('.git','refs','remotes',remote_name)).select{|folder| branch_pattern =~ folder}.sort{|first,second| second <=> first}.first
16 end
17
18 def get_all_available_non_origin_remotes
19 run_git_command("remote",true).split("\n").select{|remote| /origin/ !~ remote}
20 end
21
22 def choose_remote(remotes)
23 remotes.each_with_index do|remote,index|
24 puts "#{index + 1} - #{remote}\n"
25 end
26
27 "Choose remote:"
28 index = gets.chomp.to_i
29
30 index == 0 ? "": remotes[index-1]
31 end
32
33 def update_to_latest_branch_on(remote_name)
34 `git add -A`
35 `git commit -m "Updated"`
36 `git checkout master`
37 latest_branch = get_latest_remote_branch_name(remote_name)
38
39 new_branch = "pull_#{remote_name}_#{latest_branch}"
40 `git checkout -b #{new_branch}`
41 `git checkout #{new_branch}`
42 `git pull #{remote_name} #{latest_branch}`
43 end
44
45 remote_name = choose_remote(get_all_available_non_origin_remotes)
46 update_to_latest_branch_on(remote_name) unless remote_name.empty?
47
48
49
50
Something went wrong with that request. Please try again.