git_management/
extra.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fs::{File};
use std::io::Write;
use std::path::{Path};
use std::process::{exit};

pub fn is_git_repo(repo: &str) -> bool {
    if Path::new(format_args!("{}{}", repo, "/.git/").to_string().as_str()).exists() {
        return true
    } else { return false }
}

pub fn ignore_f(repo: &str, file: &str) {
    if is_git_repo(repo) != true {
        red_ln!("{} is not a git repository", repo);
        exit(0);
    }
    let mut ignore_file = File::open(format_args!("{}{}", repo, "/.gitignore").to_string().as_str()).unwrap();
    ignore_file.write_fmt(format_args!("{}{}", file, " \n"));
}
pub fn ignore_d(repo: &str, dir: &str) {
    if is_git_repo(repo) != true {
        red_ln!("{} is not a git repository", repo);
        exit(0);
    }
    let mut ignore_file = File::open(format_args!("{}{}", repo, "/.gitignore").to_string().as_str()).unwrap();
    ignore_file.write_fmt(format_args!("{}{}", dir, "/\n"));
}