Commits

Michał Górny committed 99e90d0

Support printing a diff before committing.

Fixes: https://github.com/mgorny/repo-commit/issues/5

Comments (0)

Files changed (2)

 commit. This option only applies to Subversion and CVS repositories.
 It makes no sense to automatically pull from remote DVCS repositories.
 
+.IP "\fB--nodiff\fP"
+
+Display a complete diff against the previous revision before committing.
+
 .IP "\fB-f\fP, \fB--force\fP"
 
 Force proceeding with the commit even if QA violations occur. With
 	fi
 }
 
+# Request VCS to provide a verbose diff.
+vcs_diff() {
+	if [ ${SC_VCS} = git ]; then
+		git --no-pager diff HEAD -- ${1-.}
+	elif [ ${SC_VCS} = hg ]; then
+		hg diff -- ${1-.}
+	elif [ ${SC_VCS} = svn ]; then
+		svn diff -- "${@}"
+	elif [ ${SC_VCS} = cvs ]; then
+		cvs -n -q diff -u -p -- "${@}"
+	fi
+}
+
 # Add particular files to the repository.
 vcs_add() {
 	${SC_VCS} add -- "${@}"
 
 # Guess what!
 main() {
-	local commitmsg force monochrome noprepend noupdate trivial
+	local commitmsg force monochrome noprepend noupdate trivial print_diff
 	unset SC_VERBOSE SC_WANT_CHANGELOG
 
 	# Command-line parsing.
 			-d|--noupdate)
 				noupdate=1
 				;;
+			--diff)
+				print_diff=1
+				;;
 			-f|--force)
 				force=1
 				;;
 						if [ ! -f metadata.xml ]; then
 							req cp ../../skel.metadata.xml metadata.xml
 							# Output similar to echangelog.
-							diff -dup /dev/null metadata.xml
+							[ -n "${print_diff}" ] || diff -dup /dev/null metadata.xml
 							req vcs_add metadata.xml
 						fi
 					fi
 				echo
 			fi
 
-			if [ ${SC_VCS} != cvs ] || [ -n "${noupdate}" ]; then
+			if [ -n "${print_diff}" ]; then
+				vcs_diff
+			elif [ ${SC_VCS} != cvs ] || [ -n "${noupdate}" ]; then
 				vcs_status
 			fi
 			echo
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.