當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。