def put_file_under_git(path, filename=None, content=None, annexed=False): """Place file under git/annex and return used Repo """ annex, file_repo_path, filename, path, repo = _prep_file_under_git(path, filename) if content is None: content = "" with open(opj(repo.path, file_repo_path), 'w') as f_: f_.write(content) if annexed: if not isinstance(repo, AnnexRepo): repo = AnnexRepo(repo.path) repo.add_to_annex(file_repo_path) else: repo.git_add(file_repo_path) ok_file_under_git(repo.path, file_repo_path, annexed) return repo
def test_update_fetch_all(src, remote_1, remote_2): rmt1 = AnnexRepo(remote_1, src) rmt2 = AnnexRepo(remote_2, src) ds = Dataset(src) ds.add_sibling(name="sibling_1", url=remote_1) ds.add_sibling(name="sibling_2", url=remote_2) # modify the remotes: with open(opj(remote_1, "first.txt"), "w") as f: f.write("some file load") rmt1.add_to_annex("first.txt") # TODO: Modify an already present file! with open(opj(remote_2, "second.txt"), "w") as f: f.write("different file load") rmt2.git_add("second.txt") rmt2.git_commit("Add file to git.") # fetch all remotes ds.update(fetch_all=True) # no merge, so changes are not in active branch: assert_not_in("first.txt", ds.repo.git_get_files(ds.repo.git_get_active_branch())) assert_not_in("second.txt", ds.repo.git_get_files(ds.repo.git_get_active_branch())) # but we know the changes in remote branches: assert_in("first.txt", ds.repo.git_get_files("sibling_1/master")) assert_in("second.txt", ds.repo.git_get_files("sibling_2/master")) # no merge strategy for multiple remotes yet: assert_raises(NotImplementedError, ds.update, merge=True, fetch_all=True) # merge a certain remote: ds.update(name="sibling_1", merge=True) # changes from sibling_2 still not present: assert_not_in("second.txt", ds.repo.git_get_files(ds.repo.git_get_active_branch())) # changes from sibling_1 merged: assert_in("first.txt", ds.repo.git_get_files(ds.repo.git_get_active_branch())) # it's known to annex, but has no content yet: ds.repo.get_file_key("first.txt") # raises if unknown eq_([False], ds.repo.file_has_content(["first.txt"]))
def put_file_under_git(path, filename=None, content=None, annexed=False): """Place file under git/annex and return used Repo """ annex, file_repo_path, filename, path, repo = _prep_file_under_git( path, filename) if content is None: content = "" with open(opj(repo.path, file_repo_path), 'w') as f_: f_.write(content) if annexed: if not isinstance(repo, AnnexRepo): repo = AnnexRepo(repo.path) repo.add_to_annex(file_repo_path) else: repo.git_add(file_repo_path) ok_file_under_git(repo.path, file_repo_path, annexed) return repo