1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
"$schema" = "https://jj-vcs.github.io/jj/prerelease/config-schema.json"

[user]
name = "Alpha Chen"
email = "alpha@kejadlen.dev"

[merge-tools.difft]
program = "difft"
diff-args = ["--color=always", "$left", "$right"]
diff-invocation-mode = "file-by-file"

# https://discord.com/channels/968932220549103686/968932220549103689/1324858422910255155
[merge-tools.gitpatch]
program = "sh"
edit-args = ["-c", '''
  set -eu
  rm -f "$right/JJ-INSTRUCTIONS"
  git -C "$left" init -q
  git -C "$left" add -A
  git -C "$left" commit -q -m baseline --allow-empty
  mv "$left/.git" "$right"
  git -C "$right" add --intent-to-add -A
  git -C "$right" add -p
  git -C "$right" diff-index --quiet --cached HEAD && { echo "No changes done, aborting split."; exit 1; }
  git -C "$right" commit -q -m split
  git -C "$right" restore . # undo changes in modified files
  git -C "$right" reset .   # undo --intent-to-add
  git -C "$right" clean -q -df # remove untracked files
''',
]
merge-args = ["-c", "echo gitpatch cannot be used as a diff tool"]
diff-args = ["-c", "echo gitpatch cannot be used as a diff tool"]

# https://github.com/bryceberger/config/commit/9a3185b6b3a7a81246f84325448e878a5a8281f4
[merge-tools.git-pkgs]
program = "git-pkgs"
diff-args = ["diff-file", "--color=always", "$left", "$right"]
diff-invocation-mode = "file-by-file"
edit-args = []

[merge-tools.zed]
program = "zed"
diff-args = ["--diff", "$left", "$right"]

[merge-tools.d3j]
program = "d3j"
merge-args = ["merge", "$base", "$left", "$right", "-o", "$output"]
merge-conflict-exit-codes = [1]
conflict-marker-style = "git"

[diff.color-words]
max-inline-alternation = 0

[colors]
"diff modified" = "blue"
"diff token" = { underline = false }
log_private = "#a8a8a8"

[signing]
backend = "ssh"
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINCttH8nEfk1uZ2291P4mbCoNcHxnr9iNBlbZckykeZ8"
backends.ssh.program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"

[git]
private-commits = "private() | wip()"
write-change-id-header = true
track-default-bookmark-on-clone = false
fetch = "glob:*"

[templates]
# show diff when committing
draft_commit_description = '''
  separate(
    "\n",
    builtin_draft_commit_description,
    "JJ: ignore-rest",
    diff.git(),
  )
'''
# show an empty diamond when unpushed, a filled diamond-with-dot when private
log_node = '''
  if(self && !current_working_copy && !immutable && !conflict && is_private(self),
    "◈",
    if(self && !current_working_copy && !immutable && !conflict && in_branch(self),
      "◇",
      builtin_log_node
    )
  )
'''

# builtin_log_compact fork: highlight the description of private commits.
# Re-check against the builtin when updating jj.
log = '''
  if(self.root(),
    format_root_commit(self),
    label(
      separate(" ",
        if(self.current_working_copy(), "working_copy"),
        if(self.immutable(), "immutable", "mutable"),
        if(self.conflict(), "conflicted"),
      ),
      concat(
        format_short_commit_header(self) ++ "\n",
        separate(" ",
          if(self.empty(), empty_commit_marker),
          if(self.description(),
            if(is_private(self) && !self.current_working_copy(),
              label("log_private", self.description().first_line()),
              self.description().first_line()
            ),
            label(if(self.empty(), "empty"), description_placeholder),
          ),
        ) ++ "\n",
      ),
    )
  )
'''

[template-aliases]
'in_branch(commit)' = 'commit.contained_in("immutable_heads()..bookmarks()")'
'is_private(commit)' = 'commit.description().starts_with("private:") || commit.description().contains("#private")'

[ui]
default-command = "st"
diff-editor = "gitpatch"
# diff-editor = ",jj-nvimdiff"
diff-formatter = "difft"
pager = ":builtin"

