multiversx_sc_meta_lib/tools/
git_describe.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::process::{Command, Output};

pub fn git_describe() -> String {
    Command::new("git")
        .args(["describe"])
        .output()
        .map(git_describe_process_output)
        .unwrap_or_default()
}

fn git_describe_process_output(output: Output) -> String {
    if output.status.success() {
        let mut result = String::from_utf8(output.stdout).unwrap_or_default();
        if result.ends_with('\n') {
            // for some reason we get a trailing newline
            let _ = result.pop();
        }
        result
    } else {
        String::new()
    }
}