def test_new_or_modified(path): def apfiles(aps): for ap in aps: yield relpath(ap["path"], path) ds = Dataset(path).create(force=True, no_annex=True) # Check out an orphan branch so that we can test the "one commit # in a repo" case. ds.repo.checkout("orph", options=["--orphan"]) ds.repo.add(".", commit=True) assert_false(ds.repo.dirty) assert_result_count(ds.repo.repo.git.rev_list("HEAD").split(), 1) # Diffing doesn't fail when the branch contains a single commit. assert_in("to_modify", apfiles(new_or_modified(ds, "HEAD"))) # New files are detected, deletions are not. ds.repo.remove(["to_remove"]) ok_(ds.repo.dirty) with open(opj(path, "to_add"), "w") as f: f.write("content5") ds.repo.add(["to_add"], commit=True) ds.repo.commit("add one, remove another") eq_(list(apfiles(new_or_modified(ds, "HEAD"))), ["to_add"]) # Modifications are detected. with open(opj(path, "to_modify"), "w") as f: f.write("updated 1") with open(opj(path, "d/to_modify"), "w") as f: f.write("updated 2") ds.repo.add(["to_modify", "d/to_modify"], commit=True) eq_(set(apfiles(new_or_modified(ds, "HEAD"))), {"to_modify", "d/to_modify"}) # Non-HEAD revisions work. ds.repo.commit("empty", options=["--allow-empty"]) assert_false(list(apfiles(new_or_modified(ds, "HEAD")))) eq_(set(apfiles(new_or_modified(ds, "HEAD~"))), {"to_modify", "d/to_modify"})
def get_new_or_modified(*args, **kwargs): return [ relpath(ap["path"], path) for ap in new_or_modified(diff_revision(*args, **kwargs)) ]
def get_new_or_modified(*args, **kwargs): return [relpath(ap["path"], path) for ap in new_or_modified(diff_revision(*args, **kwargs))]