public
Rubygem
Description: Apache Buildr
Homepage: http://incubator.apache.org/buildr
Clone URL: git://github.com/vic/buildr.git
Search Repo:
Added optparse, use --help to get an overview.
Fixed output to 80 columns
Added more documentation
Added pager from [1]

[1] http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby


git-svn-id: https://svn.apache.org/repos/asf/incubator/buildr/trunk@648544 
13f79535-47bb-0310-9956-ffa450edef68
vic (author)
Tue Apr 15 23:21:26 -0700 2008
commit  edfdc1f98f36f2bcd84fa59b48cb49d6dbf63733
tree    1036baf3eedaf9ab1e6fde3ba1347a4aa7ffc178
parent  b6bc7662c242b191e68bb97f4698f9c17fbbfdd3
...
 
 
 
 
 
 
 
1
 
 
2
3
4
5
 
 
 
 
6
7
 
8
9
 
 
 
 
 
 
 
10
11
12
13
14
15
16
17
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
...
27
28
29
30
 
31
32
33
...
37
38
39
40
 
41
42
43
44
...
53
54
55
 
 
 
 
56
57
 
 
 
 
58
59
60
61
62
63
64
...
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
...
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
...
255
256
257
 
258
259
260
261
...
265
266
267
 
268
269
270
271
272
...
281
282
283
284
285
286
287
288
 
289
290
291
292
293
294
295
296
297
298
299
...
320
321
322
 
 
 
 
323
324
 
325
326
327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
 
329
330
331
332
0
@@ -1,23 +1,251 @@
0
+# This script helps buildr developers to obtain their own git clone from
0
+# github, having a set of pre-defined aliases to work with Apache's SVN.
0
+#
0
+# You dont need to have a buildr copy to use it, just execute the buildr-git balloon:
0
+#
0
+# ruby -ropen-uri -e 'eval(open("http://balloon.hobix.com/buildr-git").read)'
0
+
0
 require 'yaml'
0
+require 'optparse'
0
+require 'ostruct'
0
 
0
-local = Dir.pwd if File.directory?(File.join('.git', Dir.pwd))
0
 
0
-local ||= ARGV.shift || File.expand_path('buildr', File.dirname(__FILE__))
0
+# Pager from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
0
+def run_pager
0
+ return if PLATFORM =~ /win32/
0
+ return unless STDOUT.tty?
0
 
0
-origin = ARGV.shift || 'git@github.com:vic/buildr.git'
0
+ read, write = IO.pipe
0
 
0
-svn_branch = "apache/trunk"
0
+ unless Kernel.fork # Child process
0
+ STDOUT.reopen(write)
0
+ STDERR.reopen(write) if STDERR.tty?
0
+ read.close
0
+ write.close
0
+ return
0
+ end
0
 
