Skip to content

Commit

Permalink
Improve rebase hint message
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed May 7, 2024
1 parent d97afc6 commit 615af06
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/handlers/no_merges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,23 @@ pub(super) async fn parse_input(
Ok(Some(NoMergesInput { merge_commits }))
}

const DEFAULT_MESSAGE: &str = "
fn get_default_message(repository_name: &str, default_branch: &str) -> String {
format!(
"
There are merge commits (commits with multiple parents) in your changes. We have a \
[no merge policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy) \
so these commits will need to be removed for this pull request to be merged.
You can start a rebase with the following commands:
```shell-session
$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git pull --rebase https://github.com/{repository_name}.git {default_branch}
$ git push --force-with-lease
```
";
"
)
}

pub(super) async fn handle_input(
ctx: &Context,
Expand Down Expand Up @@ -135,7 +138,10 @@ pub(super) async fn handle_input(
let mut message = config
.message
.as_deref()
.unwrap_or(DEFAULT_MESSAGE)
.unwrap_or(&get_default_message(
&event.repository.full_name,
&event.repository.default_branch,
))
.to_string();

let since_last_posted = if first_time {
Expand Down Expand Up @@ -212,7 +218,7 @@ mod test {

#[test]
fn message() {
let mut message = DEFAULT_MESSAGE.to_string();
let mut message = get_default_message("foo/bar", "baz").to_string();

writeln!(message, "The following commits are merge commits:").unwrap();

Expand All @@ -228,8 +234,7 @@ There are merge commits (commits with multiple parents) in your changes. We have
You can start a rebase with the following commands:
```shell-session
$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git pull --rebase https://github.com/foo/bar.git baz
$ git push --force-with-lease
```
Expand Down

0 comments on commit 615af06

Please sign in to comment.