ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

636 commits

Author SHA1 Message Date
Scott Taylor
304f6dfc3f workspace: warn if destination doesn't contain path separator
Users may try to run `jj workspace add <name>` without specifying a
path, which results in the workspace being created in the current
directory. This can be confusing, since the workspace contents will also
be snapshotted in the original workspace if it is not sparse. Adding a
warning should reduce confusion in this case.
2024-07-26 18:37:11 -05:00
Scott Taylor
4d8eee3416 test: update workspace path in test case
This test case was creating "workspace1" as a sub-directory of the
default workspace, which seems like a mistake.
2024-07-26 18:37:11 -05:00
Danny Hooper
89f5d16dc0 cli jj fix: add ability to configure multiple tools for different filesets
The high level changes include:
 - Reworking `fix_file_ids()` to loop over multiple candidate tools per file,
   piping file content between them. Only the final file content is written to
   the store, and content is no longer read for changed files that don't match
   any of the configured patterns.
 - New struct `ToolsConfig` to represent the parsed/validated configuration.
 - New function `get_tools_config()` to create a `ToolsConfig` from a `Config`.
 - New tests; the only old behavior that has changed is that we don't require
   `fix.tool-command` if `fix.tools` defines one or more tools. The general
   approach to validating the config is to fail early if anything is weird.

Co-Authored-By: Josh Steadmon <steadmon@google.com>
2024-07-25 13:40:18 -05:00
Yuya Nishihara
d6e97883df cli: port description template to templater
This implements a building block of "signed-off-by line" #1399 and "commit
--verbose" #1946. We'll probably need an easy way to customize the diff part,
but I'm not sure if it can be as simple as a template alias function. User
might want to embed diffs without "JJ: " prefixes?

Perhaps, we can deprecate "ui.default-description", but it's not addressed in
this patch. It could be replaced with "default_description" template alias,
but we might want to configure default per command. Suppose we add a default
"backout_description" template, it would have to be rendered against the
source commit, not the newly-created backout commit.

The template key is named as "draft_commit_description" because it is the
template to generate an editor template. "templates.commit_description_template"
sounds a bit odd.

There's one minor behavior change: the default description is now terminated
by "\n".

Closes #1354
2024-07-25 22:39:00 +09:00
Yuya Nishihara
d328adca7b tests: use insta::assert_snapshot!() to capture description templates 2024-07-25 00:09:39 +09:00
Martin von Zweigbergk
d740f1801b conflicts: use non-legacy MergedTreeId for root commit
This is part of migrating away from legacy trees (with path-level
conflicts). I can't think of any practical impact (we already compare
the tree ids equal).
2024-07-24 14:33:05 +02:00
Yuya Nishihara
bafb357209 git: on abandoning unreachable commits, don't count HEAD ref
This basically reverts 20eb9ecec1 "git: don't abandon HEAD commit when it
loses a branch." I think the new behavior is more consistent because the Git
HEAD is equivalent to @- in jj, so it shouldn't be considered a named ref.

Note that we've made old HEAD branch not considered at 92cfffd843 "git: on
external HEAD move, do not abandon old branch."

#4108
2024-07-24 21:22:26 +09:00
Yuya Nishihara
d7c1b97418 cli: fix "workspace add --at-op" to set up new working copy properly
Because new workspace is created for the new operation forked from the --at-op
operation, the new working copy should be writable.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
b76947c1d6 cli: error out on "init --at-op/--ignore-working-copy" or "clone --at-op"
--at-op should be invalid on repo initialization. "init --ignore-working-copy"
could be supported by using working_copy.reset(), but I don't think it's
worth the effort. If the working directory is empty, --ignore-working-copy
is meaningless, and if the directory is not empty, the user would probably
want to do snapshot at some point.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
c705afa299 cli: exit with CLI error status on "op abandon --at-op"
The command option --at-op isn't supported by "op abandon", so it's rather a
CLI error.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
b9e82f6e06 tests: run workspace-creation commands with --at-op or --ignore-working-copy
I'm going to fix misuse of CommandHelper::for_loaded_repo(), which expects
that the given repo respects the --at-operation option.

I don't think all of the added tests are useful, but "clone
--ignore-working-copy" might be legit as a replacement for bare repos.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
3f05d065b5 cli: uncapitalize op description of "workspace add" and custom command example
That's our convention.
2024-07-24 18:06:09 +09:00
Yuya Nishihara
8fec7500c3 cli: enable fileset by default
I've tested it for months and found no problems.
2024-07-24 10:49:46 +09:00
Stephen Jennings
2a9fdbac52 git: add --allow-private option to push command 2024-07-23 08:45:51 -07:00
Stephen Jennings
03b6d380f5 git: add git.private-commits setting for preventing commits from being pushed
The user can define the setting `git.private-commits` as they desire. For
example:

    git.private-commits = 'description(glob:"wip:*")'

If any commits are in this revset, then the push is aborted.

If a commit would be private but already exists on the remote, then it does
not block pushes, nor do its descendents block pushes unless they are also
contained in `git.private-commits`.