0
-puts "Buildr official commit channel is Apache's svn repository, however some"
0
-puts "developers may prefer to use git while working on several features and"
0
-puts "merging other's changes. "
0
-puts
0
-puts "This script will configure a buildr-git copy on so you can commit to svn."
0
-puts "Local git copy: #{local}"
0
-puts
0
-puts "Press RETURN to continue or anything else to abort"
0
-print "> "
0
-unless gets.chomp.empty?
0
+ # Parent process, become pager
0
+ STDIN.reopen(read)
0
+ read.close
0
+ write.close
0
+
0
+ ENV['LESS'] = 'FSRX' # Don't page if the input is short enough
0
+
0
+ Kernel.select [STDIN] # Wait until we have input before we start the pager
0
+ pager = ENV['PAGER'] || 'less'
0
+ exec pager rescue exec "/bin/sh", "-c", pager
0
+end
0
+
0
+notice = <<NOTICE
0
+ALIASES:
0
+
0
+ Some git aliases have been created for developer convenience:
0
+
0
+ git apache-fetch # get changes from apache/trunk without merging them
0
+ # you can inspect what's happening on trunk without
0
+ # having to worry about merging conflicts.
0
+ # Inspect the remote branch with `git log apache/trunk`
0
+ # Or if you have a git-ui like `tig` you can use that.
0
+
0
+ git apache-merge # Merge already fetched changes on the current branch
0
+ # Use this command to get up to date with trunk changes
0
+ # you can always cherry-pick from the apache/trunk
0
+ # branch.
0
+
0
+ git apache-pull # get apache-fetch && git apache-merge
0
+
0
+ git apache-push # Push to Apache's SVN. Only staged changes (those
0
+ # recorded using `git commit`) will be sent to SVN.
0
+ # You need not to be on the master branch.
0
+ # Actually you can work on a tiny-feature branch and
0
+ # commit directly from it.
0
+ #
0
+ # VERY IMPORTANT:
0
+ #
0
+ # Missing commits on Apache's SVN will be sent using
0
+ # your apache svn account. This means that you can
0
+ # make some commits on behalf of others (like patches
0
+ # comming from JIRA issues or casual contributors)
0
+ # Review the apache-push alias on .git/config if you
0
+ # want to change login-name used for commit to SVN.
0
+ #
0
+ # See the recommended workflow to avoid commiting
0
+ # other developers' changes and the following section.
0
+
0
+THE GITHUB MIRROR:
0
+
0
+ Buildr has an unofficial git mirror on github, maintained by Victor:
0
+
0
+ http://github.com/vic/buildr
0
+
0
+ Actually it's not Victor who manually updates it, he has a cron-job on his
0
+ server, that only runs
0
+
0
+ git synchronize
0
+
0
+ A command you also have configured on your .git/config file.
0
+
0
+ However there are some limitations due to the fact that git-svn cannot
0
+ commit as multiple authors (unless all of them provided their passwords
0
+ to Victor, yet he doesn't want to take over the world.)
0
+ This means that if a commit is pushed to vic/buildr/master and has not
0
+ already been pushed by YOU to Apache's SVN by using `git apache-push`
0
+ your change will be commited to apache/trunk having Victor as the author
0
+ (that's how he gains meritocratic points at Apache :P).
0
+
0
+ So, it's very important - if you care about meritocracy - to follow or at
0
+ least that you get an idea of the recommended workflow.
0
+
0
+RECOMMENDED WORKFLOW:
0
+
0
+ So now that you have your local buildr copy you can create topic branches
0
+ to work on independent features, and still merge easily with head changes.
0
+
0
+ They may seem lots of things to consider, but it's all for Buildr's healt.
0
+ As all things git, you can always follow your own workflow and even create
0
+ aliases on you .git/config file to avoid typing much. So, here they are:
0
+
0
+ 1) get your buildr-git configured
0
+ (you have already do so, this was the most difficult part)
0
+
0
+ 2) create a topic branch to work on, say.. you want to add cool-feature:
0
+
0
+ git checkout -b cool-feature master
0
+ # now on branch cool-feature
0
+
0
+ 3) hack hack hack.. use the source luke.
0
+ every time you feel you have something important like added failing
0
+ spec, added part of feature, or resolved some conflict from merges,
0
+ you can commit your current progress. If you want to be selective, use:
0
+
0
+ git commit --interactive
0
+
0
+ 3) review your changes, get ALL specs passing, repeat step 3 as needed
0
+
0
+ 4) let's see what are they doing on trunk
0
+
0
+ git apache-fetch
0
+ # You can inspect the upstream changes without having to merge them
0
+ git log apache/trunk # what are they doing!!
0
+
0
+ 5) integrate mainstream changes to your cool-feature branch, you can always
0
+ use `git cherry-pick` to select only some commits.
0
+
0
+ git merge apache/trunk cool-feature
0
+
0
+ 6) Go to 3 unless ALL specs are passing.
0
+
0
+ 7.a) (Skip to 7.b you have commit bit on Apache's SVN)
0
+ Create a patch using `git format-patch`
0
+ Promote your changes, create a JIRA issue and upload it granting Apache
0
+ license to include your code:
0
+
0
+ https://issues.apache.org/jira/browse/BUILDR
0
+ buildr-dev@incubator.apache.org
0
+
0
+ 7.b) Now you have everyhing on staging area and merged important changes
0
+ from apache/trunk, it's time to commit them to Apache's SVN.
0
+
0
+ git apache-push
0
+
0
+ 8) Optional. If you can push to vic/buildr/master mirror, you can just
0
+ synchronize the mirror helping others to get changes without having to
0
+ wait on Victor's cronjob to run every hour (useful for urgent changes).
0
+
0
+ git synchronize
0
+
0
+ 9) Pull changes from origin frequently.
0
+
0
+ git fetch origin
0
+ git rebase --onto origin/master master master
0
+
0
+ 10) Unconditionally, Go to step 2 ;)
0
+ Share your buildr-git workflow, git tips, etc.
0
+
0
+RESOURCES:
0
+
0
+ http://github.com/vic/buildr/tree/master
0
+ http://git.or.cz/gitwiki/GitCheatSheet
0
+ http://groups.google.com/group/git-users/web/git-references
0
+
0
+NOTICE
0
+
0
+options = OpenStruct.new
0
+opt = OptionParser.new do |opt|
0
+
0
+ if `git status 2>/dev/null`.chomp.empty?
0
+ options.local = File.expand_path('buildr', Dir.pwd)
0
+ else
0
+ puts "Current directory is a git repo: #{Dir.pwd}"
0
+ options.local = Dir.pwd
0
+ end
0
+
0
+ options.svn_branch = "apache/trunk"
0
+ options.origin = "git://github.com/vic/buildr.git"
0
+ options.member = false
0
+
0
+ opt.banner = "Usage: buildr-git.rb [options]"
0
+ opt.separator ""
0
+ opt.separator "OPTIONS:"
0
+
0
+ opt.on('-a', "--anonymous", "Use git://github.com/vic/buildr.git as origin") do
0
+ options.origin = "git://github.com/vic/buildr.git"
0
+ options.member = false
0
+ end
0
+ opt.on('-A', "--authenticated", "Use git@github.com:vic/buildr.git as origin") do
0
+ options.origin = "git@github.com/vic/buildr.git"
0
+ options.member = true
0
+ end
0
+ opt.on("-o", "--origin GIT_URL", "Clone from GIT_URL origin") do |value|
0
+ options.origin = value
0
+ end
0
+ opt.on('-l', "--local DIRECTORY", "Create local git clone on DIRECTORY") do |value|
0
+ options.local = value
0
+ end
0
+ opt.on('-b', "--branch GIT_SVN_BRANCH",
0
+ "Set the name for the remote branch tracking apache/trunk changes") do |value|
0
+ options.svn_branch = value
0
+ end
0
+ opt.on('-e', "--email EMAIL",
0
+ "Configure git to use EMAIL for commits") do |value|
0
+ options.email = value
0
+ end
0
+ opt.on('-h', "--help", "Show buildr-git help") do
0
+ puts opt
0
+ exit(0)
0
+ end
0
+ opt.on('-n', "--notice", "Show notice about aliases and git workflow") do
0
+ run_pager
0
+ puts notice
0
+ exit(0)
0
+ end
0
+end
0
+
0
+opt.parse!(ARGV)
0
+
0
+origin = options.origin
0
+local = options.local
0
+svn_branch = options.svn_branch
0
+email = options.email
0
+
0
+puts <<HEADER
0
+
0
+Buildr official commit channel is Apache's svn repository, however some
0
+developers may prefer to use git while working on several features and
0
+merging other's changes.
0
+
0
+This script will configure a buildr-git copy on so you can commit to svn.
0
+Local git copy: #{local}
0
+
0
+Press <RETURN> to continue, <-h> to see options, <-n> to see the
0
+comments on configured aliases and git workflow.
0
+Ctrl+D or write anything else to abort
0
+HEADER
0
+print '> '
0
+input = gets
0
+opt.parse! [input.chomp] if input
0
+unless input && input.chomp.empty?
0
   puts "Aborting."
