-
With git I can do
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
I believe jj always fetches from If your repo is colocated, you can use git to fetch these branches. |
Beta Was this translation helpful? Give feedback.
-
We have #4388 for pushing and fetching specific refs. We might get some forge-specific integrations some day (e.g. #4555 for GitHub integration). |
Beta Was this translation helpful? Give feedback.
-
I wrote some script to create local branches/checkouts and manages remotes
#!/usr/bin/env python3
import json
import subprocess
import argparse
import shlex
from dataclasses import dataclass
@dataclass
class PullRequest:
head_repository: str
head_ref_name: str
head_repository_owner: str
def remote_url(self) -> str:
return f"[email protected]:{self.head_repository_owner}/{self.head_repository}.git"
def get_pull_request(pull_request: int) -> PullRequest:
output = subprocess.run(
[
"gh",
"pr",
"view",
"--json",
"headRepository,headRefName,headRepositoryOwner",
str(pull_request),
],
text=True,
check=True,
stdout=subprocess.PIPE,
)
data = json.loads(output.stdout)
return PullRequest(
head_repository=data["headRepository"]["name"],
head_ref_name=data["headRefName"],
head_repository_owner=data["headRepositoryOwner"]["login"],
)
def add_or_set_remote(remote_name: str, remote_url: str) -> None:
command = ["jj", "git", "remote", "add", remote_name, remote_url]
try:
subprocess.run(
command,
check=True,
)
except subprocess.CalledProcessError:
command = ["jj", "git", "remote", "set-url", remote_name, remote_url]
print("$ " + " ".join(map(shlex.quote, command)))
subprocess.run(
command,
check=True,
)
def checkout_command(args: argparse.Namespace) -> None:
pr_number: int = args.pull_request
pull_request = get_pull_request(pr_number)
add_or_set_remote(pull_request.head_repository_owner, pull_request.remote_url())
command = [
"jj",
"git",
"fetch",
"--remote",
pull_request.head_repository_owner,
"--branch",
pull_request.head_ref_name,
]
print("$ " + " ".join(map(shlex.quote, command)))
subprocess.run(
command,
check=True,
)
command = [
"jj",
"new",
f"{pull_request.head_ref_name}@{pull_request.head_repository_owner}",
]
subprocess.run(
command,
check=True,
)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Checkout the a pull request locally with jj."
)
subparsers = parser.add_subparsers(dest="subcommand")
subparsers.required = True
checkout = subparsers.add_parser("checkout", help="")
checkout.add_argument("pull_request", type=int, help="The pull request number")
checkout.set_defaults(func=checkout_command)
return parser.parse_args()
def main() -> None:
parsed_args = parse_args()
parsed_args.func(parsed_args)
if __name__ == "__main__":
main() However a lot of other functionality in jj is not yet clear to me (how this merge conflict editor works etc). Will test this in a few months again and see if things clear up. |
Beta Was this translation helpful? Give feedback.
-
Not sure if this is helpful, but I personally still use Git in colocated repos for this. I like this alias (which does exactly the # ~/.config/git/config
[aliases]
# Simplified from https://gist.github.com/gnarf/5406589
pr = "!f() { git fetch -fu ${2:-$(git remote |grep ^upstream || echo origin)} refs/pull/$1/head:pr/$1 }; f" The original script also put The usage is simply |
Beta Was this translation helpful? Give feedback.
I believe jj always fetches from
refs/heads/*
on the remote, so I don't think there is any way to do this with jj alone.If your repo is colocated, you can use git to fetch these branches.