We should find another way that plays well with configuration. Probably it needs another version of this function with more parameters.
Unified · Split
| @@ -1,26 +1,22 @@ | |||
| 1 | use std::{ | 1 | use std::{ffi::OsStr, path::Path}; |
| 2 | ffi::OsStr, | ||
| 3 | path::{Path, PathBuf}, | ||
| 4 | }; | ||
| 5 | 2 | ||
| 6 | /// Returns true if the given `git_dir` seems to be a bare repository. | 3 | /// Returns true if the given `git_dir` seems to be a bare repository. |
| 7 | /// | 4 | /// |
| 8 | /// Please note that repositories without any file in their work tree will also appear bare. | 5 | /// Please note that repositories without an index generally _look_ bare, even though they might also be uninitialized. |
| 9 | pub fn bare(git_dir_candidate: impl AsRef<Path>) -> bool { | 6 | pub fn bare(git_dir_candidate: impl AsRef<Path>) -> bool { |
| 10 | let git_dir = git_dir_candidate.as_ref(); | 7 | let git_dir = git_dir_candidate.as_ref(); |
| 11 | !(git_dir.join("index").exists() || (git_dir.file_name() == Some(OsStr::new(".git")) && git_dir.is_file())) | 8 | !(git_dir.join("index").exists() || (git_dir.file_name() == Some(OsStr::new(".git")) && git_dir.is_file())) |
| 12 | } | 9 | } |
| 13 | 10 | ||
| 14 | /// What constitutes a valid git repository, and what's yet to be implemented, returning the guessed repository kind | 11 | /// What constitutes a valid git repository, returning the guessed repository kind |
| 15 | /// purely based on the presence of files. Note that the git-config ultimately decides what's bare. | 12 | /// purely based on the presence of files. Note that the git-config ultimately decides what's bare. |
| 16 | /// | 13 | /// |
| 17 | /// * [ ] git files | 14 | /// * [ ] git files |
| 18 | /// * [x] a valid head | 15 | /// * [x] a valid head |
| 19 | /// * [ ] git common directory | 16 | /// * [ ] git common directory |
| 20 | /// * [ ] respect GIT_COMMON_DIR | ||
| 21 | /// * [x] an objects directory | 17 | /// * [x] an objects directory |
| 22 | /// * [x] respect GIT_OBJECT_DIRECTORY | ||
| 23 | /// * [x] a refs directory | 18 | /// * [x] a refs directory |
| 19 | // TODO: allow configuring common dirs at least | ||
| 24 | pub fn git(git_dir: impl AsRef<Path>) -> Result<crate::repository::Kind, crate::is_git::Error> { | 20 | pub fn git(git_dir: impl AsRef<Path>) -> Result<crate::repository::Kind, crate::is_git::Error> { |
| 25 | let dot_git = git_dir.as_ref(); | 21 | let dot_git = git_dir.as_ref(); |
| 26 | 22 | ||
| @@ -43,9 +39,7 @@ pub fn git(git_dir: impl AsRef<Path>) -> Result<crate::repository::Kind, crate:: · 16 unmodified lines | |||
| 43 | } | 39 | } |
| 44 | 40 | ||
| 45 | { | 41 | { |
| 46 | let objects_path = std::env::var("GIT_OBJECT_DIRECTORY") | 42 | let objects_path = dot_git.join("objects"); |
| 47 | .map(PathBuf::from) | ||
| 48 | .unwrap_or_else(|_| dot_git.join("objects")); | ||
| 49 | if !objects_path.is_dir() { | 43 | if !objects_path.is_dir() { |
| 50 | return Err(crate::is_git::Error::MissingObjectsDirectory { missing: objects_path }); | 44 | return Err(crate::is_git::Error::MissingObjectsDirectory { missing: objects_path }); |
| 51 | } | 45 | } |