Returns whether the current working dir is a Git directory.

@param bool $requireRoot Require directory is the root of the Git repository,
default is true.

@return bool
968087
public function isGitDir($requireRoot = true)
    {
        $directory = $this->getGitDir();

        if ('' === $directory) {
            return false;
        }

        if ($requireRoot && str_replace('\\', '/', getcwd()) !== $directory) {
            return false;
        }

        return true;
    }
184511
public static function getInstance($Baseroot = '')
    {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self($Baseroot);
        }
        return self::$_instance;
    }
81899
public static function GetUrlParts($appRoot = '')
	{
		$urlqs = explode("?", self::GetCurrentURL(),2);
		$url = $urlqs[0];

		// if a root folder was provided, then we need to strip that out as well
		if ($appRoot) $url = str_replace($appRoot.'/','',$url);

		$parts = explode("/", $url);
		// we only want the parts starting with #3 (after http://server/)

		array_shift($parts);
		array_shift($parts);
		array_shift($parts);

		// if there is no action specified then we don't want to return an array with an empty string
		while (count($parts) && $parts[0] == '')
		{
			array_shift($parts);
		}

		return $parts;
	}
1012709
public function getRootDir()
    {
        if (!is_null($this->rootDirPrefix)) {
            return $this->rootDirPrefix;
        }

        $bundles = array_map(function ($bundle) {
            return is_object($bundle)
                ? get_class($bundle)
                : $bundle;
        }, $this->bundlesToLoad);
        $config = $this->configuration;
        $routes = $this->routes;
        sort($bundles);
        sort($routes);
        $this->sortArray($config);

        return sys_get_temp_dir().'/base-kernel/'.'kernel-'.(
            hash(
                'md5',
                json_encode([
                    $bundles,
                    $config,
                    $routes,
                ])
            )
        );
    }
908791
public function requireTree($path = null)
    {
        if ( ! is_null($path))
        {
            return $this->directory($path)->requireTree();
        }

        if ($iterator = $this->recursivelyIterateDirectory($this->path))
        {
            return $this->processRequire($iterator);
        }

        return $this;
    }
128588
public function isRoot($work_id=-1)
	{

		if($work_id != -1){
			return array_search($work_id, $this->rootWorkIdList) === false ? false : true;
		}else{
			return array_search($this->self->work_id, $this->rootWorkIdList) === false ? false : true;
		}
		
	}
857928
def rootdir(path = Dir.pwd)
      g = MiniGit.new
      g.find_git_dir(path)[1]
    end
1227294
private function getRootDirectory()
    {
        static $root;

        if (!$root) {
            $working = getcwd();
            $myself  = __DIR__;

            if (0 === strpos($myself, $working)) {
                // Local installation, the working directory is the root
                $root = $working;
            } else {
                // Global installation, back up above the vendor/ directory
                $root = realpath($myself . '/../../../../../');
            }
        }

        return $root;
    }
1005514
function chdir($dir)
    {
        if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
            return false;
        }

        if ($dir[strlen($dir) - 1] != '/') {
            $dir.= '/';
        }

        // confirm that $dir is, in fact, a valid directory
        if ($this->_is_dir($dir)) {
            $this->pwd = $dir;
            return true;
        }

        $dir = $this->_realpath($dir, false);

        if ($this->_is_dir($dir)) {
            $this->pwd = $dir;
            return true;
        }

        if (!$this->_send_sftp_packet(NET_SFTP_OPENDIR, pack('Na*', strlen($dir), $dir))) {
            return false;
        }

        // see Net_SFTP::nlist() for a more thorough explanation of the following
        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_HANDLE:
                $handle = substr($response, 4);
                break;
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
            default:
                user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS', E_USER_NOTICE);
                return false;
        }

        if (!$this->_send_sftp_packet(NET_SFTP_CLOSE, pack('Na*', strlen($handle), $handle))) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        if ($this->packet_type != NET_SFTP_STATUS) {
            user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
            return false;
        }

        extract(unpack('Nstatus', $this->_string_shift($response, 4)));
        if ($status != NET_SFTP_STATUS_OK) {
            $this->_logError($response, $status);
            return false;
        }

        $this->_save_dir($dir);

        $this->pwd = $dir;
        return true;
    }
478694
function findRoot() {

  let rootPath;

  try {
    rootPath = glob.sync('../**/Drupal.php', {ignore: ['../vendor/**', '../node_modules/**']});
  } catch (err) {
    throw new Error('No Drupal root found.');
  }

  // If we found no results for Drupal.php..then bomb out.
  if (rootPath.length === 0) {
    throw new Error('No Drupal root found.');
  }

  // Glob returns an array, even though we've only got one item.
  rootPath = rootPath[0];

  const filePathParts = rootPath.split(path.sep);
  const coreDirPosition = filePathParts.indexOf('core');

  // If we found a Drupal.php file, but no core directory..then bomb out.
  if (coreDirPosition === -1) {
    throw new Error('No Drupal root found.');
  }

  return filePathParts.slice(0, coreDirPosition).join(path.sep);

}
618489
public function rootDirExists()
    {
        $path = $this->getRootDir();
        return !empty($path) && @file_exists($path) && @is_dir($path);
    }
61741
private function _isBST(?IBinaryNode $root, ?int $min = null, ?int $max = null): bool {
        //if the root is null, the BST condition is met
        if (null === $root) return true;
        /*
         * since the whole left subtree has to be smaller than the root,
         * it is not enough to just check for
         *          left <= current < right
         *
         * the whole left subtree has to be smaller than the root. Therefore,
         * when we branch left, we check that the value is between NULL and
         * root's value. When we branch right, we check the value is between
         * roots'value and NULL.
         */
        if ((null !== $min) && (Comparator::lessThanEqual($root->getValue(), $min))) return false;
        if ((null !== $max) && (Comparator::greaterThanEqual($root->getValue(), $max))) return false;
        /*
         * If we branch left, $max gets updated (to the root's value). If we
         * branch right, $min gets updated (to the roots's value).
         *
         * If any of those comparisions fail, the method breaks immediately and returns
         * false.
         */
        if (!$this->_isBST($root->getLeft(), $min, $root->getValue())) return false;
        if (!$this->_isBST($root->getRight(), $root->getValue(), $max)) return false;
        return true;
    }
1069018
private static function _setupRoot()
	{
		if ( !empty(self::$root) ) {
			// avoid duplicating efforts... only set root if it's not already set 
			return;
		}
		
		if ( defined('ROOT') ) {
			self::$root = rtrim(ROOT, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
		}
		else if ( !empty($GLOBALS['baseDir']) ) {
			self::$root = rtrim($GLOBALS['baseDir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
		}
		else if ( strpos(__FILE__, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) !== false ) {
			// fall back to guessing the project root from the path...
			// we're in /vendor/datto/core-enumerator/src/Core

			$path = __FILE__;
			// up 5 levels
			while (!file_exists("$path/autoload.php")) {
				$path = dirname($path);
			}
			
			$path = dirname($path);

			self::$root = $path . DIRECTORY_SEPARATOR;
		}
		else if ( class_exists("Composer\\Autoload\\ClassLoader") ) {
			// go up until we find vendor/autoload.php - last resort
			$path = dirname(__FILE__);
			while ( $path && !file_exists($path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php') ) {
				$path = dirname($path);
			}

			if ( !empty($path) ) {
				var_dump($path);
				self::$root = $path . DIRECTORY_SEPARATOR;
			}
		}

		if ( empty(self::$root) ) {
			throw new \Exception("Unable to determine project base directory");
		}
	}
514902
def repo_root
      return git_directory_path if inside_bare_repo?
      
      if inside_git_directory?
        File.expand_path('..', git_directory_path)
      elsif inside_work_tree?
        execute(git_cmd('rev-parse', '--show-toplevel'))
      else
        raise 'not in git directory or work tree!?'
      end
    end
533577
public boolean isDirectory() {
		if (sftp.getVersion() > 3) {
			return type == SSH_FILEXFER_TYPE_DIRECTORY;
		} else if (permissions != null
				&& (permissions.longValue() & SftpFileAttributes.S_IFDIR) == SftpFileAttributes.S_IFDIR) {
			return true;
		} else {
			return false;
		}
	}
755980
def current_git_dir():
    """"""
    path = os.path.abspath(os.curdir)
    while path != '/':
        if os.path.isdir(os.path.join(path, '.git')):
            return os.path.join(path, '.git')
        path = os.path.dirname(path)
    return None
1060426
function chdir($dir)
    {
        if (!($this->bitmap & SSH2::MASK_LOGIN)) {
            return false;
        }

        // assume current dir if $dir is empty
        if ($dir === '') {
            $dir = './';
        // suffix a slash if needed
        } elseif ($dir[strlen($dir) - 1] != '/') {
            $dir.= '/';
        }

        $dir = $this->_realpath($dir);

        // confirm that $dir is, in fact, a valid directory
        if ($this->use_stat_cache && is_array($this->_query_stat_cache($dir))) {
            $this->pwd = $dir;
            return true;
        }

        // we could do a stat on the alleged $dir to see if it's a directory but that doesn't tell us
        // the currently logged in user has the appropriate permissions or not. maybe you could see if
        // the file's uid / gid match the currently logged in user's uid / gid but how there's no easy
        // way to get those with SFTP

        if (!$this->_send_sftp_packet(NET_SFTP_OPENDIR, pack('Na*', strlen($dir), $dir))) {
            return false;
        }

        // see \phpseclib\Net\SFTP::nlist() for a more thorough explanation of the following
        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_HANDLE:
                $handle = substr($response, 4);
                break;
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
            default:
                user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
                return false;
        }

        if (!$this->_close_handle($handle)) {
            return false;
        }

        $this->_update_stat_cache($dir, array());

        $this->pwd = $dir;
        return true;
    }