Commits

Anonymous committed 2efdeb0

getting switching branches under contorl

  • Participants
  • Parent commits 757a3fa

Comments (0)

Files changed (6)

 require 'fileutils'
 
-
-
 Amp::Bug.new do |b|
   dir  = "test_#{rand(1000)}"
   repo = nil # scoping
     repo.commit :modified => ['Ampfile'], :message => 'initial commit'
     
     # Create a new branch
-    repo[nil].branch = 'new_branch'
+    repo.dirstate.branch = 'new_branch'
     
     # Save it
     repo.commit :message => 'added a new branch'
   end
   
   b.success do
-    b.capture_stdout do
-      repo.update 'default'
-      repo[nil].branch == 'default' # repo[nil] is the working directory's changeset
-      # in theory, `repo.staging_area.branch` should do the same
-    end
+    repo.update 'default'
+    repo[nil].branch == 'default' # repo[nil] is the working directory's changeset
   end
   
   b.cleanup { FileUtils.rm_rf Dir['test_*'] } # destory all similar looking dirs
+require 'fileutils'
+
+Amp::Bug.new do |b|
+  dir  = "test_#{rand(1000)}"
+  repo = nil # scoping
+  
+  b.number  23
+  
+  b.desc    "`amp update` fails to replay uncommitted changes"
+  
+  b.setup do
+    repo = Amp::Repositories::Mercurial::LocalRepository.new dir, true # Create the repo
+    repo.staging_area.add 'Ampfile'                                    # Add a file
+    repo.commit :modified => ['Ampfile'], :message => 'initial commit' # Commit
+    
+    repo.dirstate.branch = 'new_branch'                                # Create a new branch
+    repo.commit :message => 'added a new branch'                       # Save it
+    
+    repo.switch 'default'                                              # Switch back to default
+    File.open("#{dir}/unknown", 'w') {|f| f.write 'unknown' }          # Create an untracked file
+  end
+  
+  b.success do
+    repo.switch 'new_branch'                                           # Go back to new_branch
+    File.exist? "#{dir}/unknown"                                       # And the file should be there
+  end
+  
+  b.cleanup { FileUtils.rm_rf Dir['test_*'] } # destory all similar looking dirs
+end
+require 'fileutils'
+
+Amp::Bug.new do |b|
+  dir  = "test_#{rand(1000)}"
+  repo = nil # scoping
+  
+  b.number  23
+  
+  b.desc    "Unable to change branches"
+  
+  b.setup do
+    repo = Amp::Repositories::Mercurial::LocalRepository.new dir, true # Create the repo
+    repo.staging_area.add 'Ampfile'                                    # Add a file
+    repo.commit :modified => ['Ampfile'], :message => 'initial commit' # Commit
+    
+    repo.dirstate.branch = 'new_branch'                                # Create a new branch
+    repo.commit :message => 'added a new branch'                       # Save it
+    
+    puts repo[nil].branch
+  end
+  
+  b.success do
+    repo[nil].branch == 'new_branch'
+  end
+  
+  b.cleanup { FileUtils.rm_rf Dir['test_*'] } # destory all similar looking dirs
+end

lib/amp/commands/commands/workflows/hg/branch.rb

     repo = opts[:repository]
     if opts[:clean]
       _label = repo[nil].parents[0].branch # repo[nil] is the WorkingDirectoryChangeset
-      repo[nil].branch = _label
+      repo.dirstate.branch = _label
       Amp::UI.status("Reset working directory to branch #{_label}")
     elsif args.size > 0
       _label = args.first
                                " (use --force to override)")
         end
       end
-      repo[nil].branch = _label
+      repo.dirstate.branch = _label
       Amp::UI.status("marked working directory as branch #{_label}")
     else
-      Amp::UI.say repo[nil].branch
+      Amp::UI.say repo.dirstate.branch
     end
   end
 end

lib/amp/extensions/bugs.rb

       if b # if a block is given, save it
         @success = b
       else # else, run the block
-        @success.call
+        silence_stdout { @success.call }
       end
     end
     alias_method :success?, :success
       if b # if a block is given, save it
         @cleanup = b
       else # else, run the block
-        @cleanup.call
+        silence_stdout { @cleanup.call }
         nil
       end
     end
       old, $stdout = $stdout, old # all is right with the world
       old.string
     end
+    private :capture_stdout
+    
+    ##
+    # Mandatory block. This captures what accumulates in STDOUT during the block
+    # and returns the block's value. Does not get STDERR.
+    # 
+    # @return [String] Whatever accumulates in STDOUT during the block.
+    def silence_stdout
+      old, $stdout = $stdout, StringIO.new
+      res = yield
+      old, $stdout = $stdout, old # all is right with the world
+      res
+    end
   end
 end
 

lib/amp/repository/mercurial/repo_format/updater.rb

         end
         
         ##
+        # Switch to a different branch
+        def switch(brnch, opts={})
+          opts[:force] ? clean(brnch) : update(brnch)
+        end
+        
+        ##
         # Merge two heads
         def merge(node, force=false)
           update node, true, force, false
           #
           # @return [Boolean] whether or not overwriting files is OK
           def overwrite?
+            puts(@overwrite || (force && !branch_merge))
             @overwrite || (force && !branch_merge)
           end
           
           def verify_non_destructive
             # Obviously non-destructive because we have a linear path.
             if ancestor == @local_parent || ancestor == remote
+              p 5
               @overwrite = true
               return
             end