Skip to content

Commit

Permalink
feat(cli): Add setup operation to normalize SHA lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Nov 11, 2020
1 parent 3a5714a commit 4945f53
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions assets/en-US/cli.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ type Result<T> = result::Result<T, Box<dyn error::Error>>;
/// 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(),
Expand Down Expand Up @@ -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)?)
}
2 changes: 1 addition & 1 deletion src/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand Down

0 comments on commit 4945f53

Please sign in to comment.