Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6/7] feat(test): report PrepareWorkingDirectoryError reason #1357

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion git-branchless-invoke/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ version = "0.9.0"
[dependencies]
clap = { workspace = true, features = ["derive"] }
color-eyre = { workspace = true }
cursive_core = { workspace = true }
eyre = { workspace = true }
git-branchless-opts = { workspace = true }
git2 = { workspace = true }
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-invoke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ use std::path::PathBuf;
use std::time::SystemTime;

use clap::{CommandFactory, FromArgMatches, Parser};
use cursive_core::theme::BaseColor;
use cursive_core::utils::markup::StyledString;
use eyre::Context;
use git_branchless_opts::{ColorSetting, GlobalArgs};
use lib::core::config::env_vars::{get_git_exec_path, get_path_to_git};
use lib::core::effects::Effects;
use lib::core::formatting::Glyphs;
use lib::core::formatting::{BaseColor, Glyphs, StyledString};
use lib::git::GitRunInfo;
use lib::git::{Repo, RepoError};
use lib::util::{ExitCode, EyreExitOr};
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ chrono = { workspace = true }
color-eyre = { workspace = true }
concolor = { workspace = true }
console = { workspace = true }
cursive = { workspace = true }
cursive_core = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
futures = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions git-branchless-lib/src/core/check_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use std::ffi::{OsStr, OsString};
use std::fmt::Write;
use std::time::{SystemTime, UNIX_EPOCH};

use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use eyre::Context;
use itertools::Itertools;
use tracing::instrument;

