• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MitMaro / git-interactive-rebase-tool / 6883077488

15 Nov 2023 09:23PM UTC coverage: 93.248% (-0.4%) from 93.64%
6883077488

Pull #873

github

web-flow
Merge 0ab516642 into d7655157f
Pull Request #873: When editing in the middle of a rebase, dont clear on quit

45 of 72 new or added lines in 14 files covered. (62.5%)

1 existing line in 1 file now uncovered.

4792 of 5139 relevant lines covered (93.25%)

3.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/todo_file/src/state.rs
1
use std::{
2
        fmt::{Display, Formatter},
3
        path::{Path, PathBuf},
4
};
5

6
use crate::errors::{FileReadErrorCause, IoError};
7

8
/// Describes the state of rebase when editing the rebase todo file.
9
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10
#[allow(clippy::exhaustive_enums)]
11
pub enum State {
12
        /// Editing todo at start of a rebase.
13
        Initial,
14
        /// Editing todo in the middle of a rebase with --edit.
15
        Edit,
16
        /// Editing the todo file for git-revise
17
        Revise,
18
}
19

20
pub(crate) fn detect_state(filepath: &Path) -> Result<State, IoError> {
3✔
21
        if filepath.ends_with("git-revise-todo") {
2✔
22
                return Ok(State::Revise);
1✔
23
        }
24
        if let Some(parent) = filepath.parent() {
4✔
25
                if parent.join("stopped-sha").try_exists().map_err(|err| {
4✔
NEW
26
                        IoError::FileRead {
×
NEW
27
                                file: PathBuf::from(parent),
×
NEW
28
                                cause: FileReadErrorCause::from(err),
×
29
                        }
30
                })? {
31
                        return Ok(State::Edit);
1✔
32
                }
33
        }
34
        return Ok(State::Initial);
2✔
35
}
36

37
impl State {}
38

39
impl Display for State {
40
        #[inline]
41
        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1✔
42
                write!(f, "{}", match *self {
2✔
43
                        Self::Initial => "initial",
1✔
44
                        Self::Edit => "edit",
1✔
45
                        Self::Revise => "revise",
1✔
46
                })
47
        }
48
}
49

50
#[cfg(test)]
51
mod tests {
52
        use rstest::rstest;
53

54
        use super::*;
55
        use crate::testutil::{with_todo_revise_file, TodoFileTestDirContext, with_todo_rebase_edit_file, with_todo_rebase_edit_file_stopped};
56

57
        #[rstest]
58
        #[case::edit(State::Initial, "initial")]
59
        #[case::edit(State::Edit, "edit")]
60
        #[case::edit(State::Revise, "revise")]
61
        fn to_string(#[case] action: State, #[case] expected: &str) {
62
                assert_eq!(format!("{action}"), expected);
63
        }
64

65
        #[rstest]
66
        #[case::edit(State::Initial)]
67
        #[case::edit(State::Edit)]
68
        #[case::edit(State::Revise)]
69
        fn detect(#[case] expected: State) {
70
                let check = |context: TodoFileTestDirContext| {
71
                        assert_eq!(
72
                                detect_state(context.todo_file().filepath.as_path()).unwrap(),
73
                                expected
74
                        )
75
                };
76
                match expected {
77
                        State::Initial => with_todo_rebase_edit_file(&[], check),
78
                        State::Edit => with_todo_rebase_edit_file_stopped(&[], check),
79
                        State::Revise => with_todo_revise_file(&[], check),
80
                }
81
        }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc