Skip to content

Commit

Permalink
Replace spawned git process with git2 bindings (holochain#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
c12i authored Sep 9, 2024
1 parent d415a38 commit 01494b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/scaffold/app/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ pub fn setup_git_environment<P: AsRef<Path>>(path: P) -> ScaffoldResult<()> {
Ok(())
}

pub fn is_inside_work_tree<P: AsRef<Path>>(dir: P) -> bool {
match Repository::open(dir) {
Ok(repo) => repo.is_bare(),
Err(_) => false,
}
}

pub fn gitignore() -> &'static str {
include_str!("./gitignore")
}
14 changes: 4 additions & 10 deletions src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::process::{Command, Stdio};
use crate::error::{ScaffoldError, ScaffoldResult};
use crate::file_tree::*;

use super::git::is_inside_work_tree;

pub fn flake_nix(holo_enabled: bool) -> FileTree {
let holo_inputs = holo_enabled
.then_some(
Expand Down Expand Up @@ -74,16 +76,8 @@ pub fn setup_nix_developer_environment(dir: &Path) -> ScaffoldResult<()> {
// This is here to catch the issue from this thread https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836
// If you run Scaffolding inside a Git repository when the `nix flake update` will fail. At some point Nix should report this so we don't need
// to worry about it but for now this helps solve a strange error message.
if let Ok(output) = Command::new("git")
.stdout(Stdio::piped())
.stderr(Stdio::null())
.current_dir(dir)
.args(["rev-parse", "--is-inside-work-tree"])
.output()
{
if output.status.success() && output.stdout == b"true\n" {
return Err(ScaffoldError::NixSetupError("- detected that Scaffolding is running inside an existing Git repository, please choose a different location to scaffold".to_string()));
}
if is_inside_work_tree(dir) {
return Err(ScaffoldError::NixSetupError("- detected that Scaffolding is running inside an existing Git repository, please choose a different location to scaffold".to_string()));
}

println!("Setting up nix development environment...");
Expand Down

0 comments on commit 01494b6

Please sign in to comment.