forked from GitoxideLabs/gitoxide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial sketch of
check_mode
"translation" to Rust
- Loading branch information
1 parent
ee33221
commit 967b9df
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pub(super) mod function { | ||
use anyhow::{bail, Context}; | ||
use gix::bstr::ByteSlice; | ||
use std::ffi::OsString; | ||
use std::io::{BufRead, BufReader}; | ||
use std::process::{Command, Stdio}; | ||
|
||
pub fn check_mode() -> anyhow::Result<()> { | ||
let root = find_root()?; | ||
let mut mismatch = false; | ||
|
||
let cmd = Command::new("git") | ||
.arg("-C") | ||
.arg(root) | ||
.args(["ls-files", "-sz", "--", "*.sh"]) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.context("Can't run `git` to list index")?; | ||
|
||
let stdout = cmd.stdout.expect("should have captured stdout"); | ||
let reader = BufReader::new(stdout); | ||
for record in reader.split(b'\0') { | ||
// FIXME: Use the record, displaying messages and updating `mismatch`. | ||
} | ||
|
||
// FIXME: If `cmd` did not report successful completion, bail. | ||
// FIXME: If `mismatch` (any mismatches), bail. | ||
bail!("not yet implemented"); | ||
} | ||
|
||
fn find_root() -> anyhow::Result<OsString> { | ||
let output = Command::new("git") | ||
.args(["rev-parse", "--show-toplevel"]) | ||
.output() | ||
.context("Can't run `git` to find worktree root")?; | ||
|
||
if !output.status.success() { | ||
bail!("`git` failed to find worktree root"); | ||
} | ||
|
||
let root = output | ||
.stdout | ||
.strip_suffix(b"\n") | ||
.context("Can't parse worktree root")? | ||
.to_os_str()? | ||
.to_owned(); | ||
|
||
Ok(root) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters