-
Notifications
You must be signed in to change notification settings - Fork 1.2k
cli: warn when sign-on-push skips immutable commits #9963
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ use crate::cli_util::WorkspaceCommandHelper; | |
| use crate::cli_util::WorkspaceCommandTransaction; | ||
| use crate::cli_util::has_tracked_remote_bookmarks; | ||
| use crate::cli_util::has_tracked_remote_tags; | ||
| use crate::cli_util::print_updated_commits; | ||
| use crate::cli_util::short_change_hash; | ||
| use crate::cli_util::short_commit_hash; | ||
| use crate::command_error::CommandError; | ||
|
|
@@ -795,13 +796,13 @@ fn ready_to_push_revset_expression( | |
| .flat_map(|(_, old_head)| old_head.target.added_ids()) | ||
| .cloned() | ||
| .collect_vec(); | ||
| RevsetExpression::commits(old_heads) | ||
| .union(workspace_helper.env().immutable_heads_expression()) | ||
| .range(&RevsetExpression::commits(new_heads)) | ||
| RevsetExpression::commits(old_heads).range(&RevsetExpression::commits(new_heads)) | ||
| } | ||
|
|
||
| /// Signs commits before pushing. | ||
| /// | ||
| /// Warns about commits that need a signature but are immutable. | ||
| /// | ||
| /// Returns the updated list of bookmark names and corresponding | ||
| /// [`BookmarkPushUpdate`]s. | ||
| async fn sign_commits_before_push( | ||
|
|
@@ -812,14 +813,42 @@ async fn sign_commits_before_push( | |
| ) -> Result<GitPushRefTargets, CommandError> { | ||
| let mut sign_settings = tx.settings().sign_settings(); | ||
| sign_settings.behavior = SignBehavior::Own; | ||
| let commit_ids: IndexSet<CommitId> = tx | ||
| .base_workspace_helper() | ||
| .attach_revset_evaluator(commits_to_push) | ||
| // TODO: make filter condition configurable by revset? | ||
| let needs_signing = |commit: &Commit| { | ||
| future::ready(!commit.is_signed() && sign_settings.should_sign(commit.store_commit())) | ||
| }; | ||
|
|
||
| let workspace_helper = tx.base_workspace_helper(); | ||
| let immutable = workspace_helper.env().immutable_expression(); | ||
| let skipped: Vec<Commit> = workspace_helper | ||
| .attach_revset_evaluator(commits_to_push.intersection(&immutable)) | ||
| .evaluate_to_commits()? | ||
| // TODO: make filter condition configurable by revset? | ||
| .try_filter(|commit| { | ||
| future::ready(!commit.is_signed() && sign_settings.should_sign(commit.store_commit())) | ||
| }) | ||
| .try_filter(needs_signing) | ||
| .take(11) | ||
| .try_collect() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you restrict the number of commits to collect? There may be tons of unsigned immutable commits. It seems also better to convert
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Done, I restricted to
I agree, I can do that in another commit in this PR (or a separate PR) if you want |
||
| .await?; | ||
| if !skipped.is_empty() { | ||
| let count = if skipped.len() > 10 { | ||
| "10+".to_owned() | ||
| } else { | ||
| skipped.len().to_string() | ||
| }; | ||
| writeln!( | ||
| ui.warning_default(), | ||
| "Skipped signing {count} immutable commits:" | ||
| )?; | ||
| let mut formatter = ui.stderr_formatter(); | ||
| print_updated_commits( | ||
| formatter.as_mut(), | ||
| &workspace_helper.commit_summary_template(), | ||
| &skipped, | ||
| )?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally I feel like the skipped commits should also be printed, if possible.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| let commit_ids: IndexSet<CommitId> = workspace_helper | ||
| .attach_revset_evaluator(commits_to_push.minus(&immutable)) | ||
| .evaluate_to_commits()? | ||
| .try_filter(needs_signing) | ||
| .map_ok(|commit| commit.id().clone()) | ||
| .try_collect() | ||
| .await?; | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.