Skip to content

Commit

Permalink
feat: added git-config based scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanholz committed Jun 7, 2024
1 parent 8b4dc7f commit e03225a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-ce"
version = "0.2.1"
version = "0.3.0"
edition = "2021"
license = "0BSD"

Expand Down
66 changes: 48 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ impl fmt::Display for Commit {
fn main() {
let cwd = std::env::current_dir().unwrap();
let cwd = cwd.to_str().unwrap();
let _args = Args::parse();
// let _args = Args::parse();
let repo = match Repository::discover(cwd) {
Ok(repo) => repo,
Err(_err) => {
println!("Not a git repo!");
return;
}
};
let config = repo.config().unwrap();
let scopes = config.multivar("ce.scope", None).unwrap();
let mut parsed_scopes = vec!["".to_string()];
let _ = scopes.for_each(|e| {
if let Some(value) = e.value() {
parsed_scopes.push(value.to_string());
}
});

match has_staged_changes(repo) {
match has_staged_changes(&repo) {
Ok(val) => {
if !val {
println!("No staged changes!");
Expand All @@ -50,7 +58,7 @@ fn main() {
}
Err(err) => panic!("Error: {}", err),
}

//
let selections = &[
"feat", "fix", "chore", "ci", "docs", "style", "refactor", "perf", "test",
];
Expand Down Expand Up @@ -78,23 +86,45 @@ fn main() {
}
Err(_) => return,
};
term.clear_last_lines(2).unwrap();
term.clear_last_lines(1).unwrap();
term.flush().unwrap();

let scope = Input::new()
.with_prompt("Scope")
.default("".to_string())
.interact_text();
match scope {
Ok(scope) => {
if !scope.is_empty() {
commit.commit_type = format!("{}({})", commit.commit_type, scope);
if parsed_scopes.len() == 1 {
let scope = Input::new()
.with_prompt("Scope")
.default("".to_string())
.interact_text();
match scope {
Ok(scope) => {
if !scope.is_empty() {
commit.commit_type = format!("{}({})", commit.commit_type, scope);
}
}
}
Err(_) => return,
};
term.clear_last_lines(1).unwrap();
term.flush().unwrap();
Err(_) => return,
};
term.clear_last_lines(1).unwrap();
term.flush().unwrap();
} else {
let scope = FuzzySelect::new()
.with_prompt("Scope")
.default(0)
.items(&parsed_scopes[..])
.interact_on_opt(&term);
match scope {
Ok(scope) => {
match scope {
Some(scope) => {
commit.commit_type =
format!("{}({})", commit.commit_type, parsed_scopes[scope]);
}
None => return,
};
}
Err(_) => return,
};
term.clear_last_lines(1).unwrap();
term.flush().unwrap();
}

let bc_result = Input::new()
.with_prompt("Breaking changes")
Expand Down Expand Up @@ -127,7 +157,7 @@ fn main() {
let _ = make_commit_shell(&built);
}

fn has_staged_changes(repo: Repository) -> Result<bool, git2::Error> {
fn has_staged_changes(repo: &Repository) -> Result<bool, git2::Error> {
let mut opts = StatusOptions::new();
opts.include_untracked(false)
.renames_head_to_index(true)
Expand Down

0 comments on commit e03225a

Please sign in to comment.