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
use std::path::PathBuf;
use crate::remote::fetch;
mod error {
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
FindReference(#[from] crate::reference::find::Error),
#[error("A remote reference had a name that wasn't considered valid. Corrupt remote repo or insufficient checks on remote?")]
InvalidRefName(#[from] git_validate::refname::Error),
#[error("Failed to update references to their new position to match their remote locations")]
EditReferences(#[from] crate::reference::edit::Error),
#[error("Failed to read or iterate worktree dir")]
WorktreeListing(#[from] std::io::Error),
#[error("Could not open worktree repository")]
OpenWorktreeRepo(#[from] crate::open::Error),
#[error("Could not find local commit for fast-forward ancestor check")]
FindCommit(#[from] crate::object::find::existing::Error),
}
}
pub use error::Error;
#[derive(Debug, Clone)]
pub struct Outcome {
pub edits: Vec<git_ref::transaction::RefEdit>,
pub updates: Vec<super::Update>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Mode {
NoChangeNeeded,
FastForward,
Forced,
New,
RejectedSourceObjectNotFound {
id: git_hash::ObjectId,
},
RejectedTagUpdate,
RejectedNonFastForward,
RejectedSymbolic,
RejectedCurrentlyCheckedOut {
worktree_dir: PathBuf,
},
}
impl std::fmt::Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Mode::NoChangeNeeded => "up-to-date",
Mode::FastForward => "fast-forward",
Mode::Forced => "forced-update",
Mode::New => "new",
Mode::RejectedSourceObjectNotFound { id } => return write!(f, "rejected ({} not found)", id),
Mode::RejectedTagUpdate => "rejected (would overwrite existing tag)",
Mode::RejectedNonFastForward => "rejected (non-fast-forward)",
Mode::RejectedSymbolic => "rejected (refusing to write symbolic refs)",
Mode::RejectedCurrentlyCheckedOut { worktree_dir } => {
return write!(
f,
"rejected (cannot write into checked-out branch at \"{}\")",
worktree_dir.display()
)
}
}
.fmt(f)
}
}
impl Outcome {
pub fn iter_mapping_updates<'a, 'b>(
&self,
mappings: &'a [fetch::Mapping],
refspecs: &'b [git_refspec::RefSpec],
) -> impl Iterator<
Item = (
&super::Update,
&'a fetch::Mapping,
Option<&'b git_refspec::RefSpec>,
Option<&git_ref::transaction::RefEdit>,
),
> {
self.updates.iter().zip(mappings.iter()).map(move |(update, mapping)| {
(
update,
mapping,
refspecs.get(mapping.spec_index),
update.edit_index.and_then(|idx| self.edits.get(idx)),
)
})
}
}