mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
fix: Lazy load git repo and only run module if not disabled (#306)
A couple of optimizations are done in this PR. One, we now will check config ahead of time to see if a module is disabled before running any module code. Also, we won't try to discover a git repository unless the module requests access to it.
This commit is contained in:
committed by
Matan Kushner
parent
dc8409333e
commit
9f70ffb7a7
@@ -58,20 +58,3 @@ fn config_5s_duration_10s() -> io::Result<()> {
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_disabled() -> io::Result<()> {
|
||||
let output = common::render_module("cmd_duration")
|
||||
.use_config(toml::toml! {
|
||||
[cmd_duration]
|
||||
disabled = true
|
||||
min_time = 5
|
||||
})
|
||||
.arg("--cmd-duration=10")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::{env, fs, io, process};
|
||||
|
||||
lazy_static! {
|
||||
static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
pub static ref FIXTURES_DIR: PathBuf = MANIFEST_DIR.join("tests/fixtures");
|
||||
static ref EMPTY_CONFIG: PathBuf = MANIFEST_DIR.join("empty_config.toml");
|
||||
}
|
||||
static MANIFEST_DIR: Lazy<&'static Path> = Lazy::new(|| Path::new(env!("CARGO_MANIFEST_DIR")));
|
||||
static EMPTY_CONFIG: Lazy<PathBuf> = Lazy::new(|| MANIFEST_DIR.join("empty_config.toml"));
|
||||
|
||||
/// Render the full starship prompt
|
||||
pub fn render_prompt() -> process::Command {
|
||||
|
||||
@@ -19,20 +19,6 @@ fn char_symbol_configuration() -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabled_module() -> io::Result<()> {
|
||||
let output = common::render_module("package")
|
||||
.use_config(toml::toml! {
|
||||
[package]
|
||||
disabled = true
|
||||
})
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!("", actual);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_newline_configuration() -> io::Result<()> {
|
||||
// Start prompt with newline
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use ansi_term::Color;
|
||||
use git2::Repository;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::process::Command;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use ansi_term::Color;
|
||||
use git2::Repository;
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -2,7 +2,7 @@ use ansi_term::Color;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
|
||||
use crate::common::{self, TestCommand};
|
||||
use crate::common;
|
||||
|
||||
#[test]
|
||||
fn folder_without_go_files() -> io::Result<()> {
|
||||
@@ -138,24 +138,3 @@ fn folder_with_gopkg_lock() -> io::Result<()> {
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn config_disabled() -> io::Result<()> {
|
||||
let dir = common::new_tempdir()?;
|
||||
File::create(dir.path().join("main.go"))?;
|
||||
|
||||
let output = common::render_module("golang")
|
||||
.use_config(toml::toml! {
|
||||
[golang]
|
||||
disabled = true
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir.path())
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -64,19 +64,3 @@ fn config_2_job_3() -> io::Result<()> {
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_disabled() -> io::Result<()> {
|
||||
let output = common::render_module("jobs")
|
||||
.use_config(toml::toml! {
|
||||
[jobs]
|
||||
disabled = true
|
||||
})
|
||||
.arg("--jobs=1")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use ansi_term::Color;
|
||||
use std::fs::{self, File};
|
||||
use std::io;
|
||||
|
||||
use crate::common::{self, TestCommand};
|
||||
use crate::common;
|
||||
|
||||
#[test]
|
||||
fn folder_without_node_files() -> io::Result<()> {
|
||||
@@ -70,24 +70,3 @@ fn folder_with_node_modules() -> io::Result<()> {
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn config_disabled() -> io::Result<()> {
|
||||
let dir = common::new_tempdir()?;
|
||||
File::create(dir.path().join("package.json"))?;
|
||||
|
||||
let output = common::render_module("nodejs")
|
||||
.use_config(toml::toml! {
|
||||
[nodejs]
|
||||
disabled = true
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(dir.path())
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
|
||||
let expected = "";
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user