Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
saterus committed Apr 13, 2020
1 parent 4f77554 commit dd1ab7f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl BranchLocation {
}
}

static LOCAL_CHANGES_WARNING: &'static str = "\
static LOCAL_CHANGES_WARNING: &str = "\
The Wizard advises against rebasing while there are changes to the local git repo.
Please commit, stash, or discard your changes before proceeding.";
Expand Down Expand Up @@ -88,14 +88,14 @@ pub fn current_branch_name() -> String {
.to_string()
}

pub fn extract_ref(branch_line: &str) -> &str {
pub fn extract_ref(branch_line: &str) -> Option<&str> {
let re = Regex::new(r"\s*(\w\S*)\s").unwrap();

for caps in re.captures_iter(branch_line) {
return caps.get(1).unwrap().as_str();
if let Some(capture) = re.captures_iter(branch_line).next() {
Some(capture.get(1).unwrap().as_str())
} else {
None
}

return "";
}

#[cfg(test)]
Expand All @@ -109,9 +109,9 @@ mod tests {
let sample3 = " origin/foo/bar-baz 770b0814b WIP!";
let sample4 = " fa1afe1 WIP!";

assert_eq!(extract_ref(sample), "foo/bar-baz");
assert_eq!(extract_ref(sample2), "foo/bark-bazz");
assert_eq!(extract_ref(sample3), "origin/foo/bar-baz");
assert_eq!(extract_ref(sample4), "fa1afe1");
assert_eq!(extract_ref(sample).unwrap(), "foo/bar-baz");
assert_eq!(extract_ref(sample2).unwrap(), "foo/bark-bazz");
assert_eq!(extract_ref(sample3).unwrap(), "origin/foo/bar-baz");
assert_eq!(extract_ref(sample4).unwrap(), "fa1afe1");
}
}
2 changes: 1 addition & 1 deletion src/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'b, 'a: 'b> From<SimpleOptions<'a>> for SkimOptions<'b> {
pub fn one(source: SkimItemReceiver, options: SimpleOptions) -> String {
let skim_output = Skim::run_with(&options.into(), Some(source))
.map(|out| out.selected_items)
.unwrap_or_else(|| Vec::new());
.unwrap_or_else(Vec::new);

let selected_item = skim_output.first().unwrap_or_else(|| {
eprintln!("Nothing selected. Aborting.");
Expand Down
10 changes: 7 additions & 3 deletions src/subcommands/branch_jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn jump(config: &cli::Config) {
let branch_point = pick_branch_point(&current_branch_name, &target_branch, &config);

println!("The Rebase Wizard has seen your future:");
println!("");
println!();
println!("Run the following command when you are ready:");
println!(" git rebase --onto {} {}", target_branch, branch_point);
}
Expand All @@ -37,7 +37,9 @@ pub fn pick_target_branch(current_branch_name: &str, config: &cli::Config) -> St
let branches = git::all_branches();
let selection = sk::one(sk::to_source(branches), options);

git::extract_ref(&selection).to_string()
git::extract_ref(&selection)
.expect("branch name not found")
.to_string()
}

pub fn pick_branch_point(
Expand Down Expand Up @@ -69,5 +71,7 @@ pub fn pick_branch_point(
let commits = git::recent_commits();
let selection = sk::one(sk::to_source(commits), options);

git::extract_ref(&selection).to_string()
git::extract_ref(&selection)
.expect("commit sha not found")
.to_string()
}
6 changes: 3 additions & 3 deletions src/subcommands/tutorial.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub static SECRETS_TEXT: &'static str = r"
pub static SECRETS_TEXT: &str = r"
Wizard Secrets: 🧙‍♂️
git rebase --onto TARGET_BRANCH BRANCH_POINT
Expand All @@ -12,9 +12,9 @@ Wizard Secrets: 🧙‍♂️
First commit you didn't author on this branch
";

pub static MORE_HELP_TEASER: &'static str = "For more secrets 🔮, try running the --tutorial flag.";
pub static MORE_HELP_TEASER: &str = "For more secrets 🔮, try running the --tutorial flag.";

pub static TUTORIAL_TEXT: &'static str = r"
pub static TUTORIAL_TEXT: &str = r"
*Branch Jumping*: It isn't uncommon to need to move your feature branch from
being based on one branch to another. This requires picking the exact right
arguments for `git rebase --onto`.
Expand Down

0 comments on commit dd1ab7f

Please sign in to comment.