1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Typed failures for merge, cherry-pick, revert, and sequencer state.
use thiserror::Error;
use crate::objects::ObjectId;
use crate::state::InProgressOperation;
/// Merge, replay, and in-progress operation failures.
///
/// Wrapped by [`Error::Merge`](crate::error::Error::Merge). Stable [`kind_name`](Self::kind_name)
/// slugs match the former umbrella variant names for scripts and the CLI error map.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum MergeError {
/// A merge was requested with fast-forward only, but the histories diverged.
#[error("not possible to fast-forward; refusing to merge")]
NotFastForward,
/// Merge histories share no common ancestor.
#[error("refusing to merge unrelated histories")]
UnrelatedHistories {
/// Our side commit.
ours: ObjectId,
/// Their side commit.
theirs: ObjectId,
},
/// Pick/revert does not replay merge commits without an explicit mainline.
#[error("merge commit {oid}")]
MergeCommit {
/// Object id of the merge commit that cannot be replayed yet.
oid: ObjectId,
},
/// Cherry-pick source is already checked out as `HEAD`.
#[error("commit already at HEAD")]
ReplaySourceAtHead,
/// Sequencer todo lists a command grit does not implement yet.
#[error("unknown sequencer command '{command}'")]
SequencerUnknownCommand {
/// Verb read from `.git/sequencer/todo`.
command: String,
},
/// Continue replay refuses while unmerged index entries remain.
#[error("cannot continue replay: unmerged index entries remain")]
ReplayContinueUnmerged,
/// Continue replay with a dirty index after the step was already committed.
#[error("cannot continue replay: index differs from HEAD after the step was committed")]
ReplayContinueDirtyIndex,
/// Skip replay when the current step was already committed on a moved branch tip.
#[error("nothing to skip: current step already committed; run continue instead")]
ReplaySkipAlreadyCommitted,
/// No cherry-pick or revert sequence is in progress.
#[error("no cherry-pick or revert in progress")]
NoReplayInProgress,
/// No merge is in progress (abort/continue/skip).
#[error("there is no merge in progress")]
NoMergeInProgress,
/// Another paused operation blocks the requested command.
#[error("{} in progress", .0.description())]
OperationInProgress(InProgressOperation),
/// Stage-1/2/3 entries remain when finishing a merge.
#[error("you still have unmerged paths: {}", paths.join(", "))]
ContinueUnmergedPaths {
/// Repository-relative paths still in conflict stages.
paths: Vec<String>,
},
/// Work tree resolved but index still has conflict stages.
#[error("resolved in the work tree but not staged: {}", paths.join(", "))]
ContinueResolvedNotStaged {
/// Repository-relative paths cleared of conflict markers but not staged.
paths: Vec<String>,
},
/// Continue merge message would be empty after cleanup.
#[error("empty commit message")]
ContinueEmptyMessage,
/// A pick/revert sequence is already in progress.
#[error("cherry-pick or revert is already in progress")]
ReplayAlreadyInProgress,
/// `message_override` was set while replaying more than one commit.
#[error("message_override is only valid when replaying a single commit")]
MessageOverrideNotForMultiCommit,
/// Merge or replay state on disk is incomplete for the requested operation.
#[error("merge state incomplete: missing {missing}")]
MergeStateIncomplete {
/// Recorded merge artifact that was expected but absent.
missing: &'static str,
},
/// Pull-specific failure (no upstream, detached `HEAD`, rejected fetch).
#[error(transparent)]
Pull(#[from] crate::porcelain::pull::PullError),
/// A `.git/sequencer/created` journal line could not be parsed.
#[error("invalid sequencer created record: {detail}")]
SequencerCreatedParse {
/// What was wrong with the line.
detail: &'static str,
},
}
impl MergeError {
/// Stable snake_case slug for this failure (matches former [`Error::kind_name`](crate::error::Error::kind_name) values).
#[must_use]
pub fn kind_name(&self) -> &'static str {
match self {
Self::NotFastForward => "not_fast_forward",
Self::UnrelatedHistories { .. } => "unrelated_histories",
Self::MergeCommit { .. } => "merge_commit",
Self::ReplaySourceAtHead => "replay_source_at_head",
Self::SequencerUnknownCommand { .. } => "sequencer_unknown_command",
Self::ReplayContinueUnmerged => "replay_continue_unmerged",
Self::ReplayContinueDirtyIndex => "replay_continue_dirty_index",
Self::ReplaySkipAlreadyCommitted => "replay_skip_already_committed",
Self::NoReplayInProgress => "no_replay_in_progress",
Self::NoMergeInProgress => "no_merge_in_progress",
Self::OperationInProgress(..) => "operation_in_progress",
Self::ContinueUnmergedPaths { .. } => "index_unmerged",
Self::ContinueResolvedNotStaged { .. } => "index_unmerged",
Self::ContinueEmptyMessage => "empty_commit_message",
Self::ReplayAlreadyInProgress => "operation_in_progress",
Self::MessageOverrideNotForMultiCommit => "message",
Self::MergeStateIncomplete { .. } => "message",
Self::SequencerCreatedParse { .. } => "message",
Self::Pull(..) => "pull",
}
}
}