88
99
1010def is_git_repo (dir : str ) -> bool :
11- """Is the passed directory version controlled with git?"""
11+ """Is the given directory version- controlled with git?"""
1212 return os .path .exists (os .path .join (dir , ".git" ))
1313
1414
1515def have_git () -> bool :
1616 """Can we run the git executable?"""
1717 try :
18- subprocess .check_output (["git" , "config" , "-l " ])
18+ subprocess .check_output (["git" , "--help " ])
1919 return True
2020 except subprocess .CalledProcessError :
2121 return False
@@ -27,9 +27,12 @@ def get_submodules(dir: str):
2727 # "git submodule foreach 'echo MODULE $name $path $sha1 $toplevel'"
2828 # but that wouldn't work on Windows.
2929 output = subprocess .check_output (["git" , "submodule" , "status" ], cwd = dir )
30+ # "<status><sha1> name desc"
31+ # status='-': not initialized
32+ # status='+': changed
33+ # status='u': merge conflicts
3034 for line in output .splitlines ():
31- unused_status = line [0 ]
32- unused_revision , name , * _ = line [1 :].split (b" " )
35+ name = line .split (b" " )[1 ]
3336 yield name .decode (sys .getfilesystemencoding ())
3437
3538
@@ -44,6 +47,7 @@ def submodule_revision(dir: str, submodule: str) -> bytes:
4447 # E.g.: "160000 e4a7edb949e0b920b16f61aeeb19fc3d328f3012 0 typeshed"
4548 return output .split ()[1 ]
4649
50+
4751def is_dirty (dir : str ) -> bool :
4852 """Check whether a git repository has uncommitted changes."""
4953 output = subprocess .check_output (["git" , "status" , "-uno" , "--porcelain" ], cwd = dir )
@@ -64,15 +68,15 @@ def warn_no_git_executable() -> None:
6468def warn_dirty (dir ) -> None :
6569 print ("Warning: git module '{}' has uncommitted changes." .format (dir ),
6670 file = sys .stderr )
67- print ("Got to the directory" , file = sys .stderr )
71+ print ("Go to the directory" , file = sys .stderr )
6872 print (" {}" .format (dir ), file = sys .stderr )
6973 print ("and commit or reset your changes" , file = sys .stderr )
7074
7175
7276def warn_extra_files (dir ) -> None :
7377 print ("Warning: git module '{}' has untracked files." .format (dir ),
7478 file = sys .stderr )
75- print ("Got to the directory" , file = sys .stderr )
79+ print ("Go to the directory" , file = sys .stderr )
7680 print (" {}" .format (dir ), file = sys .stderr )
7781 print ("and add & commit your new files." , file = sys .stderr )
7882
0 commit comments