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(meson + ['introspect', options.builddir, '--projectinfo'])
25 for subproj in json.loads(installed_s.decode())["subprojects"]:
26 repo_name = subproj["name"]
27 if not repo_name.startswith("gst"):
30 repo_dir = os.path.normpath(os.path.join(SCRIPTDIR, subprojects_dir, repo_name))
31 if not os.path.exists(os.path.join(repo_dir, '.git')):
34 workdir = os.path.normpath(os.path.join(worktree_subdir, repo_name))
35 if not checkout_worktree(repo_name, repo_dir, workdir, branch):
41 def checkout_worktree(repo_name, repo_dir, worktree_dir, branch):
42 print("Checking out worktree %s in %s (branch %s)" % (repo_name, worktree_dir, branch))
44 git("worktree", "add", worktree_dir, branch, repository_path=repo_dir)
45 except Exception as e:
46 out = getattr(e, "output", b"").decode()
47 print("\nCould not checkout worktree %s, please fix and try again."
48 " Error:\n\n%s %s" % (repo_dir, out, e))
52 commit_message = git("show", "--shortstat", repository_path=repo_dir).split("\n")
53 print(u" -> %s%s%s - %s" % (Colors.HEADER, repo_dir, Colors.ENDC,
54 commit_message[4].strip()))
59 if __name__ == "__main__":
60 parser = argparse.ArgumentParser(prog="git-update")
63 parser.add_argument('worktree_dir', metavar='worktree_dir', type=str,
64 help='The directory where to checkout the new worktree')
65 parser.add_argument('branch', metavar='branch', type=str,
66 help='The branch to checkout')
67 parser.add_argument("--no-color",
70 help="Do not output ansi colors.")
71 parser.add_argument("--builddir", '-C',
72 default=os.path.join(SCRIPTDIR, "build"),
73 help="The meson build directory")
74 options = parser.parse_args()
79 if not os.path.exists(options.builddir):
80 print("GStreamer not built in %s\n\nBuild it and try again" %
84 options.worktree_dir = os.path.abspath(options.worktree_dir)
85 if not checkout_worktree('gst-build', SCRIPTDIR, options.worktree_dir, options.branch):
87 if not checkout_subprojects(options.worktree_dir, options.branch):