diff --git a/eobuilder-ctl b/eobuilder-ctl index 0414c0e..e6cb665 100755 --- a/eobuilder-ctl +++ b/eobuilder-ctl @@ -418,18 +418,35 @@ def get_git_project_path(project_reference): return os.path.join(settings.GIT_PATH, get_git_project_name(project_reference)) +def get_git_branch_name(project_reference): + git_project_path = get_git_project_path(project_reference) + for branch_name in ('main', 'master'): + try: + subprocess.check_call(['git', 'rev-parse', branch_name], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + cwd=git_project_path) + except subprocess.CalledProcessError: + continue + return branch_name + else: + raise Exception('failed to determine branch') + + def setup_git_tree(project_reference, options): project_name = get_git_project_name(project_reference) git_project_path = get_git_project_path(project_reference) - if options.branch.startswith('wip/'): + if options.branch and options.branch.startswith('wip/'): if os.path.exists(git_project_path): shutil.rmtree(git_project_path) if os.path.exists(git_project_path): existing_tree = True - os.chdir(git_project_path) + branch_name = get_git_branch_name(project_reference) try: - subprocess.check_call(['git', 'checkout', '--quiet', options.branch]) - subprocess.check_call(['git', 'reset', '--hard', 'origin/%s' % options.branch]) + subprocess.check_call(['git', 'checkout', '--quiet', branch_name], + cwd=git_project_path) + subprocess.check_call(['git', 'reset', '--hard', 'origin/%s' % branch_name], + cwd=git_project_path) except subprocess.CalledProcessError as e: print(e, file=sys.stderr) shutil.rmtree(git_project_path) @@ -446,10 +463,14 @@ def setup_git_tree(project_reference, options): else: project_url = project_reference call("git clone %s" % project_url) + branch_name = get_git_branch_name(project_reference) + + if not options.branch: + options.branch = branch_name os.chdir(git_project_path) try: - subprocess.check_call(['git', 'checkout', '--quiet', options.branch]) + subprocess.check_call(['git', 'checkout', '--quiet', branch_name]) subprocess.check_call(['git', 'pull']) subprocess.check_call(['git', 'submodule', 'init']) subprocess.check_call(['git', 'submodule', 'update']) @@ -473,7 +494,7 @@ def main(): project_reference = args[0] git_project_path = get_git_project_path(project_reference) atexit.register(clean_git_on_exit, git_project_path) - if options.branch.startswith('origin/'): + if options.branch and options.branch.startswith('origin/'): # normalize without origin/ options.branch = options.branch[len('origin/'):] existing_tree = os.path.exists(git_project_path) @@ -496,11 +517,12 @@ def main(): # compare revision between last build and now to determine if something is really new new = 1 current_revision = output("git rev-parse HEAD", True).strip() + branch_name = get_git_branch_name(project_reference) last_branch_revision_file_path = os.path.join( project['lock_path'], "%s_%s.last_revision" % ( project['name'], - options.branch.replace('/', '_'))) + branch_name.replace('/', '_'))) try: with open(last_branch_revision_file_path) as f: last_branch_revision = f.read().strip() @@ -516,7 +538,7 @@ def main(): for dist in options.distrib: os.chdir(git_project_path) - call("git checkout --quiet %s" % options.branch) + call("git checkout --quiet %s" % branch_name) package = prepare_build(dist, project, options, new) if package: for arch in options.architectures: @@ -527,13 +549,13 @@ def main(): "%s_%s_%s_%s.build" % (project['name'], package['version'], package['repository'], - options.branch.replace('/', '_')) + branch_name.replace('/', '_')) )) last_version_file = os.path.join(project['lock_path'], "%s_%s_%s.last_version" % (project['name'], package['repository'], - options.branch.replace('/', '_')) + branch_name.replace('/', '_')) ) with open(last_version_file, 'w+') as f: f.write(package['version']) diff --git a/eobuilder/cmdline.py b/eobuilder/cmdline.py index 63334a6..6e50240 100644 --- a/eobuilder/cmdline.py +++ b/eobuilder/cmdline.py @@ -47,8 +47,7 @@ def parse_cmdline(): parser.add_option("-b", "--branch", action="store", type="string", dest="branch", metavar='NAME', - default="master", - help="branch to build (Default: master)") + help="branch to build (Default: main, or master)") parser.add_option("--epoch", action="store", type="string", dest="epoch", metavar='EPOCH',