Skip to main content

vcs_runner/
lib.rs

1mod detect;
2#[cfg(feature = "jj-parse")]
3mod parse;
4mod runner;
5mod types;
6
7pub use detect::{VcsBackend, detect_vcs};
8#[cfg(feature = "jj-parse")]
9pub use parse::{
10    BOOKMARK_TEMPLATE, LOG_TEMPLATE, BookmarkParseResult, LogParseResult, parse_bookmark_output,
11    parse_log_output, parse_remote_list,
12};
13pub use runner::{
14    RunOutput, binary_available, binary_version, is_transient_error, run_cmd, run_cmd_in,
15    run_cmd_in_with_env, run_cmd_inherited, run_git, run_git_with_retry, run_jj,
16    run_jj_with_retry, run_with_retry,
17};
18#[cfg(feature = "jj-parse")]
19pub use types::{
20    Bookmark, ConflictState, ContentState, GitRemote, LogEntry, RemoteStatus, WorkingCopy,
21};
22
23/// Check whether the `jj` binary is available on PATH.
24pub fn jj_available() -> bool {
25    binary_available("jj")
26}
27
28/// Get the jj version string, if available.
29pub fn jj_version() -> Option<String> {
30    binary_version("jj")
31}
32
33/// Check whether the `git` binary is available on PATH.
34pub fn git_available() -> bool {
35    binary_available("git")
36}
37
38/// Get the git version string, if available.
39pub fn git_version() -> Option<String> {
40    binary_version("git")
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn jj_available_returns_bool() {
49        let _ = jj_available();
50    }
51
52    #[test]
53    fn jj_version_returns_option() {
54        let version = jj_version();
55        if jj_available() {
56            let v = version.expect("should have version when jj is available");
57            assert!(v.contains("jj"));
58        } else {
59            assert!(version.is_none());
60        }
61    }
62
63    #[test]
64    fn git_available_returns_bool() {
65        let _ = git_available();
66    }
67
68    #[test]
69    fn git_version_returns_option() {
70        let version = git_version();
71        if git_available() {
72            let v = version.expect("should have version when git is available");
73            assert!(v.contains("git"));
74        } else {
75            assert!(version.is_none());
76        }
77    }
78}