0
# Pager from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
0
return if PLATFORM =~ /win32/
0
exec pager rescue exec "/bin/sh", "-c", pager
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
+Enter <-h> to see options, <-H> to see notes about configured aliases
0
+and recommended workflow, or any other option.
0
+Ctrl+D or an invalid option to abort
0
Some git aliases have been created for developer convenience:
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
+def optparse(options = OpenStruct.new, argv = ARGV)
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.svn_branch = "apache/trunk"
0
options.origin = "git://github.com/vic/buildr.git"
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 svn branch instead of apache/trunk") 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
+ opt.banner = "Usage: buildr-git.rb [options]"
0
+ opt.separator "OPTIONS:"
0
-origin = options.origin
0
-svn_branch = options.svn_branch
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
+ 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 svn branch instead of apache/trunk") 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('-n', "--name USER_NAME",
0
+ "Configure your USER_NAME for git commits") do |value|
0
+ options.user_name = value
0
+ opt.on('-h', "--help", "Show buildr-git help") do
0
+ opt.on('-H', "--notice", "Show notice about aliases and git workflow") do
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
-Enter <-h> to see options, <-n> to see notes about configured aliases
0
-and recommended workflow, or any other option.
0
-Ctrl+D or an invalid option to abort
0
-input = input.split if input
0
-unless input && input.empty?
0
+ options = optparse(options, input.split)
0
+ if input.nil? || (input != "\n" && input.empty?)
0
-`git clone #{origin} #{local} 1>&2` unless File.directory?(File.join('.git', origin))
0
+ origin = options.origin
0
+ member = origin =~ /@/
0
+ svn_branch = options.svn_branch
0
+ user_email = options.email
0
+ user_name = options.user_name
0
- # Load the list of git-svn committers
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
- # set the git-svn-authors file
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
- puts "Enter your email as listed on #{svn_authors_file}"
0
- # Check user lis listed
0
- svn_user, git_contact = *svn_authors.find { |entry| /#{email}/i === entry.join(' ') }
0
- fail "You need to be a buildr commmitter listed on #{svn_authors_file}"+
0
- "\nPerhaps you need to set user.email, user.name on .git/config" unless git_contact
0
- if /\s*(.*?)\s+\<(.+)\>\s*/ === git_contact
0
- user_name, user_email = $1, $2
0
- fail "Invalid contact string for #{svn_user}: #{git_contact.inspect}"
0
+ `git clone #{origin} #{local} 1>&2` unless File.directory?(File.join('.git', origin))
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"
0
+ puts "Entering #{local} directory"
0
- `git config user.name "#{user_name}"`
0
- `git config user.email "#{user_email}"`
0
+ # Load the list of git-svn committers
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
- # Ok, now obtain the last svn commit from history
0
- last_svn_log = `git log -n 10 | grep git-svn-id | head -n 1`
0
- fail "No svn metadata on last 10 commits" unless last_svn_log =~ /git-svn-id/
0
- svn_repo, svn_prev = last_svn_log.split[1].split("@")
0
- # Tell git where the svn repository is.
0
- `git config svn-remote.#{svn_branch}.url #{svn_repo}`
0
- `git config svn-remote.#{svn_branch}.fetch :refs/remotes/#{svn_branch}`
0
- # Create the svn branch, do this instead of pulling the full svn history
0
- `git push --force . refs/remotes/origin/master:refs/remotes/#{svn_branch}`
0
- # Create apache aliases for developers git-workflow.
0
- `git config alias.apache-fetch "!git-svn fetch #{svn_branch}"`
0
- `git config alias.apache-merge "!git merge #{svn_branch}"`
0
- `git config alias.apache-pull "!git apache-fetch && git apache-merge"`
0
- `git config alias.apache-push "!git-svn dcommit --username #{svn_user}"`
0
+ # set the git-svn-authors file
0
+ `git config svn.authorsfile "#{svn_authors_file}"`
0
- # Create github origin aliases
0
- `git config alias.get "!git apache-fetch && git fetch origin"`
0
- `git config alias.mrg "!git apache-merge && git merge origin"`
0
- `git config alias.put "!git apache-push && git push origin"`
0
+ # Check that git is configured for the developer
0
+ user_email ||= `git config --get user.email`.chomp
0
+ puts "Enter your email as listed on #{svn_authors_file}"
0
+ user_email = gets.chomp
0
+ puts "Provide an email address for git usage:"
0
+ user_email = gets.chomp
0
- # This is Victor's cronjob
0
- `git config alias.synchronize "!git get && git mrg && git put"`
0
+ # Check user is listed
0
+ unless user_email.empty?
0
+ svn_user, git_contact = *svn_authors.find { |entry| /#{user_email}/ === entry.join(' ') }
0
- notice = <<-NOTICE + notice
0
+ if git_contact.nil? # if using the authenticated git, he must be listed
0
+ You need to be a buildr commmitter listed on #{svn_authors_file}.
0
+ Perhaps you need to add yourself to it, commit it using SVN, and
0
+ and run this script again.
0
+ Also checks your git global values for user.email and user.name
0
+ elsif /\s*(.*?)\s+\<(.+)\>\s*/ === git_contact
0
+ user_name, user_email = $1, $2
0
+ puts "Invalid contact string for #{svn_user}: #{git_contact.inspect}"
0
+ elsif user_email =~ /^\s*$/
0
+ puts "User email shall not include spaces: #{user_email.inspect}"
0
+ user_name ||= `git config --get user.name`.chomp
0
+ if git_contact.nil? && user_name.empty?
0
+ puts "Provide a developer name for git usage:"
0
+ user_name = gets.chomp
0
+ # Configure user name and email for git sake (and github's gravatar)
0
+ puts "You claim to be #{user_name.inspect} <#{user_email}> "
0
+ puts "with apache-svn user: #{svn_user}" if svn_user
0
+ `git config user.name "#{user_name}"`
0
+ `git config user.email "#{user_email}"`
0
+ # Ok, now obtain the last svn commit from history
0
+ last_svn_log = `git log -n 10 | grep git-svn-id | head -n 1`
0
+ fail "No svn metadata on last 10 commits" unless last_svn_log =~ /git-svn-id/
0
+ svn_repo, svn_prev = last_svn_log.split[1].split("@")
0
+ # Tell git where the svn repository is.
0
+ `git config svn-remote.#{svn_branch}.url #{svn_repo}`
0
+ `git config svn-remote.#{svn_branch}.fetch :refs/remotes/#{svn_branch}`
0
+ # Create the svn branch, do this instead of pulling the full svn history
0
+ `git push --force . refs/remotes/origin/master:refs/remotes/#{svn_branch}`
0
+ # Create apache aliases for developers git-workflow.
0
+ `git config alias.apache-fetch "!git-svn fetch #{svn_branch}"`
0
+ `git config alias.apache-merge "!git merge #{svn_branch}"`
0
+ `git config alias.apache-pull "!git apache-fetch && git apache-merge"`
0
+ `git config alias.apache-push "!git-svn dcommit --username #{svn_user}"`
0
+ `git config alias.apache-push "!git-svn dcommit"`
0
+ # Create github origin aliases
0
+ `git config alias.get "!git apache-fetch && git fetch origin"`
0
+ `git config alias.mrg "!git apache-merge && git merge origin"`
0
+ `git config alias.put "!git apache-push && git push origin"`
0
+ # This is Victor's cronjob
0
+ `git config alias.synchronize "!git get && git mrg && git put"`
0
+ puts <<-NOTICE + notice
0
- Your git repo #{local} has been configured, please review the
0
- #{File.join(local, '.git/config')} file.
0
+ Your git repo #{local} has been configured, please review the
0
+ #{File.join(local, '.git/config')} file.
Comments
No one has commented yet.