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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//! Typed failures from revision parsing ([`crate::rev_parse`]).
use thiserror::Error;
/// Failure modes when resolving revision specs, upstream/push refs, paths, and reflogs.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum RevParseError {
/// `branch.<name>.merge` / remote tracking is not configured.
#[error("no upstream configured for branch '{branch}'")]
NoUpstream {
/// Short branch name shown to the user.
branch: String,
},
/// Upstream is configured but the remote-tracking ref is missing.
#[error("upstream branch '{merge}' is not stored as a remote-tracking branch")]
UpstreamNotTracked {
/// Value from `branch.*.merge` (may include `refs/heads/`).
merge: String,
},
/// No remote is configured for `@{push}` resolution.
#[error("branch has no configured push remote")]
NoPushRemote,
/// Remote has push refspecs but none map this branch.
#[error("push refspecs for '{remote}' do not include '{branch}'")]
PushRefspecMissing {
/// Remote name from config.
remote: String,
/// Short branch name.
branch: String,
},
/// `push.default = nothing` and no overriding push refspec applies.
#[error("push.default is nothing; no push destination")]
PushDefaultNothing,
/// `push.default = upstream` but no upstream tracking ref exists.
#[error("branch '{branch}' has no upstream for push.default upstream")]
NoUpstreamForPush {
/// Short branch name.
branch: String,
},
/// `push.default = simple` and upstream differs from the branch’s push ref.
#[error("push.default simple: upstream and push ref differ")]
PushDefaultSimpleMismatch,
/// Default push mode could not find a tracking ref for the branch.
#[error("no push tracking ref for branch '{branch}'")]
NoPushTrackingRef {
/// Short branch name.
branch: String,
},
/// `HEAD` is not on a local branch (detached or unborn).
#[error("HEAD does not point to a branch")]
HeadNotBranch,
/// Named branch does not exist under `refs/heads/`.
#[error("no such branch: '{branch}'")]
NoSuchBranch {
/// Branch name from the spec.
branch: String,
},
/// Could not read `.git/AUTO_MERGE`.
#[error("failed to read AUTO_MERGE: {detail}")]
AutoMergeRead {
/// Underlying I/O or parse detail.
detail: String,
},
/// Spec fragment is not a valid object name after other resolution failed.
#[error("invalid object name '{name}'")]
InvalidObjectName {
/// The unresolved token.
name: String,
},
/// Path in `rev:path` lies outside the work tree.
#[error("'{path}' is outside repository at '{work_tree}'")]
OutsideRepository {
/// Path from the revision spec.
path: String,
/// Canonical work-tree path for the message.
work_tree: String,
},
/// Revision string matches neither an object, ref, nor index path.
#[error("ambiguous revision or path '{spec}'")]
AmbiguousArgument {
/// Full user spec.
spec: String,
},
/// A short hex prefix matches more than one object.
#[error("short object id '{spec}' is ambiguous")]
AmbiguousShortObject {
/// Abbreviated object id from the user spec.
spec: String,
},
/// Reflog selector used but the reflog has no entries.
#[error("log for '{ref_display}' is empty")]
ReflogEmpty {
/// Human-readable ref label.
ref_display: String,
},
/// Reflog index is out of range.
#[error("log for '{ref_display}' only has {available} entries")]
ReflogInsufficientEntries {
/// Human-readable ref label.
ref_display: String,
/// Number of entries available.
available: usize,
},
/// Tree path exists at `HEAD` but not at the requested revision.
#[error("path '{path}' exists on disk, but not in '{revision}'")]
PathOnDiskNotInRevision {
/// Path from the revision spec.
path: String,
/// Revision label that lacks the path.
revision: String,
},
/// Tree path missing; a related path exists under the current prefix.
#[error("path '{candidate}' exists, but not '{path}'")]
PathPrefixExists {
/// Related path that exists where the requested path does not.
candidate: String,
/// Repository-relative or filesystem path related to the failure.
path: String,
/// Optional alternate `rev:path` spelling (no Git-style hint prefix).
alternate_spec: Option<String>,
},
/// Path is absent from the named tree.
#[error("path '{path}' does not exist in '{revision}'")]
PathNotInRevision {
/// Path that is missing from the tree.
path: String,
/// Revision label for the tree that was searched.
revision: String,
},
/// Index path lookup failed with no work-tree match.
#[error("path '{path}' does not exist (neither on disk nor in the index)")]
PathMissingFromWorktreeAndIndex {
/// Path that is missing from both the index and work tree.
path: String,
},
/// Index path exists at another stage.
#[error("path '{path}' is in the index, but not at stage {stage}")]
PathWrongIndexStage {
/// Repository-relative or filesystem path related to the failure.
path: String,
/// Index stage number (0–3) that was expected.
stage: u8,
/// Optional `:stage:path` spelling to try.
alternate_spec: Option<String>,
},
/// Index path mismatch under a path prefix.
#[error("path '{candidate}' is in the index, but not '{path}'")]
PathIndexPrefixMismatch {
/// Related path that exists where the requested path does not.
candidate: String,
/// Repository-relative or filesystem path related to the failure.
path: String,
/// Optional alternate `rev:path` spelling to try.
alternate_spec: Option<String>,
},
/// File exists in the work tree but is not staged.
#[error("path '{path}' exists on disk, but not in the index")]
PathOnDiskNotInIndex {
/// Work-tree path that is not staged in the index.
path: String,
},
/// Path is not present in the index at all.
#[error("path '{path}' does not exist in the index")]
PathNotInIndex {
/// Path that is absent from the index.
path: String,
},
/// Internal describe helper failed to compile its regex.
#[error("internal describe regex")]
InternalDescribeRegex,
/// A change-id prefix matches more than one commit.
#[error("ambiguous change id '{prefix}'")]
AmbiguousChangeId {
/// User-supplied change-id or prefix.
prefix: String,
/// Matching commits in stable order (oid, then change id).
candidates: Vec<AmbiguousChangeIdHint>,
},
}
/// One commit when a change-id lookup is ambiguous.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AmbiguousChangeIdHint {
/// Full commit object id (hex).
pub oid_hex: String,
/// Resolved change id (stored or derived).
pub change_id: String,
/// First line of the commit message.
pub subject: String,
}
/// One candidate line when a short object id is ambiguous.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AmbiguousObjectHint {
/// Full or abbreviated hex object id.
pub oid_hex: String,
/// `None` when the object bytes are corrupt (`[bad object]` in Git).
pub kind: Option<&'static str>,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::error::Error;
fn assert_rev_parse_variant(result: Result<(), Error>, f: impl FnOnce(&RevParseError) -> bool) {
match result {
Err(Error::RevParse(e)) if f(&e) => {}
other => panic!("expected RevParse variant, got {other:?}"),
}
}
#[test]
fn variant_no_upstream() {
let err = Error::from(RevParseError::NoUpstream {
branch: "main".into(),
});
assert!(matches!(
err,
Error::RevParse(RevParseError::NoUpstream { .. })
));
}
#[test]
fn variant_push_default_nothing() {
let err = Error::from(RevParseError::PushDefaultNothing);
assert!(matches!(
err,
Error::RevParse(RevParseError::PushDefaultNothing)
));
}
#[test]
fn variant_ambiguous_argument() {
let err = Error::from(RevParseError::AmbiguousArgument { spec: "foo".into() });
assert!(matches!(
err,
Error::RevParse(RevParseError::AmbiguousArgument { .. })
));
}
#[test]
fn display_is_neutral() {
let msg = RevParseError::NoPushRemote.to_string();
assert!(!msg.contains("fatal:"));
assert!(!msg.contains("hint:"));
}
// Placeholder so `assert_rev_parse_variant` is used when integration tests call it.
#[test]
fn assert_helper_compiles() {
let r: Result<(), Error> = Err(RevParseError::HeadNotBranch.into());
assert_rev_parse_variant(r, |e| matches!(e, RevParseError::HeadNotBranch));
}
}