├── README.md ├── .gitmodules └── Rakefile /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ruby-on-rails.tmbundle"] 2 | path = ruby-on-rails.tmbundle 3 | url = git://github.com/drnic/ruby-on-rails-tmbundle.git 4 | [submodule "capybara.tmbundle"] 5 | path = capybara.tmbundle 6 | url = git://github.com/lucasefe/capybara-tmbundle.git 7 | [submodule "sass.tmbundle"] 8 | path = sass.tmbundle 9 | url = git://github.com/seaofclouds/sass-textmate-bundle.git 10 | [submodule "handcrafted-haml.tmbundle"] 11 | path = handcrafted-haml.tmbundle 12 | url = git://github.com/handcrafted/handcrafted-haml-textmate-bundle.git 13 | [submodule "jquery.tmbundle"] 14 | path = jquery.tmbundle 15 | url = git://github.com/kswedberg/jquery-tmbundle.git 16 | [submodule "Scalate.tmbundle"] 17 | path = Scalate.tmbundle 18 | url = git://github.com/scalate/Scalate.tmbundle.git 19 | [submodule "Showoff.tmbundle"] 20 | path = Showoff.tmbundle 21 | url = git://github.com/drnic/Showoff.tmbundle.git 22 | [submodule "cucumber-tmbundle"] 23 | path = cucumber-tmbundle 24 | url = git://github.com/cucumber/cucumber-tmbundle.git 25 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'erb' 3 | 4 | $my_verbose = 1 5 | $my_verbose = false if $my_verbose == 0 6 | 7 | desc "update then install" 8 | task :default => [:update, :install] do 9 | end 10 | 11 | desc "Update the files" 12 | task :update => [:pull, :upgrade] do 13 | end 14 | 15 | desc "Pull new changes, via `git pull`" 16 | task :pull do 17 | puts "Pulling.." if $my_verbose 18 | system %Q{git pull} or raise "Git pull failed." 19 | end 20 | 21 | desc "Upgrade submodules to current master" 22 | task :upgrade do 23 | ignore_modified = true 24 | system %Q{ git diff --cached --exit-code > /dev/null } or raise "The git index is not clean." 25 | 26 | submodules = {} 27 | get_submodule_status.each do |path, sm| 28 | if ignore_modified && sm["state"] == "+" 29 | puts "Skipping modified submodule #{path}." 30 | next 31 | end 32 | if sm["state"] == "-" 33 | puts "Skipping uninitialized submodule #{path}." 34 | next 35 | end 36 | submodules[path] = sm 37 | end 38 | 39 | begin 40 | submodules.each do |path,sm| 41 | puts "Upgrading #{path}.." if $my_verbose 42 | 43 | # puts "Fetching all remotes" if $my_verbose 44 | output = %x[cd #{path} && git fetch --all] 45 | 46 | sm_url = %x[git config --get submodule.#{path}.url].chomp 47 | puts "Fetching #{path} from #{sm_url}" if $my_verbose 48 | output = %x[cd #{path} && git fetch #{sm_url} 2>&1] 49 | puts output if $my_verbose and $my_verbose > 1 50 | if not $?.success? 51 | raise "Fetching failed: " + output 52 | end 53 | 54 | # Check that current commit is ancestor of FETCH_HEAD 55 | # sm_commit = %x[cd #{path} && git rev-parse #{sm["commit"]}].chomp 56 | sm_commit = sm['commit'] 57 | merge_base = %x[cd #{path} && git merge-base #{sm_commit} FETCH_HEAD].chomp 58 | if sm_commit != merge_base 59 | # puts "Skipping #{path}: Current commit does not appear to be ancestor of FETCH_HEAD." 60 | # puts "Info: sm_commit: #{sm_commit}, merge_base: #{merge_base}" 61 | # next 62 | output = %x[cd #{path} && git merge FETCH_HEAD] 63 | puts "Merged FETCH_HEAD:\n" + output 64 | end 65 | 66 | output = %x[cd #{path} && git merge --ff-only FETCH_HEAD 2>&1] 67 | if ! output.split("\n")[-1] =~ /^Already up-to-date.( Yeeah!)?/ 68 | puts output 69 | else 70 | puts output if $my_verbose and $my_verbose > 1 71 | # TODO: pull result 72 | end 73 | if not $?.success? 74 | raise "Merging FETCH_HEAD failed: " + output 75 | end 76 | next 77 | 78 | # 1. get available remotes 79 | # 2. find newest one, via 80 | # git --describe always 81 | # git branch (-a) --contains $DESC 82 | # get available master branches via gb -r 83 | # remotes = %x[git --git-dir '#{path}/.git' remote] 84 | # if not $?.success? 85 | # raise "Pulling failed: " + output 86 | # end 87 | # 88 | output = output.split("\n") 89 | # Output important lines 90 | puts output.select{|x| x=~/^Your branch is/} 91 | end 92 | rescue Exception => exc 93 | puts "Exception: " + exc.message 94 | puts exc.backtrace.join("\n") 95 | ensure 96 | Rake::Task[:commitsubmodules].invoke(submodules) 97 | end 98 | end 99 | 100 | desc "install the tmbundles into '~/Library/Application Support/TextMate/Bundles' directory" 101 | task :install do 102 | base = "~/Library/Application Support/TextMate/Bundles" 103 | if not base 104 | system %Q{mkdir -p "#{bash}"} 105 | end 106 | 107 | Dir['*'].each do |file| 108 | next if %w[Rakefile README.md].include? file 109 | 110 | puts "linking #{file}" 111 | 112 | link_file(File.expand_path(file), File.expand_path(File.join(base, file))) 113 | end 114 | 115 | # reload textmate bundles 116 | system %x[osascript -e 'tell application \"TextMate\" to reload bundles'] 117 | 118 | end 119 | 120 | def link_file(file, target) 121 | system %Q{ln -sfn "#{file}" "#{target}"} 122 | end 123 | 124 | def get_submodule_status(sm_args='') 125 | # return { 'vim/bundle/solarized' => {'state'=>' '} } 126 | puts "Getting submodules status.." if $my_verbose 127 | status = %x[ git submodule status #{sm_args} ] or raise "Getting submodule status failed" 128 | r = {} 129 | status.split("\n").each do |line| 130 | if not line =~ /^([ +-])(\w{40}) (.*?)(?: \(.*\))?$/ 131 | raise "Found unexpected submodule line: #{line}" 132 | end 133 | path = $3 134 | next if ! path 135 | r[path] = {"state" => $1, "commit" => $2} 136 | end 137 | return r 138 | end 139 | --------------------------------------------------------------------------------