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_inherited, run_git, run_git_with_retry, run_jj, run_jj_with_retry, run_with_retry,
16};
17#[cfg(feature = "jj-parse")]
18pub use types::{
19    Bookmark, ConflictState, ContentState, GitRemote, LogEntry, RemoteStatus, WorkingCopy,
20};
21
22/// Check whether the `jj` binary is available on PATH.
23pub fn jj_available() -> bool {
24    binary_available("jj")
25}
26
27/// Get the jj version string, if available.
28pub fn jj_version() -> Option<String> {
29    binary_version("jj")
30}
31
32/// Check whether the `git` binary is available on PATH.
33pub fn git_available() -> bool {
34    binary_available("git")
35}
36
37/// Get the git version string, if available.
38pub fn git_version() -> Option<String> {
39    binary_version("git")
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn jj_available_returns_bool() {
48        let _ = jj_available();
49    }
50
51    #[test]
52    fn jj_version_returns_option() {
53        let version = jj_version();
54        if jj_available() {
55            let v = version.expect("should have version when jj is available");
56            assert!(v.contains("jj"));
57        } else {
58            assert!(version.is_none());
59        }
60    }
61
62    #[test]
63    fn git_available_returns_bool() {
64        let _ = git_available();
65    }
66
67    #[test]
68    fn git_version_returns_option() {
69        let version = git_version();
70        if git_available() {
71            let v = version.expect("should have version when git is available");
72            assert!(v.contains("git"));
73        } else {
74            assert!(version.is_none());
75        }
76    }
77}