Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revset: drop support for HEAD@git symbol resolution #4632

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

* Evaluation error of `revsets.short-prefixes` configuration is now reported.

* The `HEAD@git` symbol no longer resolves to the Git HEAD revision. Use
`git_head()` or `@-` revset expression instead. The `git_head` template
keyword now returns a boolean.

* Help command doesn't work recursively anymore, i.e. `jj workspace help root`
doesn't work anymore.

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn cmd_git_import(
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let mut tx = workspace_command.start_transaction();
// In non-colocated repo, HEAD@git will never be moved internally by jj.
// In non-colocated repo, Git HEAD will never be moved internally by jj.
// That's why cmd_git_export() doesn't export the HEAD ref.
git::import_head(tx.repo_mut())?;
let stats = git::import_refs(tx.repo_mut(), &command.settings().git_settings())?;
Expand Down
16 changes: 5 additions & 11 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use jj_lib::extensions_map::ExtensionsMap;
use jj_lib::fileset;
use jj_lib::fileset::FilesetDiagnostics;
use jj_lib::fileset::FilesetExpression;
use jj_lib::git;
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::id_prefix::IdPrefixIndex;
use jj_lib::matchers::Matcher;
Expand Down Expand Up @@ -703,8 +702,11 @@ fn builtin_commit_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, Comm
|language, _diagnostics, _build_ctx, self_property, function| {
function.expect_no_arguments()?;
let repo = language.repo;
let out_property = self_property.map(|commit| extract_git_head(repo, &commit));
Ok(L::wrap_ref_name_opt(out_property))
let out_property = self_property.map(|commit| {
let target = repo.view().git_head();
target.added_ids().contains(commit.id())
});
Ok(L::wrap_boolean(out_property))
},
);
map.insert(
Expand Down Expand Up @@ -1230,14 +1232,6 @@ fn build_ref_names_index<'a>(
index
}

fn extract_git_head(repo: &dyn Repo, commit: &Commit) -> Option<Rc<RefName>> {
let target = repo.view().git_head();
target
.added_ids()
.contains(commit.id())
.then(|| RefName::remote_only("HEAD", git::REMOTE_NAME_FOR_LOCAL_GIT_REPO, target.clone()))
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum CommitOrChangeId {
Commit(CommitId),
Expand Down
4 changes: 2 additions & 2 deletions cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if(root,
bookmarks,
tags,
working_copies,
git_head,
if(git_head, label("git_head", "git_head()")),
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
if(empty, label("empty", "(empty)")),
Expand All @@ -103,7 +103,7 @@ if(root,
bookmarks,
tags,
working_copies,
git_head,
if(git_head, label("git_head", "git_head()")),
format_short_commit_id(commit_id),
if(conflict, label("conflict", "conflict")),
) ++ "\n",
Expand Down
24 changes: 9 additions & 15 deletions cli/tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,27 +671,21 @@ fn test_log_git_head() {
test_env.jj_cmd_ok(&repo_path, &["new", "-m=initial"]);
std::fs::write(repo_path.join("file"), "foo\n").unwrap();

let template = r#"
separate(", ",
if(git_head, "name: " ++ git_head.name()),
"remote: " ++ git_head.remote(),
) ++ "\n"
"#;
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", template]);
insta::assert_snapshot!(stdout, @r###"
@ remote: <Error: No RefName available>
○ name: HEAD, remote: git
◆ remote: <Error: No RefName available>
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "git_head"]);
insta::assert_snapshot!(stdout, @r#"
@ false
○ true
◆ false
"#);

let stdout = test_env.jj_cmd_success(&repo_path, &["log", "--color=always"]);
insta::assert_snapshot!(stdout, @r###"
insta::assert_snapshot!(stdout, @r#"
@ rlvkpnrz [38;5;[email protected] 2001-02-03 08:05:09 50aaf475
│ initial
○ qpvuntsm [38;5;[email protected] 2001-02-03 08:05:07 HEAD@git 230dd059
○ qpvuntsm [38;5;[email protected] 2001-02-03 08:05:07 git_head() 230dd059
│ (empty) (no description set)
◆ zzzzzzzz root() 00000000
"###);
"#);
}

#[test]
Expand Down
Loading