cargo_spec/
git.rs

1#![allow(dead_code, unused_variables)]
2
3use std::path::Path;
4use std::process::Command;
5
6fn get_github_url(filepath: &Path, line: usize) -> Option<String> {
7    let local_repo = get_local_repo_path()?;
8    let github_repo = get_github_repo()?;
9
10    None
11}
12
13/// runs `git remote -v` and checks if it's a github URL
14fn get_github_repo() -> Option<String> {
15    let res = Command::new("git").args(&["remote", "-v"]).output().ok()?;
16
17    if !res.status.success() {
18        return None;
19    }
20
21    let res = String::from_utf8(res.stdout).ok()?;
22
23    None
24}
25
26/// runs `git rev-parse --show-toplevel` to get filepath of root
27pub fn get_local_repo_path() -> Option<String> {
28    let res = Command::new("git")
29        .args(&["rev-parse", "--show-toplevel"])
30        .output()
31        .ok()?;
32
33    if !res.status.success() {
34        return None;
35    }
36
37    let res = String::from_utf8(res.stdout).ok()?;
38
39    Some(res)
40}