Skip to content

Commit

Permalink
Always pass commit message to git::create_derived_commit
Browse files Browse the repository at this point in the history
This function used to take an `Option<&str>` as commit message and provided a default. However, there was only one place where we passed `None`, so it's cleaner to just always pass the message.
We used to trim the message and append a new line at the end. However, `git2` provides a function to clean up a commit message, which is used here now.

Test Plan: `cargo build` and use the fresh build to submit this Pull Request

Reviewers: jozef-mokry

Reviewed By: jozef-mokry

Pull Request: #32
  • Loading branch information
Sven Over authored Apr 21, 2022
1 parent ce208e5 commit b96b62b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ async fn diff_impl(

Some(git.create_derived_commit(
local_commit.parent_oid,
Some(if pull_request.is_some() {
if pull_request.is_some() {
"[𝘀𝗽𝗿] 𝘤𝘩𝘢𝘯𝘨𝘦𝘴 𝘪𝘯𝘵𝘳𝘰𝘥𝘶𝘤𝘦𝘥 𝘵𝘩𝘳𝘰𝘶𝘨𝘩 𝘳𝘦𝘣𝘢𝘴𝘦\n\n[skip ci]"
} else {
"[𝘀𝗽𝗿] 𝘤𝘩𝘢𝘯𝘨𝘦𝘴 𝘵𝘰 𝘮𝘢𝘴𝘵𝘦𝘳 𝘵𝘩𝘪𝘴 𝘤𝘰𝘮𝘮𝘪𝘵 𝘪𝘴 𝘣𝘢𝘴𝘦𝘥 𝘰𝘯\n\n[skip ci]"
}),
},
parent_tree_oid,
&parents[..],
)?)
Expand Down Expand Up @@ -377,7 +377,10 @@ async fn diff_impl(
// Create the new commit
let pr_commit = git.create_derived_commit(
local_commit.oid,
github_commit_message.as_ref().map(|s| &s[..]),
github_commit_message
.as_ref()
.map(|s| &s[..])
.unwrap_or("[𝘀𝗽𝗿] 𝘪𝘯𝘪𝘵𝘪𝘢𝘭 𝘷𝘦𝘳𝘴𝘪𝘰𝘯"),
cherrypicked_tree.unwrap_or(tree_oid),
&pr_commit_parents[..],
)?;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/land.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub async fn land(
// what we want.
let final_commit = git.create_derived_commit(
prepared_commit.oid,
Some("[𝘀𝗽𝗿] 𝘭𝘢𝘯𝘥𝘦𝘥 𝘷𝘦𝘳𝘴𝘪𝘰𝘯\n\n[skip ci]"),
"[𝘀𝗽𝗿] 𝘭𝘢𝘯𝘥𝘦𝘥 𝘷𝘦𝘳𝘴𝘪𝘰𝘯\n\n[skip ci]",
our_tree_oid,
&[pull_request.head_oid, current_master],
)?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub async fn patch(

parent_oid = git.create_derived_commit(
pr.base_oid,
Some(&format!("[𝘀𝗽𝗿] Base of Pull Request #{}", pr.number)),
&format!("[𝘀𝗽𝗿] Base of Pull Request #{}", pr.number),
pr_base_tree,
&[parent_oid],
)?;
Expand All @@ -79,7 +79,7 @@ pub async fn patch(
// the commit we created above to prepare the base of this commit.
git.create_derived_commit(
pr.head_oid,
Some(&build_commit_message(&pr.sections)),
&build_commit_message(&pr.sections),
git.get_tree_oid_for_commit(pr.head_oid)?,
&[parent_oid],
)?
Expand Down
8 changes: 2 additions & 6 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl Git {
pub fn create_derived_commit(
&self,
original_commit_oid: Oid,
message: Option<&str>,
message: &str,
tree_oid: Oid,
parent_oids: &[Oid],
) -> Result<Oid> {
Expand All @@ -373,11 +373,7 @@ impl Git {
.map(|oid| self.repo.find_commit(*oid))
.collect::<std::result::Result<Vec<_>, _>>()?;
let parent_refs = parents.iter().collect::<Vec<_>>();
let message = if let Some(text) = message {
format!("{}\n", text.trim())
} else {
"[𝘀𝗽𝗿] 𝘪𝘯𝘪𝘵𝘪𝘢𝘭 𝘷𝘦𝘳𝘴𝘪𝘰𝘯\n".into()
};
let message = git2::message_prettify(message, None)?;

// The committer signature should be the default signature (i.e. the
// current user - as configured in Git as `user.name` and `user.email` -
Expand Down

0 comments on commit b96b62b

Please sign in to comment.