Skip to content

Commit

Permalink
Ignore "extensions.worktreeconfig" error
Browse files Browse the repository at this point in the history
- Ignore "extensions.worktreeconfig" error until the upstream issue is
  resolved and git2-rs receives the fix.
  - Issue: libgit2/libgit2#6044
- Add unknown status with red color
- Change unpushed status to use blue color
- Split crate imports from external ones in gfold crate

Signed-off-by: Nick Gerace <[email protected]>
  • Loading branch information
nickgerace committed Dec 21, 2022
1 parent d7a3510 commit e0ce979
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ For new changes prior to version 4.0.0, please see [CHANGELOG_PRE_V4](./docs/CHA

## Unreleased

The latest version contains all changes.
<!-- The latest version contains all changes. -->

### Changed

- Add "unknown" status for repositories hitting the "extensions.worktreeconfig" error
- Bump dependencies
- Change "unpushed" color to blue
- Ignore the "extensions.worktreeconfig" error until the corresponding upstream issue is resolved: https://github.com/libgit2/libgit2/issues/6044

## 4.1.2 - 2022-12-20

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions crates/gfold/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! This module contains the CLI entrypoint, CLI options and config generation based on the user's
//! settings and environment.

use crate::config::{ColorMode, Config, DisplayMode};
use crate::error::Error;
use crate::run;
use clap::Parser;
use log::debug;
use std::env;

use crate::config::{ColorMode, Config, DisplayMode};
use crate::error::Error;
use crate::run;

const HELP: &str = "\
More information: https://github.com/nickgerace/gfold
Expand Down
3 changes: 2 additions & 1 deletion crates/gfold/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! This module contains the config specification and functionality for creating a config.

use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::{env, fs, io};

use crate::error::Error;

/// This struct is the actual config type consumed through the codebase. It is boostrapped via its
/// public methods and uses [`EntryConfig`], a private struct, under the hood in order to
/// deserialize empty, non-existent, partial, and complete config files.
Expand Down
9 changes: 5 additions & 4 deletions crates/gfold/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! This module contains the functionality for displaying reports to `stdout`.

use crate::config::{ColorMode, DisplayMode};
use crate::display::color::ColorHarness;
use crate::error::Error;
use crate::report::LabeledReports;
use log::debug;
use log::warn;
use std::io;
use std::path::Path;

use crate::config::{ColorMode, DisplayMode};
use crate::display::color::ColorHarness;
use crate::error::Error;
use crate::report::LabeledReports;

mod color;

const PAD: usize = 2;
Expand Down
10 changes: 6 additions & 4 deletions crates/gfold/src/display/color.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! This module provides a harness for non-trivial displays of information to `stdout`.

use crate::config::ColorMode;
use crate::status::Status;
use std::io::{self, Write};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

use crate::config::ColorMode;
use crate::status::Status;

/// This harness provides methods to write to `stdout`. It maps the internal [`ColorMode`] type to
/// our dependency's [`ColorChoice`] type due to discrepancies in behavior and naming.
pub struct ColorHarness {
Expand All @@ -26,9 +27,10 @@ impl ColorHarness {
pub fn write_status(&self, status: &Status, status_width: usize) -> io::Result<()> {
let mut stdout = StandardStream::stdout(self.color_choice);
stdout.set_color(ColorSpec::new().set_fg(Some(match status {
Status::Bare => Color::Red,
Status::Bare | Status::Unknown => Color::Red,
Status::Clean => Color::Green,
_ => Color::Yellow,
Status::Unpushed => Color::Blue,
Status::Unclean => Color::Yellow,
})))?;
write!(
&mut stdout,
Expand Down
22 changes: 17 additions & 5 deletions crates/gfold/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! This module contains the functionality for generating reports.

use crate::config::DisplayMode;
use crate::error::Error;
use crate::status::Status;
use git2::{ErrorCode, Reference, Remote, Repository, StatusOptions};
use log::{debug, trace};
use log::{debug, error, trace};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::path::Path;

use crate::config::DisplayMode;
use crate::error::Error;
use crate::status::Status;

mod target;

const HEAD: &str = "HEAD";
Expand Down Expand Up @@ -106,14 +107,25 @@ fn generate_report(repo_path: &Path, include_email: bool) -> anyhow::Result<Repo
"attempting to generate report for repository at path: {:?}",
repo_path
);
let repo = Repository::open(repo_path)?;

let repo = match Repository::open(repo_path) {
Ok(repo) => repo,
Err(e) if e.message() == "unsupported extension name extensions.worktreeconfig" => {
error!("skipping error ({e}) until upstream libgit2 issue is resolved: https://github.com/libgit2/libgit2/issues/6044");
let unknown_report = Report::new(repo_path, "unknown", &Status::Unknown, None, None)?;
return Ok(unknown_report);
}
Err(e) => return Err(e.into()),
};

let head = match repo.head() {
Ok(head) => Some(head),
Err(ref e) if e.code() == ErrorCode::UnbornBranch || e.code() == ErrorCode::NotFound => {
None
}
Err(e) => return Err(e.into()),
};

let branch = match &head {
Some(head) => head
.shorthand()
Expand Down
2 changes: 2 additions & 0 deletions crates/gfold/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum Status {
Bare,
Clean,
Unclean,
Unknown,
Unpushed,
}

Expand All @@ -17,6 +18,7 @@ impl Status {
Self::Bare => "bare",
Self::Clean => "clean",
Self::Unclean => "unclean",
Self::Unknown => "unknown",
Self::Unpushed => "unpushed",
}
}
Expand Down

0 comments on commit e0ce979

Please sign in to comment.