stage/unstage all actions added
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import sublime # the stub, via conftest
|
||||
@@ -599,6 +601,45 @@ def test_stage_all_and_unstage_all_need_something_to_do(monkeypatch):
|
||||
assert messages[-1] == "stage all works on uncommitted changes only"
|
||||
|
||||
|
||||
def watched(monkeypatch, tmp_path, all_mode):
|
||||
"""A working-tree view of a.py and b.py on disk with its fingerprint taken; returns (st, refreshes)"""
|
||||
for name in ("a.py", "b.py", "index"):
|
||||
(tmp_path / name).write_text(name)
|
||||
monkeypatch.setattr(commands.git, "index_path", lambda repo: str(tmp_path / "index"))
|
||||
refreshes = []
|
||||
monkeypatch.setattr(commands, "refresh_listing", lambda view, st: refreshes.append(st))
|
||||
st = state.ViewState(str(tmp_path))
|
||||
st.files = [change("a.py"), change("b.py")]
|
||||
st.change, st.all_mode = st.files[0], all_mode
|
||||
st.fingerprint = commands.render.fingerprint(st)
|
||||
return st, refreshes
|
||||
|
||||
|
||||
def touch(path):
|
||||
"""Push the file's mtime forward, as an edit would"""
|
||||
stat = path.stat()
|
||||
os.utime(path, (stat.st_atime, stat.st_mtime + 5))
|
||||
|
||||
|
||||
def test_refresh_if_changed_watches_every_file_of_the_all_files_view(monkeypatch, tmp_path):
|
||||
st, refreshes = watched(monkeypatch, tmp_path, all_mode=True)
|
||||
commands.refresh_if_changed(sublime.View(), st)
|
||||
assert refreshes == []
|
||||
touch(tmp_path / "b.py") # not the file under the caret
|
||||
commands.refresh_if_changed(sublime.View(), st)
|
||||
assert refreshes == [st]
|
||||
|
||||
|
||||
def test_refresh_if_changed_watches_the_shown_file_and_the_index(monkeypatch, tmp_path):
|
||||
st, refreshes = watched(monkeypatch, tmp_path, all_mode=False)
|
||||
touch(tmp_path / "b.py") # another file: the single-file view does not show it
|
||||
commands.refresh_if_changed(sublime.View(), st)
|
||||
assert refreshes == []
|
||||
touch(tmp_path / "index")
|
||||
commands.refresh_if_changed(sublime.View(), st)
|
||||
assert refreshes == [st]
|
||||
|
||||
|
||||
def test_staging_the_only_file_leaves_an_empty_listing(monkeypatch):
|
||||
messages = []
|
||||
monkeypatch.setattr(commands.render, "render_message", lambda view, st, text: messages.append(text))
|
||||
|
||||
@@ -97,6 +97,16 @@ def test_stage_all_unstage_all(repo):
|
||||
assert changes["sub/n.py"].status == "?"
|
||||
|
||||
|
||||
def test_index_path_finds_a_worktrees_index(repo, tmp_path_factory):
|
||||
assert git.index_path(repo) == os.path.join(repo, ".git", "index")
|
||||
# a worktree's .git is a file pointing into the main repository
|
||||
tree = str(tmp_path_factory.mktemp("tree") / "wt")
|
||||
sh(repo, "worktree", "add", "-q", tree)
|
||||
index = git.index_path(tree)
|
||||
assert os.path.isfile(os.path.join(tree, ".git")) and os.path.isfile(index)
|
||||
assert os.path.realpath(index).startswith(os.path.realpath(os.path.join(repo, ".git", "worktrees")))
|
||||
|
||||
|
||||
def test_commits(repo):
|
||||
write(repo, "a.py", "def f():\n return 10\n\n\ndef g():\n return 2\n")
|
||||
write(repo, "c.py", "c\n")
|
||||
|
||||
Reference in New Issue
Block a user