-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
549 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
use anyhow::Result; | ||
use crate::{run_piped_command, GitUserConfig}; | ||
use anyhow::{Ok, Result}; | ||
use git2::Repository; | ||
use std::{env, path::Path}; | ||
|
||
/// apply git config to current directory | ||
pub fn apply(_config_id: String) -> Result<()> { | ||
Ok(()) | ||
pub fn apply(config_id: String) -> Result<()> { | ||
// check if it is a git repository | ||
if !is_git_repo(env::current_dir()?) { | ||
return Err(anyhow::anyhow!("The current directory is not a git repository")); | ||
} | ||
|
||
let git_user_configs = GitUserConfig::get_all()?; | ||
let git_user_config = git_user_configs.iter().find(|c| c.config_id == config_id); | ||
match git_user_config { | ||
Some(git_user_config) => { | ||
run_piped_command(vec!["git", "config", "user.name", git_user_config.name.as_str()])?; | ||
run_piped_command(vec!["git", "config", "user.email", git_user_config.email.as_str()])?; | ||
Ok(()) | ||
} | ||
None => Err(anyhow::anyhow!("Config id: {} is not found", config_id)), | ||
} | ||
} | ||
|
||
fn is_git_repo<P: AsRef<Path>>(path: P) -> bool { | ||
Repository::open(path).is_ok() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters