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
+# You dont need to have a buildr copy to use it, just execute the buildr-git balloon:
0
+# ruby -ropen-uri -e 'eval(open("http://balloon.hobix.com/buildr-git").read)'
0
-local = Dir.pwd if File.directory?(File.join('.git', Dir.pwd))
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
+ return if PLATFORM =~ /win32/
0
+ return unless STDOUT.tty?
0
-
origin = ARGV.shift || 'git@github.com:vic/buildr.git'0
-svn_branch = "apache/trunk"
0
+ unless Kernel.fork # Child process
0
+ STDERR.reopen(write) if STDERR.tty?
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 "This script will configure a buildr-git copy on so you can commit to svn."
0
-puts "Local git copy: #{local}"
0
-puts "Press RETURN to continue or anything else to abort"
0
-unless gets.chomp.empty?
0
+ # Parent process, become pager
0
+ ENV['LESS'] = 'FSRX' # Don't page if the input is short enough
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
+ Some git aliases have been created for developer convenience:
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
+ 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
+ git apache-pull # get apache-fetch && git apache-merge
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
+ # 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
+ # See the recommended workflow to avoid commiting
0
+ # other developers' changes and the following section.
0
+ Buildr has an unofficial git mirror on github, maintained by Victor:
0
+ http://github.com/vic/buildr
0
+ Actually it's not Victor who manually updates it, he has a cron-job on his
0
+ server, that only runs
0
+ A command you also have configured on your .git/config file.
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
+ 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
+ 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
+ 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
+ 1) get your buildr-git configured
0
+ (you have already do so, this was the most difficult part)
0
+ 2) create a topic branch to work on, say.. you want to add cool-feature:
0
+ git checkout -b cool-feature master
0
+ # now on branch cool-feature
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
+ git commit --interactive
0
+ 3) review your changes, get ALL specs passing, repeat step 3 as needed
0
+ 4) let's see what are they doing on trunk
0
+ # You can inspect the upstream changes without having to merge them
0
+ git log apache/trunk # what are they doing!!
0
+ 5) integrate mainstream changes to your cool-feature branch, you can always
0
+ use `git cherry-pick` to select only some commits.
0
+ git merge apache/trunk cool-feature
0
+ 6) Go to 3 unless ALL specs are passing.
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
+ https://issues.apache.org/jira/browse/BUILDR
0
+ buildr-dev@incubator.apache.org
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
+ 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
+ 9) Pull changes from origin frequently.
0
+ git rebase --onto origin/master master master
0
+ 10) Unconditionally, Go to step 2 ;)
0
+ Share your buildr-git workflow, git tips, etc.
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
+options = OpenStruct.new
0
+opt = OptionParser.new do |opt|
0
+ if `git status 2>/dev/null`.chomp.empty?
0
+ options.local = File.expand_path('buildr', Dir.pwd)
0
+ puts "Current directory is a git repo: #{Dir.pwd}"
0
+ options.local = Dir.pwd
0
+ options.svn_branch = "apache/trunk"
0
+ options.origin = "git://github.com/vic/buildr.git"
0
+ options.member = false
0
+ opt.banner = "Usage: buildr-git.rb [options]"
0
+ opt.separator "OPTIONS:"
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
+ opt.on('-A', "--authenticated", "Use git@github.com:vic/buildr.git as origin") do
0
+ options.origin = "git@github.com/vic/buildr.git"
0
+ opt.on("-o", "--origin GIT_URL", "Clone from GIT_URL origin") do |value|
0
+ options.origin = value
0
+ opt.on('-l', "--local DIRECTORY", "Create local git clone on DIRECTORY") do |value|
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
+ opt.on('-e', "--email EMAIL",
0
+ "Configure git to use EMAIL for commits") do |value|
0
+ opt.on('-h', "--help", "Show buildr-git help") do
0
+ opt.on('-n', "--notice", "Show notice about aliases and git workflow") do
0
+origin = options.origin
0
+svn_branch = options.svn_branch
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
+This script will configure a buildr-git copy on so you can commit to svn.
0
+Local git copy: #{local}
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
+opt.parse! [input.chomp] if input
0
+unless input && input.chomp.empty?
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
`git config svn.authorsfile "#{svn_authors_file}"`
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
puts "Enter your email as listed on #{svn_authors_file}"
0
fail "Invalid contact string for #{svn_user}: #{git_contact.inspect}"
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 "You claim to be #{user_name} <#{user_email}> with apache-svn user"
0
`git config user.name "#{user_name}"`
0
`git config user.email "#{user_email}"`
0
`git config alias.synchronize "!git get && git mrg && git put"`
0
- Your git repo #{local} has been configured, please review the .git/config file.
0
+ notice = <<-NOTICE + notice
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
- 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
- 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
- git apache-pull # get apache-fetch && git apache-merge
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
- # 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
- # See the recommended workflow to avoid commiting other developers' changes,
0
- # and the notes on github mirror.
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
- A command you also have configured on your .git/config file.
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
- 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
- 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
- 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
- 1) get your buildr-git configured (you have already do so, this was the most difficult part)
0
- 2) create a topic branch to work on, say.. you want to add cool-feature:
0
- git checkout -b cool-feature master
0
- # now on branch cool-feature
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
- 3) review your changes, get ALL specs passing, repeat step 3 as needed
0
- 4) let's see what are they doing on trunk
0
- # You can inspect the upstream changes without having to merge them
0
- git log apache/trunk # what are they doing!!
0
- 5) integrate mainstream changes to your cool-feature branch (you can always use cherry-pick)
0
- git merge apache/trunk cool-feature
0
- 6) Go to 3 unless ALL specs are passing.
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
- 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
- git rebase --into origin/master master
0
- git push origin master:master
0
- 9) Pull changes from origin frequently.
0
- git rebase --onto origin/master master master
0
- 10) Unconditionally, Go to step 2 ;) or share your buildr-git workflow, tips, etc.
Comments
No one has commented yet.