From 4945f534cdece4ed504af5570b5f0ad8dbb500f8 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 11 Nov 2020 14:05:28 +0300 Subject: [PATCH] feat(cli): Add setup operation to normalize SHA lengths --- assets/en-US/cli.ftl | 3 +++ src/setup/mod.rs | 15 +++++++++++++-- src/status/mod.rs | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/assets/en-US/cli.ftl b/assets/en-US/cli.ftl index a0d781b..8b23e48 100644 --- a/assets/en-US/cli.ftl +++ b/assets/en-US/cli.ftl @@ -109,6 +109,9 @@ setup-gitignore-committing = setup-gitignore-fresh = Existing .gitignore file is up to date +setup-short-shas = + Set default length of short SHA hashes in repository + status-header = Scanning project status diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 511f729..df93cab 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -11,11 +11,15 @@ type Result = result::Result>; /// Setup Fontship for use on a new Font project pub fn run() -> Result<()> { crate::header("setup-header"); - let path = CONFIG.get_string("path")?; + let path = &CONFIG.get_string("path")?; let metadata = fs::metadata(&path)?; match metadata.is_dir() { true => match Repository::open(path) { - Ok(repo) => regen_gitignore(repo), + Ok(repo) => { + regen_gitignore(repo)?; + configure_short_shas(Repository::open(path)?)?; + Ok(()) + } Err(_error) => Err(Box::new(io::Error::new( io::ErrorKind::InvalidInput, LocalText::new("setup-error-not-git").fmt(), @@ -54,3 +58,10 @@ fn regen_gitignore(repo: Repository) -> Result<()> { } } } + +fn configure_short_shas(repo: Repository) -> Result<()> { + let text = LocalText::new("setup-short-shas").fmt(); + eprintln!("{} {}", "┠┄".cyan(), text); + let mut conf = repo.config()?; + Ok(conf.set_i32("core.abbrev", 7)?) +} diff --git a/src/status/mod.rs b/src/status/mod.rs index edfd391..e984647 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -225,7 +225,7 @@ pub fn get_git_version() -> String { let desc = match repo.describe(&opts) { Ok(a) => { let mut fmt = DescribeFormatOptions::new(); - fmt.abbreviated_size(7).always_use_long_format(true); + fmt.always_use_long_format(true); a.format(Some(&fmt)).unwrap() } Err(_) => {