Skip to content

Commit 1c019a8

Browse files
authored
Merge branch 'master' into unapply-virtual-branch
2 parents b8b7201 + fd3e846 commit 1c019a8

File tree

12 files changed

+56
-50
lines changed

12 files changed

+56
-50
lines changed

app/src/lib/commit/CommitMessageInput.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@
161161
const value = e.currentTarget.value;
162162
if (e.key === 'Backspace' && value.length === 0) {
163163
e.preventDefault();
164-
titleTextArea?.focus();
164+
if (titleTextArea) {
165+
titleTextArea?.focus();
166+
titleTextArea.selectionStart = titleTextArea.textLength;
167+
}
165168
useAutoHeight(e.currentTarget);
166169
} else if (e.key === 'a' && (e.metaKey || e.ctrlKey) && value.length === 0) {
167170
// select previous textarea on cmd+a if this textarea is empty

app/src/lib/vbranches/virtualBranch.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,21 @@ export class VirtualBranchService {
8585
.map(async (b) => {
8686
const upstreamName = b.upstream?.name;
8787
if (upstreamName) {
88-
const data = await getRemoteBranchData(projectId, upstreamName);
89-
const commits = data.commits;
90-
commits.forEach((uc) => {
91-
const match = b.commits.find((c) => commitCompare(uc, c));
92-
if (match) {
93-
match.relatedTo = uc;
94-
uc.relatedTo = match;
95-
}
96-
});
97-
linkAsParentChildren(commits);
98-
b.upstreamData = data;
88+
try {
89+
const data = await getRemoteBranchData(projectId, upstreamName);
90+
const commits = data.commits;
91+
commits.forEach((uc) => {
92+
const match = b.commits.find((c) => commitCompare(uc, c));
93+
if (match) {
94+
match.relatedTo = uc;
95+
uc.relatedTo = match;
96+
}
97+
});
98+
linkAsParentChildren(commits);
99+
b.upstreamData = data;
100+
} catch (e: any) {
101+
console.log(e);
102+
}
99103
}
100104
return b;
101105
})

crates/gitbutler-core/src/error.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,30 @@ impl AnyhowContextExt for anyhow::Error {
231231
})
232232
}
233233
}
234+
235+
/// A way to mark errors using `[anyhow::Context::context]` for later retrieval, e.g. to know
236+
/// that a certain even happened.
237+
///
238+
/// Note that the display implementation is visible to users in logs, so it's a bit 'special'
239+
/// to signify its marker status.
240+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
241+
pub enum Marker {
242+
/// Invalid state was detected, making the repository invalid for operation.
243+
VerificationFailure,
244+
/// An indicator for a conflict in the project.
245+
///
246+
/// See usages for details on what these conflicts can be.
247+
ProjectConflict,
248+
/// An indicator that a branch conflicted during applying to the workspace.
249+
BranchConflict,
250+
}
251+
252+
impl std::fmt::Display for Marker {
253+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
254+
match self {
255+
Marker::VerificationFailure => f.write_str("<verification-failed>"),
256+
Marker::ProjectConflict => f.write_str("<project-conflict>"),
257+
Marker::BranchConflict => f.write_str("<branch-conflict>"),
258+
}
259+
}
260+
}

crates/gitbutler-core/src/project_repository/repository.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
ssh, users,
1616
virtual_branches::{Branch, BranchId},
1717
};
18-
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
18+
use crate::{error::Marker, git::RepositoryExt};
1919

2020
pub struct Repository {
2121
git_repository: git2::Repository,

crates/gitbutler-core/src/rebase/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::{
2-
git::CommitExt, git::RepositoryExt, project_repository, virtual_branches::errors::Marker,
3-
};
1+
use crate::{error::Marker, git::CommitExt, git::RepositoryExt, project_repository};
42
use anyhow::{anyhow, Context, Result};
53
use bstr::ByteSlice;
64

crates/gitbutler-core/src/virtual_branches/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use super::{
1212
},
1313
target, BranchId, RemoteCommit, VirtualBranchHunk, VirtualBranchesHandle,
1414
};
15-
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
15+
16+
use crate::{git::RepositoryExt, error::Marker};
1617
use crate::{
1718
git::{self, diff},
1819
project_repository::{self, LogUntil},

crates/gitbutler-core/src/virtual_branches/errors.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

crates/gitbutler-core/src/virtual_branches/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use bstr::ByteSlice;
55
use lazy_static::lazy_static;
66

77
use super::VirtualBranchesHandle;
8+
use crate::error::Marker;
89
use crate::git::RepositoryExt;
9-
use crate::virtual_branches::errors::Marker;
1010
use crate::{
1111
git::{self, CommitExt},
1212
project_repository::{self, conflicts, LogUntil},

crates/gitbutler-core/src/virtual_branches/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ pub mod branch;
22
pub use branch::{Branch, BranchId};
33
pub mod target;
44

5-
pub mod errors;
6-
75
mod files;
86
pub use files::*;
97

crates/gitbutler-core/src/virtual_branches/virtual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ use super::{
2727
branch_to_remote_branch, target, RemoteBranch, VirtualBranchesHandle,
2828
};
2929
use crate::error::Code;
30+
use crate::error::Marker;
3031
use crate::git::diff::GitHunk;
3132
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
3233
use crate::git::{CommitBuffer, CommitExt, RepositoryExt};
3334
use crate::rebase::{cherry_rebase, cherry_rebase_group};
3435
use crate::time::now_since_unix_epoch_ms;
3536
use crate::virtual_branches::branch::HunkHash;
36-
use crate::virtual_branches::errors::Marker;
3737
use crate::{
3838
dedup::{dedup, dedup_fmt},
3939
git::{

crates/gitbutler-core/tests/suite/virtual_branches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22
use std::{fs, path, str::FromStr};
33

4-
use gitbutler_core::virtual_branches::errors::Marker;
4+
use gitbutler_core::error::Marker;
55
use gitbutler_core::{
66
git,
77
projects::{self, Project, ProjectId},

crates/gitbutler-watcher/src/handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::PathBuf;
22
use std::sync::Arc;
33

44
use anyhow::{Context, Result};
5+
use gitbutler_core::error::Marker;
56
use gitbutler_core::ops::entry::{OperationKind, SnapshotDetails};
67
use gitbutler_core::projects::ProjectId;
78
use gitbutler_core::synchronize::sync_with_gitbutler;
@@ -101,8 +102,8 @@ impl Handler {
101102
}
102103
Err(err)
103104
if matches!(
104-
err.downcast_ref::<virtual_branches::errors::Marker>(),
105-
Some(virtual_branches::errors::Marker::VerificationFailure)
105+
err.downcast_ref::<Marker>(),
106+
Some(Marker::VerificationFailure)
106107
) =>
107108
{
108109
Ok(())

0 commit comments

Comments
 (0)