diff --git a/hm/common.nix b/hm/common.nix index f0274c6..ec28e98 100644 --- a/hm/common.nix +++ b/hm/common.nix @@ -148,6 +148,7 @@ rename which file + cached-nix-shell # For scripts # Pipe utils gnugrep diff --git a/hm/git/default.nix b/hm/git/default.nix index 985dd44..ea6f1ef 100644 --- a/hm/git/default.nix +++ b/hm/git/default.nix @@ -21,7 +21,7 @@ in then ${lib.getExe config.programs.jujutsu.package} git fetch ${lib.getExe config.programs.jujutsu.package} rebase -d main@origin - ${lib.getExe config.programs.jujutsu.package} branch set main -r @- + ${lib.getExe config.programs.jujutsu.package} bookmark set main -r @- ${lib.getExe config.programs.jujutsu.package} git push else ${pkgs.git}/bin/git --no-optional-locks diff --quiet || echo "Repository is dirty!" diff --git a/hm/scripts/jlab b/hm/scripts/jlab new file mode 100755 index 0000000..1c0bf1e --- /dev/null +++ b/hm/scripts/jlab @@ -0,0 +1,67 @@ +#!/usr/bin/env cached-nix-shell +#! nix-shell -i python3 +#! nix-shell -p python3 python3Packages.gitpython + +""" +glab wrapper for jujutsu +""" + +import json +import pathlib +import pprint +import subprocess +import sys + +import git + + +def git_repo() -> git.Repo: + directory = pathlib.Path.cwd() + for parent in [directory] + list(directory.parents): + if parent.joinpath(".git").is_dir(): + break + else: + raise FileNotFoundError("Not a git repository") + return git.Repo(parent.as_posix()) + +def current_branch() -> str: + # FIXME + # Need to extract this from jj, can do with jj log --no-graph -T 'commit_id' + # (see templates) or show, also see revsets. + # How to search is a good question, usually it will be before @, + # but when editing it will be after. + # How to deal with nested MRs? (at least fail in that case) + + # sp = subprocess.run( + # ["glab", "mr", "view", branch, "--output", "json"], stdout=subprocess.PIPE + # ) + return "pouet" + + +def mr_info(branch: str) -> dict: + sp = subprocess.run( + ["glab", "mr", "view", branch, "--output", "json"], stdout=subprocess.PIPE + ) + return json.loads(sp.stdout) + + +def to_glab() -> None: + subprocess.run(["glab"] + sys.argv[1:]) + + +if sys.argv[1] == "mr": + branch = current_branch() + # TODO If no number specified, add it + if sys.argv[2] == "checkout": + data = mr_info(branch) + pprint.pprint(data) + # TODO If no commit on the branch, then create a jj one and make it have the title of the issue, + # also the branch name + else: + to_glab() +else: + to_glab() + +# TODO Push command that signs and pushes to the right repo + +# TODO Autocomplete