File tree 2 files changed +34
-2
lines changed
scmrepo/git/backend/dulwich
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 7
7
from io import BytesIO , StringIO
8
8
from typing import (
9
9
TYPE_CHECKING ,
10
+ Any ,
10
11
Callable ,
11
12
Dict ,
12
13
Iterable ,
@@ -344,8 +345,10 @@ def is_tracked(self, path: str) -> bool:
344
345
return False
345
346
346
347
def is_dirty (self , untracked_files : bool = False ) -> bool :
347
- staged , unstaged , untracked = self .status ()
348
- return bool (staged or unstaged or (untracked_files and untracked ))
348
+ kwargs : Dict [str , Any ] = (
349
+ {} if untracked_files else {"untracked_files" : "no" }
350
+ )
351
+ return any (self .status (** kwargs ))
349
352
350
353
def active_branch (self ) -> str :
351
354
raise NotImplementedError
Original file line number Diff line number Diff line change @@ -1041,3 +1041,32 @@ 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
+ def test_is_dirty (
1048
+ tmp_dir : TmpDir ,
1049
+ scm : Git ,
1050
+ git : Git ,
1051
+ ):
1052
+ tmp_dir .gen ("foo" , "foo" )
1053
+ scm .add ("foo" )
1054
+ assert git .is_dirty ()
1055
+ scm .commit ("commit" )
1056
+ assert not git .is_dirty ()
1057
+
1058
+ tmp_dir .gen ("foo" , "modified" )
1059
+ assert git .is_dirty ()
1060
+ scm .add_commit ("foo" , message = "modified" )
1061
+ assert not git .is_dirty ()
1062
+
1063
+ os .unlink (tmp_dir / "foo" )
1064
+ assert git .is_dirty ()
1065
+ scm .add ("foo" )
1066
+ assert git .is_dirty ()
1067
+ scm .commit ("deleted" )
1068
+ assert not git .is_dirty ()
1069
+
1070
+ tmp_dir .gen ("untracked" , "untracked" )
1071
+ assert git .is_dirty (untracked_files = True )
1072
+ assert not git .is_dirty (untracked_files = False )
You can’t perform that action at this time.
0 commit comments