当前位置: 首页>>代码示例>>Python>>正文


Python Repo.init方法代码示例

本文整理汇总了Python中git.Repo.init方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.init方法的具体用法?Python Repo.init怎么用?Python Repo.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Repo的用法示例。


在下文中一共展示了Repo.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_common

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def download_common(self):
        try:
            repo = Repo(os.path.dirname(utils.get_base_dir()))
            origin = repo.remote("origin")
            r = origin.pull()
            new_commit = repo.head.commit
            for info in r:
                if info.old_commit:
                    for d in new_commit.diff(info.old_commit):
                        if d.b_path == "requirements.txt":
                            return True
            return False
        except git.exc.InvalidGitRepositoryError:
            repo = Repo.init(os.path.dirname(utils.get_base_dir()))
            origin = repo.create_remote("origin", self.config["GIT_ORIGIN_URL"])
            origin.fetch()
            repo.create_head("master", origin.refs.master)
            repo.heads.master.set_tracking_branch(origin.refs.master)
            repo.heads.master.checkout(True)
            return False  # Heroku never needs to install dependencies because we redeploy 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:22,代码来源:updater.py

示例2: create_git_repository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def create_git_repository(test_case, bare=False):
    """
    Create a git repository with a ``master`` branch and ``README``.

    :param test_case: The ``TestCase`` calling this.
    """
    directory = FilePath(test_case.mktemp())
    repository = Repo.init(path=directory.path, bare=bare)

    if not bare:
        directory.child('README').makedirs()
        directory.child('README').touch()
        repository.index.add(['README'])
        repository.index.commit('Initial commit')
        repository.create_head('master')
    return repository 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:18,代码来源:test_release.py

示例3: init_repository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def init_repository(self, force=False):
        """Initialize an empty Renku repository."""
        from git import Repo
        from renku.core.models.provenance.agents import Person

        # verify if folder is empty
        if self.repo is not None and not force:
            raise errors.InvalidFileOperation(
                'Folder {0} already contains file. Use --force to overwrite'.
                format(self.repo.git_dir)
            )

        # initialize repo
        path = self.path.absolute()
        self.repo = Repo.init(str(path))

        # verify if author information is available
        Person.from_git(self.repo) 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:20,代码来源:repository.py

示例4: tmp_repo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def tmp_repo(tmpdir):
    # initialize new repository and change working directory
    directory = str(tmpdir)
    repo = Repo.init(directory)
    os.chdir(directory)

    # set up logging and trace
    logging.basicConfig()
    logging.root.setLevel(logging.INFO)
    type(repo.git).GIT_PYTHON_TRACE = 'full'

    # create initial commit
    file_path = os.path.join(directory, 'initial-commit.txt')
    subprocess.check_call(['touch', file_path])
    repo.git.add('--all')
    subprocess.check_call(['git', 'config', 'user.email', 'test@innolitics.com'])
    subprocess.check_call(['git', 'config', 'user.name', 'Tester Bot'])
    repo.git.commit('-m', '\'message\'', '--no-verify')

    subprocess.check_call(['rdm', 'hooks'])

    yield repo

    subprocess.check_call(['rm', '-rf', directory]) 
开发者ID:innolitics,项目名称:rdm,代码行数:26,代码来源:hook_test.py

示例5: test_one_commit_in_new_repository

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_one_commit_in_new_repository(tmpdir):
    """Ensure that it is possible to detect one commit in a new Git repository."""
    temp_file = tmpdir.mkdir("sub").join("hello.txt")
    temp_file.write("content")
    assert temp_file.read() == "content"
    assert len(tmpdir.listdir()) == 1
    testing_repository = Repo.init(tmpdir)
    # create an empty file and perform a commit on it
    testing_repository.index.add([str(temp_file)])
    testing_repository.index.commit("Add the hello.txt file.")
    # since the repository was created in the tmpdir
    # the check for the existence of a repository should be True
    detected_git_repository = repository.is_git_repository(str(tmpdir))
    assert detected_git_repository is True
    # since an empty file was committed, the count should be 1
    commits = repository.get_commits(str(tmpdir))
    assert len(commits) == 1 
开发者ID:GatorEducator,项目名称:gatorgrader,代码行数:19,代码来源:test_repository.py

