Commits

Anonymous committed 757a3fa

added branch changing functionality to update.rb

Comments (0)

Files changed (10)

     repo.commit :modified => ['Ampfile'], :message => 'initial commit'
     
     # Create a new branch
-    repo.staging_area.branch = 'new_branch'
+    repo[nil].branch = 'new_branch'
     
     # Save it
     repo.commit :message => 'added a new branch'
   end
   
   b.success do
-    repo.update :branch => 'default'
-    repo[nil].branch == 'default' # repo[nil] is the working directory's changeset
-    # in theory, `repo.staging_area.branch` should do the same
+    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
   end
   
   b.cleanup { FileUtils.rm_rf Dir['test_*'] } # destory all similar looking dirs

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.staging_area.branch = _label
+      repo[nil].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.staging_area.branch = _label
+      repo[nil].branch = _label
       Amp::UI.status("marked working directory as branch #{_label}")
     else
-      Amp::UI.say repo.staging_area.branch
+      Amp::UI.say repo[nil].branch
     end
   end
 end

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

       raise ArgumentError.new("Please only specify either --rev or --node.")
     end
     
-    rev = opts[:rev] ? opts[:rev] : opts[:node]
+    rev = opts[:rev] || opts[:node] || args.shift
     
     # TODO: add --date option
     if opts[:clean]

lib/amp/extensions/bugs.rb

       old, $stdout = $stdout, old # all is right with the world
       old.string
     end
-    private :capture_stdout
   end
 end
 

lib/amp/repository/abstract/abstract_staging_area.rb

       def removed
         raise NotImplementedError.new("removed() must be implemented by subclasses of AbstractStagingArea.")
       end
-      
-      ##
-      # Set the branch name of the staging area.
-      # 
-      # @param  [String] name The name of the new branch
-      # @return [String] +name+
-      def branch=(name)
-        raise NotImplementedError.new("branch=() must be implemented by subclasses of AbstractStagingArea.")
-      end
-      
-      ##
-      # The branch name of the staging area.
-      # 
-      # @return [String] The branch name of the staging area.
-      def branch
-        raise NotImplementedError.new("branch() must be implemented by subclasses of AbstractStagingArea.")
-      end
     end
   end
 end

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

             # Now we need to try to get an open head, but we'll take a closed
             # one if we have to.
 
-            tipmost = list.reverse.find do |node|
-              !self[node].extra["close"]
+            tipmost = list.reverse.find do |node| # find the first
+              !self[node].extra["close"] # that isn't closing a branch
             end
-            tipmost ||= list.last
+            tipmost ||= list.last # if they're all closing branches, pick the latest
             hash[branch] = tipmost
             hash
           end
         # @return [Hash{String => Array<String>}] a mapping of branch names to a list
         #   of heads of the branch with the same name
         def scan_for_branch_heads(from = 0, to = self.size - 1)
-          puts "scanning"
+          Amp::UI.status "scanning for branch heads"
           result = ArrayHash.new
           from.upto(to) do |idx|
             changeset = self[idx]

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

       end
       
       ##
+      # What's the hex hash of this revision? Just return nil, because we
+      # haven't been committed yet.
+      def hex
+        nil # noop
+      end
+      
+      ##
       # Recursively walk the directory tree, getting all files that +match+ says
       # are good.
       # 
       # What files are pristine since the last revision?
       def clean; status[:normal] || []; end
       # What branch are we in?
-      def branch; @extra["branch"]; end
+      def branch; @extra['branch']; end
+      # Set the branch
+      def branch=(name); @extra['branch'] = name; end
       # Any other extra data? i'd like to hear it
       def extra; @extra; end
       # No children. Returns the empty array.

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

         ######### API Methods #################################################
         
         ##
-        # Set the branch name of the staging area.
-        # 
-        # @param  [String] name The name of the new branch
-        # @return [String] +name+
-        def branch=(name)
-          dirstate.branch = name
-        end
-
-        ##
-        # The branch name of the staging area.
-        # 
-        # @return [String] The branch name of the staging area.
-        def branch
-          dirstate.branch
-        end
-        
-        ##
         # All the files that are either added, modified, or merged.
         # 
         # @return [Array<String>] the files to be added in a commit

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

             end
           end
         end
+        
         ##
         # Class responsible for logic relating to updating the repository.
         #
         # a hash of values through each function, which just isn't necessary. Though
         # it is cute.
         class Updater
+          
           ##
           # the default options for running an update.
           DEFAULT_OPTIONS = {:node => nil, :branch_merge => false, :force => false, :filter => nil}

lib/amp/repository/mercurial/repositories/local_repository.rb

           @dirstate    = nil
           @staging_area = StagingArea.new(self)
           @working_lock_ref = @lock_ref = nil
+          @config = Amp::AmpConfig.new :parent_config => config
+          @config.read_file join("hgrc")
           requirements = []
         
           # make a repo if necessary
           unless File.directory? @hg
             if create
-            then requirements = init config
+            then requirements = init @config
             else raise RepoError.new("Repository #{path} not found")
             end
           end
           end
           
           @store = Stores.pick requirements, @hg, Amp::Opener
-          @config = Amp::AmpConfig.new :parent_config => config
-          @config.read_file join("hgrc")
         end
         
         def local?; true; end
           # make the directory if it's not there
           super
           FileUtils.makedirs @hg
-        
           requirements = ["revlogv1"]
           
           # add some requirements