# default will be `glob:` in the future, so switch to it proactively
# and remove this once it actually becomes the default
revsets-use-glob-by-default = true

[ui.movement]
edit = true

[revsets]
# Advance to the newest commit worth pushing rather than the usually-empty
# working copy. Left deliberately unambiguous: above a megamerge this resolves
# to every stack tip at once and jj refuses, which beats picking one by guess.
bookmark-advance-to = 'closest_pushable(@)'
# Default, minus the megamerge bookmark, so advancing lands on the trunk-side
# bookmark under it. Pattern form is empty when `mm` is gone; bare `mm` errors.
bookmark-advance-from = 'heads(::to & bookmarks() & ~bookmarks(exact:"mm"))'
git-sign-on-push = "~signed() & mine()"

[revset-aliases]
'immutable_heads()' = 'builtin_immutable_heads() | heads(~mine())'

'closest_bookmark(to)' = 'heads(::to & bookmarks())'
'closest_merge()' = 'closest_merge(@)'
'closest_merge(to)' = 'heads(::to & merges())'
'closest_pushable(to)' = 'heads(::to & pushable())'

# Commits a remote would actually accept: ours to rewrite, described, carrying
# content, and not stranded above something git.private-commits refuses to push.
# Excluding private descendants is what makes heads(pushable()) land on the
# individual stack tips instead of the megamerge that swallows them.
'pushable()' = 'mutable() & ~description(exact:"") & (~empty() | merges()) & ~(private() | wip())::'

'user(x)' = 'author(x) | committer(x)'

# Paren-free spelling of trunk(): Claude Code's shell parser reads () as a
# subshell even when quoted. Respects per-repo overrides (not all are main@origin).
'trunk' = 'trunk()'

'wip()' = 'description("wip:*")'
'private()' = 'description("private:*") | description("*#private*")'

[aliases]
accuse = ["file", "annotate"]
jj = []
sweep = ["abandon", 'trunk():: & empty() & ~bookmarks(exact:"mm") & mine() & mutable()']
stack = ["util", "exec", "--", "bash", "-c", """
  jj rebase \
    --insert-after 'trunk()' \
    --insert-before 'heads(closest_merge(@) | mm)' \
    --revisions "${1:-mm+::@-}"
""", ""]
pr = ["util", "exec", "--", "bash", "-c", """
  gh pr create --head \
    $(jj log -r 'closest_bookmark(@)' -T 'bookmarks' --no-graph | cut -d ' ' -f 1)
"""]
pull = ["util", "exec", "--", "bash", "-c", """
  jj git fetch
  # Rebase the stacks we own onto the new trunk by moving the roots of our
  # mutable commits, not their branch heads. A megamerge is the only visible
  # head, so a head-based --branch either fails on the immutable commits it
  # merges or, once those are excluded, drops the whole merge and rebases
  # nothing. Rebasing the roots moves each stack and carries its descendants,
  # so the megamerge keeps merging a colleague's immutable branch. Excluding
  # the direct children of non-trunk immutable commits leaves work we have
  # stacked on someone else's branch in place.
  jj rebase \
    --source "roots(trunk()..reachable(@, mutable()))" \
    --onto "trunk()" \
    --simplify-parents
  jj sweep
"""]

# https://github.com/jj-vcs/jj/discussions/3549
# [experimental-advance-branches]
# enabled-branches = ["glob:*"]
# disabled-branches = ["main", "mm"]

[fix.tools.ruff-format]
command = ["ruff", "format", "--stdin-filename", "$path", "-"]
patterns = ["'**/*.py'"]

[fix.tools.ruff-check]
command = ["ruff", "check", "--fix", "--stdin-filename", "$path", "-"]
patterns = ["'**/*.py'"]

[fix.tools.cargo-fmt]
command = ["rustfmt"]
patterns = ["'**/*.rs'"]

[snapshot]
auto-update-stale = true

[remotes.origin]
auto-track-bookmarks = "alpha/*"
fetch-tags = '~*'