Commits

seydar  committed 634f8be

made #branch and #branch= a feature of StagingArea

  • Participants
  • Parent commits e1422fb

Comments (0)

Files changed (4)

     repo.commit :modified => ['Ampfile'], :message => 'initial commit'
     
     # Create a new branch
-    repo.
+    repo.staging_area.branch = 
   end
   
   b.success { repo[nil].branch == 'default' } # repo[nil] is the working directory's changeset

File 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.dirstate.branch = _label
+      repo.staging_area.branch = _label
       Amp::UI.status("Reset working directory to branch #{_label}")
     elsif args.size > 0
       _label = args.first
       if !opts[:force] && repo.branch_tags.include?(_label)
-        if !repo.parents.map {|p| p.branch}.include?(_label)
+        if !repo.parents.map {|p| p.branch }.include?(_label)
           raise abort("a branch of the same name already exists!"+
                                " (use --force to override)")
         end
       end
-      repo.dirstate.branch = _label
+      repo.staging_area.branch = _label
       Amp::UI.status("marked working directory as branch #{_label}")
     else
-      Amp::UI.say repo.dirstate.branch
+      Amp::UI.say repo.staging_area.branch
     end
   end
 end

File lib/amp/repository/abstract/abstract_staging_area.rb

         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

File 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
         def modified
           dirstate.files.select {|f| f.merged? || f.modified? || f.added? }
         end
         
+        ##
+        # All the files that are to be removed.
+        # 
+        # @return [Array<String>] the files to be removed in a commit
         def removed
           dirstate.files.select {|f| f.removed? }
         end