-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.rake
More file actions
75 lines (61 loc) · 1.76 KB
/
Copy pathgit.rake
File metadata and controls
75 lines (61 loc) · 1.76 KB
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
namespace :git do
desc "Rebase a branch from master"
task :rebase, :branch do |t, args|
#make sure we have a branch
branch = args[:branch]
if(branch.nil?)
puts "Must specify branch"
exit
end
`git co master`
`git fetch`
`git pull origin master`
if local_branch? branch
`git co #{branch}`
else
`git co --track origin/#{branch}`
end
`git pull origin #{branch}`
`git rebase origin/master`
puts "Assuming the rebase worked you should be able to push your changes:"
puts "git push origin #{branch}"
end
desc "Convert an existing issue into a pull request"
task :pullrequest, :issue, :head, :base do |t, args|
hub = `hub`
if (hub.include? 'command not found')
puts "Must have the 'hub' command line tool installed: https://github.com/defunkt/hub"
exit
end
base_ref = args[:issue]
if(base_ref.nil?)
puts "Must specify a GitHub issue"
exit
end
head_sha = args[:head] || get_branch
base_sha = args[:base] || 'master'
output = `hub pull-request -i #{base_ref} -b #{OWNER}:#{base_sha} -h #{OWNER}:#{head_sha}`
puts "Assuming the conversion worked, issue \##{base_ref} is now a pull request:"
puts "#{output}"
end
end
def change_branch branch
current_branch = get_branch
puts current_branch
if(current_branch != branch)
puts "Switching to the #{branch} branch"
`git checkout --track -b #{branch} origin/#{branch} `
end
end
def get_branch
`git status | grep '# On branch '`.sub('# On branch ','').strip!
end
def local_branch? branch
`git branch -l | grep '#{branch}' | wc -l`
end
def store_hash build_dir
`git log --format='%H' -n1 > #{build_dir}/hash.txt`
end
def get_hash build_dir
`cat #{build_dir}/hash.txt`.strip!
end