當前位置: 首頁>>代碼示例>>Python>>正文


Python GitRepo.git_checkout方法代碼示例

本文整理匯總了Python中datalad.support.gitrepo.GitRepo.git_checkout方法的典型用法代碼示例。如果您正苦於以下問題:Python GitRepo.git_checkout方法的具體用法?Python GitRepo.git_checkout怎麽用?Python GitRepo.git_checkout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datalad.support.gitrepo.GitRepo的用法示例。


在下文中一共展示了GitRepo.git_checkout方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_publish_simple

# 需要導入模塊: from datalad.support.gitrepo import GitRepo [as 別名]
# 或者: from datalad.support.gitrepo.GitRepo import git_checkout [as 別名]
def test_publish_simple(origin, src_path, dst_path):

    # prepare src
    source = install(path=src_path, source=origin, recursive=True)
    # TODO: For now, circumnavigate the detached head issue.
    # Figure out, what to do.
    for subds in source.get_dataset_handles(recursive=True):
        AnnexRepo(opj(src_path, subds), init=True, create=True).git_checkout("master")
    # forget we cloned it (provide no 'origin' anymore), which should lead to
    # setting tracking branch to target:
    source.repo.git_remote_remove("origin")

    # create plain git at target:
    target = GitRepo(dst_path, create=True)
    target.git_checkout("TMP", "-b")
    source.repo.git_remote_add("target", dst_path)

    res = publish(dataset=source, dest="target")
    eq_(res, source)

    ok_clean_git(src_path, annex=False)
    ok_clean_git(dst_path, annex=False)
    eq_(list(target.git_get_branch_commits("master")),
        list(source.repo.git_get_branch_commits("master")))

    # don't fail when doing it again
    res = publish(dataset=source, dest="target")
    eq_(res, source)

    ok_clean_git(src_path, annex=False)
    ok_clean_git(dst_path, annex=False)
    eq_(list(target.git_get_branch_commits("master")),
        list(source.repo.git_get_branch_commits("master")))
    eq_(list(target.git_get_branch_commits("git-annex")),
        list(source.repo.git_get_branch_commits("git-annex")))

    # 'target/master' should be tracking branch at this point, so
    # try publishing without `dest`:

    # some modification:
    with open(opj(src_path, 'test_mod_file'), "w") as f:
        f.write("Some additional stuff.")
    source.repo.git_add(opj(src_path, 'test_mod_file'))
    source.repo.git_commit("Modified.")
    ok_clean_git(src_path, annex=False)

    res = publish(dataset=source)
    eq_(res, source)

    ok_clean_git(dst_path, annex=False)
    eq_(list(target.git_get_branch_commits("master")),
        list(source.repo.git_get_branch_commits("master")))
    eq_(list(target.git_get_branch_commits("git-annex")),
        list(source.repo.git_get_branch_commits("git-annex")))
開發者ID:glalteva,項目名稱:datalad,代碼行數:56,代碼來源:test_publish.py

示例2: test_publish_submodule

# 需要導入模塊: from datalad.support.gitrepo import GitRepo [as 別名]
# 或者: from datalad.support.gitrepo.GitRepo import git_checkout [as 別名]
def test_publish_submodule(origin, src_path, target_1, target_2):
    # prepare src
    source = install(path=src_path, source=origin, recursive=True)
    # TODO: For now, circumnavigate the detached head issue.
    # Figure out, what to do.
    for subds in source.get_dataset_handles(recursive=True):
        AnnexRepo(opj(src_path, subds), init=True, create=True).git_checkout("master")

    # first, try publishing from super dataset using `path`
    source_super = source
    source_sub = Dataset(opj(src_path, 'sub1'))
    target = GitRepo(target_1, create=True)
    target.git_checkout("TMP", "-b")
    source_sub.repo.git_remote_add("target", target_1)

    res = publish(dataset=source_super, dest="target", path="sub1")
    assert_is_instance(res, Dataset)
    eq_(res.path, source_sub.path)

    eq_(list(GitRepo(target_1, create=False).git_get_branch_commits("master")),
        list(source_sub.repo.git_get_branch_commits("master")))
    eq_(list(GitRepo(target_1, create=False).git_get_branch_commits("git-annex")),
        list(source_sub.repo.git_get_branch_commits("git-annex")))

    # now, publish directly from within submodule:
    target = GitRepo(target_2, create=True)
    target.git_checkout("TMP", "-b")
    source_sub.repo.git_remote_add("target2", target_2)

    res = publish(dataset=source_sub, dest="target2")
    eq_(res, source_sub)

    eq_(list(GitRepo(target_2, create=False).git_get_branch_commits("master")),
        list(source_sub.repo.git_get_branch_commits("master")))
    eq_(list(GitRepo(target_2, create=False).git_get_branch_commits("git-annex")),
        list(source_sub.repo.git_get_branch_commits("git-annex")))