Closes #3376
2024-07-23 08:45:51 -07:00
Benjamin Tan
dade156859 cli: add jj operation show command 2024-07-22 19:16:42 +08:00
Benjamin Tan
a6d82cc344 cli: add jj operation diff command 2024-07-22 19:16:42 +08:00
Yuya Nishihara
ddc601fbf9 str_util: add regex pattern
This patch adds minimal support for the regex pattern. We might have to add
"regex-i:" for completeness, but it can be achieved by "regex:'(?i)..'".
2024-07-22 12:00:52 +09:00
Scott Taylor
14d3bb85bc workspace: use cwd for printing relative path
The user probably would expect the path to be relative to their current
directory rather than the workspace root. For instance, if the user is
in a child directory and runs `jj workspace add ../../name`, then they
might be surprised if we printed "../name" instead of "../../name".
2024-07-21 14:26:18 -05:00
Yuya Nishihara
b762dd55cd cli_util: cache IdPrefixContext by transaction wrapper
This addresses lifetime issue in the next patch, in which the context has to
be borrowed from a known location.
2024-07-20 09:08:59 +09:00
Scott Taylor
d5c526f496 branch: ignore git tracking branches for rename warning
Prevents a warning from being printed when renaming branches in a
colocated repo, since git tracking branches were being considered as
remote tracking branches.
2024-07-18 17:27:19 -05:00
Yuya Nishihara
5649ee4f45 fileset: parse glob characters as identifier
It's inconvenient that we have to quote glob patterns as 'glob:"*.rs"'. Suppose
filesets are usually specified in shell, it's better to allow unquoted strings
if possible. This change also means we'll probably abandon #2101 "make the
parsing of string arguments stricter."

Note that we can no longer introduce ? operator or [] subscript syntax in
filesets.

Closes #4053
2024-07-18 13:49:10 +09:00
Yuya Nishihara
d1912bf016 templater: add commit.diff().<format>() methods
This patch adds TreeDiff template type to host formatting options. The main
reason of this API design is that diff formats have various incompatible
parameters, so a single .diff(files, format[, options..]) method would become
messy pretty quickly. Another reason is that we can probably add custom
summary templating support as diff.files().map(|file| file.path()..).

RepoPathUiConverter is passed to templater explicitly because the one stored
in RevsetParseContext is behind Option<_>.
2024-07-17 18:52:49 +09:00
Vincent Ging Ho Yim
79b326d56b cli_util: add missing word in conflict resolution instructions 2024-07-17 08:10:25 +02:00
Anton Älgmyr
c7eac90200 Enable the new graph nodes by default.
It's been tested in various places now, so this is probably mature
enough to be the default.
2024-07-16 12:54:24 +02:00
Yuya Nishihara
a757fddcf1 revset: parse file() argument as fileset expression
Since fileset and revset languages are syntactically close, we can reparse
revset expression as a fileset. This might sound a bit scary, but helps
eliminate nested quoting like file("~glob:'*.rs'"). One oddity exists in alias
substitution, though. Another possible problem is that we'll need to add fake
operator parsing rules if we introduce incompatibility in fileset, or want to
embed revset expressions in a fileset.

Since "file(x, y)" is equivalent to "file(x|y)", the former will be deprecated.
I'll probably add a mechanism to collect warnings during parsing.
2024-07-16 10:18:57 +09:00
Scott Taylor
91504cae02 obslog: reverse order of predecessors in topo traversal
Currently, when there is a commit with two predecessors, the graph
splits into two branches, and all of the predecessors on the first
branch are printed before all of the predecessors on the second branch.
This causes the graph to grow wider with each squashed commit, since the
second branch must always get indented one level farther each time a
commit is squashed. I have some commits where the graph is indented more
than 10 levels due to squashing more than 10 times, making it very
difficult to read.

Reversing the order and printing the second branch before the first
branch prevents this unnecessary indentation and makes the graph easier
to read. This does not change the order of the edges in the graph (i.e.
the first predecessor is still the first edge and the second predecessor
is still the second edge in the graph).
2024-07-15 20:10:31 -05:00
Scott Taylor
fcf1ca95f2 obslog: update test to show multiple squashes 2024-07-15 20:10:31 -05:00
Yuya Nishihara
692c9960c0 diff: do not emit unified diff for binary files 2024-07-15 14:45:59 +09:00
Yuya Nishihara
e3055e5aaf diff: do not emit unified diff header on absent/empty transitions
---/+++ lines are part of unified diff hunks, not Git diff header.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
07a6a8016c diff: fix typo in Git diff "index old..new" header
Spotted while consolidating "index" line generation. Git appears to use ".." to
separate hashes.
2024-07-15 14:45:59 +09:00
Yuya Nishihara
0912c74ecf diff: add tests for mode changes and absent/empty transitions
This captures a bug of "diff --git" which emits unified diff header without
hunks.
2024-07-15 14:45:59 +09:00
Jonathan Tan
de2940f9b7 --color=debug: combine segments with same labels
This not only makes the output easier to read, but also protects against
implementation detail changes in `write!` when used with a format
string (especially, how many times and with what strings it calls the
underlying writer).
2024-07-11 10:39:05 -07:00
Jonathan Tan
579ba8031b --color=debug: print unlabeled text without markup
This makes the debug output cleaner and makes the subsequent commit
easier to write.
2024-07-11 10:39:05 -07:00
Scott Taylor
b27ff28956 cli: skip formatting instructions if not required
`tx.format_commit_summary()` can be expensive because it needs to build
an IdPrefixContext now, so it's best to avoid formatting instruction
messages unless they are actually required.
2024-07-09 20:24:14 -05:00
Martin von Zweigbergk
fefe07b3c3 diff: consider uncommon words to match only if they have the same count
Patience diff starts by lining up unique elements (e.g. lines) to find
matching segments of the inputs. After that, it refines the
non-matching segments by repeating the process. Histogram expands on
that by not just considering unique elements but by continuing with
elements of count 2, then 3, etc.

