public
Fork of eventualbuddha/sake-git
Description: A set of Sake tasks to make developing with Git easier.
Clone URL: git://github.com/granth/sake-git.git
Search Repo:
First commit
Tue Mar 04 13:49:54 -0800 2008
commit  53acbc6559aa5e88b69c5543d423d81866c7a791
tree    0a7802bc47d602b1729913715303c1ce296a7812
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -0,0 +1,57 @@
0
+Sake-Git
0
+========
0
+
0
+Here are a few Sake tasks to make developing with Git easier (and some corresponding Git aliases to make invoking them easier). Install them with:
0
+
0
+$ rake install
0
+
0
+
0
+Common Commands
0
+---------------
0
+
0
+$ sake git:update
0
+
0
+Updates your current git repository, autodetecting whether you have a regular ol' git project or a git-svn project. Alias it to `git up' with this alias:
0
+
0
+[alias]
0
+ up = !sake git:update
0
+
0
+
0
+$ sake git:push
0
+
0
+Commits any changes in your current branch not yet pushed upstream AND ports 'em over to master. Another alias for ya:
0
+
0
+[alias]
0
+ ci = !sake git:push
0
+
0
+
0
+$ sake git:open [NAME=mynewbranch]
0
+
0
+Creates a new branch off master. Think of this as opening an issue, or a new path of development. Because of the way Rake handles (or _doesn't_ handle) arguments, the alias for this one is a little weird:
0
+
0
+[alias]
0
+ open = !sake git:open NAME= -- $1
0
+
0
+Allowing you to call it like so:
0
+
0
+$ git open mynewbranch
0
+
0
+You can even call it without the branch name and it'll ask you for it:
0
+
0
+$ git open
0
+* Name your branch: mynewbranch
0
+
0
+
0
+$ sake git:close [NAME=mynewbranch]
0
+
0
+This is open's brother, and should be used when you finish something and have already moved it to master or upstream. If you haven't yet, don't worry - this won't eat your data. Aliases for everyone:
0
+
0
+[alias]
0
+ close = !sake git:close NAME= -- $1
0
+
0
+
0
+
0
+Credits
0
+-------
0
+
0
+Thanks to Coda Hale and everyone else at Wesabe for trying these out when I first wrote them and contributing tasks of their own.
...
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -0,0 +1,11 @@
0
+desc "Install the sake-git tasks (use FORCE=yes to overwrite)"
0
+task :install do
0
+ if ENV['FORCE'] == 'yes'
0
+ tasks = `rake -f #{Dir.pwd}/git.rake -T`.to_a.grep(/^rake/).map {|l| l[/^rake (\S+)/, 1]}
0
+ `sake -u #{tasks.join(' ')} 2>/dev/null`
0
+ end
0
+
0
+ exec("sake -i #{Dir.pwd}/git.rake")
0
+end
0
+
0
+task :default => :install
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
0
@@ -0,0 +1,195 @@
0
+desc "This is just here for the other tasks and isn't intended for your use"
0
+task 'git:helpers' do
0
+ def git_branch
0
+ `git-branch | grep \"*\"`.strip[(2..-1)]
0
+ end
0
+ def git_branches
0
+ `git-branch`.to_a.map { |b| b[(2..-1)].chomp }
0
+ end
0
+ def git?
0
+ `git-status`
0
+ (not ($?.exitstatus == 128))
0
+ end
0
+ def git_stash
0
+ `git-diff-files --quiet`
0
+ if ($?.exitstatus == 1) then
0
+ stash = true
0
+ clear = (`git-stash list`.scan("\n").size == 0)
0
+ puts("* Saving changes...")
0
+ `git-stash save`
0
+ else
0
+ stash = false
0
+ end
0
+ begin
0
+ yield rescue puts("* Encountered an error, backing out...")
0
+ ensure
0
+ if stash then
0
+ puts("* Applying changes...")
0
+ sh("git-stash apply")
0
+ `git-stash clear` if clear
0
+ end
0
+ end
0
+ end
0
+ def git_fetch
0
+ sh("git#{"-svn" if git_svn?} fetch")
0
+ end
0
+ def git_rebase(what = nil)
0
+ if git_svn? then
0
+ sh("git-rebase git-svn #{what}")
0
+ else
0
+ sh("git-rebase origin/master #{what}")
0
+ end
0
+ end
0
+ def git_push
0
+ git_svn? ? (sh("git-svn dcommit")) : (sh("git-push"))
0
+ end
0
+ def git_svn?
0
+ `git-branch -a` =~ /^\s*git-svn/
0
+ end
0
+ def argv
0
+ ARGV.inject([]) do |argv, arg|
0
+ if (argv.last and argv.last =~ /=$/) then
0
+ (argv.last << arg)
0
+ else
0
+ (argv << arg.dup)
0
+ end
0
+ argv
0
+ end
0
+ end
0
+ def correct_env_from_argv
0
+ argv.grep(/^[A-Z]+=/).each { |kv| ENV.send(:[]=, *kv.split("=", 2)) }
0
+ end
0
+ def env(name)
0
+ case val = ENV[name]
0
+ when "", nil then
0
+ nil
0
+ else
0
+ val
0
+ end
0
+ end
0
+ correct_env_from_argv
0
+end
0
+
0
+desc 'Pull new commits from the repository'
0
+task 'git:update' => [ 'git:helpers' ] do
0
+ git_stash do
0
+ branch = git_branch
0
+ if (branch == "master") then
0
+ switch = false
0
+ else
0
+ switch = true
0
+ `git-checkout master`
0
+ puts("* Switching back to master...")
0
+ end
0
+ puts("* Pulling in new commits...")
0
+ git_fetch
0
+ git_rebase
0
+ if switch then
0
+ puts("* Porting changes into #{branch}...")
0
+ `git-checkout #{branch}`
0
+ sh("git-rebase master")
0
+ end
0
+ end
0
+end
0
+
0
+desc 'Push local commits into the Wesabe repository'
0
+task 'git:push' => [ 'git:update' ] do
0
+ git_stash do
0
+ puts("* Pushing changes...")
0
+ git_push
0
+ branch = git_branch
0
+ unless (branch == "master") then
0
+ `git-checkout master`
0
+ puts("* Porting changes into master")
0
+ git_rebase
0
+ `git-checkout #{branch}`
0
+ end
0
+ end
0
+end
0
+
0
+desc 'Delete the current branch and switch back to master'
0
+task 'git:close' => [ 'git:helpers' ] do
0
+ branch = (env("NAME") or git_branch)
0
+ current = git_branch
0
+ if (branch == "master") then
0
+ $stderr.puts("* Cannot delete master branch")
0
+ exit(1)
0
+ end
0
+ if (current == branch) then
0
+ puts("* Switching to master")
0
+ `git-checkout master 2>/dev/null`
0
+ end
0
+ puts("* Deleting branch #{branch}")
0
+ `git-branch -d #{branch} 2>/dev/null`
0
+ if ($?.exitstatus == 1) then
0
+ $stderr.puts("* Branch #{branch} isn't a strict subset of master, quitting")
0
+ `git-checkout #{current} 2>/dev/null`
0
+ exit(1)
0
+ end
0
+ `git-checkout #{current} 2>/dev/null` unless (current == branch)
0
+ exit(0)
0
+end
0
+
0
+desc 'Create a new branch off master'
0
+task 'git:open' => [ 'git:helpers' ] do
0
+ newbranch = (env("NAME") or begin
0
+ (require("readline")
0
+ print("* Name your branch: ")
0
+ Readline.readline.chomp)
0
+ end)
0
+ branch = git_branch
0
+ unless (branch == "master") then
0
+ puts("* Switching to master")
0
+ `git-checkout master`
0
+ end
0
+ `git-checkout -b #{newbranch}`
0
+ unless $?.exitstatus.zero? then
0
+ puts("* Couldn't create branch #{newbranch}, switching back to #{branch}")
0
+ `git-checkout #{branch}`
0
+ exit(1)
0
+ end
0
+ exit(0)
0
+end
0
+
0
+desc 'Merge the current branch into the master branch.'
0
+task 'git:fold' => [ 'git:helpers' ] do
0
+ branch = git_branch
0
+ if (branch == "master") then
0
+ $stderr.puts("* Cannot fold master branch")
0
+ exit(1)
0
+ end
0
+ puts("* Switching to master")
0
+ `git-checkout master 2>/dev/null`
0
+ puts("* Merging #{branch}")
0
+ system("git-merge #{@merge_flags} #{branch}")
0
+ if ($?.exitstatus == 1) then
0
+ $stderr.puts("* Merge had errors -- see to your friend")
0
+ exit(1)
0
+ end
0
+ puts("* Switching to #{branch}")
0
+ `git-checkout #{branch} 2>/dev/null`
0
+end
0
+
0
+desc 'Squash the current branch into the master branch.'
0
+task 'git:squash' do
0
+ @merge_flags = "--squash"
0
+ Rake::Task["git:fold"].invoke
0
+end
0
+
0
+desc 'Update all branches'
0
+task 'git:update:all' => [ 'git:helpers' ] do
0
+ git_stash do
0
+ branch = git_branch
0
+ switch = true
0
+ git_branches.each do |b|
0
+ puts("* Updating branch #{b}")
0
+ git_rebase(b)
0
+ unless $?.exitstatus.zero? then
0
+ puts("* Couldn't rebase #{b}, aborting so you can clean it up")
0
+ switch = false
0
+ break
0
+ end
0
+ end
0
+ `git-checkout #{branch} 2>/dev/null` if switch
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
0
@@ -0,0 +1,8 @@
0
+[alias]
0
+ ci = !sake git:push
0
+ up = !sake git:update
0
+ upa = !sake git:update:all
0
+ open = !sake git:open NAME= -- $1
0
+ close = !sake git:close NAME= -- $1
0
+ fold = !sake git:fold
0
+ sq = !sake git:squash

Comments

    No one has commented yet.