summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2018-10-27 21:49:16 -0230
committerGitHub <noreply@github.com>2018-10-27 21:49:16 -0230
commitc57946f90032da8feeb3c8316c3af5405b94ccc3 (patch)
tree7bb89700d7c6365b81971fff7735abe840da1a18
parent393a0958bc7df4b25b4d7b094ffa9353e31f2103 (diff)
parente625fc42f64eb552198168cd3fdc3d6b856f3de4 (diff)
Merge pull request #69 from MitMaro/support-exec-command
Add basic support for the exec action
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/action.rs48
-rw-r--r--src/application.rs38
-rw-r--r--src/config.rs2
-rw-r--r--src/git_config.rs5
-rw-r--r--src/git_interactive.rs6
-rw-r--r--src/line.rs24
-rw-r--r--src/window.rs3
-rw-r--r--test/git-rebase-todo-all-actions.in2
-rw-r--r--test/git-rebase-todo-exec.in1
10 files changed, 92 insertions, 38 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d8561b3..9c08440 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Configuration of colors
+- Support for the exec action
### Fixed
- Windows creating a new window on run (hopefully)
diff --git a/src/action.rs b/src/action.rs
index 8ecafad..8c458d6 100644
--- a/src/action.rs
+++ b/src/action.rs
@@ -1,34 +1,37 @@
#[derive(PartialEq, Debug)]
pub enum Action {
+ Drop,
+ Edit,
+ Exec,
+ Fixup,
Pick,
Reword,
- Edit,
Squash,
- Fixup,
- Drop
}
pub fn action_from_str(s: &str) -> Result<Action, String> {
match s {
+ "drop" | "d" => Ok(Action::Drop),
+ "edit" | "e" => Ok(Action::Edit),
+ "exec" | "x" => Ok(Action::Exec),
+ "fixup" | "f" => Ok(Action::Fixup),
"pick" | "p" => Ok(Action::Pick),
"reword" | "r" => Ok(Action::Reword),
- "edit" | "e" => Ok(Action::Edit),
"squash" | "s" => Ok(Action::Squash),
- "fixup" | "f" => Ok(Action::Fixup),
- "drop" | "d" => Ok(Action::Drop),
_ => Err(format!("Invalid action: {}", s))
}
}
pub fn action_to_str(action: &Action) -> String {
String::from(match *action {
+ Action::Drop => "drop",
+ Action::Edit => "edit",
+ Action::Exec => "exec",
+ Action::Fixup => "fixup",
Action::Pick => "pick",
Action::Reword => "reword",
- Action::Edit => "edit",
Action::Squash => "squash",
- Action::Fixup => "fixup",
- Action::Drop => "drop"
})
}
@@ -42,28 +45,31 @@ mod tests {
#[test]
fn action_to_str_all() {
+ assert_eq!(action_to_str(&Action::Drop), "drop");
+ assert_eq!(action_to_str(&Action::Edit), "edit");
+ assert_eq!(action_to_str(&Action::Exec), "exec");
+ assert_eq!(action_to_str(&Action::Fixup), "fixup");
assert_eq!(action_to_str(&Action::Pick), "pick");
assert_eq!(action_to_str(&Action::Reword), "reword");
- assert_eq!(action_to_str(&Action::Edit), "edit");
assert_eq!(action_to_str(&Action::Squash), "squash");
- assert_eq!(action_to_str(&Action::Fixup), "fixup");
- assert_eq!(action_to_str(&Action::Drop), "drop");
}
#[test]
fn action_from_str_all() {
- assert_eq!(action_from_str("pick"), Ok(Action::Pick));
+ assert_eq!(action_from_str("d"), Ok(Action::Drop));
+ assert_eq!(action_from_str("drop"), Ok(Action::Drop));
+ assert_eq!(action_from_str("e"), Ok(Action::Edit));
+ assert_eq!(action_from_str("edit"), Ok(Action::Edit));
+ assert_eq!(action_from_str("x"), Ok(Action::Exec));
+ assert_eq!(action_from_str("exec"), Ok(Action::Exec));
+ assert_eq!(action_from_str("f"), Ok(Action::Fixup));
+ assert_eq!(action_from_str("fixup"), Ok(Action::Fixup));
assert_eq!(action_from_str("p"), Ok(Action::Pick));
- assert_eq!(action_from_str("reword"), Ok(Action::Reword));
+ assert_eq!(action_from_str("pick"), Ok(Action::Pick));
assert_eq!(action_from_str("r"), Ok(Action::Reword));
- assert_eq!(action_from_str("edit"), Ok(Action::Edit));
- assert_eq!(action_from_str("e"), Ok(Action::Edit));
- assert_eq!(action_from_str("squash"), Ok(Action::Squash));
+ assert_eq!(action_from_str("reword"), Ok(Action::Reword));
assert_eq!(action_from_str("s"), Ok(Action::Squash));
- assert_eq!(action_from_str("fixup"), Ok(Action::Fixup));
- assert_eq!(action_from_str("f"), Ok(Action::Fixup));
- assert_eq!(action_from_str("drop"), Ok(Action::Drop));
- assert_eq!(action_from_str("d"), Ok(Action::Drop));
+ assert_eq!(action_from_str("squash"), Ok(Action::Squash));
}
}
diff --git a/src/application.rs b/src/application.rs
index b3978ae..3657cf2 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -179,7 +179,7 @@ mod tests {
let config = Config::new(&GitConfig::new().unwrap());
let window = Window::new(config);
let app = Application::new(gi, window);
- assert_eq!(app.git_interactive.get_lines().len(), 12);
+ assert_eq!(app.git_interactive.get_lines().len(), 14);
}
#[test]
@@ -283,7 +283,33 @@ mod tests {
app.process_input();
assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Edit);
}
-
+
+ #[test]
+ fn application_not_set_exec_action() {
+ let gi = GitInteractive::new_from_filepath("test/git-rebase-todo-exec.in", "#").unwrap();
+ let config = Config::new(&GitConfig::new().unwrap());
+ let window = Window::new(config);
+ let mut app = Application::new(gi, window);
+ app.window.window.next_char = Input::Character('p');
+ app.process_input();
+ assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Exec);
+ app.window.window.next_char = Input::Character('r');
+ app.process_input();
+ assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Exec);
+ app.window.window.next_char = Input::Character('e');
+ app.process_input();
+ assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Exec);
+ app.window.window.next_char = Input::Character('s');
+ app.process_input();
+ assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Exec);
+ app.window.window.next_char = Input::Character('f');
+ app.process_input();
+ assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Exec);
+ app.window.window.next_char = Input::Character('d');
+ app.process_input();
+ assert_eq!(*app.git_interactive.get_lines()[0].get_action(), Action::Exec);
+ }
+
#[test]
fn application_set_squash() {
let gi = GitInteractive::new_from_filepath("test/git-rebase-todo-all-actions.in", "#").unwrap();
@@ -314,8 +340,8 @@ mod tests {
let mut app = Application::new(gi, window);
app.window.window.next_char = Input::Character('j');
app.process_input();
- assert_eq!(*app.git_interactive.get_lines()[0].get_hash(), "bbb");
- assert_eq!(*app.git_interactive.get_lines()[1].get_hash(), "aaa");
+ assert_eq!(*app.git_interactive.get_lines()[0].get_hash_or_command(), "bbb");
+ assert_eq!(*app.git_interactive.get_lines()[1].get_hash_or_command(), "aaa");
assert_eq!(*app.git_interactive.get_selected_line_index(), 2);
}
@@ -329,8 +355,8 @@ mod tests {
app.process_input();
app.window.window.next_char = Input::Character('k');
app.process_input();
- assert_eq!(*app.git_interactive.get_lines()[0].get_hash(), "bbb");
- assert_eq!(*app.git_interactive.get_lines()[1].get_hash(), "aaa");
+ assert_eq!(*app.git_interactive.get_lines()[0].get_hash_or_command(), "bbb");
+ assert_eq!(*app.git_interactive.get_lines()[1].get_hash_or_command(), "aaa");
assert_eq!(*app.git_interactive.get_selected_line_index(), 1);
}
diff --git a/src/config.rs b/src/config.rs
index a880f9e..9542fe8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -10,6 +10,7 @@ pub struct Config {
pub pick_color: Color,
pub reword_color: Color,
pub edit_color: Color,
+ pub exec_color: Color,
pub squash_color: Color,
pub fixup_color: Color,
pub drop_color: Color,
@@ -40,6 +41,7 @@ impl Config {
pick_color: string_to_color(git_config.pick_color.as_ref(), Color::Green),
reword_color: string_to_color(git_config.reword_color.as_ref(), Color::Yellow),
edit_color: string_to_color(git_config.edit_color.as_ref(), Color::Blue),
+ exec_color: string_to_color(git_config.edit_color.as_ref(), Color::White),
squash_color: string_to_color(git_config.squash_color.as_ref(), Color::Cyan),
fixup_color: string_to_color(git_config.fixup_color.as_ref(), Color::Magenta),
drop_color: string_to_color(git_config.drop_color.as_ref(), Color::Red),
diff --git a/src/git_config.rs b/src/git_config.rs
index ec5391d..f18c99b 100644
--- a/src/git_config.rs
+++ b/src/git_config.rs
@@ -13,6 +13,7 @@ pub struct GitConfig {
pub pick_color: String,
pub reword_color: String,
pub edit_color: String,
+ pub exec_color: String,
pub squash_color: String,
pub fixup_color: String,
pub drop_color: String,
@@ -75,6 +76,10 @@ impl GitConfig {
Ok(edit_color_value) => edit_color_value.to_lowercase(),
Err(_msg) => String::from("")
},
+ exec_color: match config.get_string("interactive-rebase-tool.execColor") {
+ Ok(exec_color_value) => exec_color_value.to_lowercase(),
+ Err(_msg) => String::from("")
+ },
squash_color: match config.get_string("interactive-rebase-tool.squashColor") {
Ok(squash_color_value) => squash_color_value.to_lowercase(),
Err(_msg) => String::from("")
diff --git a/src/git_interactive.rs b/src/git_interactive.rs
index e6f3897..a35e23d 100644
--- a/src/git_interactive.rs
+++ b/src/git_interactive.rs
@@ -126,11 +126,13 @@ impl GitInteractive {
}
pub fn set_selected_line_action(&mut self, action: Action) {
- self.lines[self.selected_line_index - 1].set_action(action);
+ if *self.lines[self.selected_line_index - 1].get_action() != Action::Exec {
+ self.lines[self.selected_line_index - 1].set_action(action);
+ }
}
pub fn get_selected_line_hash(&self) -> &String {
- self.lines[self.selected_line_index - 1].get_hash()
+ self.lines[self.selected_line_index - 1].get_hash_or_command()
}
pub fn get_selected_line_index(&self) -> &usize {
diff --git a/src/line.rs b/src/line.rs
index c8fe94e..b22349c 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -7,18 +7,26 @@ use action::{
#[derive(PartialEq, Debug)]
pub struct Line {
action: Action,
- hash: String,
+ hash_or_command: String,
comment: String,
mutated: bool
}
impl Line {
pub fn new(input_line: &str) -> Result<Self, String> {
- let input: Vec<&str> = input_line.splitn(3, ' ').collect();
+ let split_count = if input_line.starts_with("exec") || input_line.starts_with('x') {2} else {3};
+
+ let input: Vec<&str> = input_line.splitn(split_count, ' ').collect();
match input.len() {
+ 2 => Ok(Line {
+ action: action_from_str(input[0])?,
+ hash_or_command: String::from(input[1]),
+ comment: String::from(""),
+ mutated: false
+ }),
3 => Ok(Line {
action: action_from_str(input[0])?,
- hash: String::from(input[1]),
+ hash_or_command: String::from(input[1]),
comment: String::from(input[2]),
mutated: false
}),
@@ -38,15 +46,15 @@ impl Line {
pub fn get_action(&self) -> &Action {
&self.action
}
- pub fn get_hash(&self) -> &String {
- &self.hash
+ pub fn get_hash_or_command(&self) -> &String {
+ &self.hash_or_command
}
pub fn get_comment(&self) -> &String {
&self.comment
}
pub fn to_text(&self) -> String {
- format!("{} {} {}", action_to_str(&self.action), self.hash, self.comment)
+ format!("{} {} {}", action_to_str(&self.action), self.hash_or_command, self.comment)
}
}
@@ -59,7 +67,7 @@ mod tests {
fn new_with_valid_line() {
let line = Line::new("pick aaa comment").unwrap();
assert_eq!(line.action, Action::Pick);
- assert_eq!(line.hash, "aaa");
+ assert_eq!(line.hash_or_command, "aaa");
assert_eq!(line.comment, "comment");
assert_eq!(line.mutated, false);
}
@@ -86,7 +94,7 @@ mod tests {
fn getters() {
let line = Line::new("pick aaa comment").unwrap();
assert_eq!(line.get_action(), &Action::Pick);
- assert_eq!(line.get_hash(), &"aaa");
+ assert_eq!(line.get_hash_or_command(), &"aaa");
assert_eq!(line.get_comment(), &"comment");
}
diff --git a/src/window.rs b/src/window.rs
index 1a374bb..d4994fd 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -127,13 +127,14 @@ impl Window {
Action::Pick => self.set_color(&self.config.pick_color),
Action::Reword => self.set_color(&self.config.reword_color),
Action::Edit => self.set_color(&self.config.edit_color),
+ Action::Exec => self.set_color(&self.config.exec_color),
Action::Squash => self.set_color(&self.config.squash_color),
Action::Fixup => self.set_color(&self.config.fixup_color),
Action::Drop => self.set_color(&self.config.drop_color)
}
self.window.addstr(&format!("{:6}", action_to_str(line.get_action())));
self.set_color(&self.config.foreground_color);
- self.window.addstr(&format!(" {} {}\n", line.get_hash(), line.get_comment()));
+ self.window.addstr(&format!(" {} {}\n", line.get_hash_or_command(), line.get_comment()));
}
fn draw_footer(&self) {
diff --git a/test/git-rebase-todo-all-actions.in b/test/git-rebase-todo-all-actions.in
index 3350999..18c518b 100644
--- a/test/git-rebase-todo-all-actions.in
+++ b/test/git-rebase-todo-all-actions.in
@@ -2,12 +2,14 @@
pick aaa Added tests
reword bbb Added tests
edit ccc Added tests
+exec git commit --amend -m "Foo bar"
squash ddd Added tests
fixup eee Added tests
drop fff Added tests
p 111 Added tests
r 222 Added tests
e 333 Added tests
+x git commit --amend -m "Foo bar"
s 444 Added tests
f 555 Added tests
d 666 Added tests
diff --git a/test/git-rebase-todo-exec.in b/test/git-rebase-todo-exec.in
new file mode 100644
index 0000000..16f4558
--- /dev/null
+++ b/test/git-rebase-todo-exec.in
@@ -0,0 +1 @@
+exec git commit --amend -m "Foo bar"