11 package = pkgs-unstable.jujutsu;
15 fsmonitor.watchman.register-snapshot-trigger = true;
19 max-new-file-size = "2MiB";
20 auto-update-stale = true;
32 "(trunk()..@):: | (trunk()..@)-"
34 #l = ["log" "-r" "more()"];
39 # Figures out the closest bookmark
40 # and pulls it up to the latest change that can be pushed.
63 ]; # commit interactive
92 ]; # describe previous
102 "git_format_patch_email_headers"
134 ]; # new bookmark (for creating bookmark to push)
140 ]; # new change before
173 jj bookmark move --from "closest_bookmark(@)" --to "closest_pushable(@)"
175 jj bookmark move --to "closest_pushable(@)" "$@"
186 "jj up && jj git push"
197 gh pr view --json headRepository,headRefName,headRepositoryOwner $PR --jq '"
199 jj 2>/dev/null git remote add \"$1\" \"$2\" ||
200 jj git remote set-url \"$1\" \"$2\"
202 set_remote \(.headRepositoryOwner.login) git@github.com:\(.headRepositoryOwner.login)/\(.headRepository.name)
203 jj git fetch --remote \(.headRepositoryOwner.login) --branch \(.headRefName)
204 jj bookmark track --remote=\(.headRepositoryOwner.login) \(.headRefName)
205 origin=$(gh repo view --json owner,name --jq .owner.login)
206 set_remote \"$origin\" \"$(gh repo view --json sshUrl --jq .sshUrl)\"
207 git fetch --force --update-head-ok \"$origin\" \"refs/pull/'"$PR"'/head:refs/remotes/$origin/pull/'"$PR"'\"
213 untrack-github-PR = [
221 gh pr view --json headRepository,headRefName,headRepositoryOwner $PR --jq '"
222 jj bookmark forget \(.headRefName) || true
223 origin=$(gh repo view --json owner,name --jq .owner.login)
224 git for-each-ref --format \"delete %(refname)\" \\
225 \"refs/remotes/\(.headRepositoryOwner.login)/\(.headRefName)\" \\
226 \"refs/remotes/$origin/pull/'"$PR"'\" |
228 git update-ref --stdin
232 "jj-untrack-github-PR"
234 # Get all open stacks of work.
245 # Retrunk a series. Typically used as `jj retrunk -s ...` and notably can be
247 # - jj retrunk -s 'all:roots(open())'
253 # Retrunk the current stack of work.
259 "all:roots(trunk()..stack(@))"
261 # Take content from any change and move it into @.
262 # - jj consume xyz path/to/file`
269 # Eject content from @ into any other change.
270 # - jj eject xyz --interactive
282 # All operations, with more whitespace
287 "builtin_op_log_comfortable"
293 "description(exact:'') ~ root()"
295 # Move $commit just after the bookmark, and then move $bookmark on top of it.
297 # "$bookmark+" works, because after rebase -A, the only child of $bookmark is $commit.
298 # I do not use $commit itself because it might point to a
299 # different commit after the rebase (e.g. @-).
301 # My workflow uses mega-merge: I write a commit or two,
302 # and then move them to relevant branches with jj to.
303 # As a bonus, bookmarks are kept up-to-date for easy pushing.
304 # https://github.com/jj-vcs/jj/discussions/5568#discussioncomment-14289564
315 # default to latest non-ephemeral commit
316 if [ -z "$commit" ]; then
317 commit=$(jj log --no-graph -T change_id -r '@ ~ ephemeral')
318 if [ -n "$commit" ]; then
319 # Moving current commit, create a new one to preserve
320 # current position in the commit DAG
326 jj rebase -r "$commit" -A "$bookmark"
327 jj bookmark move -f "$bookmark" -t "$bookmark+"
338 # Focus current commit, trunk(), on local work and remote work by removing ancestors of trunk()
340 "@ | trunk() | ancestors_and_children(bookmarks() | tracked_remote_bookmarks()) ~ ..trunk()";
342 "active(rev)" = "(ancestors(rev) | descendants(rev)) ~ immutable()";
343 "ancestors_and_children(x)" = "..x | x::";
345 # Remote commits not merged in trunk()
346 "review()" = "ancestors_and_children(@) ~ ..trunk()";
347 "review(x)" = "ancestors_and_children(remote_bookmarks(x)) ~ ..trunk()";
348 "reviews()" = "ancestors_and_children(remote_bookmarks()) ~ ..trunk()";
351 "wip()" = "ancestors_and_children(bookmarks()) ~ ..(remote_bookmarks() | trunk())";
352 "wip(x)" = "trunk() | ..bookmarks(x) ~ ..(remote_bookmarks() | trunk())";
354 # Authored or committed by specified user
355 "user(x)" = "author(x) | committer(x)";
357 "closest_tip()" = "heads(::@ & remote_bookmarks())";
359 # Those who would be abandoned if you check out something else
360 ephemeral = "(empty() ~ merges() ~ root()) & description(exact:\" \")";
362 # show everything in the current set of branches off of trunk():
363 branch = "(coalesce(trunk(),root())..@)- | (coalesce(trunk(),root())..@)::";
366 "closest_bookmark(to)" = "heads(::to & bookmarks())";
367 "closest_pushable(to)" =
368 "heads(::to & mutable() & ~description(exact:\" \") & (~empty() | merges()))";
370 "desc(x)" = "description(x)";
371 "pending()" = ".. ~ ::tags() ~ ::remote_bookmarks() ~ @ ~ private()";
373 "description(glob:'wip:*') | description(glob:'private:*') | description(glob:'WIP:*') | description(glob:'PRIVATE:*') | conflicts() | (empty() ~ merges()) | description('substring-i:\"DO NOT MAIL\"')";
374 #"trunk()" = "main@rad";
375 #"immutable_heads()" = "tags()";
376 "immutable_heads()" =
377 "present(trunk()) | tags() | ( untracked_remote_bookmarks() ~ untracked_remote_bookmarks(remote=glob:'rad') ~ untracked_remote_bookmarks(regex:'^patch(es)/',remote=glob:'rad'))";
378 #'default()' = 'coalesce(trunk(), root())::present(@) | ancestors(visible_heads(), 2)'
381 "bases" = "present(main@rad) | present(master@origin) | present(main@origin)";
382 "downstream(x,y)" = "(x::y) & y";
383 "branches" = "downstream(trunk(), bookmarks()) & mine()";
384 "branchesandheads" = "branches | (heads(trunk()::) & mine())";
385 "curbranch" = "latest(branches::@- & branches)";
386 "nextbranch" = "roots(@:: & branchesandheads)";
388 "more" = "log | ancestors(visible_heads(), 2)";
389 "unmerged()" = "bookmarks() & ~(trunk():: | trunk())";
390 "recent()" = "committer_date(after:\"1 months ago\")";
391 "recent(revset)" = "revset & recent()";
393 # stack(x, n) is the set of mutable commits reachable from 'x', with 'n'
394 # parents. 'n' is often useful to customize the display and return set for
395 # certain operations. 'x' can be used to target the set of 'roots' to traverse,
396 # e.g. @ is the current stack.
397 "stack()" = "ancestors(reachable(@, mutable()), 2)";
398 "stack(x)" = "ancestors(reachable(x, mutable()), 2)";
399 "stack(x, n)" = "ancestors(reachable(x, mutable()), n)";
401 # The current set of "open" works. It is defined as:
403 # - given the set of commits not in trunk, that are written by me,
404 # - calculate the given stack() for each of those commits
406 # n = 1, meaning that nothing from `trunk()` is included, so all resulting
407 # commits are mutable by definition.
408 "open()" = "stack(trunk().. & mine(), 1)";
410 # the set of 'ready()' commits. defined as the set of open commits, but nothing
411 # that is blacklisted or any of their children.
413 # often used with gerrit, which you can use to submit whole stacks at once:
415 # - jj gerrit send -r 'ready()' --dry-run
416 "ready()" = "open() ~ blacklist()::";
420 # Hide unnecessary bits to make the jj log more concise
421 #"format_short_change_id(id)" = "id.shortest(4)"
422 #"format_short_commit_id(id)" = "id.shortest(4)"
423 "format_timestamp(timestamp)" = "timestamp.ago()";
425 #"format_short_signature(signature)" = "signature.email()"
426 # Both name and email address
427 #"format_short_signature(signature)" = "signature"
428 # Username part of the email address
429 #"format_short_signature(signature)" = "signature.email().local()"
430 "format_short_signature(signature)" = "signature.name()";
434 write-change-id-header = true;
435 # Prevent pushing work in progress or anything explicitly labeled "private";
436 private-commits = "description(glob:'wip:*') | description(glob:'private:*')";
437 # Don't require --allow-new when pushing a new bookmark
446 origin.auto-track-bookmarks = "glob:*";
447 ju1m.auto-track-bookmarks = "glob:*";
452 default-command = "log";
453 diff-editor = ":builtin";
454 # From https://github.com/julienvincent/hunk.nvim
455 #diff-editor = ["nvim", "-c", "DiffEditor $left $right $output"];
456 show-cryptographic-signatures = true;
459 merge-tools.diffconflicts = {
463 "let g:jj_diffconflicts_marker_length=$marker_length"
471 merge-tool-edits-conflict-markers = true;
474 # # via @dubi steinkek in the jj discord
475 # [merge-tools.gitpatch];
477 # edit-args = ["-c", '''
479 # rm -f "$right/JJ-INSTRUCTIONS"
480 # git -C "$left" init -q
481 # git -C "$left" add -A
482 # git -C "$left" commit -q -m baseline --allow-empty
483 # mv "$left/.git" "$right"
484 # git -C "$right" add --intent-to-add --ignore-removal . # tell git to include new files in interactive patch mode
485 # git -C "$right" add -p
486 # git -C "$right" diff-index --quiet --cached HEAD && { echo "No changes done, aborting split."; exit 1; }
487 # git -C "$right" commit -q -m split
488 # git -C "$right" reset -q --hard # undo changes in modified files, remove added files
491 # merge-args = ["-c", "echo gitpatch cannot be used as a diff tool"];
492 # diff-args = ["-c", "echo gitpatch cannot be used as a diff tool"];
495 home.packages = lib.mkIf config.programs.git.enable [
501 xdg.configFile."jjui".source = jujutsu/jjui;
502 programs.bash = lib.mkIf config.programs.git.enable {
505 jer = "jj-edit-review";
508 jj-edit () { local revs=$1; shift; $EDITOR $(jj diff -r "$revs" --name-only "$@"); }
509 jj-edit-review () { local revs=$1; shift; $EDITOR $(jj diff -r "review($revs)" --name-only "$@"); }