Commits

Nathan Phillip Brink committed 30b944f Merge

Merge branch 'spellcheck'

  • Participants
  • Parent commits ff6cb3a, 535b716

Comments (0)

Files changed (2)

 
 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
 	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|[Gg]entoo|[Gg]entoo-x86|${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
 				;;
 				if ! repoman full; then
 					[ -n "${force}" ] || die 'Please correct the problems shown by repoman.'
 				fi
-				confirm
 			fi
 
 			# 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}")"
+			${old_repoman+confirm}
+
 			sayv "Now, let's let repoman do its job..."
 			exec repoman commit ${old_repoman--a} ${force+-f} -m "${noprepend-${SC_CP}: }${commitmsg}"
 			;;
 				echo
 			fi
 
-			say "Ready to commit ${WHITE}$(echo ${SC_REMOVED_PACKAGE_LIST} | wc -w)${RESET} package removal(s), with commit message:"
-			say "${BGREEN}${SC_CP}: ${commitmsg}${RESET}"
+			say "${BGREEN}Ready to commit ${WHITE}$(echo ${SC_REMOVED_PACKAGE_LIST} | wc -w)${BGREEN} package removal(s), with commit message:${RESET}"
+			say "${SC_CP}: $(check_spelling "${commitmsg}")"
 			confirm
 
 			if [ -z "${noupdate}" ]; then