@@ -28,16 +28,22 @@ def get_submodules(dir: str):
2828 # but that wouldn't work on Windows.
2929 output = subprocess .check_output (["git" , "submodule" , "status" ], cwd = dir )
3030 for line in output .splitlines ():
31- status = line [0 ]
32- revision , name , * _ = line [1 :].split (b" " )
33- yield ( status , revision , name .decode (sys .getfilesystemencoding () ))
31+ unused_status = line [0 ]
32+ unused_revision , name , * _ = line [1 :].split (b" " )
33+ yield name .decode (sys .getfilesystemencoding ())
3434
3535
3636def git_revision (dir : str ) -> bytes :
3737 """Get the SHA-1 of the HEAD of a git repository."""
3838 return subprocess .check_output (["git" , "rev-parse" , "HEAD" ], cwd = dir ).strip ()
3939
4040
41+ def submodule_revision (dir : str , submodule : str ) -> bytes :
42+ """Get the SHA-1 a submodule is supposed to have."""
43+ output = subprocess .check_output (["git" , "ls-files" , "-s" , submodule ], cwd = dir ).strip ()
44+ # E.g.: "160000 e4a7edb949e0b920b16f61aeeb19fc3d328f3012 0 typeshed"
45+ return output .split ()[1 ]
46+
4147def is_dirty (dir : str ) -> bool :
4248 """Check whether a git repository has uncommitted changes."""
4349 output = subprocess .check_output (["git" , "status" , "-uno" , "--porcelain" ], cwd = dir )
@@ -84,7 +90,7 @@ def error_submodule_not_updated(name: str, dir: str) -> None:
8490 print (" cd {}" .format (pipes .quote (dir )), file = sys .stderr )
8591 print (" git submodule update {}" .format (name ), file = sys .stderr )
8692 print ("(If you got this message because you updated {}" .format (name ), file = sys .stderr )
87- print (" then run \" git add {}\" to silence this check)" )
93+ print (" then run \" git add {}\" to silence this check)" . format ( name ), file = sys . stderr )
8894
8995
9096def verify_git_integrity_or_abort (datadir : str ) -> None :
@@ -99,12 +105,12 @@ def verify_git_integrity_or_abort(datadir: str) -> None:
99105 if not have_git ():
100106 warn_no_git_executable ()
101107 return
102- for _ , revision , submodule in get_submodules (datadir ):
108+ for submodule in get_submodules (datadir ):
103109 submodule_path = os .path .join (datadir , submodule )
104110 if not is_git_repo (submodule_path ):
105111 error_submodule_not_initialized (submodule , datadir )
106112 sys .exit (1 )
107- elif revision != git_revision (submodule_path ):
113+ elif submodule_revision ( datadir , submodule ) != git_revision (submodule_path ):
108114 error_submodule_not_updated (submodule , datadir )
109115 sys .exit (1 )
110116 elif is_dirty (submodule_path ):
0 commit comments