-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix hooks dir for Git submodules/worktrees. (#1765)
* Clean up submodule. * Add worktree. * Update tests. * Debug test. * Fix python.
- Loading branch information
Showing
8 changed files
with
159 additions
and
63 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
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
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,35 @@ | ||
use crate::git::GitError; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[derive(Debug, Default, PartialEq)] | ||
pub struct GitWorktree { | ||
/// Absolute path to where the worktree is checked out to within the repository. | ||
pub checkout_dir: PathBuf, | ||
|
||
/// Absolute path to the worktree's `.git` directory, which is housed in the | ||
/// parent's `.git/worktrees`. | ||
pub git_dir: PathBuf, | ||
} | ||
|
||
pub fn extract_gitdir_from_worktree(path: &Path) -> miette::Result<PathBuf> { | ||
let contents = fs::read_to_string(path).map_err(|error| GitError::LoadWorktreeFailed { | ||
path: path.to_owned(), | ||
error: Box::new(error), | ||
})?; | ||
|
||
for line in contents.lines() { | ||
if let Some(suffix) = line.strip_prefix("gitdir:") { | ||
let git_dir = PathBuf::from(suffix.trim()); | ||
|
||
return Ok(git_dir | ||
.canonicalize() | ||
.map_err(|error| GitError::LoadWorktreeFailed { | ||
path: git_dir, | ||
error: Box::new(error), | ||
})?); | ||
} | ||
} | ||
|
||
Err(GitError::ParseWorktreeFailed.into()) | ||
} |
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
Oops, something went wrong.