use crate::core::config::get_auto_switch_branches;
use crate::core::formatting::{BaseColor, StyledString};
use crate::git::{
update_index, CategorizedReferenceName, GitRunInfo, MaybeZeroOid, NonZeroOid, ReferenceName,
Repo, Stage, UpdateIndexCommand, WorkingCopySnapshot,
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-lib/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ use std::ffi::OsString;
use std::fmt::Write;
use std::path::PathBuf;

use cursive::theme::{BaseColor, Effect, Style};
use cursive::utils::markup::StyledString;
use eyre::Context;
use tracing::{instrument, warn};

use crate::core::formatting::StyledStringBuilder;
use crate::core::formatting::{BaseColor, Effect, Style, StyledString, StyledStringBuilder};
use crate::git::{ConfigRead, GitRunInfo, GitRunOpts, Repo};

use super::effects::Effects;
Expand Down
1 change: 0 additions & 1 deletion git-branchless-lib/src/core/eventlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ INSERT INTO event_log VALUES (
///
/// Returns: All the events in the database, ordered from oldest to newest.
#[instrument]

pub fn get_events(&self) -> eyre::Result<Vec<Event>> {
let mut stmt = self.conn.prepare(
"
Expand Down
7 changes: 3 additions & 4 deletions git-branchless-lib/src/core/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use std::fmt::Display;

use cursive::theme::{Effect, Style};
use cursive::utils::markup::StyledString;
use cursive::utils::span::Span;
pub use cursive_core::theme::{BaseColor, Color, ColorType, Effect, Style};
pub use cursive_core::utils::markup::StyledString;
pub use cursive_core::utils::span::Span;

/// Pluralize a quantity, as appropriate. Example:
///
Expand Down Expand Up @@ -369,7 +369,6 @@ fn render_style_as_ansi(content: &str, style: Style) -> eyre::Result<String> {
let Style { effects, color } = style;
let output = {
use console::style;
use cursive::theme::{BaseColor, Color, ColorType};
let output = content.to_string();
match color.front {
ColorType::Palette(_) => {
Expand Down
12 changes: 5 additions & 7 deletions git-branchless-lib/src/core/node_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use std::sync::{Arc, Mutex};
use std::time::SystemTime;

use bstr::{ByteSlice, ByteVec};
use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use lazy_static::lazy_static;
use regex::Regex;
use tracing::instrument;
Expand All @@ -18,15 +16,15 @@ use crate::core::config::{
get_commit_descriptors_branches, get_commit_descriptors_differential_revision,
get_commit_descriptors_relative_time,
};
use crate::core::eventlog::{Event, EventCursor, EventReplayer};
use crate::core::formatting::Glyphs;
use crate::core::formatting::{BaseColor, StyledString, StyledStringBuilder};
use crate::core::repo_ext::RepoReferencesSnapshot;
use crate::core::rewrite::find_rewrite_target;
use crate::git::{
CategorizedReferenceName, Commit, NonZeroOid, ReferenceName, Repo, ResolvedReferenceInfo,
};

use super::eventlog::{Event, EventCursor, EventReplayer};
use super::formatting::{Glyphs, StyledStringBuilder};
use super::repo_ext::RepoReferencesSnapshot;
use super::rewrite::find_rewrite_target;

/// An object which can be rendered in the smartlog.
#[derive(Clone, Debug)]
pub enum NodeObject<'repo> {
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-lib/src/git/object.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::path::Path;

use bstr::{BString, ByteSlice};
use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use git2::message_trailers_bytes;
use tracing::instrument;

use crate::core::formatting::{Glyphs, StyledStringBuilder};
use crate::core::formatting::{BaseColor, Glyphs, StyledString, StyledStringBuilder};
use crate::core::node_descriptors::{
render_node_descriptors, CommitMessageDescriptor, CommitOidDescriptor, NodeObject, Redactor,
};
Expand Down
4 changes: 1 addition & 3 deletions git-branchless-lib/src/git/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ use std::{io, time};

use bstr::ByteVec;
use chrono::NaiveDateTime;
use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;
use git2::DiffOptions;
use itertools::Itertools;
use thiserror::Error;
use tracing::{instrument, warn};

use crate::core::effects::{Effects, OperationType};
use crate::core::eventlog::EventTransactionId;
use crate::core::formatting::Glyphs;
use crate::core::formatting::{BaseColor, Glyphs, StyledString};
use crate::git::config::{Config, ConfigRead};
use crate::git::object::Blob;
use crate::git::oid::{make_non_zero_oid, MaybeZeroOid, NonZeroOid};
Expand Down
1 change: 1 addition & 0 deletions git-branchless-lib/src/git/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl std::fmt::Debug for GitRunInfo {
}

/// Options for invoking Git.
#[derive(Clone)]
pub struct GitRunOpts {
/// If set, a non-zero exit code will be treated as an error.
pub treat_git_failure_as_error: bool,
Expand Down
1 change: 0 additions & 1 deletion git-branchless-navigation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repository = "https://github.com/arxanas/git-branchless"
version = "0.9.0"

[dependencies]
cursive = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-opts = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions git-branchless-navigation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use std::ffi::OsString;
use std::fmt::Write;
use std::time::SystemTime;

use cursive::theme::BaseColor;
use cursive::utils::markup::StyledString;

use lib::core::check_out::{check_out_commit, CheckOutCommitOptions, CheckoutTarget};
use lib::core::repo_ext::RepoExt;
use lib::util::{ExitCode, EyreExitOr};
Expand All @@ -32,7 +29,7 @@ use lib::core::config::get_next_interactive;
use lib::core::dag::{sorted_commit_set, CommitSet, Dag};
use lib::core::effects::Effects;
use lib::core::eventlog::{EventLogDb, EventReplayer};
use lib::core::formatting::Pluralize;
use lib::core::formatting::{BaseColor, Pluralize, StyledString};
use lib::core::node_descriptors::{
BranchesDescriptor, CommitMessageDescriptor, CommitOidDescriptor,
DifferentialRevisionDescriptor, NodeDescriptor, Redactor, RelativeTimeDescriptor,
Expand Down
2 changes: 0 additions & 2 deletions git-branchless-record/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ repository = "https://github.com/arxanas/git-branchless"
version = "0.9.0"

[dependencies]
cursive = { version = "0.20.0", default-features = false, features = [ "crossterm-backend", ] }
cursive_buffered_backend = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-invoke = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion git-branchless-smartlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repository = "https://github.com/arxanas/git-branchless"
version = "0.9.0"

[dependencies]
cursive_core = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-invoke = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions git-branchless-smartlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,13 @@ mod render {
use std::cmp::Ordering;
use std::collections::HashSet;

use cursive_core::theme::{BaseColor, Effect};
use cursive_core::utils::markup::StyledString;
use tracing::instrument;

use lib::core::dag::{CommitSet, Dag};
use lib::core::effects::Effects;
use lib::core::formatting::{set_effect, Pluralize};
use lib::core::formatting::{Glyphs, StyledStringBuilder};
use lib::core::formatting::{
set_effect, BaseColor, Effect, Glyphs, Pluralize, StyledString, StyledStringBuilder,
};
use lib::core::node_descriptors::{render_node_descriptors, NodeDescriptor};
use lib::git::{NonZeroOid, Repo};

Expand Down
1 change: 0 additions & 1 deletion git-branchless-submit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version = "0.9.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cursive_core = { workspace = true }
eden_dag = { workspace = true }
eyre = { workspace = true }
git-branchless-invoke = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-submit/src/branch_forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ These remotes are available: {}",
commit_status.local_commit_name.map(|local_commit_name| {
(
commit_oid,
CreateStatus {
CreateStatus::Created {
final_commit_oid: commit_oid,
local_commit_name,
},
Expand Down
35 changes: 30 additions & 5 deletions git-branchless-submit/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::env;
use std::fmt::{Debug, Write};
use std::hash::Hash;

use cursive_core::theme::Effect;
use cursive_core::utils::markup::StyledString;
use indexmap::IndexMap;
use itertools::Itertools;
use lib::core::config::get_main_branch_name;
Expand All @@ -15,6 +13,7 @@ use lib::core::dag::Dag;
use lib::core::effects::Effects;
use lib::core::effects::OperationType;
use lib::core::eventlog::EventLogDb;
use lib::core::formatting::{Effect, StyledString};
use lib::core::repo_ext::RepoExt;
use lib::core::repo_ext::RepoReferencesSnapshot;
use lib::git::CategorizedReferenceName;
Expand Down Expand Up @@ -290,6 +289,25 @@ impl Forge for GithubForge<'_> {
}),
options
)?);
for (commit_oid, create_status) in created_branch.iter() {
match create_status {
CreateStatus::Created { .. } => {}
CreateStatus::Skipped | CreateStatus::Err => {
// FIXME: surface the inner branch forge error somehow?
writeln!(
effects.get_output_stream(),
"Could not create branch for commit: {}",
effects.get_glyphs().render(
self.repo.friendly_describe_commit_from_oid(
effects.get_glyphs(),
*commit_oid
)?,
)?
)?;
return Ok(Err(ExitCode(1)));
}
}
}
created_branches.extend(created_branch.into_iter());
}

Expand All @@ -298,7 +316,7 @@ impl Forge for GithubForge<'_> {
.copied()
.map(|(commit_oid, commit_status)| {
let commit_status = match created_branches.get(&commit_oid) {
Some(CreateStatus {
Some(CreateStatus::Created {
final_commit_oid: _,
local_commit_name,
}) => CommitStatus {
Expand All @@ -309,11 +327,18 @@ impl Forge for GithubForge<'_> {
// Expecting this to be the same as the local branch name (for now):
remote_commit_name: Some(local_commit_name.clone()),
},

Some(
CreateStatus::Skipped | CreateStatus::Err ,
) => {
warn!(?commits_to_create, ?created_branches, ?commit_oid, ?commit_status, "commit failed to be created");
eyre::bail!("BUG: should have been handled in previous call to branch_forge.create: {commit_oid:?} has status {commit_status:?}");
}
None => commit_status.clone(),
};
(commit_oid, commit_status)
Ok((commit_oid, commit_status))
})
.collect();
.try_collect()?;

// Create the pull requests only after creating all the branches because
// we rely on the presence of a branch on each commit in the stack to
Expand Down
Loading