Add support for picking up the previous commit message if it wasn't used

main
Julius Riegel 7 months ago
parent 7a1e3cf345
commit fbd8f57ed0

@ -312,14 +312,28 @@ export def gc [
--all (-A)
--amend (-a)
--keep (-k)
--no-promt (-n)
] {
let m = $message | with-flag -m
let a = if $all {[--all]} else {[]}
let n = if $amend {[--amend]} else {[]}
let k = if $keep {[--no-edit]} else {[]}
mut e = []
let previous = git_previous_message
mut message = $message
if $previous != null {
print $"Previous message:\n ($previous)"
if (input -n 1 "Use previous message? [y/N]: " | str downcase) == "y" {
$message = $previous
$e = ["-e"]
}
}
if $message == null and (glob "*commitlint*" | length) > 0 {
let type = ([ci chore feat fix docs test refactor] | input list "Change type")
if $message == null and (glob "*commitlint*" | length) > 0 and not $no_promt {
let type = ([ci chore feat fix docs test refactor] | input list -f "Change type")
let subject = input "Subject: "
let message = input "Message: "
@ -328,9 +342,9 @@ export def gc [
}
let message = if $subject != null and ($subject | str length) > 0 {
$"($type)\(($subject)\): ($message)"
$"# ($type)\(($subject)\): ($message)"
} else {
$"($type): ($message)"
$"# ($type): ($message)"
}
print $"(ansi {attr: i})($message)(ansi reset)"
@ -339,7 +353,8 @@ export def gc [
git commit -v -e ...$m ...$a ...$n ...$k
} else {
git commit -v ...$m ...$a ...$n ...$k
let m = $message | with-flag -m
git commit -v ...$m ...$a ...$n ...$k ...$e
}
}
@ -719,3 +734,32 @@ def git_main_branch [] {
| str replace --regex 'HEAD .*?[: ](.+)' '$1'
}
def git_previous_message [] {
let msg_file = ".git/COMMIT_EDITMSG"
if not ($msg_file | path exists) {
return
}
let lines = open $msg_file | lines
if ($lines | is-empty) {
return
}
let msg_line = $lines | first
if $msg_line == null or ($msg_line | str trim | str length) == 0 {
return
}
let logs = gl
if ($logs | is-empty) {
return $msg_line
}
let last_commit_msg = $logs | last | get message
if $last_commit_msg =~ $"^($msg_line)" {
return
}
return $msg_line
}

Loading…
Cancel
Save