def test_GitRepo_flyweight(path1, path2): repo1 = GitRepo(path1, create=True) assert_is_instance(repo1, GitRepo) # instantiate again: repo2 = GitRepo(path1, create=False) assert_is_instance(repo2, GitRepo) # the very same object: ok_(repo1 is repo2) # reference the same in a different way: with chpwd(path1): repo3 = GitRepo(op.relpath(path1, start=path2), create=False) # it's the same object: ok_(repo1 is repo3) # and realpath attribute is the same, so they are still equal: ok_(repo1 == repo3)
def test_knows_annex(here=None, there=None): from datalad.support.annexrepo import AnnexRepo from datalad.support.gitrepo import GitRepo GitRepo(path=here, create=True) assert_false(knows_annex(here)) AnnexRepo(path=here, create=True) assert_true(knows_annex(here)) GitRepo.clone(path=there, url=here, create=True) assert_true(knows_annex(there))
def test_GitRepo_add_submodule(source, path): top_repo = GitRepo(path, create=True) top_repo.add_submodule('sub', name='sub', url=source) top_repo.commit('submodule added') eq_([s.name for s in top_repo.get_submodules()], ['sub']) ok_clean_git(path) ok_clean_git(op.join(path, 'sub'))
def test_publish_simple(origin, src_path, dst_path): # prepare src source = install(src_path, source=origin, recursive=True) # forget we cloned it (provide no 'origin' anymore), which should lead to # setting tracking branch to target: source.repo.remove_remote("origin") # create plain git at target: target = GitRepo(dst_path, create=True) target.checkout("TMP", ["-b"]) source.repo.add_remote("target", dst_path) res = publish(dataset=source, to="target", result_xfm='datasets') eq_(res, [source]) ok_clean_git(source.repo, annex=None) ok_clean_git(target, annex=None) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) # don't fail when doing it again res = publish(dataset=source, to="target") # and nothing is pushed assert_result_count(res, 1, status='notneeded') ok_clean_git(source.repo, annex=None) ok_clean_git(target, annex=None) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) eq_(list(target.get_branch_commits("git-annex")), list(source.repo.get_branch_commits("git-annex"))) # 'target/master' should be tracking branch at this point, so # try publishing without `to`: # MIH: Nope, we don't automatically add this anymore # some modification: with open(opj(src_path, 'test_mod_file'), "w") as f: f.write("Some additional stuff.") source.save(opj(src_path, 'test_mod_file'), to_git=True, message="Modified.") ok_clean_git(source.repo, annex=None) res = publish(dataset=source, to='target', result_xfm='datasets') eq_(res, [source]) ok_clean_git(dst_path, annex=None) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) # Since git-annex 6.20170220, post-receive hook gets triggered # which results in entry being added for that repo into uuid.log on remote # end since then finally git-annex senses that it needs to init that remote, # so it might have 1 more commit than local. # see https://github.com/datalad/datalad/issues/1319 ok_(set(source.repo.get_branch_commits("git-annex")).issubset( set(target.get_branch_commits("git-annex"))))
def test_normalize_path(git_path): gr = GitRepo(git_path) # cwd is currently outside the repo, so any relative path # should be interpreted as relative to `annex_path` assert_raises(FileNotInRepositoryError, _normalize_path, gr.path, getpwd()) result = _normalize_path(gr.path, "testfile") eq_(result, "testfile", "_normalize_path() returned %s" % result) # result = _normalize_path(gr.path, op.join('.', 'testfile')) # eq_(result, "testfile", "_normalize_path() returned %s" % result) # # result = _normalize_path(gr.path, op.join('testdir', '..', 'testfile')) # eq_(result, "testfile", "_normalize_path() returned %s" % result) # Note: By now, normpath within normalize_paths() is disabled, therefore # disable these tests. result = _normalize_path(gr.path, op.join('testdir', 'testfile')) eq_(result, op.join("testdir", "testfile"), "_normalize_path() returned %s" % result) result = _normalize_path(gr.path, op.join(git_path, "testfile")) eq_(result, "testfile", "_normalize_path() returned %s" % result) # now we are inside, so # OLD PHILOSOPHY: relative paths are relative to cwd and have # to be converted to be relative to annex_path # NEW PHILOSOPHY: still relative to repo! unless starts with . (curdir) or .. (pardir) with chpwd(op.join(git_path, 'd1', 'd2')): result = _normalize_path(gr.path, "testfile") eq_(result, 'testfile', "_normalize_path() returned %s" % result) # if not joined as directory name but just a prefix to the filename, should # behave correctly for d in (op.curdir, op.pardir): result = _normalize_path(gr.path, d + "testfile") eq_(result, d + 'testfile', "_normalize_path() returned %s" % result) result = _normalize_path(gr.path, op.join(op.curdir, "testfile")) eq_(result, op.join('d1', 'd2', 'testfile'), "_normalize_path() returned %s" % result) result = _normalize_path(gr.path, op.join(op.pardir, 'testfile')) eq_(result, op.join('d1', 'testfile'), "_normalize_path() returned %s" % result) assert_raises(FileNotInRepositoryError, _normalize_path, gr.path, op.join(git_path, '..', 'outside')) result = _normalize_path(gr.path, op.join(git_path, 'd1', 'testfile')) eq_(result, op.join('d1', 'testfile'), "_normalize_path() returned %s" % result)
def test_GitRepo_remove(path): gr = GitRepo(path, create=True) gr.add('*') gr.commit("committing all the files") eq_(gr.remove('file'), ['file']) eq_(set(gr.remove('d', r=True, f=True)), {'d/f1', 'd/f2'}) eq_(set(gr.remove('*', r=True, f=True)), {'file2', 'd2/f1', 'd2/f2'})
def test_GitRepo_commit(path): gr = GitRepo(path) filename = "test_git_add.dat" with open(os.path.join(path, filename), 'w') as f: f.write("File to add to git") gr.git_add(filename) gr.git_commit("Testing GitRepo.git_commit().") ok_clean_git(path, annex=False, untracked=[])
def test_GitRepo_add(src, path): gr = GitRepo(path, src) filename = "test_git_add.dat" with open(os.path.join(path, filename), 'w') as f: f.write("File to add to git") gr.git_add(filename) assert_in(filename, gr.get_indexed_files(), "%s not successfully added to %s" % (filename, path))
def test_having_annex(path): ok_(os.path.exists(os.path.join(path, '.git'))) repo = GitRepo(path) # might not necessarily be present upon initial submodule init #branches = [r.name for r in repo.branches] #ok_('git-annex' in branches, msg="Didn't find git-annex among %s" % branches) # look for it among remote refs refs = repo.get_remote_branches() ok_('origin/git-annex' in refs, msg="Didn't find git-annex among refs %s" % refs)
def clone_url(url): # delay import of our code until needed for certain from ..cmd import Runner runner = Runner() tdir = tempfile.mkdtemp(**get_tempfile_kwargs({}, prefix='clone_url')) _ = runner(["git", "clone", url, tdir], expect_stderr=True) if GitRepo(tdir).is_with_annex(): AnnexRepo(tdir, init=True) _TEMP_PATHS_CLONES.add(tdir) return tdir
def test_get_commit_date(path): gr = GitRepo(path, create=True) eq_(gr.get_commit_date(), None) # Let's make a commit with a custom date DATE = "Wed Mar 14 03:47:30 2018 -0000" DATE_EPOCH = 1520999250 gr.add('1') gr.commit("committed", date=DATE) gr = GitRepo(path, create=True) date = gr.get_commit_date() neq_(date, None) eq_(date, DATE_EPOCH) eq_(date, gr.get_commit_date('master')) # and even if we get into a detached head gr.checkout(gr.get_hexsha()) eq_(gr.get_active_branch(), None) eq_(date, gr.get_commit_date('master'))
def test_GitRepo_gitpy_injection(path, path2): gr = GitRepo(path, create=True) gr._GIT_COMMON_OPTIONS.extend(['test-option']) with assert_raises(GitCommandError) as cme: gr.repo.git.unknown_git_command() assert_in('test-option', exc_str(cme.exception)) # once set, these option should be persistent across git calls: with assert_raises(GitCommandError) as cme: gr.repo.git.another_unknown_git_command() assert_in('test-option', exc_str(cme.exception)) # but other repos should not be affected: gr2 = GitRepo(path2, create=True) with assert_raises(GitCommandError) as cme: gr2.repo.git.unknown_git_command() assert_not_in('test-option', exc_str(cme.exception))
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")))
def test_publish_simple(origin, src_path, dst_path): # prepare src source = install(src_path, source=origin, recursive=True) # forget we cloned it (provide no 'origin' anymore), which should lead to # setting tracking branch to target: source.repo.remove_remote("origin") # create plain git at target: target = GitRepo(dst_path, create=True) target.checkout("TMP", ["-b"]) source.repo.add_remote("target", dst_path) res = publish(dataset=source, to="target", result_xfm='datasets') eq_(res, [source]) assert_repo_status(source.repo, annex=None) assert_repo_status(target, annex=None) eq_(list(target.get_branch_commits_(DEFAULT_BRANCH)), list(source.repo.get_branch_commits_(DEFAULT_BRANCH))) # don't fail when doing it again res = publish(dataset=source, to="target") # and nothing is pushed assert_result_count(res, 1, status='notneeded') assert_repo_status(source.repo, annex=None) assert_repo_status(target, annex=None) eq_(list(target.get_branch_commits_(DEFAULT_BRANCH)), list(source.repo.get_branch_commits_(DEFAULT_BRANCH))) assert_git_annex_branch_published(source.repo, target) # 'target/<default branch>' should be tracking branch at this point, so # try publishing without `to`: # MIH: Nope, we don't automatically add this anymore # some modification: with open(opj(src_path, 'test_mod_file'), "w") as f: f.write("Some additional stuff.") source.save(opj(src_path, 'test_mod_file'), to_git=True, message="Modified.") assert_repo_status(source.repo, annex=None) res = publish(dataset=source, to='target', result_xfm='datasets') eq_(res, [source]) assert_repo_status(dst_path, annex=None) eq_(list(target.get_branch_commits_(DEFAULT_BRANCH)), list(source.repo.get_branch_commits_(DEFAULT_BRANCH))) assert_git_annex_branch_published(source.repo, target) eq_(filter_fsck_error_msg(source.repo.fsck()), filter_fsck_error_msg(source.repo.fsck(remote='target')))
def test_publish_plain_git(origin, src_path, dst_path): # TODO: Since it's mostly the same, melt with test_publish_simple # prepare src source = install(src_path, source=origin, recursive=True) # forget we cloned it (provide no 'origin' anymore), which should lead to # setting tracking branch to target: source.repo.remove_remote("origin") # create plain git at target: target = GitRepo(dst_path, create=True) target.checkout("TMP", ["-b"]) source.repo.add_remote("target", dst_path) res = publish(dataset=source, to="target", result_xfm='datasets') eq_(res, [source]) ok_clean_git(source.repo, annex=None) ok_clean_git(target, annex=None) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) # don't fail when doing it again res = publish(dataset=source, to="target") # and nothing is pushed assert_result_count(res, 1, status='notneeded') ok_clean_git(source.repo, annex=None) ok_clean_git(target, annex=None) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) # some modification: with open(opj(src_path, 'test_mod_file'), "w") as f: f.write("Some additional stuff.") source.add(opj(src_path, 'test_mod_file'), to_git=True, message="Modified.") ok_clean_git(source.repo, annex=None) res = publish(dataset=source, to='target', result_xfm='datasets') eq_(res, [source]) ok_clean_git(dst_path, annex=None) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) # amend and change commit msg in order to test for force push: source.repo.commit("amended", options=['--amend']) # push should be rejected (non-fast-forward): assert_raises(IncompleteResultsError, publish, dataset=source, to='target', result_xfm='datasets') # push with force=True works: res = publish(dataset=source, to='target', result_xfm='datasets', force=True) eq_(res, [source])
def test_ignored(topdir): # create annex, git repos AnnexRepo(opj(topdir, 'annexdir'), create=True) GitRepo(opj(topdir, 'gitdir'), create=True) # non-git or annex should not be ignored assert_equal(ignored(topdir), False) # git, annex and hidden nodes should be ignored for subdir in ["annexdir", "gitdir", ".hidden"]: assert_equal(ignored(opj(topdir, subdir)), True) # ignore only hidden nodes(not git or annex repos) flag should work assert_equal(ignored(opj(topdir, "annexdir"), only_hidden=True), False)
def test_gitattributes(path): gr = GitRepo(path, create=True) # starts without any attributes file ok_(not op.exists(op.join(gr.path, '.gitattributes'))) eq_(gr.get_gitattributes('.')['.'], {}) # bool is a tag or unsets, anything else is key/value gr.set_gitattributes([('*', {'tag': True}), ('*', {'sec.key': 'val'})]) ok_(op.exists(op.join(gr.path, '.gitattributes'))) eq_(gr.get_gitattributes('.')['.'], {'tag': True, 'sec.key': 'val'}) # unset by amending the record, but does not remove notion of the # tag entirely gr.set_gitattributes([('*', {'tag': False})]) eq_(gr.get_gitattributes('.')['.'], {'tag': False, 'sec.key': 'val'}) # attributes file is not added or commited, we can ignore such # attributes eq_(gr.get_gitattributes('.', index_only=True)['.'], {}) # we can send absolute path patterns and write to any file, and # the patterns will be translated relative to the target file gr.set_gitattributes([(op.join(gr.path, 'relative', 'ikethemike/**'), { 'bang': True })], attrfile=op.join('relative', '.gitattributes')) # directory and file get created ok_(op.exists(op.join(gr.path, 'relative', '.gitattributes'))) eq_( gr.get_gitattributes( op.join(gr.path, 'relative', 'ikethemike', 'probe')), # always comes out relative to the repo root, even if abs goes in { op.join('relative', 'ikethemike', 'probe'): { 'tag': False, 'sec.key': 'val', 'bang': True } }) if get_encoding_info()['default'] != 'ascii': # do not perform this on obscure systems without anything like UTF # it is not relevant whether a path actually exists, and paths # with spaces and other funky stuff are just fine funky = u'{} {}'.format(get_most_obscure_supported_name(), get_most_obscure_supported_name()) gr.set_gitattributes([(funky, {'this': 'that'})]) eq_( gr.get_gitattributes(funky)[funky], { 'this': 'that', 'tag': False, 'sec.key': 'val', }) # mode='w' should replace the entire file: gr.set_gitattributes([('**', {'some': 'nonsense'})], mode='w') eq_(gr.get_gitattributes('.')['.'], {'some': 'nonsense'})
def test_GitRepo_remote_update(path1, path2, path3): git1 = GitRepo(path1) git2 = GitRepo(path2) git3 = GitRepo(path3) git1.add_remote('git2', path2) git1.add_remote('git3', path3) # Setting up remote 'git2' with open(op.join(path2, 'masterfile'), 'w') as f: f.write("git2 in master") git2.add('masterfile') git2.commit("Add something to master.") git2.checkout('branch2', ['-b']) with open(op.join(path2, 'branch2file'), 'w') as f: f.write("git2 in branch2") git2.add('branch2file') git2.commit("Add something to branch2.") # Setting up remote 'git3' with open(op.join(path3, 'masterfile'), 'w') as f: f.write("git3 in master") git3.add('masterfile') git3.commit("Add something to master.") git3.checkout('branch3', ['-b']) with open(op.join(path3, 'branch3file'), 'w') as f: f.write("git3 in branch3") git3.add('branch3file') git3.commit("Add something to branch3.") git1.update_remote() # checkouts are 'tests' themselves, since they'll raise CommandError # if something went wrong git1.checkout('branch2') git1.checkout('branch3') branches1 = git1.get_branches() eq_({'branch2', 'branch3'}, set(branches1))
def test_publish_simple(origin, src_path, dst_path): # prepare src source = install(src_path, source=origin, recursive=True)[0] # forget we cloned it (provide no 'origin' anymore), which should lead to # setting tracking branch to target: source.repo.remove_remote("origin") # create plain git at target: target = GitRepo(dst_path, create=True) target.checkout("TMP", ["-b"]) source.repo.add_remote("target", dst_path) res = publish(dataset=source, to="target") eq_(res, ([source], [])) ok_clean_git(src_path, annex=False) ok_clean_git(dst_path, annex=False) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) # don't fail when doing it again res = publish(dataset=source, to="target") eq_(res, ([source], [])) ok_clean_git(src_path, annex=False) ok_clean_git(dst_path, annex=False) eq_(list(target.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) eq_(list(target.get_branch_commits("git-annex")), list(source.repo.get_branch_commits("git-annex"))) # 'target/master' should be tracking branch at this point, so # try publishing without `to`: # some modification: with open(opj(src_path, 'test_mod_file'), "w") as f: f.write("Some additional stuff.") source.repo.add(opj(src_path, 'test_mod_file'), git=True, commit=True, msg="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.get_branch_commits("master")), list(source.repo.get_branch_commits("master"))) eq_(list(target.get_branch_commits("git-annex")), list(source.repo.get_branch_commits("git-annex")))
def test_multiway_merge(path): # prepare ds with two siblings, but no tracking branch ds = Dataset(op.join(path, 'ds_orig')).create() r1 = AnnexRepo(path=op.join(path, 'ds_r1'), git_opts={'bare': True}) r2 = GitRepo(path=op.join(path, 'ds_r2'), git_opts={'bare': True}) ds.siblings(action='add', name='r1', url=r1.path) ds.siblings(action='add', name='r2', url=r2.path) assert_status('ok', ds.publish(to='r1')) assert_status('ok', ds.publish(to='r2')) # just a fetch should be no issue assert_status('ok', ds.update()) # ATM we do not support multi-way merges assert_status('impossible', ds.update(merge=True, on_failure='ignore'))
def test_clone_dataladri(src, topurl, path): # make plain git repo ds_path = Path(src) / 'ds' gr = GitRepo(ds_path, create=True) gr.add('test.txt') gr.commit('demo') Runner(cwd=gr.path).run(['git', 'update-server-info']) # now install it somewhere else with patch('datalad.consts.DATASETS_TOPURL', topurl): ds = clone('///ds', path, result_xfm='datasets', return_type='item-or-list') eq_(ds.path, path) assert_repo_status(path, annex=False) ok_file_has_content(ds.pathobj / 'test.txt', 'some')
def test_bare(path): # can we handle a bare repo? gr = GitRepo(path, create=True, bare=True) # any sensible (and also our CI) test environment(s) should have this assert_in('user.name', gr.config) # not set something that wasn't there obscure_key = 'sec.reallyobscurename!@@.key' assert_not_in(obscure_key, gr.config) # to the local config, which is easily accessible gr.config.set(obscure_key, 'myvalue', where='local') assert_equal(gr.config.get(obscure_key), 'myvalue') # now make sure the config is where we think it is assert_in(obscure_key.split('.')[1], (gr.pathobj / 'config').read_text())
def test_GitRepo_get_toppath(repo, tempdir, repo2): reporeal = op.realpath(repo) eq_(GitRepo.get_toppath(repo, follow_up=False), reporeal) eq_(GitRepo.get_toppath(repo), repo) # Generate some nested directory GitRepo(repo2, create=True) repo2real = op.realpath(repo2) nested = op.join(repo2, "d1", "d2") os.makedirs(nested) eq_(GitRepo.get_toppath(nested, follow_up=False), repo2real) eq_(GitRepo.get_toppath(nested), repo2) # and if not under git, should return None eq_(GitRepo.get_toppath(tempdir), None)
def test_GitRepo_instance_from_not_existing(path, path2): # 1. create=False and path doesn't exist: assert_raises(NoSuchPathError, GitRepo, path, create=False) assert_false(op.exists(path)) # 2. create=False, path exists, but no git repo: os.mkdir(path) ok_(op.exists(path)) assert_raises(InvalidGitRepositoryError, GitRepo, path, create=False) assert_false(op.exists(op.join(path, '.git'))) # 3. create=True, path doesn't exist: gr = GitRepo(path2, create=True) assert_is_instance(gr, GitRepo, "GitRepo was not created.") ok_(op.exists(op.join(path2, '.git'))) ok_clean_git(path2, annex=False) # 4. create=True, path exists, but no git repo: gr = GitRepo(path, create=True) assert_is_instance(gr, GitRepo, "GitRepo was not created.") ok_(op.exists(op.join(path, '.git'))) ok_clean_git(path, annex=False)
def test_crazy_cfg(path=None): cfg = ConfigManager(GitRepo(opj(path, 'ds'), create=True), source='branch') assert_in('crazy.padry', cfg) # make sure crazy config is not read when in local mode cfg = ConfigManager(Dataset(opj(path, 'ds')), source='local') assert_not_in('crazy.padry', cfg) # it will make it in in 'any' mode though cfg = ConfigManager(Dataset(opj(path, 'ds')), source='any') assert_in('crazy.padry', cfg) # typos in the source mode arg will not have silent side-effects assert_raises(ValueError, ConfigManager, Dataset(opj(path, 'ds')), source='locale')
def test_install_dataladri(src, topurl, path): # make plain git repo ds_path = opj(src, 'ds') gr = GitRepo(ds_path, create=True) gr.add('test.txt') gr.commit('demo') Runner(cwd=gr.path)(['git', 'update-server-info']) # now install it somewhere else with patch('datalad.consts.DATASETS_TOPURL', topurl), \ swallow_logs(): ds = install(path, source='///ds') eq_(ds.path, path) ok_clean_git(path, annex=False) ok_file_has_content(opj(path, 'test.txt'), 'some')
def test_hierarchy(topdir): # GH 1178 from datalad.api import create_test_dataset with swallow_logs(), swallow_outputs(): dss = create_test_dataset(topdir, spec='1/1') eq_(len(dss), 3) eq_(dss[0], topdir) for ids, ds in enumerate(dss): ok_clean_git(ds, annex=False) # each one should have 2 commits (but the last one)-- one for file and # another one for sub-dataset repo = GitRepo(ds) eq_(len(list(repo.get_branch_commits())), 1 + int(ids < 2))
def test_target_ssh_recursive(origin, src_path, target_path): # prepare src source = install(src_path, source=origin, recursive=True)[0] sub1 = Dataset(opj(src_path, "subm 1")) sub2 = Dataset(opj(src_path, "subm 2")) for flat in False, True: target_path_ = target_dir_tpl = target_path + "-" + str(flat) if flat: target_dir_tpl += "/%NAME" sep = '-' else: sep = os.path.sep if flat: # now that create_sibling also does fetch -- the related problem # so skipping this early raise SkipTest( 'TODO: Make publish work for flat datasets, it currently breaks' ) remote_name = 'remote-' + str(flat) # TODO: there is f.ckup with paths so assert_create fails ATM # And let's test without explicit dataset being provided with chpwd(source.path): #assert_create_sshwebserver( create_sibling(target=remote_name, sshurl="ssh://localhost" + target_path_, target_dir=target_dir_tpl, recursive=True, ui=True) # raise if git repos were not created for suffix in [sep + 'subm 1', sep + 'subm 2', '']: target_dir = opj(target_path_, basename(src_path) if flat else "").rstrip( os.path.sep) + suffix # raise if git repos were not created GitRepo(target_dir, create=False) _test_correct_publish(target_dir, rootds=not suffix, flat=flat) for repo in [source.repo, sub1.repo, sub2.repo]: assert_not_in("local_target", repo.get_remotes()) # now, push should work: publish(dataset=source, to=remote_name)
def test_GitRepo_push_n_checkout(orig_path, clone_path): origin = GitRepo(orig_path) clone = GitRepo.clone(orig_path, clone_path) filename = get_most_obscure_supported_name() with open(op.join(clone_path, filename), 'w') as f: f.write("New file.") clone.add(filename) clone.commit("new file added.") # TODO: need checkout first: clone.push('origin', '+master:new-branch') origin.checkout('new-branch') ok_(op.exists(op.join(orig_path, filename)))
def knows_annex(path): """Returns whether at a given path there is information about an annex This includes actually present annexes, but also uninitialized ones, or even the presence of a remote annex branch. """ from os.path import exists if not exists(path): lgr.debug("No annex: test path {0} doesn't exist".format(path)) return False from datalad.support.gitrepo import GitRepo repo = GitRepo(path, create=False) return "origin/git-annex" in repo.git_get_remote_branches() \ or "git-annex" in repo.git_get_branches()