git-up 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
 - data/.gitignore +21 -0
 - data/LICENSE +20 -0
 - data/README.md +9 -0
 - data/Rakefile +55 -0
 - data/VERSION +1 -0
 - data/bin/git-up +6 -0
 - data/git-up.gemspec +62 -0
 - data/lib/git-up.rb +132 -0
 - data/test/helper.rb +10 -0
 - data/test/test_git-up.rb +7 -0
 - metadata +96 -0
 
    
        data/.document
    ADDED
    
    
    
        data/.gitignore
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2009 Aanand Prasad
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 4 
     | 
    
         
            +
            a copy of this software and associated documentation files (the
         
     | 
| 
      
 5 
     | 
    
         
            +
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 6 
     | 
    
         
            +
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 7 
     | 
    
         
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 8 
     | 
    
         
            +
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 9 
     | 
    
         
            +
            the following conditions:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be
         
     | 
| 
      
 12 
     | 
    
         
            +
            included in all copies or substantial portions of the Software.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 15 
     | 
    
         
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 16 
     | 
    
         
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 17 
     | 
    
         
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 18 
     | 
    
         
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 19 
     | 
    
         
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 20 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,9 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            git-up
         
     | 
| 
      
 2 
     | 
    
         
            +
            ======
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            So `git pull` merges by default, when it [should really rebase](http://www.gitready.com/advanced/2009/02/11/pull-with-rebase.html). You can [ask it to rebase instead](http://d.strelau.net/post/47338904/git-pull-rebase-by-default), but it still won't touch anything other than the currently checked-out branch. If you're tracking a bunch of remote branches, you'll get non-fast-forward complaints next time you push.
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Solve it once and for all:
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            begin
         
     | 
| 
      
 5 
     | 
    
         
            +
              require 'jeweler'
         
     | 
| 
      
 6 
     | 
    
         
            +
              Jeweler::Tasks.new do |gem|
         
     | 
| 
      
 7 
     | 
    
         
            +
                gem.name = "git-up"
         
     | 
| 
      
 8 
     | 
    
         
            +
                gem.summary = %Q{git command to fetch and rebase all branches}
         
     | 
| 
      
 9 
     | 
    
         
            +
                gem.email = "aanand.prasad@gmail.com"
         
     | 
| 
      
 10 
     | 
    
         
            +
                gem.homepage = "http://github.com/aanand/git-up"
         
     | 
| 
      
 11 
     | 
    
         
            +
                gem.authors = ["Aanand Prasad"]
         
     | 
| 
      
 12 
     | 
    
         
            +
                gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
         
     | 
| 
      
 13 
     | 
    
         
            +
                # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                gem.add_dependency "colored"
         
     | 
| 
      
 16 
     | 
    
         
            +
                gem.add_dependency "grit"
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
              Jeweler::GemcutterTasks.new
         
     | 
| 
      
 19 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 20 
     | 
    
         
            +
              puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            require 'rake/testtask'
         
     | 
| 
      
 24 
     | 
    
         
            +
            Rake::TestTask.new(:test) do |test|
         
     | 
| 
      
 25 
     | 
    
         
            +
              test.libs << 'lib' << 'test'
         
     | 
| 
      
 26 
     | 
    
         
            +
              test.pattern = 'test/**/test_*.rb'
         
     | 
| 
      
 27 
     | 
    
         
            +
              test.verbose = true
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            begin
         
     | 
| 
      
 31 
     | 
    
         
            +
              require 'rcov/rcovtask'
         
     | 
| 
      
 32 
     | 
    
         
            +
              Rcov::RcovTask.new do |test|
         
     | 
| 
      
 33 
     | 
    
         
            +
                test.libs << 'test'
         
     | 
| 
      
 34 
     | 
    
         
            +
                test.pattern = 'test/**/test_*.rb'
         
     | 
| 
      
 35 
     | 
    
         
            +
                test.verbose = true
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 38 
     | 
    
         
            +
              task :rcov do
         
     | 
| 
      
 39 
     | 
    
         
            +
                abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            task :test => :check_dependencies
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            task :default => :test
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            require 'rake/rdoctask'
         
     | 
| 
      
 48 
     | 
    
         
            +
            Rake::RDocTask.new do |rdoc|
         
     | 
| 
      
 49 
     | 
    
         
            +
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
      
 52 
     | 
    
         
            +
              rdoc.title = "git-up #{version}"
         
     | 
| 
      
 53 
     | 
    
         
            +
              rdoc.rdoc_files.include('README*')
         
     | 
| 
      
 54 
     | 
    
         
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
    
        data/VERSION
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            0.0.0
         
     | 
    
        data/bin/git-up
    ADDED
    
    
    
        data/git-up.gemspec
    ADDED
    
    | 
         @@ -0,0 +1,62 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Generated by jeweler
         
     | 
| 
      
 2 
     | 
    
         
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         
     | 
| 
      
 3 
     | 
    
         
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
         
     | 
| 
      
 4 
     | 
    
         
            +
            # -*- encoding: utf-8 -*-
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Gem::Specification.new do |s|
         
     | 
| 
      
 7 
     | 
    
         
            +
              s.name = %q{git-up}
         
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.0.0"
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
      
 11 
     | 
    
         
            +
              s.authors = ["Aanand Prasad"]
         
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2009-12-22}
         
     | 
| 
      
 13 
     | 
    
         
            +
              s.default_executable = %q{git-up}
         
     | 
| 
      
 14 
     | 
    
         
            +
              s.email = %q{aanand.prasad@gmail.com}
         
     | 
| 
      
 15 
     | 
    
         
            +
              s.executables = ["git-up"]
         
     | 
| 
      
 16 
     | 
    
         
            +
              s.extra_rdoc_files = [
         
     | 
| 
      
 17 
     | 
    
         
            +
                "LICENSE",
         
     | 
| 
      
 18 
     | 
    
         
            +
                 "README.md"
         
     | 
| 
      
 19 
     | 
    
         
            +
              ]
         
     | 
| 
      
 20 
     | 
    
         
            +
              s.files = [
         
     | 
| 
      
 21 
     | 
    
         
            +
                ".document",
         
     | 
| 
      
 22 
     | 
    
         
            +
                 ".gitignore",
         
     | 
| 
      
 23 
     | 
    
         
            +
                 "LICENSE",
         
     | 
| 
      
 24 
     | 
    
         
            +
                 "README.md",
         
     | 
| 
      
 25 
     | 
    
         
            +
                 "Rakefile",
         
     | 
| 
      
 26 
     | 
    
         
            +
                 "VERSION",
         
     | 
| 
      
 27 
     | 
    
         
            +
                 "bin/git-up",
         
     | 
| 
      
 28 
     | 
    
         
            +
                 "git-up.gemspec",
         
     | 
| 
      
 29 
     | 
    
         
            +
                 "lib/git-up.rb",
         
     | 
| 
      
 30 
     | 
    
         
            +
                 "test/helper.rb",
         
     | 
| 
      
 31 
     | 
    
         
            +
                 "test/test_git-up.rb"
         
     | 
| 
      
 32 
     | 
    
         
            +
              ]
         
     | 
| 
      
 33 
     | 
    
         
            +
              s.homepage = %q{http://github.com/aanand/git-up}
         
     | 
| 
      
 34 
     | 
    
         
            +
              s.rdoc_options = ["--charset=UTF-8"]
         
     | 
| 
      
 35 
     | 
    
         
            +
              s.require_paths = ["lib"]
         
     | 
| 
      
 36 
     | 
    
         
            +
              s.rubygems_version = %q{1.3.5}
         
     | 
| 
      
 37 
     | 
    
         
            +
              s.summary = %q{git command to fetch and rebase all branches}
         
     | 
| 
      
 38 
     | 
    
         
            +
              s.test_files = [
         
     | 
| 
      
 39 
     | 
    
         
            +
                "test/helper.rb",
         
     | 
| 
      
 40 
     | 
    
         
            +
                 "test/test_git-up.rb"
         
     | 
| 
      
 41 
     | 
    
         
            +
              ]
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              if s.respond_to? :specification_version then
         
     | 
| 
      
 44 
     | 
    
         
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         
     | 
| 
      
 45 
     | 
    
         
            +
                s.specification_version = 3
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
         
     | 
| 
      
 48 
     | 
    
         
            +
                  s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
         
     | 
| 
      
 49 
     | 
    
         
            +
                  s.add_runtime_dependency(%q<colored>, [">= 0"])
         
     | 
| 
      
 50 
     | 
    
         
            +
                  s.add_runtime_dependency(%q<grit>, [">= 0"])
         
     | 
| 
      
 51 
     | 
    
         
            +
                else
         
     | 
| 
      
 52 
     | 
    
         
            +
                  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
         
     | 
| 
      
 53 
     | 
    
         
            +
                  s.add_dependency(%q<colored>, [">= 0"])
         
     | 
| 
      
 54 
     | 
    
         
            +
                  s.add_dependency(%q<grit>, [">= 0"])
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
              else
         
     | 
| 
      
 57 
     | 
    
         
            +
                s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
         
     | 
| 
      
 58 
     | 
    
         
            +
                s.add_dependency(%q<colored>, [">= 0"])
         
     | 
| 
      
 59 
     | 
    
         
            +
                s.add_dependency(%q<grit>, [">= 0"])
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
    
        data/lib/git-up.rb
    ADDED
    
    | 
         @@ -0,0 +1,132 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'colored'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'grit'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class GitUp
         
     | 
| 
      
 5 
     | 
    
         
            +
              def initialize(args)
         
     | 
| 
      
 6 
     | 
    
         
            +
                @repo   = Grit::Repo.new(args.first || File.expand_path("."))
         
     | 
| 
      
 7 
     | 
    
         
            +
                @head   = @repo.head
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def run
         
     | 
| 
      
 11 
     | 
    
         
            +
                @repo.git.fetch
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                with_stash do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  returning_to_current_branch do
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @repo.branches.each do |branch|
         
     | 
| 
      
 16 
     | 
    
         
            +
                      next unless remote = remote_for_branch(branch)
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                      print branch.name.ljust(20)
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                      if remote.commit.sha == branch.commit.sha
         
     | 
| 
      
 21 
     | 
    
         
            +
                        puts "up to date".green
         
     | 
| 
      
 22 
     | 
    
         
            +
                        next
         
     | 
| 
      
 23 
     | 
    
         
            +
                      end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                      base = merge_base(branch.name, remote.name)
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                      if base == remote.commit.sha
         
     | 
| 
      
 28 
     | 
    
         
            +
                        puts "ahead of upstream".green
         
     | 
| 
      
 29 
     | 
    
         
            +
                        next
         
     | 
| 
      
 30 
     | 
    
         
            +
                      end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                      if base == branch.commit.sha
         
     | 
| 
      
 33 
     | 
    
         
            +
                        puts "fast-forwarding...".yellow
         
     | 
| 
      
 34 
     | 
    
         
            +
                      else
         
     | 
| 
      
 35 
     | 
    
         
            +
                        puts "rebasing...".yellow
         
     | 
| 
      
 36 
     | 
    
         
            +
                      end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                      checkout(branch.name)
         
     | 
| 
      
 39 
     | 
    
         
            +
                      rebase(remote)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              rescue GitError => e
         
     | 
| 
      
 44 
     | 
    
         
            +
                puts e.message.red
         
     | 
| 
      
 45 
     | 
    
         
            +
                puts "Here's what Git said:".red
         
     | 
| 
      
 46 
     | 
    
         
            +
                puts e.output
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              def remote_for_branch(branch)
         
     | 
| 
      
 50 
     | 
    
         
            +
                if remote_name = @repo.config["branch.#{branch.name}.remote"]
         
     | 
| 
      
 51 
     | 
    
         
            +
                  @repo.remotes.find { |r| r.name == "#{remote_name}/#{branch.name}" }
         
     | 
| 
      
 52 
     | 
    
         
            +
                else
         
     | 
| 
      
 53 
     | 
    
         
            +
                  nil
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              def with_stash
         
     | 
| 
      
 58 
     | 
    
         
            +
                stashed = false
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                status = @repo.status
         
     | 
| 
      
 61 
     | 
    
         
            +
                change_count = status.added.length + status.changed.length + status.deleted.length
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                if change_count > 0
         
     | 
| 
      
 64 
     | 
    
         
            +
                  puts "stashing #{change_count} changes".magenta
         
     | 
| 
      
 65 
     | 
    
         
            +
                  @repo.git.stash
         
     | 
| 
      
 66 
     | 
    
         
            +
                  stashed = true
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                yield
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                if stashed
         
     | 
| 
      
 72 
     | 
    
         
            +
                  puts "unstashing".magenta
         
     | 
| 
      
 73 
     | 
    
         
            +
                  @repo.git.stash({}, "apply")
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              def returning_to_current_branch
         
     | 
| 
      
 78 
     | 
    
         
            +
                unless @repo.head.respond_to?(:name)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  puts "You're not currently on a branch. I'm exiting in case you're in the middle of something.".red
         
     | 
| 
      
 80 
     | 
    
         
            +
                  return
         
     | 
| 
      
 81 
     | 
    
         
            +
                end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                branch_name = @repo.head.name
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                yield
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                unless on_branch?(branch_name)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  puts "returning to #{branch_name}".magenta
         
     | 
| 
      
 89 
     | 
    
         
            +
                  checkout(branch_name)
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
              def checkout(branch_name)
         
     | 
| 
      
 94 
     | 
    
         
            +
                output = @repo.git.checkout({}, branch_name)
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                unless on_branch?(branch_name)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  raise GitError.new("Failed to checkout #{branch_name}", output)
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
              end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
              def rebase(target_branch)
         
     | 
| 
      
 102 
     | 
    
         
            +
                current_branch = @repo.head
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                output, err = @repo.git.sh("#{Grit::Git.git_binary} rebase #{target_branch.name}")
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                unless on_branch?(current_branch.name) and is_fast_forward?(current_branch, target_branch)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  raise GitError.new("Failed to rebase #{current_branch.name} onto #{target_branch.name}", output+err)
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              def is_fast_forward?(a, b)
         
     | 
| 
      
 112 
     | 
    
         
            +
                merge_base(a.name, b.name) == b.commit.sha
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
              def merge_base(a, b)
         
     | 
| 
      
 116 
     | 
    
         
            +
                @repo.git.send("merge-base", {}, a, b).strip
         
     | 
| 
      
 117 
     | 
    
         
            +
              end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
              def on_branch?(branch_name=nil)
         
     | 
| 
      
 120 
     | 
    
         
            +
                @repo.head.respond_to?(:name) and @repo.head.name == branch_name
         
     | 
| 
      
 121 
     | 
    
         
            +
              end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
              class GitError < StandardError
         
     | 
| 
      
 124 
     | 
    
         
            +
                attr_reader :output
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                def initialize(message, output)
         
     | 
| 
      
 127 
     | 
    
         
            +
                  super(message)
         
     | 
| 
      
 128 
     | 
    
         
            +
                  @output = output
         
     | 
| 
      
 129 
     | 
    
         
            +
                end
         
     | 
| 
      
 130 
     | 
    
         
            +
              end
         
     | 
| 
      
 131 
     | 
    
         
            +
            end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
    
        data/test/helper.rb
    ADDED
    
    
    
        data/test/test_git-up.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,96 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: git-up
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Aanand Prasad
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-12-22 00:00:00 -05:00
         
     | 
| 
      
 13 
     | 
    
         
            +
            default_executable: git-up
         
     | 
| 
      
 14 
     | 
    
         
            +
            dependencies: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 16 
     | 
    
         
            +
              name: thoughtbot-shoulda
         
     | 
| 
      
 17 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 18 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 19 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 20 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 21 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 22 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 23 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 24 
     | 
    
         
            +
                version: 
         
     | 
| 
      
 25 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 26 
     | 
    
         
            +
              name: colored
         
     | 
| 
      
 27 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 28 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 29 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 34 
     | 
    
         
            +
                version: 
         
     | 
| 
      
 35 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 36 
     | 
    
         
            +
              name: grit
         
     | 
| 
      
 37 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 38 
     | 
    
         
            +
              version_requirement: 
         
     | 
| 
      
 39 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 40 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 41 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 42 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 43 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 44 
     | 
    
         
            +
                version: 
         
     | 
| 
      
 45 
     | 
    
         
            +
            description: 
         
     | 
| 
      
 46 
     | 
    
         
            +
            email: aanand.prasad@gmail.com
         
     | 
| 
      
 47 
     | 
    
         
            +
            executables: 
         
     | 
| 
      
 48 
     | 
    
         
            +
            - git-up
         
     | 
| 
      
 49 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            extra_rdoc_files: 
         
     | 
| 
      
 52 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 53 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 54 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 55 
     | 
    
         
            +
            - .document
         
     | 
| 
      
 56 
     | 
    
         
            +
            - .gitignore
         
     | 
| 
      
 57 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 58 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 59 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 60 
     | 
    
         
            +
            - VERSION
         
     | 
| 
      
 61 
     | 
    
         
            +
            - bin/git-up
         
     | 
| 
      
 62 
     | 
    
         
            +
            - git-up.gemspec
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/git-up.rb
         
     | 
| 
      
 64 
     | 
    
         
            +
            - test/helper.rb
         
     | 
| 
      
 65 
     | 
    
         
            +
            - test/test_git-up.rb
         
     | 
| 
      
 66 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 67 
     | 
    
         
            +
            homepage: http://github.com/aanand/git-up
         
     | 
| 
      
 68 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 71 
     | 
    
         
            +
            rdoc_options: 
         
     | 
| 
      
 72 
     | 
    
         
            +
            - --charset=UTF-8
         
     | 
| 
      
 73 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 74 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 75 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 76 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 77 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 78 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 79 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 80 
     | 
    
         
            +
              version: 
         
     | 
| 
      
 81 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 82 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 83 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 84 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 85 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 86 
     | 
    
         
            +
              version: 
         
     | 
| 
      
 87 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 90 
     | 
    
         
            +
            rubygems_version: 1.3.5
         
     | 
| 
      
 91 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 92 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 93 
     | 
    
         
            +
            summary: git command to fetch and rebase all branches
         
     | 
| 
      
 94 
     | 
    
         
            +
            test_files: 
         
     | 
| 
      
 95 
     | 
    
         
            +
            - test/helper.rb
         
     | 
| 
      
 96 
     | 
    
         
            +
            - test/test_git-up.rb
         
     |