Repository: starship/starship
File: src/modules/directory.rs (Rust)

Code before:
    // Attempt repository path contraction (if we are in a git repository)
    // Otherwise use the logical path, automatically contracting
    let repo = if config.truncate_to_repo || config.repo_root_style.is_some() {
        context.get_repo().ok()
    } else {
        None
    };
    let dir_string = if config.truncate_to_repo {
        repo.and_then(|r| r.workdir.as_ref())
            .filter(|&root| root != &home_dir)
            .and_then(|root| contract_repo_path(display_dir, root))
    } else {
        None
    };

    let mut is_truncated = dir_string.is_some();

    // the home directory if required.
    let dir_string = dir_string
        .unwrap_or_else(|| contract_path(display_dir, &home_dir, config.home_symbol).to_string());

    #[cfg(windows)]
    let dir_string = remove_extended_path_prefix(dir_string);

    // Apply path substitutions
    let dir_string = match substitute_path(dir_string.clone(), &config.substitutions) {
        Ok(result) => result,
        Err(err) => {
            log::warn!("{err}");
            dir_string
        }
    };

    // Truncate the dir string to the maximum number of path components
    let dir_string =
        if let Some(truncated) = truncate(&dir_string, config.truncation_length as usize) {
            is_truncated = true;
            truncated
        } else {
            dir_string
        };

    let prefix = if is_truncated {
        // Substitutions could have changed the prefix, so don't allow them and
        // fish-style path contraction together
        if config.fish_style_pwd_dir_length > 0 && config.substitutions_empty() {
            // If user is using fish style path, we need to add the segment first
            let contracted_home_dir = contract_path(display_dir, &home_dir, config.home_symbol);
            to_fish_style(
                config.fish_style_pwd_dir_length as usize,
                &contracted_home_dir,

Review comment (suggestion):
Is it ok to clone here? Otherwise, the value is moved and I can't move it later (if I understood correctly).

Code after:
    // Attempt repository path contraction (if we are in a git repository)
    // Otherwise use the logical path, automatically contracting
    let repo = if config.truncate_to_repo || config.repo_root_style.is_some() {
        context.get_repo().ok()
    } else {
        None
    };
    let dir_string = if config.truncate_to_repo {
        repo.and_then(|r| r.workdir.as_ref())
            .filter(|&root| root != &home_dir)
            .and_then(|root| contract_repo_path(display_dir, root))
    } else {
        None
    };

    let mut is_truncated = dir_string.is_some();

    // the home directory if required.
    let dir_string = dir_string
        .unwrap_or_else(|| contract_path(display_dir, &home_dir, config.home_symbol).to_string());

    #[cfg(windows)]
    let dir_string = remove_extended_path_prefix(dir_string);

    // Apply path substitutions
    let dir_string = match substitute_path(dir_string.clone(), &config.substitutions) {
        Ok(result) => result,
        Err(err) => {
            log::warn!("Invalid regex in directory substitutions: {err}");
            dir_string
        }
    };

    // Truncate the dir string to the maximum number of path components
    let dir_string =
        if let Some(truncated) = truncate(&dir_string, config.truncation_length as usize) {
            is_truncated = true;
            truncated
        } else {
            dir_string
        };

    let prefix = if is_truncated {
        // Substitutions could have changed the prefix, so don't allow them and
        // fish-style path contraction together
        if config.fish_style_pwd_dir_length > 0 && config.substitutions_empty() {
            // If user is using fish style path, we need to add the segment first
            let contracted_home_dir = contract_path(display_dir, &home_dir, config.home_symbol);
            to_fish_style(
                config.fish_style_pwd_dir_length as usize,
                &contracted_home_dir,