def test_git_stash_drop(tmp_dir, scm, ref): from dvc.scm.git import Stash tmp_dir.scm_gen({"file": "0"}, commit="init") tmp_dir.gen("file", "1") stash = Stash(scm, ref=ref) stash.push() tmp_dir.gen("file", "2") expected = stash.push() stash.drop(1) assert expected == scm.get_ref(stash.ref) assert len(stash) == 1
def test_git_stash_pop(tmp_dir, scm, ref): from dvc.scm.git import Stash tmp_dir.scm_gen({"file": "0"}, commit="init") tmp_dir.gen("file", "1") stash = Stash(scm, ref=ref) first = stash.push() tmp_dir.gen("file", "2") second = stash.push() assert second == stash.pop() assert len(stash) == 1 assert first == scm.get_ref(stash.ref) assert "2" == (tmp_dir / "file").read_text()
def test_git_stash_clear(tmp_dir, scm, ref): from dvc.scm.git import Stash tmp_dir.scm_gen({"file": "0"}, commit="init") tmp_dir.gen("file", "1") stash = Stash(scm, ref=ref) stash.push() tmp_dir.gen("file", "2") stash.push() stash.clear() assert len(stash) == 0 parts = list(stash.ref.split("/")) assert not os.path.exists(os.path.join(os.fspath(tmp_dir), ".git", *parts)) assert not os.path.exists( os.path.join(os.fspath(tmp_dir), ".git", "logs", *parts))
def test_git_stash_clear(tmp_dir, scm, ref): from dvc.scm.git import Stash tmp_dir.scm_gen({"file": "0"}, commit="init") tmp_dir.gen("file", "1") stash = Stash(scm, ref=ref) stash.push() tmp_dir.gen("file", "2") stash.push() stash.clear() assert len(stash) == 0 parts = list(stash.ref.split("/")) assert not os.path.exists(os.path.join(os.fspath(tmp_dir), ".git", *parts)) # NOTE: some backends will completely remove reflog file on clear, some # will only truncate it, either case means an empty stash log_path = os.path.join(os.fspath(tmp_dir), ".git", "logs", *parts) assert not os.path.exists(log_path) or not open(log_path).read()
def test_git_stash_push(tmp_dir, scm, ref, include_untracked): from dvc.scm.git import Stash tmp_dir.scm_gen({"file": "0"}, commit="init") tmp_dir.gen({"file": "1", "untracked": "0"}) stash = Stash(scm, ref=ref) rev = stash.push(include_untracked=include_untracked) assert rev == scm.get_ref(stash.ref) assert "0" == (tmp_dir / "file").read_text() assert include_untracked != (tmp_dir / "untracked").exists() assert len(stash) == 1 stash.apply(rev) assert "1" == (tmp_dir / "file").read_text() assert "0" == (tmp_dir / "untracked").read_text() parts = list(stash.ref.split("/")) assert os.path.exists(os.path.join(os.fspath(tmp_dir), ".git", *parts)) assert os.path.exists( os.path.join(os.fspath(tmp_dir), ".git", "logs", *parts))