Skip to content

Commit b37525b

Browse files
jbower-fbfacebook-github-bot
authored andcommitted
Add ability to clone Git repo branches
Summary: Unfortunately we can't just use `git.rev` in manifests to specify branches as we clone using `--depth`. This means `rev-parse` on a remote branch name will fail. This diff adds `git.branch` which allows us to be explicit when we want a branch and so check this out in the first place. By doing this future uses of `rev-parse` will also understand the branch name. Reviewed By: martindemello Differential Revision: D79660472 fbshipit-source-id: 6b04158bdd72c28864322be28d88ee4e41f54bc8
1 parent e0cd994 commit b37525b

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

build/fbcode_builder/getdeps/fetcher.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __init__(self) -> None:
218218
class GitFetcher(Fetcher):
219219
DEFAULT_DEPTH = 1
220220

221-
def __init__(self, build_options, manifest, repo_url, rev, depth) -> None:
221+
def __init__(self, build_options, manifest, repo_url, rev, depth, branch) -> None:
222222
# Extract the host/path portions of the URL and generate a flattened
223223
# directory name. eg:
224224
# github.com/facebook/folly.git -> github.com-facebook-folly.git
@@ -249,10 +249,11 @@ def __init__(self, build_options, manifest, repo_url, rev, depth) -> None:
249249
"Using pinned rev %s for %s" % (rev, repo_url), file=sys.stderr
250250
)
251251

252-
self.rev = rev or "main"
252+
self.rev = rev or branch or "main"
253253
self.origin_repo = repo_url
254254
self.manifest = manifest
255255
self.depth = depth if depth else GitFetcher.DEFAULT_DEPTH
256+
self.branch = branch
256257

257258
def _update(self) -> ChangeStatus:
258259
current_hash = (
@@ -295,17 +296,19 @@ def _clone(self) -> None:
295296
# eg: this python process is native win32, but the git.exe is cygwin
296297
# or msys and doesn't like the absolute windows path that we'd otherwise
297298
# pass to it. Careful use of cwd helps avoid headaches with cygpath.
298-
run_cmd(
299-
[
300-
"git",
301-
"clone",
302-
"--depth=" + str(self.depth),
303-
"--",
304-
self.origin_repo,
305-
os.path.basename(self.repo_dir),
306-
],
307-
cwd=os.path.dirname(self.repo_dir),
308-
)
299+
cmd = [
300+
"git",
301+
"clone",
302+
"--depth=" + str(self.depth),
303+
]
304+
if self.branch:
305+
cmd.append("--branch=" + self.branch)
306+
cmd += [
307+
"--",
308+
self.origin_repo,
309+
os.path.basename(self.repo_dir),
310+
]
311+
run_cmd(cmd, cwd=os.path.dirname(self.repo_dir))
309312
self._update()
310313

311314
def clean(self) -> None:

build/fbcode_builder/getdeps/manifest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@
5757
"depends.environment": {"optional_section": True},
5858
"git": {
5959
"optional_section": True,
60-
"fields": {"repo_url": REQUIRED, "rev": OPTIONAL, "depth": OPTIONAL},
60+
"fields": {
61+
"repo_url": REQUIRED,
62+
"rev": OPTIONAL,
63+
"depth": OPTIONAL,
64+
"branch": OPTIONAL,
65+
},
6166
},
6267
"download": {
6368
"optional_section": True,
@@ -461,7 +466,8 @@ def _create_fetcher(self, build_options, ctx):
461466
if repo_url:
462467
rev = self.get("git", "rev")
463468
depth = self.get("git", "depth")
464-
return GitFetcher(build_options, self, repo_url, rev, depth)
469+
branch = self.get("git", "branch")
470+
return GitFetcher(build_options, self, repo_url, rev, depth, branch)
465471

466472
if url:
467473
# We need to defer this import until now to avoid triggering

build/fbcode_builder/manifests/meta-python-3_12

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ shipit_fbcode_builder = false
88
shipit_external_branch = meta/3.12
99

1010
[git]
11-
repo_url = https://github.com/facebookincubator/cinder.git#meta/3.12
11+
repo_url = https://github.com/facebookincubator/cinder.git
12+
branch = meta/3.12
1213

1314
[build]
1415
builder = autoconf

0 commit comments

Comments
 (0)