0
   exit(0)
0
 end
0
@@ -27,7 +255,7 @@
0
 Dir.chdir(local) do
0
   
0
   # Load the list of git-svn committers
0
- svn_authors_file = File.expand_path('etc/git-svn-authors', local)
0
+ svn_authors_file = File.expand_path('etc/git-svn-authors', Dir.pwd)
0
   svn_authors = File.read(svn_authors_file)
0
   svn_authors.gsub!(/\s+=\s+/, ': ')
0
   svn_authors = YAML.load(svn_authors)
0
@@ -37,7 +265,7 @@
0
   `git config svn.authorsfile "#{svn_authors_file}"`
0
 
0
   # Check that git is configured for the git developer
0
- email = `git config --get user.email`.chomp
0
+ email ||= `git config --get user.email`.chomp
0
   if email.empty?
0
     puts "Enter your email as listed on #{svn_authors_file}"
0
     print "> "
0
0
@@ -53,8 +281,15 @@
0
   else
0
     fail "Invalid contact string for #{svn_user}: #{git_contact.inspect}"
0
   end
0
+
0
+ # Start the pager
0
+ run_pager
0
+
0
   # Configure user name and email for git sake (and github's gravatar)
0
- puts "You claim to be #{user_name} <#{user_email}> with apache-svn user: #{svn_user}"
0
+ puts
0
+ puts "You claim to be #{user_name} <#{user_email}> with apache-svn user"
0
+ puts " #{svn_user}"
0
+ puts
0
   `git config user.name "#{user_name}"`
0
   `git config user.email "#{user_email}"`
0
 
0
0
0
0
0
@@ -85,112 +320,14 @@
0
   `git config alias.synchronize "!git get && git mrg && git put"`
0
 
0
   # Final notices.
