Commits

Michael Gatto  committed f2655ce

* We now pass $hg into the command class' constructor instead of setting it with an mutator after initialization. This way, we have access to the root $hg object within the constructor, useful for testing if a repository was set already since we allow null repository paths.

  • Participants
  • Parent commits b470b48

Comments (0)

Files changed (7)

File Trunk/VersionControl/Hg/Command/Abstract.php

      *
      * @return void
      */
-    abstract function __construct($params);
+    abstract function __construct($params, VersionControl_Hg $hg);
 
     /**
      * Executes the actual mercurial command
     }
 
     /**
-     * Sets the base $hg instance on whose behalf command operates
-     *
-     * @param VersionControl_Hg $hg The root object instance
-     *
-     * @return null
-     */
-    public function setContainer(VersionControl_Hg $hg)
-    {
-        $this->hg = $hg;
-    }
-
-    /**
-     * Returns the base $hg instance on whose behalf the command operates
-     *
-     * @return VersionControl_Hg
-     */
-    public function getContainer()
-    {
-        return $this->hg;
-    }
-
-    /**
      * Sets the command string
      *
      * @return void
      *
      * @return  VersionControl_Hg_Command
      *
+     * @TODO Deprecated: mark for deletion
+     *
      * @TODO Handle $last as well!
      * @TODO Consider whether this is a good idea, since between() handles
      * this for some commands...

File Trunk/VersionControl/Hg/Command/Archive.php

      *
      * @return void
      */
-    public function __construct($params = null)
+    public function __construct($params = null, VersionControl_Hg $hg)
     {
         /* should always be called so we have a full array of valid options */
         $this->setOptions(array()); //should be renamed as joinPossibleOptions()
     }
 
     /**
-     * Adds 'rev' to the stack of command line options
+     * Specified the revision to restrict the archive operation to
      *
-     * Specified the revision to restrict the status operation to
-
      * Usage:
      * <code>$hg->archive()->revision(7)->run();</code>
      * or

File Trunk/VersionControl/Hg/Command/Init.php

      *
      * @return void
      */
-    public function __construct($params = null)
+    public function __construct($params = null, VersionControl_Hg $hg)
     {
-        if ( (array_key_exists(0, $params)) && (! empty($params[0])) ) {
-            /* This is a psuedo-hack because init has no arugment prefix;
-               our current inmplementation of 'files' doesn't give one = cool!
-             */
-            $this->addOption('files', $params[0]);
+        /* check if a repository has been designated already or not */
+        if ( empty($this->hg->repository->getPath()) ) {
+            /* are the argument(s) correctly formed? */
+            if ( (array_key_exists(0, $params)) && (! empty($params[0])) ) {
+                /* if its an array, check for the 'repository' key */
+                if ( (is_array($params[0])) && (! array_key_exists('repository', $params[0])) ) {
+                    throw new VersionControl_Hg_Command_Exception(
+                        VersionControl_Hg_Command_Exception::BAD_ARGUMENT,
+                        "The repository must be defined either at
+                         instantiation, as a string path arugment to clone()
+                         or as the 'repository' key in an array of options."
+                    );
 
+                    /* should always be called so we have a full array of valid options */
+                    $this->setOptions($params);
+                } elseif ( is_scalar($params[0])) {
+                    /* if scalar, we have to assume its a path */
+                    /* This is a psuedo-hack because init has no arugment prefix;
+                     * our current inmplementation of 'files' doesn't give one = cool! */
+                    $this->addOption('files', $params[0]);
+                }
+            }
         } else {
             /* should always be called so we have a full array of valid options */
-            $this->setOptions($params); //should be renamed as joinPossibleOptions()
+            $this->setOptions($params);
         }
     }
 

File Trunk/VersionControl/Hg/Command/Log.php

      *
      * @return void
      */
-    public function __construct($params = null)
+    public function __construct($params = null, VersionControl_Hg $hg)
     {
         /* should always be called so we have a full array of valid options */
         $this->setOptions($params);

File Trunk/VersionControl/Hg/Command/Status.php

      *
      * @return void
      */
-    public function __construct($params = null)
+    public function __construct($params = null, VersionControl_Hg $hg)
     {
         /* should always be called so we have a full array of valid options */
         $this->setOptions($params);

File Trunk/VersionControl/Hg/Command/Version.php

      * @param   VersionControl_Hg $hg
      * @return  void
      */
-    public function __construct($param = null) {
+    public function __construct($param = null, VersionControl_Hg $hg) {
 
     }
 

File Trunk/VersionControl/Hg/CommandProxy.php

             );
         }
 
-        $this->command = new $class($arguments);
-        $this->command->setContainer($this->hg);
+        $this->command = new $class($arguments, $this->hg);
 
         /* for fluent API */
         return $this->command;