Skip to content

Commit 615af06

Browse files
committed
Improve rebase hint message
1 parent d97afc6 commit 615af06

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/handlers/no_merges.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,23 @@ pub(super) async fn parse_input(
8080
Ok(Some(NoMergesInput { merge_commits }))
8181
}
8282

83-
const DEFAULT_MESSAGE: &str = "
83+
fn get_default_message(repository_name: &str, default_branch: &str) -> String {
84+
format!(
85+
"
8486
There are merge commits (commits with multiple parents) in your changes. We have a \
8587
[no merge policy](https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy) \
8688
so these commits will need to be removed for this pull request to be merged.
8789
8890
You can start a rebase with the following commands:
8991
```shell-session
9092
$ # rebase
91-
$ git rebase -i master
92-
$ # delete any merge commits in the editor that appears
93+
$ git pull --rebase https://github.com/{repository_name}.git {default_branch}
9394
$ git push --force-with-lease
9495
```
9596
96-
";
97+
"
98+
)
99+
}
97100

98101
pub(super) async fn handle_input(
99102
ctx: &Context,
@@ -135,7 +138,10 @@ pub(super) async fn handle_input(
135138
let mut message = config
136139
.message
137140
.as_deref()
138-
.unwrap_or(DEFAULT_MESSAGE)
141+
.unwrap_or(&get_default_message(
142+
&event.repository.full_name,
143+
&event.repository.default_branch,
144+
))
139145
.to_string();
140146

141147
let since_last_posted = if first_time {
@@ -212,7 +218,7 @@ mod test {
212218

213219
#[test]
214220
fn message() {
215-
let mut message = DEFAULT_MESSAGE.to_string();
221+
let mut message = get_default_message("foo/bar", "baz").to_string();
216222

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

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

0 commit comments

Comments
 (0)