grit_lib/porcelain/
commit_error.rs1use thiserror::Error;
4
5use crate::config::ident_resolve::IdentityError;
6use crate::error::ApplyError;
7use crate::ident::CommitIdentityError;
8use crate::porcelain::hunk_select::HunkSelectError;
9
10#[derive(Debug, Error)]
15#[non_exhaustive]
16pub enum CommitError {
17 #[error("empty commit message")]
19 EmptyCommitMessage,
20
21 #[error("you must specify path(s)")]
24 CommitPathsRequired,
25
26 #[error("cannot do a partial commit during a merge")]
28 PartialCommitDuringMerge,
29
30 #[error("cannot do a partial commit during a cherry-pick or revert")]
32 PartialCommitDuringReplay,
33
34 #[error("nothing to commit")]
36 NothingToCommit,
37
38 #[error("nothing staged to commit")]
40 NothingStagedToCommit {
41 unstaged: usize,
43 untracked: usize,
45 },
46
47 #[error("cannot amend: no commits on this branch yet")]
49 AmendUnborn,
50
51 #[error(transparent)]
53 InvalidIdentity(#[from] CommitIdentityError),
54
55 #[error(transparent)]
57 Identity(#[from] IdentityError),
58
59 #[error("commit signing failed")]
61 Signing {
62 program: String,
64 status: Option<i32>,
66 stderr: Box<String>,
68 },
69
70 #[error(transparent)]
72 HunkSelect(#[from] HunkSelectError),
73
74 #[error(transparent)]
76 PatchApply(#[from] ApplyError),
77
78 #[error("invalid commit message")]
80 InvalidCommitMessage,
81
82 #[error(transparent)]
84 ChangeId(#[from] crate::change_id::ChangeIdError),
85}
86
87impl CommitError {
88 #[must_use]
90 pub fn kind_name(&self) -> &'static str {
91 match self {
92 Self::EmptyCommitMessage => "empty_commit_message",
93 Self::CommitPathsRequired => "commit_paths_required",
94 Self::PartialCommitDuringMerge => "partial_commit_during_merge",
95 Self::PartialCommitDuringReplay => "partial_commit_during_replay",
96 Self::NothingToCommit => "nothing_to_commit",
97 Self::NothingStagedToCommit { .. } => "nothing_staged_to_commit",
98 Self::AmendUnborn => "amend_unborn",
99 Self::InvalidIdentity(..) => "invalid_identity",
100 Self::Identity(..) => "identity",
101 Self::Signing { .. } => "signing",
102 Self::HunkSelect(..) => "hunk_selection",
103 Self::PatchApply(..) => "apply",
104 Self::InvalidCommitMessage => "empty_commit_message",
105 Self::ChangeId(..) => "message",
106 }
107 }
108}
109
110impl CommitError {
111 #[must_use]
113 pub fn signing_from_message(message: String) -> Self {
114 Self::Signing {
115 program: String::new(),
116 status: None,
117 stderr: Box::new(message),
118 }
119 }
120
121 #[must_use]
123 pub fn signing_failure(
124 program: impl Into<String>,
125 status: Option<i32>,
126 stderr: impl Into<String>,
127 ) -> Self {
128 Self::Signing {
129 program: program.into(),
130 status,
131 stderr: Box::new(stderr.into()),
132 }
133 }
134}