Skip to content

Commit 2c5fb01

Browse files
committed
[scripts] ,git-pr-for-line: add jj support
Detect jj repos and use jj git remote list for URL lookup. Set GIT_DIR via jj git root so git blame and gh work correctly. Also update meain/github-pr-url to use jj root for project root.
1 parent c225a27 commit 2c5fb01

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

emacs/.config/emacs/lisp/web.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
(defun meain/github-pr-url ()
2424
"Open the Github PR page for the current file and line."
2525
(interactive)
26-
(let* ((project-root (locate-dominating-file default-directory ".git")) ; Find the project root
26+
(let* ((is-jj (not (string-empty-p
27+
(string-trim
28+
(shell-command-to-string "jj root 2>/dev/null")))))
29+
(project-root (if is-jj
30+
(file-name-as-directory
31+
(string-trim (shell-command-to-string "jj root")))
32+
(locate-dominating-file default-directory ".git")))
2733
(relative-path (if project-root
28-
(file-relative-name (buffer-file-name) project-root) ; Get relative path
29-
(buffer-file-name)))) ; Fallback to absolute path
34+
(file-relative-name (buffer-file-name) project-root)
35+
(buffer-file-name))))
3036
(message "%s"
3137
(shell-command-to-string
3238
(format ",git-pr-for-line %s %s"

scripts/.local/bin/git/,git-pr-for-line

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ if [ "$#" -ne 2 ]; then
77
exit 1
88
fi
99

10-
REPOURL=$(git remote get-url upstream 2>/dev/null || true)
11-
if [ -z "$REPOURL" ]; then
12-
REPOURL=$(git remote get-url origin)
10+
if jj root >/dev/null 2>&1; then
11+
export GIT_DIR=$(jj git root)
12+
REPOURL=$(jj git remote list 2>/dev/null | awk '/^upstream / {print $2}')
13+
if [ -z "$REPOURL" ]; then
14+
REPOURL=$(jj git remote list 2>/dev/null | awk '/^origin / {print $2}')
15+
fi
16+
else
17+
REPOURL=$(git remote get-url upstream 2>/dev/null || true)
18+
if [ -z "$REPOURL" ]; then
19+
REPOURL=$(git remote get-url origin)
20+
fi
1321
fi
1422

1523
if [ -z "$REPOURL" ]; then

0 commit comments

Comments
 (0)