0
- notice = <<-NOTICE
0
- Your git repo #{local} has been configured, please review the .git/config file.
0
-
0
- ALIASES:
0
+ notice = <<-NOTICE + notice
0
 
0
- Some git aliases have been created for developer's convenience:
0
+ Your git repo #{local} has been configured, please review the
0
+ #{File.join(local, '.git/config')} file.
0
 
0
- git apache-fetch # get changes from apache/trunk without merging them
0
- # you can inspect what's happening on trunk without
0
- # having to worry about merging conflicts.
0
- # Inspect the remote branch with `git log apache/trunk`
0
- # Or if you have a git-ui like `tig` you can use that.
0
-
0
- git apache-merge # Merge already fetched changes on the current branch
0
- # Use this command to get up to date with trunk changes
0
- # you can always cherry-pick from the apache/trunk branch.
0
-
0
- git apache-pull # get apache-fetch && git apache-merge
0
-
0
- git apache-push # Push to Apache's SVN. Only staged changed (commited patches)
0
- # will be sent to SVN. You need not to be on the master branch.
0
- # Actually you can work on a tiny-feature branch and commit
0
- # directly from it.
0
- #
0
- # VERY IMPORTANT:
0
- # Missing commits on Apache's SVN will be sent using
0
- # your #{svn_user} svn account. This means that you can make
0
- # some commits on behalf of others (like user-contributed patches
0
- # from JIRA). Review the .git/config if you want to change login-name.
0
- #
0
- # See the recommended workflow to avoid commiting other developers' changes,
0
- # and the notes on github mirror.
0
-
0
- THE GITHUB MIRROR:
0
-
0
- Buildr has an unofficial git mirror on github, maintained by Victor: http://github.com/vic/buildr
0
- Actually it's not Victor who manually updates it, he has a cron-job on his server, that only runs
0
- git synchronize
0
- A command you also have configured on your .git/config file.
0
-
0
- However there are some limitations due that git-svn cannot commit as multiple authors (unless all
0
- of them provided their passwords to Victor, yet he doesn't want to take over the world.)
0
- This means that if a commit "A" is pushed to vic/buildr/master and has not already been pushed
0
- by #{svn_user} using `git apache-push` your change will be commited to apache/trunk having Victor as the
0
- author (that's how he gains meritocratic points on Apache :P).
0
-
0
- So, it's very important - if you care about meritocracy - to follow or at least that you get an
0
- idea of the recommended workflow.
0
-
0
- RECOMMENDED WORKFLOW:
0
-
0
- So now that you have your local buildr copy you can create topic branches to work on
0
- independent features, and still merge easily with head changes.
0
-
0
- They may seem lots of things to consider, but it's all for Buildr's healt. As all things git,
0
- you can always follow your own workflow and even create aliases on you .git/config file to
0
- avoid typing much. So, here here they are:
0
-
0
- 1) get your buildr-git configured (you have already do so, this was the most difficult part)
0
-
0
- 2) create a topic branch to work on, say.. you want to add cool-feature:
0
-
0
- git checkout -b cool-feature master
0
- # now on branch cool-feature
0
-
0
- 3) hack hack hack.. use the source luke.
0
- every time you feel you have something important (added failing spec, added part of feature)
0
- you can commit your changes. If you want to be selective, use: git commit --interactive
0
-
0
- 3) review your changes, get ALL specs passing, repeat step 3 as needed
0
-
0
- 4) let's see what are they doing on trunk
0
-
0
- git apache-fetch
0
- # You can inspect the upstream changes without having to merge them
0
- git log apache/trunk # what are they doing!!
0
-
0
- 5) integrate mainstream changes to your cool-feature branch (you can always use cherry-pick)
0
-
0
- git merge apache/trunk cool-feature
0
-
0
- 6) Go to 3 unless ALL specs are passing.
0
-
0
- 7) Now you have everyhing on stage area (git commit) and merged important changes from
0
- apache/trunk. It's time to commit them to Apache's SVN.
0
-
0
- git apache-push
0
-
0
- 8) (Optional)
0
- Now your changes are on Apache SVN, you can wait for them to get synched to vic/buildr/master
0
- or push them yourself. You need Victor to add you as member, just ask for it.
0
-
0
- git fetch origin
0
- git rebase --into origin/master master
0
- git push origin master:master
0
-
0
- 9) Pull changes from origin frequently.
0
-
0
- git fetch origin
0
- git rebase --onto origin/master master master
0
-
0
- 10) Unconditionally, Go to step 2 ;) or share your buildr-git workflow, tips, etc.
0
-
0
   NOTICE
0
-
0
- puts notice
0
 
0
+ puts notice
0
+
0
 end

Comments

    No one has commented yet.