示例6: get_repo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def get_repo():
    """Helper to get the repo, making it if not found"""
    try:
        repo = Repo(os.path.dirname(utils.get_base_dir()))
    except InvalidGitRepositoryError:
        repo = Repo.init(os.path.dirname(utils.get_base_dir()))
        origin = repo.create_remote("origin", "https://gitlab.com/friendly-telegram/friendly-telegram")
        origin.fetch()
        repo.create_head("master", origin.refs.master)
        repo.heads.master.set_tracking_branch(origin.refs.master)
        repo.heads.master.checkout(True)
    return repo 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:14,代码来源:heroku.py

示例7: get_repo

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def get_repo(repo_name):
    directory = os.path.join(test_dir, repo_name)
    repo = Repo.init(directory)
    # Ensure the default branch is using a fixed name.
    # User config could change that,
    # breaking tests with implicit assumptions further down the line.
    repo.head.reference = Head(repo, 'refs/heads/master')

    # We need to synthesize the time stamps of commits to each be a second
    # apart, otherwise the commits may be at exactly the same second, which
    # means they won't always sort in order, and thus the merging of identical
    # metrics in adjacent commits may not happen correctly.
    base_time = time.time()

    base_path = os.path.join(base_dir, repo_name)
    for i in range(num_commits):
        files_dir = os.path.join(base_path, str(i))
        if not os.path.exists(files_dir):
            break

        files = os.listdir(files_dir)
        for filename in files:
            print("Copying file " + filename)
            path = os.path.join(base_path, str(i), filename)
            destination = os.path.join(directory, filename)
            shutil.copyfile(path, destination)

        repo.index.add("*")
        commit_date = datetime.datetime.fromtimestamp(base_time + i).isoformat()
        commit_date = commit_date[:commit_date.find('.')]
        repo.index.commit(
            "Commit {index}".format(index=i),
            commit_date=commit_date
        )

    return directory 
开发者ID:mozilla,项目名称:probe-scraper,代码行数:38,代码来源:test_git_scraper.py

示例8: test_build_crash

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_build_crash(tmpdir):
    """
    Simulate a runtime error in the build.
    """
    repo = Repo.init(path=tmpdir)
    tmppath = pathlib.Path(tmpdir)

    # Write a test file to the repo
    with open(tmppath / "test.py", "w") as test_txt:
        test_txt.write("import abc")

    index = repo.index
    index.add(["test.py"])

    author = Actor("An author", "author@example.com")
    committer = Actor("A committer", "committer@example.com")

    index.commit("basic test", author=author, committer=committer)
    repo.close()

    import wily.commands.build

    with patch.object(
        wily.commands.build.Bar, "finish", side_effect=RuntimeError("arggh")
    ) as bar_finish:
        runner = CliRunner()
        result = runner.invoke(main.cli, ["--path", tmpdir, "build", "test.py"])
        assert bar_finish.called_once
        assert result.exit_code == 1, result.stdout 
开发者ID:tonybaloney,项目名称:wily,代码行数:31,代码来源:test_build.py

示例9: test_build

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_build(tmpdir, cache_path):
    """
    Test that build works in a basic repository.
    """
    repo = Repo.init(path=tmpdir)
    tmppath = pathlib.Path(tmpdir)

    # Write a test file to the repo
    with open(tmppath / "test.py", "w") as test_txt:
        test_txt.write("import abc")

    index = repo.index
    index.add(["test.py"])

    author = Actor("An author", "author@example.com")
    committer = Actor("A committer", "committer@example.com")

    commit = index.commit("basic test", author=author, committer=committer)
    repo.close()

    runner = CliRunner()
    result = runner.invoke(
        main.cli,
        ["--debug", "--path", tmpdir, "--cache", cache_path, "build", "test.py"],
    )
    assert result.exit_code == 0, result.stdout

    cache_path = pathlib.Path(cache_path)
    assert cache_path.exists()
    index_path = cache_path / "git" / "index.json"
    assert index_path.exists()
    rev_path = cache_path / "git" / (commit.name_rev.split(" ")[0] + ".json")
    assert rev_path.exists() 
开发者ID:tonybaloney,项目名称:wily,代码行数:35,代码来源:test_build.py

示例10: test_build_no_git_history

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_build_no_git_history(tmpdir):
    repo = Repo.init(path=tmpdir)
    repo.close()

    with patch("wily.logger") as logger:
        runner = CliRunner()
        result = runner.invoke(main.cli, ["--path", tmpdir, "build", _path])
        assert result.exit_code == 1, result.stdout 
开发者ID:tonybaloney,项目名称:wily,代码行数:10,代码来源:test_build.py