Before this commit, when diffing "a b a b b" against "a b a b a b", we
would match the two "a"s in the first input against the first two "a"s
in the second input. After this patch, we ignore the "a"s because
their counts differ, so we try to align the "b"s instead.

I have had this commit lying around since I wrote the histogram diff
implementation in 1e657c5331. I vaguely remember thinking that the
way I had implemented it (without this commit) was a bit weird, but I
wasn't sure if this commit would be an improvement or not. The bug
report from @chooglen today of a case where we behave differently from
Git is enough to make me think that we make this change after all.

#761
2024-07-09 20:35:36 +09:00
Scott Taylor
a983abb594 cli_util: short-prefixes for commit summary in transaction
I've run into change ID prefixes being 4-5 characters instead of the
usual 1-2 characters in commands like `jj duplicate` and `jj split`
fairly often, and it seems like this should resolve that.
2024-07-08 08:23:39 -05:00
Vladimir Petrzhikovskii
802d2f5327 cli: recursively create clone destination path 2024-07-07 23:02:41 +02:00
Benjamin Tan
cd41bc3584 backout: accept multiple revisions to back out
Closes #3339.
2024-07-07 17:58:10 +08:00
Yuya Nishihara
5c649e734d cli: show commit summary at end of "branch set"
For the same reason as the previous commit.

Created and moved stats are printed separately because it's unusual to do both
within one "branch set" invocation.
2024-07-06 10:12:43 +09:00
Yuya Nishihara
a5095c1da6 cli: show commit summary at end of "branch create"
For the same reason as cdc0cc3601. This will help notice problems like wrong
target revision.

The warning for multiple branches is reorganized as a hint for "-r" option,
which I think is the main purpose of this warning. Unlike "squash", we don't
check if an argument can be parsed as a revset because branch name is usually
a valid symbol expression.
2024-07-06 10:12:43 +09:00
Yuya Nishihara
e02c576282 cli: print branch update stats within transaction
It's weird that export failure was emitted before the branch changes. Spotted
while adding "Created N branches" stats.
2024-07-06 10:12:43 +09:00
Benjamin Tan
d2eb4d9b56 backout: include backed out commit's subject in new commit 2024-07-05 17:11:37 +08:00
Benjamin Tan
456356aacb backout: add initial tests 2024-07-05 17:11:37 +08:00
Yuya Nishihara
44a39017f0 diff: highlight word-level changes in git diffs
The output looks somewhat similar to color-words diffs. Unified diffs are
verbose, but are easier to follow if adjacent lines are added/removed + modified
for example.

Word-level diffing is forcibly enabled. We can also add a config knob (or
!color condition) to turn it off to save CPU time.

I originally considered disabling highlights in block insertion/deletion, but
that wasn't always great. This can be addressed separately as it also applies
to color-words diffs. #3958
2024-07-05 16:07:12 +09:00
Scott Taylor
54877e1f79 workspace: abandon discardable working copy on forget
Forgetting a workspace removes its working-copy commit, so it makes
sense for it to be abandoned if it is discardable just like editing a
new commit will cause the old commit to be abandoned if it is
discardable.
2024-07-04 19:37:56 -05:00
Scott Taylor
fa398ab405 cli: fix typo in jj workspace help 2024-07-04 19:37:56 -05:00
Yuya Nishihara
1cae93ce27 cli: rephrase hint for updating just one branch by "branch move"
Suggested by Ilya.
2024-07-05 07:58:18 +09:00
Yuya Nishihara
cdc0cc3601 cli: show commit summary at end of "branch move"
It's nice to see the result of "branch move", "create", etc., and this is more
important in "branch move" because the source branches can be specified in an
abstracted way. I originally considered printing a list of affected branches,
but it looked rather verbose. Since the destination revision is unique, we can
use commit_summary template instead.

This patch also removes a warning about multiple branches because the branch
names are included in the commit summary. I think the hint message is good
enough to signal possible mistake.
2024-07-05 07:58:18 +09:00
Benjamin Tan
0c0e001262 git init: add revset alias for trunk() when intializing with existing git repository 2024-07-04 23:04:19 +08:00