4 def find_git(env
=None):
5 """Find the git binary."""
6 if env
is not None and 'GIT' in env
:
7 return env
.get_flat('GIT')
10 if os
.path
.exists("/usr/bin/git"):
11 # this is useful when doing make dist without configuring
17 def has_submodules(path
):
18 """Check whether a source directory is git-versioned and has submodules.
20 :param path: Path to Samba source directory
22 return (os
.path
.isdir(os
.path
.join(path
, ".git")) and
23 os
.path
.isfile(os
.path
.join(path
, ".gitmodules")))
26 def read_submodule_status(path
, env
=None):
27 """Check status of submodules.
29 :param path: Path to git directory
30 :param env: Optional waf environment
31 :return: Yields tuples with submodule relpath and status
32 (one of: 'out-of-date', 'not-checked-out', 'up-to-date')
33 :raise RuntimeError: raised when parsing of 'git submodule status' output
36 if not has_submodules(path
):
37 # No point in running git.
42 p
= subprocess
.Popen([git
, "submodule", "status"], stdout
=subprocess
.PIPE
,
44 (stdout
, stderr
) = p
.communicate(None)
45 for l
in stdout
.splitlines():
51 if len(parts
) > 2 and status
in ("-", "+"):
52 yield (parts
[1], "out-of-date")
53 elif len(parts
) == 2 and status
== "-":
54 yield (parts
[1], "not-checked-out")
55 elif len(parts
) > 2 and status
== " ":
56 yield (parts
[1], "up-to-date")
58 raise RuntimeError("Unable to parse submodule status: %r, %r" % (status
, parts
))