示例11: test_dirty_git

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_dirty_git(tmpdir):
    """ Check that repository fails to initialise if unchecked files are in the repo """
    repo = Repo.init(path=tmpdir)
    tmppath = pathlib.Path(tmpdir)

    index = repo.index
    author = Actor("An author", "author@example.com")
    committer = Actor("A committer", "committer@example.com")

    # First commit
    with open(tmppath / ".gitignore", "w") as ignore:
        ignore.write(".wily/")

    index.add([".gitignore"])
    commit1 = index.commit("commit1", author=author, committer=committer)

    # Write a test file to the repo
    with open(tmppath / "blah.py", "w") as ignore:
        ignore.write("*.py[co]\n")
    index.add(["blah.py"])
    repo.close()

    config = DEFAULT_CONFIG
    config.path = tmpdir

    with pytest.raises(DirtyGitRepositoryError):
        archiver = GitArchiver(config)
        archiver.revisions(tmpdir, 2) 
开发者ID:tonybaloney,项目名称:wily,代码行数:30,代码来源:test_archiver.py

示例12: test_detached_head

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def test_detached_head(tmpdir):
    """ Check that repo can initialize in detached head state"""
    repo = Repo.init(path=tmpdir)
    tmppath = pathlib.Path(tmpdir)

    index = repo.index
    author = Actor("An author", "author@example.com")
    committer = Actor("A committer", "committer@example.com")

    # First commit
    with open(tmppath / "test.py", "w") as ignore:
        ignore.write("print('hello world')")

    index.add(["test.py"])
    commit1 = index.commit("commit1", author=author, committer=committer)

    # Second commit
    with open(tmppath / "test.py", "w") as ignore:
        ignore.write("print('hello world')\nprint(1)")

    index.add(["test.py"])
    commit2 = index.commit("commit2", author=author, committer=committer)

    repo.git.checkout(commit2.hexsha)
    repo.close()

    config = DEFAULT_CONFIG
    config.path = tmpdir

    archiver = GitArchiver(config)
    assert archiver.revisions(tmpdir, 1) is not None 
开发者ID:tonybaloney,项目名称:wily,代码行数:33,代码来源:test_archiver.py

示例13: calculate_base_branch

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def calculate_base_branch(version, path):
    """
    The branch a release branch is created from depends on the release
    type and sometimes which pre-releases have preceeded this.

    :param bytes version: The version of Flocker to get a base branch for.
    :param bytes path: See :func:`git.Repo.init`.
    :returns: The base branch from which the new release branch was created.
    """
    if not (is_release(version) or
            is_weekly_release(version) or
            is_pre_release(version)):
        raise NotARelease()

    repo = Repo(path=path, search_parent_directories=True)
    existing_tags = [tag for tag in repo.tags if tag.name == version]

    if existing_tags:
        raise TagExists()

    # We always base releases off master now.
    base_branch_name = 'master'

    # We create a new branch from a branch, not a tag, because a maintenance
    # or documentation change may have been applied to the branch and not the
    # tag.
    # The branch must be available locally for the next step.
    repo.git.checkout(base_branch_name)

    return (
        branch for branch in repo.branches if
        branch.name == base_branch_name).next() 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:34,代码来源:release.py

示例14: check_git_user_config

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def check_git_user_config():
    """Check that git user information is configured."""
    dummy_git_folder = mkdtemp()
    repo = Repo.init(dummy_git_folder)
    git_config = repo.config_reader()
    try:
        git_config.get_value('user', 'name', None)
        git_config.get_value('user', 'email', None)
        return True
    except (configparser.NoOptionError, configparser.NoSectionError):
        return False 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:13,代码来源:init.py

示例15: __attrs_post_init__

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import init [as 别名]
def __attrs_post_init__(self):
        """Initialize computed attributes."""
        #: Configure Renku path.
        path = Path(self.renku_home)
        if not path.is_absolute():
            path = self.path / path

        path.relative_to(path)
        self.renku_path = path

        data_dir = self.get_value(
            'renku', self.DATA_DIR_CONFIG_KEY, local_only=True
        )
        self.data_dir = data_dir or self.data_dir

        self._subclients = {}

        self._project = None

        super().__attrs_post_init__()

        # initialize submodules
        if self.repo:
            try:
                check_output([
                    'git', 'submodule', 'update', '--init', '--recursive'
                ],
                             cwd=str(self.path))
            except subprocess.CalledProcessError:
                pass 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:32,代码来源:repository.py


注:本文中的git.Repo.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。