Skip to content

Commit acd64fb

Browse files
committed
make gix independent of the git2 feature
That way we can properly test `gix` by itself and get closer to how users would build this crate.
1 parent c4519c7 commit acd64fb

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

.github/workflows/check.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ jobs:
8787
with:
8888
command: clippy
8989
args: --all-features --all --tests -- -D warnings
90+
- name: Clippy with all features (gitoxide only)
91+
uses: actions-rs/cargo@v1
92+
with:
93+
command: clippy
94+
args: --features=gix --all --tests -- -D warnings
9095
- name: Clippy example_project
9196
uses: actions-rs/cargo@v1
9297
with:

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ readme = "README.md"
1010
keywords = ["cargo", "build"]
1111
edition = "2021"
1212

13-
[features]
14-
gitoxide = ["gix", "git2"]
15-
1613
[dependencies]
1714
cargo-lock = { version = "9.0", optional = true, default-features = false }
1815
semver = { version = "1.0", optional = true }

src/gix.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::git_shared::RepoInfo;
2-
use crate::{fmt_option_str, write_variable};
3-
use std::{fs, io, io::Write, path};
2+
use std::{fs, io, path};
43

54
fn get_repo_info(manifest_location: &path::Path) -> Option<RepoInfo> {
65
let repo = gix::discover(manifest_location).ok()?;
@@ -25,20 +24,9 @@ fn get_repo_info(manifest_location: &path::Path) -> Option<RepoInfo> {
2524
Some(repo_info)
2625
}
2726

28-
// TODO: replace git2 with gitoxide once this functionality becomes available in git-repository.
29-
fn is_dirty(manifest_location: &path::Path) -> Option<bool> {
30-
let mut options = git2::StatusOptions::new();
31-
options.include_ignored(false);
32-
options.include_untracked(false);
33-
34-
let dirty = git2::Repository::discover(manifest_location)
35-
.ok()?
36-
.statuses(Some(&mut options))
37-
.ok()?
38-
.iter()
39-
.any(|status| !matches!(status.status(), git2::Status::CURRENT));
40-
41-
Some(dirty)
27+
// TODO: implement this with `gix`
28+
fn is_dirty(_manifest_location: &path::Path) -> Option<bool> {
29+
None
4230
}
4331

4432
pub(crate) fn write_git_version(
@@ -52,7 +40,9 @@ pub(crate) fn write_git_version(
5240
// NOTE: Copy-pasted test from `git2` with adaptation to `gix`
5341

5442
#[cfg(test)]
43+
#[cfg(feature = "git2")]
5544
mod tests {
45+
// TODO: unify tests
5646
#[test]
5747
fn parse_git_repo() {
5848
use std::fs;
@@ -109,7 +99,7 @@ mod tests {
10999
// The commit, the commit-id is something and the repo is not dirty
110100
let repo_info = super::get_repo_info(&project_root).unwrap();
111101
assert!(!repo_info.tag.unwrap().is_empty());
112-
assert_eq!(repo_info.dirty, Some(false));
102+
assert_eq!(repo_info.dirty, None, "Needs implementation");
113103

114104
// Tag the commit, it should be retrieved
115105
repo.tag(
@@ -125,13 +115,13 @@ mod tests {
125115

126116
let repo_info = super::get_repo_info(&project_root).unwrap();
127117
assert_eq!(repo_info.tag, Some(String::from("foobar")));
128-
assert_eq!(repo_info.dirty, Some(false));
118+
assert_eq!(repo_info.dirty, None, "needs implementation");
129119

130120
// Make some dirt
131121
std::fs::write(cruft_file, "now dirty").unwrap();
132122
let repo_info = super::get_repo_info(&project_root).unwrap();
133123
assert_eq!(repo_info.tag, Some(String::from("foobar")));
134-
assert_eq!(repo_info.dirty, Some(true));
124+
assert_eq!(repo_info.dirty, None, "needs implementation");
135125

136126
let branch_short_name = "baz";
137127
let branch_name = "refs/heads/baz";

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ mod dependencies;
213213
mod environment;
214214
#[cfg(feature = "git2")]
215215
mod git;
216-
#[cfg(feature = "gitoxide")]
217-
#[allow(dead_code, unused_imports, unused_variables)]
216+
#[cfg(feature = "gix")]
218217
mod gix;
219218

220-
#[cfg(any(feature = "git2", feature = "gitoxide"))]
219+
#[cfg(any(feature = "git2", feature = "gix"))]
221220
mod git_shared;
222221

223222
#[cfg(feature = "chrono")]
@@ -346,7 +345,7 @@ impl Options {
346345
/// result. `GIT_VERSION` and `GIT_DIRTY` will therefor always be `None` if
347346
/// a CI-platform is detected.
348347
///
349-
#[cfg(any(feature = "git2", feature = "gitoxide"))]
348+
#[cfg(any(feature = "git2", feature = "gix"))]
350349
pub fn set_git(&mut self, enabled: bool) -> &mut Self {
351350
self.git = enabled;
352351
self
@@ -509,7 +508,8 @@ impl Options {
509508
/// `OUR_DIR`.
510509
pub fn write_built_file_with_opts(
511510
options: &Options,
512-
#[cfg(any(feature = "cargo-lock", feature = "git2"))] manifest_location: &path::Path,
511+
#[cfg(any(feature = "cargo-lock", feature = "git2", feature = "gix"))]
512+
manifest_location: &path::Path,
513513
dst: &path::Path,
514514
) -> io::Result<()> {
515515
let mut built_file = fs::File::create(dst)?;
@@ -539,7 +539,7 @@ pub fn write_built_file_with_opts(
539539
{
540540
o!(git, git::write_git_version(manifest_location, &built_file)?);
541541
}
542-
#[cfg(feature = "gitoxide")]
542+
#[cfg(feature = "gix")]
543543
{
544544
o!(
545545
git,
@@ -578,7 +578,7 @@ pub fn write_built_file() -> io::Result<()> {
578578
let dst = path::Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs");
579579
write_built_file_with_opts(
580580
&Options::default(),
581-
#[cfg(any(feature = "cargo-lock", feature = "git2"))]
581+
#[cfg(any(feature = "cargo-lock", feature = "git2", feature = "gix"))]
582582
env::var("CARGO_MANIFEST_DIR").unwrap().as_ref(),
583583
&dst,
584584
)?;

0 commit comments

Comments
 (0)