Permalink
Browse files

Imported rubyspec and git rake libs from rubinius and added a few Mac…

…Ruby specific tasks for merging back upstream.

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1325 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent ad8219f commit b4dfa5d354b4c50c15ad00b2322600846c85591e @alloy alloy committed Apr 4, 2009
Showing with 234 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +117 −0 rakelib/git.rb
  3. +115 −0 rakelib/rubyspec.rake
View
@@ -9,4 +9,5 @@ parse.c
prelude.c
revision.h
y.tab.c
-include/ruby/config.h
+include/ruby/config.h
+spec/ruby
View
@@ -0,0 +1,117 @@
+# Various convenience methods for working with Git
+# repositories in the rubyspec and mspec tasks.
+
+MINIMUM_GIT_VERSION = [1, 5, 3]
+
+def is_git_project(dir, project)
+ system "cd #{dir}; git config --get remote.origin.url '#{project}' >/dev/null"
+ $?.exitstatus == 0
+end
+
+def is_git_dir(dir)
+ File.directory?(dir) and File.directory?(File.join(dir, ".git"))
+end
+
+def git_branch
+ `git branch | grep "*"`.strip[2..-1]
+end
+
+def compare_git_ver
+ v = `git version`.scan(/version (\d+).(\d+).(\d+)/).flatten.map { |s| s.to_i }
+ m = [1, 5, 3]
+
+ (v <=> MINIMUM_GIT_VERSION) >= 0
+end
+
+def check_git_ver
+ raise "Invalid git version, use at least #{MINIMUM_GIT_VERSION.join(".")}" unless
+ compare_git_ver
+end
+
+def on_master
+ branch = git_branch()
+ switch = if branch != "master" then
+ `git checkout master`
+ puts "* Switching back to master..."
+ true
+ end
+
+ yield
+
+ if switch
+ puts "* Porting changes into #{branch}..."
+ `git checkout #{branch}`
+ sh "git rebase master"
+ end
+end
+
+def with_git_changes
+ `git diff-files --quiet`
+ if $?.exitstatus == 1 then
+ yield
+ true
+ end
+end
+
+def git_update
+ check_git_ver
+
+ clear = false
+ stash = with_git_changes do
+ clear = `git stash list`.scan("\n").size == 0
+ puts "* Saving changes..."
+ `git stash save`
+ true
+ end
+
+ on_master do
+ puts "* Pulling in new commits..."
+ sh "git fetch"
+ sh "git rebase origin"
+ end
+
+ if stash then
+ puts "* Applying changes..."
+ sh "git stash apply"
+ `git stash clear` if clear
+ end
+end
+
+def git_push
+ branch = git_branch
+
+ with_git_changes do
+ abort "You have outstanding changes. Please commit them first."
+ end if branch != "master"
+
+ on_master do
+ puts "* Merging topic '#{branch}' back into master..."
+ sh "git merge #{branch}"
+ puts "* Pushing changes..."
+ sh "git push"
+ end
+end
+
+def git_checkout(rev, branch = nil)
+ with_git_changes do
+ abort "You have outstanding changes. Please commit them first."
+ end
+ if branch
+ sh "git checkout -b #{branch} #{rev}"
+ else
+ sh "git checkout #{rev}"
+ end
+end
+
+def spec_ruby
+ "./spec/ruby"
+end
+
+# Don't use -a (--archive) as it includes -t, --times which can
+# cause .rbc files to not be regenerated when they should.
+Rsync_options = "-rlpgoDvP --delete --exclude '*svn*' --exclude '*swp' " \
+ "--exclude '*rbc' --exclude '*.rej' --exclude '*.orig' --exclude 'tags'"
+
+def rsync(left, right, options = nil)
+ sh "rsync #{options || Rsync_options} #{left} #{right}"
+end
View
@@ -0,0 +1,115 @@
+require 'rakelib/git'
+
+namespace :rubyspec do
+ desc "Initialize spec/ruby with a rubyspec clone"
+ task :init do
+ if File.exists? spec_ruby
+ unless is_git_project spec_ruby, "rubyspec.git"
+ raise "#{spec_ruby} is not a rubyspec clone. Please remove before running this task."
+ end
+ else
+ sh "git clone git://github.com/rubyspec/rubyspec.git #{spec_ruby}"
+ end
+ end
+
+ desc "Update rubyspec"
+ task :update => :init do
+ puts "\nUpdating rubyspec repository..."
+ Dir.chdir spec_ruby do
+ git_update
+ end
+ end
+
+ desc "Report changes to the rubyspec sources"
+ task :status do
+ Dir.chdir spec_ruby do
+ system "git status"
+ end
+ end
+
+ desc "Commit changes to the rubyspec sources"
+ task :commit do
+ puts "\nCommitting changes to rubyspec sources..."
+ Dir.chdir spec_ruby do
+ sh "git commit -a"
+ end
+ end
+
+ desc "Push changes to the rubyspec repository"
+ task :push => :update do
+ puts "\nPushing changes to the rubyspec repository..."
+ Dir.chdir spec_ruby do
+ git_push
+ end
+ end
+
+ desc "Switch to the `master' branch"
+ task :master do
+ Dir.chdir spec_ruby do
+ git_checkout('master')
+ end
+ end
+
+ MERGE_OPTIONS = {
+ :exclude => %w{ upstream macruby.mspec tags/macruby },
+ :revert => %w{ ruby.1.9.mspec }
+ }
+
+ desc "Synchronize a checkout with spec/frozen (upstream)"
+ task :merge do
+ rev = ENV['REV'] || File.read('spec/frozen/upstream')
+ puts "\nSwitching to a `merge' branch with current revision of spec/frozen: #{rev}"
+ Dir.chdir(spec_ruby) { git_checkout(rev, 'merge') }
+
+ dir = ENV['DIR'] || spec_ruby
+ sh "rm -rf #{dir}/**"
+
+ rsync_options = Rsync_options.sub("--exclude 'tags'", '')
+ rsync_options += MERGE_OPTIONS[:exclude].map { |f| "--exclude '#{f}'" }.join(' ')
+ rsync "spec/frozen/*", dir, rsync_options
+
+ Dir.chdir(spec_ruby) do
+ sh "git checkout #{MERGE_OPTIONS[:revert].join(' ')}"
+ sh "git status"
+ end
+ end
+
+ desc "Remove the `merge' branch and switch to the `master' branch (cleans all untracked files!)"
+ task :remove_merge do
+ puts "\nRemoving the `merge' branch and all untracked files!"
+ Dir.chdir spec_ruby do
+ sh "git clean -f"
+ sh "git checkout ."
+ git_checkout('master')
+ sh "git branch -D merge"
+ end
+ end
+
+ desc "Synchronize spec/frozen with a current checkout (downstream)"
+ task :sync => :update do
+ dir = ENV['DIR'] || spec_ruby
+
+ rm_rf "spec/frozen"
+ rsync dir + "/*", "spec/frozen"
+
+ version = Dir.chdir(dir) { `git log --pretty=oneline -1`[0..7] }
+ sh "git add spec/frozen/"
+ sh "git commit -m 'Updated CI frozen specs to RubySpec #{version}.' spec/frozen"
+ end
+
+ desc "Switch to the rubyspec commiter URL"
+ task :committer do
+ Dir.chdir spec_ruby do
+ sh "git config remote.origin.url git@github.com:rubyspec/rubyspec.git"
+ end
+ puts "\nYou're now accessing rubyspec via the committer URL."
+ end
+
+ desc "Switch to the rubyspec anonymous URL"
+ task :anon do
+ Dir.chdir spec_ruby do
+ sh "git config remote.origin.url git://github.com/rubyspec/rubyspec.git"
+ end
+ puts "\nYou're now accessing rubyspec via the anonymous URL."
+ end
+end

0 comments on commit b4dfa5d

Please sign in to comment.