Skip to content

Commit

Permalink
bots: Add make-checkout option to checkout a different cockpit bots/ ref
Browse files Browse the repository at this point in the history
For testing external projects for changes to cockpit's bots/ directory,
we need to be able to check out the project plus Cockpit's bots/ from a
ref other than master (i. e. usually a pull request, like
pull/1234/head). Add a new `--bots-ref` option to it which does that.
When not given, bots/ will continue to be checked out from
`origin/master`.

Closes cockpit-project#9605
  • Loading branch information
martinpitt committed Jul 6, 2018
1 parent f02c0a0 commit 3f81fa0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bots/make-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def main():
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
parser.add_argument("--base", nargs='?', help="Base branch that revision is for")
parser.add_argument("--repo", nargs='?', help="Repository to check out")
parser.add_argument("--bots-ref", help="bots/ ref to check out from cockpit, for non-default --repo")
parser.add_argument("ref", help="The git ref to fetch")
parser.add_argument("revision", nargs='?', help="Actual commit to check out, defaults to ref")

Expand All @@ -54,6 +55,13 @@ def main():
sys.stderr.write("> " + output + "\n")
return output

# do this before fetching the actual test repo, so that FETCH_HEAD always points to that at the end
if opts.bots_ref:
execute("git", "fetch", "origin", opts.bots_ref)
bots_ref = execute("git", "rev-parse", "FETCH_HEAD").strip()
else:
bots_ref = "origin/master"

if opts.repo:
if "test\n" in subprocess.check_output([ "git", "remote" ], universal_newlines=True):
execute("git", "remote", "remove", "test")
Expand All @@ -64,8 +72,8 @@ def main():

# If the bots directory doesn't exist in this branch or repo, check it out from master
if opts.repo or (opts.base and opts.base != "master"):
sys.stderr.write("Checking out bots directory from Cockpit master ...\n")
execute("git", "checkout", "--force", "origin/master", "--", "bots/")
sys.stderr.write("Checking out bots directory from Cockpit %s ...\n" % (opts.bots_ref or bots_ref))
execute("git", "checkout", "--force", bots_ref, "--", "bots/")


if __name__ == '__main__':
Expand Down

0 comments on commit 3f81fa0

Please sign in to comment.