Commit graph

1919 commits

Author SHA1 Message Date
Martin von Zweigbergk
fd02dc2dc2 cli: disallow creating branch with empty name
If the user creates a branch with an empty name, it seems very likely
to be an accident. Let's help them realize that by erroring out.

I didn't add the same checks to `jj branch delete`, since that would
make it hard to delete a branch with an empty name from existing
repos.
2022-11-28 09:17:43 -10:00
Yuya Nishihara
7fbd7b48e5 revset: highlight whole function expression on substitution failed
The error may be caused by arguments passed in to the alias function.
2022-11-29 04:17:12 +09:00
Yuya Nishihara
70292f79b7 revset: implement function alias expansion
Function parameters are processed as local symbols while substituting
alias expression. This isn't as efficient as Mercurial which caches
a tree of fully-expanded function template, but that wouldn't matter in
practice.
2022-11-29 04:17:12 +09:00
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
dependabot[bot]
a7ff8d5ee3 cargo: bump insta from 1.21.1 to 1.21.2
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.21.1 to 1.21.2.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.21.1...1.21.2)

---
updated-dependencies:
- dependency-name: insta
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 05:29:03 -10:00
dependabot[bot]
374d8f1208 cargo: bump rpassword from 7.1.0 to 7.2.0
Bumps [rpassword](https://github.com/conradkleinespel/rpassword) from 7.1.0 to 7.2.0.
- [Release notes](https://github.com/conradkleinespel/rpassword/releases)
- [Commits](https://github.com/conradkleinespel/rpassword/compare/v7.1.0...v7.2.0)

---
updated-dependencies:
- dependency-name: rpassword
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 05:27:12 -10:00
dependabot[bot]
cc9ca6dfdb cargo: bump serde from 1.0.147 to 1.0.148
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.147 to 1.0.148.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.147...v1.0.148)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 05:25:56 -10:00
dependabot[bot]
d90a08676c github: bump dtolnay/rust-toolchain
Bumps [dtolnay/rust-toolchain](https://github.com/dtolnay/rust-toolchain) from 55c7845fad90d0ae8b2e83715cb900e5e861e8cb to e645b0cf01249a964ec099494d38d2da0f0b349f.
- [Release notes](https://github.com/dtolnay/rust-toolchain/releases)
- [Commits](55c7845fad...e645b0cf01)

---
updated-dependencies:
- dependency-name: dtolnay/rust-toolchain
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 05:22:27 -10:00
Yuya Nishihara
e40c041384 revset: merge AmbiguousChange/CommitIdPrefix error into one
Follows up c5ed3e1477. Now change/commit ids are resolved at the same
precedence, which means there are at least three types of ambiguity.
I don't think we would need to discriminate these.
2022-11-28 22:49:07 +09:00
Yuya Nishihara
c5ed3e1477 revset: for short hash, look up both commit and change ids to disambiguate
Because the use of the change id is recommended, any operation should abort
if a valid change id happens to match a commit id. We still try the commit
id lookup first as the change id lookup is more costly.

Ambiguous change/commit id is reported as AmbiguousCommitIdPrefix for now.
Maybe we can merge AmbiguousCommit/ChangeIdPrefix errors into one?

Closes #799
2022-11-28 17:30:53 +09:00
Yuya Nishihara
1fa0392a3e revset: wrap internal symbol resolution result with Option
Option<T> or Result<Option<T>, _> is easier to pattern match than testing
RevsetError::NoSuchRevision.
2022-11-28 17:30:53 +09:00
Ilya Grigoriev
ff42dede05 Polish jj development environment suggestions
Fixups to b33126e1b
2022-11-27 23:43:21 -08:00
Benjamin Saunders
e1152c5846 git: revert change to SSH agent detection
84b924946f switched to requiring both
SSH_AUTH_SOCK and SSH_AGENT_PID for an agent to be used. This doesn't
seem to be a typical situation, so perhaps it was not intended.
2022-11-27 18:53:18 -08:00
Ilya Grigoriev
b33126e1b0 Document suggestions for a jj development environment
I worte up some things I wish I knew when I wrote my first PR.
2022-11-27 12:57:10 -08:00
Yuya Nishihara
8b00a64ab2 cli: load revset aliases from config file
Aliases are loaded at WorkspaceCommandHelper::new() as it's easier to warn
invalid declarations there. Not all commands use revsets, but many do, so
I think it's okay to always pay the loading cost. Parsing the declaration
part (i.e. a symbol) should be fast anyway.

The nested error message isn't super readable, but seems good enough.

Config syntax to bikeshed:
- naming: [revset-alias] vs [revset-aliases] ?
- function alias will need quotes: 'f(x)' = 'x'
2022-11-27 20:12:22 +09:00
Yuya Nishihara
11ee2f22c4 revset: implement simple symbol alias expansion
Since syntactic information like symbol or function name is lost after
parse(), alias substitution is inserted to the middle of the post-parsing
stage, not after the whole RevsetExpression tree is built. This is the main
difference from Mercurial. Mercurial also caches parsed aliases, but I don't
think that would have a measurable impact.
2022-11-27 20:12:22 +09:00
Yuya Nishihara
5df25cd834 revset: add origin field to RevsetParseError to chain alias errors
This could be embedded in a variant of RevsetParseErrorKind, but I want to
keep the enum comparable.
2022-11-27 20:12:22 +09:00
Yuya Nishihara
7632466cc0 revset: add table of symbol aliases and pass around parse functions
The CLI will load aliases from config, insert them one by one, and warn if
declaration part is invalid. That's why RevsetAliasesMap is a public struct
and needs to be instantiated by the caller.
2022-11-27 20:12:22 +09:00
Yuya Nishihara
f0b1221749 revset: pack parsing state into struct
I'll add aliases map, substitution stack (to detect recursion), and locals
(for function aliases) there. Fortunately, we can avoid shared mutables
so a copyable struct should be good.

parse_function_argument_to_string() doesn't need a workspace_ctx, but there
should be no reason to explicitly nullify it either.
2022-11-27 20:12:22 +09:00
Ruben Slabbert
01817e4321 feature: support relative timestamps as a config option 2022-11-27 08:35:17 +10:00
Martin von Zweigbergk
c7fb8709b4 cli: when export to git fails, report failed branches
This adds a warning whenever export to the backing Git repo fails,
whether it's by an explicit `jj git export` or an automatic export. It
might be too spammy to print the message after every failed command in
the colocated case, but let's try it and see.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
a90ef20976 git: on export, delete deleted refs before adding added refs
To reduce conflicts between branches like `main` and `main/sub`, it's
better to first delete refs in git that have been deleted in jj, and
then add/update refs that have been added/updated in jj.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
4a03b94d65 git: on export, skip failed refs instead of failing whole export
Since we now write a (partial) view object of the exported branches to
disk (since 7904474320), we can safely skip exporting some
branches. We already skip conflicted branches. This commit makes us
also skip branches that we fail to write to the backing Git repo,
instead of failing the whole operation (after possibly updating some
Git refs).

I made the `export_refs()` function return the branches that
failed. We should probably make that a struct later and have a
separate field for branches that we skipped due to conflicts.

Closes #493.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
8139a84b22 git: remove stale comment about first export being a no-op
This should have been part of commit 759ddd1e60.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
0dbbd4266f git: update exported_view after updating in Git repo
When skipping branches we fail to update in the backing Git repo, we
must also skip updating the `exported_view` object, so we don't trick
ourselves into thinking the branch was already updated in the Git repo
on the next export.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
a09763f340 git: in export code, work with branch names (not ref names) a bit longer
I'm going to make the export skip branches that we fail to update in
the Git repo. For that, we need to know the branch name while
interacting with the `git2::Repository` object. This little
refactoring prepares for that.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
dbe5615260 git: update mostly incorrect comment in export function
The comment says that we collect the changes to make before making
them, in order to reduce the risk of making some changes before
failing. However, there is nothing in the code that collects changes
that can fail, and it's all doing comparisons in memory, so it should
be very fast. It's been like that since I added it in 47b3abd0f7. We
still need to preserve the structure to avoid mutating `mut_repo`
while iterating over branches, however, so I just updated the comment.
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
6a2f295ae4 git: add test for exporting refs that fail
This adds a test for attempting to export both a branch called `main`
and one called `main/sub` (#493), as well as for exporting a branch
with an empty string as name (reported directly to me by @lkorinth).
2022-11-26 06:05:29 -10:00
Martin von Zweigbergk
2a87815006 cleanup: remove a few unnecessary borrows, as reported by Clippy 2022-11-26 06:05:29 -10:00
Ruben Slabbert
84b924946f feature: add verbose logging for clone/fetch command 2022-11-26 10:58:00 +10:00
dependabot[bot]
f372b04395 cargo: bump clap_complete from 4.0.5 to 4.0.6
Bumps [clap_complete](https://github.com/clap-rs/clap) from 4.0.5 to 4.0.6.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.0.5...clap_complete-v4.0.6)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-25 06:30:32 -10:00
dependabot[bot]
02f91884a8 cargo: bump clap from 4.0.26 to 4.0.27
Bumps [clap](https://github.com/clap-rs/clap) from 4.0.26 to 4.0.27.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.0.26...v4.0.27)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-25 06:10:07 -10:00
dependabot[bot]
68e9559caa cargo: bump pest_derive from 2.4.1 to 2.5.0
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.4.1 to 2.5.0.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.4.1...v2.5.0)

---
updated-dependencies:
- dependency-name: pest_derive
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-25 06:09:37 -10:00
dependabot[bot]
d3f8951da0 cargo: bump clap_mangen from 0.2.4 to 0.2.5
Bumps [clap_mangen](https://github.com/clap-rs/clap) from 0.2.4 to 0.2.5.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_mangen-v0.2.4...clap_mangen-v0.2.5)

---
updated-dependencies:
- dependency-name: clap_mangen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-25 06:08:23 -10:00
Ilya Grigoriev
092aca46c0 Test split commit message
In particular, tests functionality from cf3b6ee2
2022-11-24 20:29:17 -08:00
Ilya Grigoriev
f4b175a86d Make fake-editor and fake-diff-editor error output more verbose 2022-11-24 20:29:17 -08:00
Ilya Grigoriev
2150166652 Add next invocation command to fake-editor
This adds a `next invocation` command to `fake-editor` that ignores the
rest of the script for *this* invocation, but overwrites the script
with whatever follows `next invocation`.

This is useful to test commands that invoke `fake-editor` several times,
especially the `jj split` command.
2022-11-24 20:29:17 -08:00
Ilya Grigoriev
0b528eb587 Fix some cargo +nightly clippy warnings 2022-11-24 20:29:17 -08:00
Yuya Nishihara
ce3397c2cb revset: combine operator parsing steps
I'm thinking of adding alias expansion at this stage, and it would be a bit
tedious to pass around mutable context by function parameter. So let's reduce
the number of the intermediate functions.

This also produces a better error message.
2022-11-25 11:01:15 +09:00
Yuya Nishihara
78e34d2f81 revset: migrate operator parsing to PrattParser 2022-11-25 11:01:15 +09:00
Yuya Nishihara
5491b5581f revset: decouple prefix/infix/postfix range operators
This unblocks the use of PrattParser, which builds an operator map keyed
solely by Rule, not by (Rule, prefix/infix/postfix) pair.
2022-11-25 11:01:15 +09:00
Yuya Nishihara
f8aa6b1deb revset: simplify range expression rule by grouping operators 2022-11-25 11:01:15 +09:00
Martin von Zweigbergk
37e30a4b68 tests: use snapshot testing for operation log
The operation IDs are now predictable in tests.
2022-11-24 16:00:20 -10:00
Martin von Zweigbergk
56f94e5192 cli: record program name in operation metadata as exactly "jj"
This is a simple workaround to make operation IDs predictable (so they
don't include the path to `.../target/debug/jj` or similar). The full
path can probably be useful for troubleshooting, but we can deal with
that later if we see a need for it. It might also be less confusing
for Windows users if it says "jj.exe".
2022-11-24 16:00:20 -10:00
Martin von Zweigbergk
802e21bf25 operations: allow overriding timestamps for tests
It would be nice to be able to use snapshot testing and not have to
parse the output of `jj op log`. This patch lets us do that by
providing a new environment variable and config for overriding the
timestamps. Unlike `operation.hostname` and `operation.username`,
these are only meant for tests.
2022-11-24 16:00:20 -10:00
Martin von Zweigbergk
7c99fa0750 diff_edit: remove unnecessary settings argument
We already get the settings via the ui object here.
2022-11-24 16:00:20 -10:00
Martin von Zweigbergk
c7b90bbe1c cli_util: make resolve_aliases() take only settings, not whole ui 2022-11-24 16:00:20 -10:00
Martin von Zweigbergk
8d7a9e729b tests: set test hostname and username for operation log
This makes the tests more hermetic, even though I don't think the
default values (taken from `whoami`) can break any tests (then we
would have already seen them break). Now we just need to make the
operation log's timestamps predictable and then we can start using
operation IDs in snapshot tests.
2022-11-24 16:00:20 -10:00
dependabot[bot]
90ce94e262 cargo: bump pest from 2.4.1 to 2.5.0
Bumps [pest](https://github.com/pest-parser/pest) from 2.4.1 to 2.5.0.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.4.1...v2.5.0)

---
updated-dependencies:
- dependency-name: pest
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-24 05:34:57 -10:00
dependabot[bot]
20c7514649 cargo: bump serde_json from 1.0.88 to 1.0.89
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.88 to 1.0.89.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.88...v1.0.89)

---
updated-dependencies:
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-23 21:45:41 -10:00