summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2019-07-24 10:20:59 -0230
committerTim Oram <dev@mitmaro.ca>2019-07-24 20:18:17 -0230
commite2fb2733fb59b70215e294da359c94b6b910270a (patch)
tree5438404aaa7909b67028c4ff32666956055fbddb
parent3bebbdc48500ca0028c0827eb2e390c64f8aaeec (diff)
Fix non-zero status code on noop status code
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/action.rs19
-rw-r--r--src/git_interactive.rs27
-rw-r--r--src/line.rs15
-rw-r--r--src/list/utils.rs1
-rw-r--r--src/main.rs9
-rw-r--r--test/git-rebase-todo-empty.in1
-rw-r--r--test/git-rebase-todo-noop.in1
8 files changed, 60 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ab9ae40..30fbddb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Configurable key bindings
- Horizontal scrolling
+### Fixed
+- A noop rebase will no longer return a non-zero status code
+
## [1.0.0] - 2019-04-10
### Added
diff --git a/src/action.rs b/src/action.rs
index 19ab8ba..c9e08cb 100644
--- a/src/action.rs
+++ b/src/action.rs
@@ -7,6 +7,7 @@ pub enum Action {
Edit,
Exec,
Fixup,
+ Noop,
Pick,
Reword,
Squash,
@@ -20,6 +21,7 @@ impl Action {
Action::Edit => "edit",
Action::Exec => "exec",
Action::Fixup => "fixup",
+ Action::Noop => "noop",
Action::Pick => "pick",
Action::Reword => "reword",
Action::Squash => "squash",
@@ -33,6 +35,7 @@ impl Action {
Action::Edit => "e",
Action::Exec => "x",
Action::Fixup => "f",
+ Action::Noop => "n",
Action::Pick => "p",
Action::Reword => "r",
Action::Squash => "s",
@@ -50,6 +53,7 @@ impl TryFrom<&str> for Action {
"edit" | "e" => Ok(Action::Edit),
"exec" | "x" => Ok(Action::Exec),
"fixup" | "f" => Ok(Action::Fixup),
+ "noop" | "n" => Ok(Action::Noop),
"pick" | "p" => Ok(Action::Pick),
"reword" | "r" => Ok(Action::Reword),
"squash" | "s" => Ok(Action::Squash),
@@ -89,6 +93,11 @@ mod tests {
}
#[test]
+ fn action_to_str_noop() {
+ assert_eq!(Action::Noop.as_string(), "noop");
+ }
+
+ #[test]
fn action_to_str_pick() {
assert_eq!(Action::Pick.as_string(), "pick");
}
@@ -154,6 +163,16 @@ mod tests {
}
#[test]
+ fn action_from_str_n() {
+ assert_eq!(Action::try_from("n").unwrap(), Action::Noop);
+ }
+
+ #[test]
+ fn action_from_str_noop() {
+ assert_eq!(Action::try_from("noop").unwrap(), Action::Noop);
+ }
+
+ #[test]
fn action_from_str_p() {
assert_eq!(Action::try_from("p").unwrap(), Action::Pick);
}
diff --git a/src/git_interactive.rs b/src/git_interactive.rs
index 8ef42c7..60c59a2 100644
--- a/src/git_interactive.rs
+++ b/src/git_interactive.rs
@@ -25,20 +25,15 @@ fn load_filepath(path: &PathBuf, comment_char: &str) -> Result<Vec<Line>, String
}
// catch noop rebases
- match s.lines().nth(0) {
- Some("noop") => Ok(Vec::new()),
- _ => {
- s.lines()
- .filter(|l| !l.starts_with(comment_char) && !l.is_empty())
- .map(|l| {
- match Line::new(l) {
- Ok(line) => Ok(line),
- Err(e) => Err(format!("Error reading file, {}", e)),
- }
- })
- .collect()
- },
- }
+ s.lines()
+ .filter(|l| !l.starts_with(comment_char) && !l.is_empty())
+ .map(|l| {
+ match Line::new(l) {
+ Ok(line) => Ok(line),
+ Err(e) => Err(format!("Error reading file, {}", e)),
+ }
+ })
+ .collect()
}
pub struct GitInteractive {
@@ -226,6 +221,10 @@ impl GitInteractive {
Err(String::from("Cannot load commit for the selected action"))
}
+ pub fn is_noop(&self) -> bool {
+ !self.lines.is_empty() && *self.lines[0].get_action() == Action::Noop
+ }
+
pub fn get_commit_stats(&self) -> &Option<Commit> {
&self.selected_commit_stats
}
diff --git a/src/line.rs b/src/line.rs
index 1ca8ac8..d031d77 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -11,6 +11,16 @@ pub struct Line {
}
impl Line {
+ pub fn new_noop() -> Self {
+ Self {
+ action: Action::Noop,
+ command: String::from(""),
+ comment: String::from(""),
+ hash: String::from(""),
+ mutated: false,
+ }
+ }
+
pub fn new_break() -> Self {
Self {
action: Action::Break,
@@ -22,7 +32,10 @@ impl Line {
}
pub fn new(input_line: &str) -> Result<Self, String> {
- if input_line.starts_with("break") || input_line.starts_with('b') {
+ if input_line.starts_with("noop") {
+ return Ok(Self::new_noop());
+ }
+ else if input_line.starts_with("break") || input_line.starts_with('b') {
return Ok(Self::new_break());
}
else if input_line.starts_with("exec") || input_line.starts_with('x') {
diff --git a/src/list/utils.rs b/src/list/utils.rs
index 656f016..b10be85 100644
--- a/src/list/utils.rs
+++ b/src/list/utils.rs
@@ -39,6 +39,7 @@ pub fn get_action_color(action: Action) -> WindowColor {
Action::Edit => WindowColor::ActionEdit,
Action::Exec => WindowColor::ActionExec,
Action::Fixup => WindowColor::ActionFixup,
+ Action::Noop => WindowColor::Foreground,
Action::Pick => WindowColor::ActionPick,
Action::Reword => WindowColor::ActionReword,
Action::Squash => WindowColor::ActionSquash,
diff --git a/src/main.rs b/src/main.rs
index 0c4edd0..2cc7aca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -72,9 +72,16 @@ fn try_main() -> Result<ExitStatus, Exit> {
},
};
+ if git_interactive.is_noop() {
+ return Err(Exit {
+ message: String::from("A noop rebase was provided, skipping editing"),
+ status: ExitStatus::Good,
+ });
+ }
+
if git_interactive.get_lines().is_empty() {
return Err(Exit {
- message: String::from("Nothing to rebase"),
+ message: String::from("An empty rebase was provided, nothing to edit"),
status: ExitStatus::FileReadError,
});
}
diff --git a/test/git-rebase-todo-empty.in b/test/git-rebase-todo-empty.in
new file mode 100644
index 0000000..66f3fca
--- /dev/null
+++ b/test/git-rebase-todo-empty.in
@@ -0,0 +1 @@
+# This is an empty rebase file
diff --git a/test/git-rebase-todo-noop.in b/test/git-rebase-todo-noop.in
new file mode 100644
index 0000000..e804f19
--- /dev/null
+++ b/test/git-rebase-todo-noop.in
@@ -0,0 +1 @@
+noop