git_management/
extra.rs

1use std::fs::{File};
2use std::io::Write;
3use std::path::{Path};
4use std::process::{exit};
5
6pub fn is_git_repo(repo: &str) -> bool {
7    if Path::new(format_args!("{}{}", repo, "/.git/").to_string().as_str()).exists() {
8        return true
9    } else { return false }
10}
11
12pub fn ignore_f(repo: &str, file: &str) {
13    if is_git_repo(repo) != true {
14        red_ln!("{} is not a git repository", repo);
15        exit(0);
16    }
17    let mut ignore_file = File::open(format_args!("{}{}", repo, "/.gitignore").to_string().as_str()).unwrap();
18    ignore_file.write_fmt(format_args!("{}{}", file, " \n"));
19}
20pub fn ignore_d(repo: &str, dir: &str) {
21    if is_git_repo(repo) != true {
22        red_ln!("{} is not a git repository", repo);
23        exit(0);
24    }
25    let mut ignore_file = File::open(format_args!("{}{}", repo, "/.gitignore").to_string().as_str()).unwrap();
26    ignore_file.write_fmt(format_args!("{}{}", dir, "/\n"));
27}