Commits

Nathan Phillip Brink committed 61bb673

Add support for spell-checking the commit message.

  • Participants
  • Parent commits 8d0b842

Comments (0)

Files changed (2)

File repo-commit.1.in

 
 Ignored (provided for backwards compatibility).
 
+.IP "\fB-S\fP, \fB--no-spelling\fP"
+
+Disable attempt to check the commit message's spelling.
+
 .IP "\fB-t\fP, \fB--trivial\fP"
 
 Assume the changes are trivial and thus do not require a ChangeLog

File repo-commit.in

 	fi
 }
 
+# Check the spelling of the commit message if enabled
+check_spelling() {
+	if [ -n "${no_check_spelling}" ]; then
+		echo "${@}"
+		return
+	fi
+
+	local speller misspelled_words
+	for speller in "enchant -l -d en | cat" \
+		"aspell -l en list | cat" \
+		"hunspell -l -d en_US | hunspell -l -d en_GB" \
+		"ispell -l -denglish | ispell -l -dbritish"; do
+		if echo | ${speller%|*} | ${speller#*|} 2>/dev/null; then
+			misspelled_words=$(echo "${@}" | ${speller%|*} | ${speller#*|})
+			break
+		fi
+	done
+
+	local word expressions
+	for word in ${misspelled_words}; do
+		case ${word} in
+			[Ee]build|${SC_CP#*/}*|${SC_CP%/*})
+				continue
+				;;
+		esac
+		expressions="${expressions} -e s/\\(^\\|[^a-zA-Z]\\)\\(${word}\\)\\([^a-zA-Z]\\|\$\\)/\\1${RED}\\2${RESET}\\3/g"
+	done
+
+	# sed can't handle zero expressions.
+	if [ -z "${expressions}" ]; then
+		echo "${@}"
+		return
+	fi
+
+	echo "${@}" | sed ${expressions}
+}
+
 # Print the help message.
 print_help() {
 	cat <<_EOH_
 
 # Guess what!
 main() {
-	local commitmsg force monochrome noprepend noupdate trivial print_diff
+	local no_check_spelling commitmsg force monochrome noprepend noupdate \
+		trivial print_diff
 	unset SC_VERBOSE SC_WANT_CHANGELOG
 
 	# Command-line parsing.
 				;;
 			-q|--quiet)
 				;;
+			-S|--no-spelling)
+				no_check_spelling=1
+				;;
 			-t|--trivial)
 				trivial=1
 				;;
 			# In CVS, we don't prepend the package name to the commit message.
 			[ ${SC_VCS} = cvs ] && noprepend=
 
+			say "${BGREEN}Ready to commit using the following commit message:${RESET}"
+			say "${noprepend-${SC_CP}: }$(check_spelling "${commitmsg}")"
+
 			sayv "Now, let's let repoman do its job..."
 			exec repoman commit ${old_repoman--a} ${force+-f} -m "${noprepend-${SC_CP}: }${commitmsg}"
 			;;