開發者ID:glalteva,項目名稱:datalad,代碼行數:38,代碼來源:test_publish.py

示例3: test_publish_recursive

# 需要導入模塊: from datalad.support.gitrepo import GitRepo [as 別名]
# 或者: from datalad.support.gitrepo.GitRepo import git_checkout [as 別名]
def test_publish_recursive(origin, src_path, dst_path, sub1_pub, sub2_pub):

    # prepare src
    source = install(path=src_path, source=origin, recursive=True)
    # TODO: For now, circumnavigate the detached head issue.
    # Figure out, what to do.
    for subds in source.get_dataset_handles(recursive=True):
        AnnexRepo(opj(src_path, subds), init=True, create=True).git_checkout("master")

    # create plain git at target:
    target = GitRepo(dst_path, create=True)
    target.git_checkout("TMP", "-b")
    source.repo.git_remote_add("target", dst_path)

    # subdatasets have no remote yet, so recursive publishing should fail:
    with assert_raises(ValueError) as cm:
        publish(dataset=source, dest="target", recursive=True)
    assert_in("No sibling 'target' found.", str(cm.exception))

    # now, set up targets for the submodules:
    sub1_target = GitRepo(sub1_pub, create=True)
    sub1_target.git_checkout("TMP", "-b")
    sub2_target = GitRepo(sub2_pub, create=True)
    sub2_target.git_checkout("TMP", "-b")
    sub1 = GitRepo(opj(src_path, 'sub1'), create=False)
    sub2 = GitRepo(opj(src_path, 'sub2'), create=False)
    sub1.git_remote_add("target", sub1_pub)
    sub2.git_remote_add("target", sub2_pub)

    # publish recursively
    res = publish(dataset=source, dest="target", recursive=True)

    # testing result list
    # (Note: Dataset lacks __eq__ for now. Should this be based on path only?)
    assert_is_instance(res, list)
    for item in res:
        assert_is_instance(item, Dataset)
    eq_(res[0].path, src_path)
    eq_(res[1].path, sub1.path)
    eq_(res[2].path, sub2.path)

    eq_(list(target.git_get_branch_commits("master")),
        list(source.repo.git_get_branch_commits("master")))
    eq_(list(target.git_get_branch_commits("git-annex")),
        list(source.repo.git_get_branch_commits("git-annex")))
    eq_(list(sub1_target.git_get_branch_commits("master")),
        list(sub1.git_get_branch_commits("master")))
    eq_(list(sub1_target.git_get_branch_commits("git-annex")),
        list(sub1.git_get_branch_commits("git-annex")))
    eq_(list(sub2_target.git_get_branch_commits("master")),
        list(sub2.git_get_branch_commits("master")))
    eq_(list(sub2_target.git_get_branch_commits("git-annex")),
        list(sub2.git_get_branch_commits("git-annex")))
開發者ID:glalteva,項目名稱:datalad,代碼行數:55,代碼來源:test_publish.py


注:本文中的datalad.support.gitrepo.GitRepo.git_checkout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。