@@ -1041,3 +1041,50 @@ def test_status(
1041
1041
assert staged ["modify" ] == ["foo" ]
1042
1042
assert unstaged == ["bar" ]
1043
1043
assert untracked == expected_untracked
1044
+
1045
+
1046
+ @pytest .mark .skip_git_backend ("pygit2" )
1047
+ @pytest .mark .parametrize ("untracked_files" , [False , True ])
1048
+ def test_is_dirty (
1049
+ tmp_dir : TmpDir ,
1050
+ scm : Git ,
1051
+ git : Git ,
1052
+ tmp_dir_factory : TempDirFactory ,
1053
+ mocker ,
1054
+ untracked_files : str ,
1055
+ ):
1056
+ tmp_dir .gen (
1057
+ {
1058
+ "foo" : "foo" ,
1059
+ }
1060
+ )
1061
+ scm .add_commit (["foo" ], message = "init" )
1062
+
1063
+ assert not git .is_dirty ()
1064
+
1065
+ with (tmp_dir / "foo" ).open ("a" ) as fobj :
1066
+ fobj .write ("modified" )
1067
+
1068
+ assert git .is_dirty (untracked_files )
1069
+ scm .add_commit (["foo" ], message = "commit" )
1070
+
1071
+ with (tmp_dir / "untracked" ).open ("w" ) as fobj :
1072
+ fobj .write ("untracked" )
1073
+
1074
+ backend = list (git .backends )[0 ]
1075
+ assert backend in ("dulwich" , "gitpython" )
1076
+ if backend == "dulwich" :
1077
+ spy = mocker .spy (git .dulwich , "status" )
1078
+ elif backend == "gitpython" :
1079
+ spy = mocker .spy (git .gitpython .repo , "is_dirty" )
1080
+
1081
+ assert git .is_dirty (untracked_files ) == untracked_files
1082
+ assert spy .called
1083
+ args , kwargs = spy .call_args
1084
+ if backend == "dulwich" :
1085
+ if untracked_files :
1086
+ assert not kwargs
1087
+ else :
1088
+ assert kwargs ["untracked_files" ] == "no"
1089
+ elif backend == "gitpython" :
1090
+ assert kwargs ["untracked_files" ] == untracked_files
0 commit comments