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

cli: move make_branch_term out of commands/mod.rs #2595

Merged
merged 1 commit into from
Nov 18, 2023
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
8 changes: 7 additions & 1 deletion cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::cli_util::{
parse_string_pattern, user_error, user_error_with_hint, CommandError, CommandHelper,
RevisionArg,
};
use crate::commands::make_branch_term;
use crate::formatter::Formatter;
use crate::ui::Ui;

Expand Down Expand Up @@ -231,6 +230,13 @@ impl fmt::Display for RemoteBranchNamePattern {
}
}

fn make_branch_term(branch_names: &[impl fmt::Display]) -> String {
match branch_names {
[branch_name] => format!("branch {}", branch_name),
branch_names => format!("branches {}", branch_names.iter().join(", ")),
}
}

pub fn cmd_branch(
ui: &mut Ui,
command: &CommandHelper,
Expand Down
10 changes: 8 additions & 2 deletions cli/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Mutex;
use std::time::Instant;
use std::{fs, io};
use std::{fmt, fs, io};

use clap::{ArgGroup, Subcommand};
use itertools::Itertools;
Expand Down Expand Up @@ -33,7 +33,6 @@ use crate::cli_util::{
resolve_multiple_nonempty_revsets, short_change_hash, short_commit_hash, user_error,
user_error_with_hint, CommandError, CommandHelper, RevisionArg, WorkspaceCommandHelper,
};
use crate::commands::make_branch_term;
use crate::progress::Progress;
use crate::ui::Ui;

Expand Down Expand Up @@ -191,6 +190,13 @@ pub struct GitSubmodulePrintGitmodulesArgs {
revisions: RevisionArg,
}

fn make_branch_term(branch_names: &[impl fmt::Display]) -> String {
match branch_names {
[branch_name] => format!("branch {}", branch_name),
branch_names => format!("branches {}", branch_names.iter().join(", ")),
}
}

fn get_git_repo(store: &Store) -> Result<git2::Repository, CommandError> {
match store.backend_impl().downcast_ref::<GitBackend>() {
None => Err(user_error("The repo is not backed by a git repo")),
Expand Down
9 changes: 0 additions & 9 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ mod util;
mod version;
mod workspace;

use std::fmt;
use std::fmt::Debug;

use clap::{Command, CommandFactory, FromArgMatches, Subcommand};
use itertools::Itertools;
use tracing::instrument;

use crate::cli_util::{user_error_with_hint, Args, CommandError, CommandHelper};
Expand Down Expand Up @@ -147,13 +145,6 @@ struct DummyCommandArgs {
_args: Vec<String>,
}

fn make_branch_term(branch_names: &[impl fmt::Display]) -> String {
match branch_names {
[branch_name] => format!("branch {}", branch_name),
branch_names => format!("branches {}", branch_names.iter().join(", ")),
}
}

pub fn default_app() -> Command {
Commands::augment_subcommands(Args::command())
}
Expand Down