summaryrefslogtreecommitdiffstats
path: root/tests/staged_files_only_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-04 03:57:54 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-12-04 03:57:54 +0000
commitfc1651ef0b7ccedc604b28d5893f5cd486cd4091 (patch)
tree3ea033abb546734a46b2e947756e0d9f792b0e80 /tests/staged_files_only_test.py
parentReleasing debian version 2.15.0-1. (diff)
downloadpre-commit-fc1651ef0b7ccedc604b28d5893f5cd486cd4091.tar.xz
pre-commit-fc1651ef0b7ccedc604b28d5893f5cd486cd4091.zip
Merging upstream version 2.16.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/staged_files_only_test.py')
-rw-r--r--tests/staged_files_only_test.py43
1 files changed, 38 insertions, 5 deletions
diff --git a/tests/staged_files_only_test.py b/tests/staged_files_only_test.py
index ddb9574..2e3f620 100644
--- a/tests/staged_files_only_test.py
+++ b/tests/staged_files_only_test.py
@@ -181,9 +181,11 @@ def test_img_conflict(img_staged, patch_dir):
@pytest.fixture
-def submodule_with_commits(tempdir_factory):
+def repo_with_commits(tempdir_factory):
path = git_dir(tempdir_factory)
with cwd(path):
+ open('foo', 'a+').close()
+ cmd_output('git', 'add', 'foo')
git_commit()
rev1 = cmd_output('git', 'rev-parse', 'HEAD')[1].strip()
git_commit()
@@ -196,18 +198,21 @@ def checkout_submodule(rev):
@pytest.fixture
-def sub_staged(submodule_with_commits, tempdir_factory):
+def sub_staged(repo_with_commits, tempdir_factory):
path = git_dir(tempdir_factory)
with cwd(path):
+ open('bar', 'a+').close()
+ cmd_output('git', 'add', 'bar')
+ git_commit()
cmd_output(
- 'git', 'submodule', 'add', submodule_with_commits.path, 'sub',
+ 'git', 'submodule', 'add', repo_with_commits.path, 'sub',
)
- checkout_submodule(submodule_with_commits.rev1)
+ checkout_submodule(repo_with_commits.rev1)
cmd_output('git', 'add', 'sub')
yield auto_namedtuple(
path=path,
sub_path=os.path.join(path, 'sub'),
- submodule=submodule_with_commits,
+ submodule=repo_with_commits,
)
@@ -242,6 +247,34 @@ def test_sub_something_unstaged(sub_staged, patch_dir):
_test_sub_state(sub_staged, 'rev2', 'AM')
+def test_submodule_does_not_discard_changes(sub_staged, patch_dir):
+ with open('bar', 'w') as f:
+ f.write('unstaged changes')
+
+ foo_path = os.path.join(sub_staged.sub_path, 'foo')
+ with open(foo_path, 'w') as f:
+ f.write('foo contents')
+
+ with staged_files_only(patch_dir):
+ with open('bar') as f:
+ assert f.read() == ''
+
+ with open(foo_path) as f:
+ assert f.read() == 'foo contents'
+
+ with open('bar') as f:
+ assert f.read() == 'unstaged changes'
+
+ with open(foo_path) as f:
+ assert f.read() == 'foo contents'
+
+
+def test_submodule_does_not_discard_changes_recurse(sub_staged, patch_dir):
+ cmd_output('git', 'config', 'submodule.recurse', '1', cwd=sub_staged.path)
+
+ test_submodule_does_not_discard_changes(sub_staged, patch_dir)
+
+
def test_stage_utf8_changes(foo_staged, patch_dir):
contents = '\u2603'
with open('foo', 'w', encoding='UTF-8') as foo_file: