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

323 commits

Author SHA1 Message Date
Yuya Nishihara
01d474563e templater: make branches, tags, git_refs, and git_head return list type
I'm not going to change the default output, but this allows us to highlight
or dim only the @remote component.
2023-10-28 05:29:50 +09:00
Yuya Nishihara
2b33a97c35 templater: add types for local/remote ref names
Both local and remote refs are backed by the same value type since we'll need
some kind of runtime abstraction to represent "branches" keyword (which is a
list of local + remote branches.) It's tedious to implement separate
local/remote/both ref types.

The "unsynced" flag is inverted just because the positive term is slightly
easier to document.
2023-10-28 05:29:50 +09:00
Yuya Nishihara
f7f08cbe77 templater: consistently use double ?? to denote conflicted refs
I think this is just a remainder of 65de7cb0eb "`jj log`: Change conflicted
branches from `br?` to `br??`."
2023-10-28 05:29:50 +09:00
Yuya Nishihara
b30d5bf1c7 templater: allow implicit list-to-boolean cast
I'm going to change "branches" to return a list instead of formatted string,
and I don't think "if(branches, ..)" should be invalidated by that. Perhaps,
a container type like String, Vec<T>, Option<T> can implement the cast.
2023-10-28 05:29:50 +09:00
Yuya Nishihara
38d60002d1 templater: match exhaustively in boolean cast function
I'm going to change list types to be implicitly cast to boolean. Exhaustive
match will prevent future bugs.
2023-10-28 05:29:50 +09:00
Ilya Grigoriev
eeb93cc8be cli change id templates: make "hidden" override "divergent"
See the test changes in `test_undo.rs` for motivation. This matters rarely, but
seems to be better.
2023-10-26 17:58:13 -07:00
Ilya Grigoriev
1733ae22c7 cli templates: include info on divergent change ids in short commit template
Fixes #2411
2023-10-26 17:58:13 -07:00
Ilya Grigoriev
a91b6d9dd9 templates: no-op refactor to reduce duplication and simplify next commit 2023-10-26 17:58:13 -07:00
Ilya Grigoriev
6a128f56ed cli: rebase descendants earlier for jj diffedit and jj restore
Makes sure that, at the point the commit summary for the new commit is written,
the original commit that is being rewritten is already abandoned. Otherwise,
once we show divergent change ids (in a subsequent commit) in the short commit
template, the commits would be shown as divergent.

This also has an effect on whether branches are displayed next to the commit;
the changes in test_resotre_command happen because, now, the branch is properly
propagated to the restored commit before its summary is displayed.
2023-10-26 17:58:13 -07:00
Yuya Nishihara
2874a69faf tests: migrate most tests from test_templater.rs
test_templater_alias(), test_templater_alias_override(), and
test_templater_bad_alias_decl() aren't moved since they also test config loading
and error formatting. The first test in test_templater_parse_error() is left for
the same reason. test_templater_upper_lower() depends on the commit templater.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
957360dc83 tests: use color formatter in core template tests
test_templater_label_function() is migrated as example.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
96f8ca5d54 tests: add minimal template language and test helpers
I don't think many of the tests in test_templater.rs should use "jj log" command
as they check very specific template syntax and function behaviors. Let's move
them to in-module tests. We could add a separate test file, but we would have
to export a couple of templater macros.

test_templater_timestamp_method() is migrated as example.
2023-10-27 05:30:53 +09:00
Yuya Nishihara
b455335983 tests: move test_templater_branches() to test_commit_template.rs
It's not testing the core templater functionality.
2023-10-27 05:30:53 +09:00
Martin von Zweigbergk
a1ef9dc845 merged_tree: propagate backend errors in diff iterator
I want to fix error propagation before I start using async in this
code. This makes the diff iterator propagate errors from reading tree
objects.

Errors include the path and don't stop the iteration. The idea is that
we should be able to show the user an error inline in diff output if
we failed to read a tree. That's going to be especially useful for
backends that can return `BackendError::AccessDenied`. That error
variant doesn't yet exist, but I plan to add it, and use it in
Google's internal backend.
2023-10-26 06:20:56 -07:00
Martin von Zweigbergk
309f1200d6 merge: introduce a type alias for Merge<Option<TreeValue>>
Reasons to introduce this alias:

* Reduces complexity of a type, to silence Clippy warnings in the
  future if we use this type as a type parameter

* The type is used quite frequently, so it makes sense to have a name
  for it

* It's easier to visually scan for the end of the type when you don't
  have to match opening and closing angle brackets
2023-10-26 06:20:56 -07:00
Yuya Nishihara
1bfe5b5b56 cli: add string pattern support to "git push --branch"
Since "jj git fetch --branch" supports glob patterns, users would expect that
"jj git push --branch glob:.." also works.

The error handling bits are copied from "branch" sub commands. We might want to
extract it to a common helper function, but I haven't figured out a reasonable
boundary point yet.
2023-10-26 04:51:17 +09:00
Ilya Grigoriev
fcd02a6091 merge_tools.toml: add VS Code as a default merge tool.
Thanks to @glencbz for noticing that VS Code works fine now as a
merge tool, and thanks to @solson for suggesting
`merge-tool-edits-conflict-markers = true`.
2023-10-25 12:47:51 -07:00
Ilya Grigoriev
5e407982b1 cli templates: include hidden (AKA abandoned) status in short commit template
This is mainly relevant for `jj abandon` and `jj branch list`. #2411
2023-10-24 12:37:26 -07:00
Ilya Grigoriev
94c55d6152 test_abandon_command: add test where a commit is abandoned twice 2023-10-24 12:37:26 -07:00
Yuya Nishihara
a6ac9b46e7 git: simply call fetch() with one or more branch name filters 2023-10-25 03:58:48 +09:00
Yuya Nishihara
560b63544a cli: parse "git fetch --branch" parameter as string pattern
Even though "*" can't be used as a branch name to fetch, it should be better
to explicitly enable glob matching like the other commands.
2023-10-25 03:58:48 +09:00
Yuya Nishihara
09529b63e5 cli: move parse_name_pattern() to cli_util, rename the function
We'll use it in git subcommands.
2023-10-25 03:58:48 +09:00
Martin von Zweigbergk
8157d4ff63 merge: materialize conflicts in executable files like regular files
AFAICT, all callers of `Merge::to_file_merge()` are already well
prepared for working with executable files. It's called from these
places:

* `local_working_copy.rs`: Materialized conflicts are correctly
  updated using `Merge::with_new_file_ids()`.

* `merge_tools/`: Same as above.

* `cmd_cat()`: We already ignore the executable bit when we print
  non-conflicted files, so it makes sense to also ignore it for
  conflicted files.

* `git_diff_part()`: We print all conflicts with mode "100644" (the
  mode for regular files). Maybe it's best to use "100755" for
  conflicts that are unambiguously executable, or maybe it's better to
  use a fake mode like "000000" for all conflicts. Either way, the
  current behavior seems fine.

* `diff_content()`: We use the diff content in various diff
  formats. We could add more detail about the executable bits in some
  of them, but I think the current output is fine. For example,
  instead of our current "Created conflict in my-file", we could say
  "Created conflict in executable file my-file" or "Created conflict
  in ambiguously executable file my-file". That's getting verbose,
  though.

So, I think all we need to do is to make `Merge::to_file_merge()` not
require its inputs to be non-executable.

Closes #1279.
2023-10-24 06:45:45 -07:00
Martin von Zweigbergk
daa23173c5 cli: add a jj debug tree command for printing the tree
I'm about to make conflicts also get materialized in executable
files. We'll lose some of the test coverage in `test_chmod_command.rs`
then, because the those tests rely on the materialized content to
describe the executable bits. So this commit adds a debug command for
printing tree values and uses that in the tests.
2023-10-24 06:45:45 -07:00
Yuya Nishihara
5543f7a11c refs: merge tracking state of remote branches
Otherwise "jj op undo" can't roll back tracking states (whereas "op restore"
can.)
2023-10-24 07:13:58 +09:00
Yuya Nishihara
baef7f1da2 cli: show stats if multiple branches are tracked/untracked
Just like the other branch commands.
2023-10-24 06:46:17 +09:00
Yuya Nishihara
d7f504c98c cli: allow to select branches to track/untrack by string pattern 2023-10-24 06:46:17 +09:00
Yuya Nishihara
d43704c978 cli: do not error out on re-track/untrack, show warning instead
If we add glob support, users will probably want to do something like
'jj branch untrack glob:"*@origin"'. It would be annoying if the command
failed just because one of the remote branches has already been untracked.
Since branch tracking/untracking is idempotent, it's safe to continue in
those cases.
2023-10-24 06:46:17 +09:00
Yuya Nishihara
8dbe12da2a cli: deprecate branch delete/forget --glob option in favor of glob: syntax
I'm not going to remove --glob anytime soon, but I won't add --glob option to
new commands.
2023-10-22 04:07:49 +09:00
Yuya Nishihara
c3f167e6cc cli: add kind:pattern syntax to branch delete/forget commands
The parse rule is lax compared to revset. We could require the pattern to be
quoted, but that would mean glob patterns have to be quoted like 'glob:"foo*"'.
2023-10-22 04:07:49 +09:00
Yuya Nishihara
65c033e5d5 cli: restore fast path to look up local branch by exact pattern
find_forgettable_branches() is unchanged for now. I might want to rewrite it
to not remove untracked remote branches (because untracked branches aren't
associated with the local counterparts.)
2023-10-22 04:07:49 +09:00
Yuya Nishihara
eb2f2783df cli: use StringPattern to find branches to delete/forget
The error message for unmatched patterns is adjusted so that it can be applied
to both exact and glob patterns.
2023-10-22 04:07:49 +09:00
Yuya Nishihara
5707a194d5 str_util: extract StringPattern from revset module
Branch name filtering in CLI will be migrated to this, and I'll probably add
glob:<pattern> in place of --glob option.
2023-10-21 09:55:01 +09:00
Martin von Zweigbergk
8764ad9826 conflicts: make materialization async
We need to let async-ness propagate up from the backend because
`block_on()` doesn't like to be called recursively. The conflict
materialization code is a good place to make async because it doesn't
depends on anything that isn't already async-ready.
2023-10-20 07:38:34 -07:00
Yuya Nishihara
d92be6635c cli: do not list non-tracking remote branches by default
I personally don't mind if "jj branch list" showed all non-tracking branches,
but I agree it would be a mess if ~500 remote branches were listed. So let's
hide them by default as non-tracking branches aren't so interesting.

Closes #1136
2023-10-19 05:23:38 +09:00
Yuya Nishihara
12b879dc8f cli: add "branch list --all" option to include all remote branches
This will be the option to include non-tracking remote branches. We could add
more fine-grained filtering flags, but I think --all is good enough and easier
to remember.

This patch also updates many of the test outputs to include synchronized remote
branches. I think verbose outputs will help catch future bugs.
2023-10-19 05:23:38 +09:00
Martin von Zweigbergk
872265a220 git: add .jj/.gitignore when creating colocated repo
This replaces our existing mechanism of adding `/.jj/` to
`.git/info/exclude` by adding `*` to `.jj/.gitignore`, as suggested by
@ppwwyyxx. That simplifies the code quite a bit, and it avoids the
problem with `.git/info/exclude` not existing (it apparently doesn't
exist when the user uses
https://git-scm.com/docs/git-init#_template_directory).

Closes #2385.
2023-10-18 13:19:22 -07:00
Yuya Nishihara
bcf159c545 templater: take non-tracking remote branches as unrelated to local branch
This corresponds to the change I've made for "jj branch list". Non-tracking
remote branches have no relation to local branches.
2023-10-17 16:42:36 +09:00
Yuya Nishihara
eb78ae9758 cli: show hints for branches rejected to push 2023-10-17 15:06:03 +09:00
Yuya Nishihara
9e0b9e6dc8 refs: error out push if non-tracking remote branches exist
We can provide more actionable error message than "not fast-forwardable". If
the push was fast-forwardable, "jj branch track" should be able to merge the
remote branch without conflicts, so the added step would be minimal.
2023-10-17 15:06:03 +09:00
Yuya Nishihara
089503abfb refs: classify push action based on tracking target
Although this is logically correct, the error message is a bit cryptic. It's
probably better to reject push if non-tracking remote branches exist.

#1136
2023-10-17 15:06:03 +09:00
Yuya Nishihara
30fb7995c2 view: make local/remote branches iterator yield RemoteRef instead of RefTarget
We'll use remote_ref.tracking_target() to classify push action, but not all
callers of local_remote_branches() need tracking_target() instead of target.
2023-10-17 15:06:03 +09:00
Yuya Nishihara
e0965c4533 git: on push, update jj's view of remote branches without using import_refs()
This means that the commits previously pinned by remote branches are no longer
abandoned. I think that's more correct since "push" is the operation to
propagate local view to remote, and uninteresting commits should have been
locally abandoned.
2023-10-17 15:06:03 +09:00
Yuya Nishihara
c8a848d260 git: prohibit push to remote named "git"
Since I'm going to make git::push_branches() update the repo view internally,
it should fail fast if the remote name is reserved. Before, the problem was
detected on git::import_refs().
2023-10-17 15:06:03 +09:00
Yuya Nishihara
58897d79c7 git: extract push function that processes branches instead of git refs
Since pushed remote branches will share the common base targets with locals,
these branches should be marked as tracking. git::push_branches() will handle
that. It looks ugly that the public GitBranchPushTargets type keeps "force"-d
branches as a separate set, but we'll need to rework that anyway when we
implement --force-with-lease behavior. So let's leave it for now.

Some of the git::push_updates() tests have been migrated to the new function.
I left a couple of basic tests for git::push_updates() because push_updates()
will be used to implement a low-level "jj git push-refs" command.
2023-10-17 15:06:03 +09:00
Martin von Zweigbergk
c3b45b6fd1 workspace: make working-copy type customizable
This add support for custom `jj` binaries to use custom working-copy
backends. It works in the same way as with the other backends, i.e. we
write a `.jj/working_copy/type` file when the working copy is
initialized, and then we let that file control which implementation to
use (see previous commit).

I included an example of a (useless) working-copy implementation. I
hope we can figure out a way to test the examples some day.
2023-10-16 22:33:44 -07:00
Martin von Zweigbergk
6bfd618275 workspace: load working copy implementation dynamically
This makes `Workspace::load()` look a new `.jj/working_copy/type` file
in order to load the right working copy implementation, just like
`Repo::load()` picks the right backends based on `.jj/store/type`,
`.jj/op_store/type`, etc. We don't write the file yet, and we don't
have a way of adding alternative working copy implementations, so it
will always be `LocalWorkingCopy` for now.
2023-10-16 22:33:44 -07:00
Martin von Zweigbergk
e1f00d9426 working copy: pass commit instead of tree into check_out()
Our internal working copy implementations at Google will need the
commit so they can walk history backwards until they get to a "public"
commit. They'll then use that to tell build tools and virtual file
systems to present that as a base.

I'm not sure if we'll need to update `reset()` too. It's currently
only used by `jj untrack`, which doesn't change the commit's parent,
so it wouldn't affect any history walks.
2023-10-16 22:33:44 -07:00
Martin von Zweigbergk
7c8a0a18f9 repo: define types for backend initializer functions
`ReadonlyRepo::init()` takes callbacks for initializing each kind of
backend. We called these things like `op_store_initializer`. I found
that confusing because it is not a `OpStoreFactory` (which is for
loading an existing backend). This patch tries to clarify that by
renaming the arguments and adding types for each kind of callback
function.
2023-10-16 22:33:44 -07:00
Yuya Nishihara
940e2438ee cli: pass remote_name to "git clone" helper as argument 2023-10-17 14:13:42 +09:00