A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/GitoxideLabs/gitoxide/commit/b985766c9c9c5eb09ea4c4b17be9e380bfdad9b4 below:

is_empty()` to emulate the similar `git2` API · GitoxideLabs/gitoxide@b985766 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+27

-0

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+27

-0

lines changed Original file line number Diff line number Diff line change

@@ -1,3 +1,4 @@

1 +

use std::borrow::Cow;

1 2

use std::path::{Path, PathBuf};

2 3 3 4

use gix_path::realpath::MAX_SYMLINKS;

@@ -108,4 +109,20 @@ impl crate::Repository {

108 109

None => crate::repository::Kind::Bare,

109 110

}

110 111

}

112 + 113 +

/// Returns `Some(true)` if the reference database [is untouched](gix_ref::file::Store::is_pristine()).

114 +

/// This typically indicates that the repository is new and empty.

115 +

/// Return `None` if a defect in the database makes the answer uncertain.

116 +

#[doc(alias = "is_empty", alias = "git2")]

117 +

pub fn is_pristine(&self) -> Option<bool> {

118 +

let name = self

119 +

.config

120 +

.resolved

121 +

.string(crate::config::tree::Init::DEFAULT_BRANCH)

122 +

.unwrap_or(Cow::Borrowed("master".into()));

123 +

let default_branch_ref_name: gix_ref::FullName = format!("refs/heads/{name}")

124 +

.try_into()

125 +

.unwrap_or_else(|_| gix_ref::FullName::try_from("refs/heads/master").expect("known to be valid"));

126 +

self.refs.is_pristine(default_branch_ref_name.as_ref())

127 +

}

111 128

}

Original file line number Diff line number Diff line change

@@ -56,6 +56,16 @@ mod index {

56 56

repo.index_or_load_from_head_or_empty()?.entries().is_empty(),

57 57

"an empty index is created on the fly"

58 58

);

59 +

assert_eq!(

60 +

repo.is_pristine(),

61 +

Some(false),

62 +

"not pristine as it things the initial ref was changed to 'main'"

63 +

);

64 +

assert_eq!(

65 +

repo.refs.is_pristine("refs/heads/main".try_into()?),

66 +

Some(true),

67 +

"This is a quirk of default values in gix and the way we override the initial branch for test fixtures"

68 +

);

59 69

Ok(())

60 70

}

61 71

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4