def testGetGitGitdir(self):
        git.Init(self.fake_git_dir)
        os.makedirs(os.path.join(self.fake_git_dir, '.git', 'refs', 'heads'))
        os.makedirs(os.path.join(self.fake_git_dir, '.git', 'objects'))
        other_file = os.path.join(self.fake_git_dir, 'other_file')
        osutils.Touch(other_file)

        ret = git.GetGitGitdir(self.fake_git_dir)
        self.assertEqual(ret, os.path.join(self.fake_git_dir, '.git'))
    def testGetGitGitdir_bare(self):
        git.Init(self.fake_git_dir)
        os.makedirs(os.path.join(self.fake_git_dir, 'refs', 'heads'))
        os.makedirs(os.path.join(self.fake_git_dir, 'objects'))
        config_file = os.path.join(self.fake_git_dir, 'config')
        osutils.Touch(config_file)

        ret = git.GetGitGitdir(self.fake_git_dir)
        self.assertEqual(ret, self.fake_git_dir)
    def SetUp(self):
        """Sets up Chromium repo.

    It skips repo set up if reuse_repo is set and repo exists.
    Setup steps:
    1. Make sure chromium_dir doesn't exist.
    2. mkdir chromium_dir and cd to it
    3. Run "fetch --nohooks chromium"
    4. Set up gclient config ('managed' set to False)
    5. In chromium_dir/src, run "git pull origin master"
    6. "gclient sync --nohooks"
    """
        if self.reuse_repo and os.path.exists(self.repo_dir):
            if git.GetGitGitdir(self.repo_dir):
                return
            else:
                raise Exception(
                    'Chromium repo broken. Please manually remove it: %s' %
                    self.chromium_dir)
        if os.path.exists(self.chromium_dir):
            raise Exception(
                'Chromium repo exists. Please manually remove it: %s' %
                self.chromium_dir)

        osutils.SafeMakedirs(self.chromium_dir)
        cros_build_lib.run(['fetch', '--nohooks', 'chromium'],
                           cwd=self.chromium_dir,
                           log_output=True)
        # 'managed' should be set to False. Otherwise, 'gclient sync' will call
        # 'git pull' to ruin bisecting point.
        gclient.WriteConfigFile(self.gclient,
                                self.chromium_dir,
                                True,
                                None,
                                managed=False)

        # Need to perform git pull before gclient sync when managed is set to False.
        git.RunGit(self.repo_dir, ['pull', 'origin', 'master'])
        self.GclientSync(reset=True, nohooks=True)
 def testGetGitGitdir_negative(self):
     ret = git.GetGitGitdir(self.tempdir)
     self.assertFalse(ret)