7 import xml.etree.ElementTree as ET
10 from common import git
11 from common import Colors
12 from common import get_meson
13 from common import accept_command
16 SCRIPTDIR = os.path.normpath(os.path.dirname(__file__))
19 def checkout_subprojects(worktree_dir, branch):
20 subprojects_dir = os.path.join(SCRIPTDIR, "subprojects")
21 worktree_subdir = os.path.join(worktree_dir, "subprojects")
24 installed_s = subprocess.check_output([sys.executable, meson, 'introspect',
25 options.builddir, '--projectinfo'])
26 for subproj in json.loads(installed_s.decode())["subprojects"]:
27 repo_name = subproj["name"]
28 if not repo_name.startswith("gst"):
31 repo_dir = os.path.normpath(os.path.join(SCRIPTDIR, subprojects_dir, repo_name))
32 if not os.path.exists(os.path.join(repo_dir, '.git')):
35 workdir = os.path.normpath(os.path.join(worktree_subdir, repo_name))
36 if not checkout_worktree(repo_name, repo_dir, workdir, branch):
42 def checkout_worktree(repo_name, repo_dir, worktree_dir, branch):
43 print("Checking out worktree %s in %s (branch %s)" % (repo_name, worktree_dir, branch))
45 git("worktree", "add", worktree_dir, branch, repository_path=repo_dir)
46 except Exception as e:
47 out = getattr(e, "output", b"").decode()
48 print("\nCould not checkout worktree %s, please fix and try again."
49 " Error:\n\n%s %s" % (repo_dir, out, e))
53 commit_message = git("show", repository_path=repo_dir).split("\n")
54 print(u" -> %s%s%s - %s" % (Colors.HEADER, repo_dir, Colors.ENDC,
55 commit_message[4].strip()))
60 if __name__ == "__main__":
61 parser = argparse.ArgumentParser(prog="git-update")
64 parser.add_argument('worktree_dir', metavar='worktree_dir', type=str,
65 help='The directory where to checkout the new worktree')
66 parser.add_argument('branch', metavar='branch', type=str,
67 help='The branch to checkout')
68 parser.add_argument("--no-color",
71 help="Do not output ansi colors.")
72 parser.add_argument("--builddir", '-C',
73 default=os.path.join(SCRIPTDIR, "build"),
74 help="The meson build directory")
75 options = parser.parse_args()
80 if not os.path.exists(options.builddir):
81 print("GStreamer not built in %s\n\nBuild it and try again" %
85 options.worktree_dir = os.path.abspath(options.worktree_dir)
86 if not checkout_worktree('gst-build', SCRIPTDIR, options.worktree_dir, options.branch):
88 if not checkout_subprojects(options.worktree_dir, options.branch):