]> git.xonotic.org Git - xonotic/div0-gittools.git/blobdiff - git-identify-revision
proper error exit on no revision found
[xonotic/div0-gittools.git] / git-identify-revision
index 64e9495d681f7ab3a784ad8b6dc06c863cd142dc..b1abf9c05b6fbd4e6511ba1c453678c0e5ba6782 100755 (executable)
@@ -4,16 +4,38 @@
 # arguments: git rev-list arguments
 # we now identify the one revision with least differences
 
+usage()
+{
+       echo "Usage: $0 [--cached] git-rev-list args..."
+       echo
+       echo "Example: $0 --all"
+       echo "Compares current work tree to all revisions, and identifies the"
+       echo "closest match."
+       echo
+       echo "Example: $0 --cached v1.0..HEAD"
+       echo "Compares current work tree to all revisions between v1.0 and HEAD,"
+       echo "and identifies the closest match."
+}
+
 case "$1" in
        --cached)
                use_worktree=false
                shift
                ;;
+       --help|-h)
+               usage
+               exit 0
+               ;;
        *)
                use_worktree=true
                ;;
 esac
 
+if [ $# = 0 ]; then
+       usage >&2
+       exit 1
+fi
+
 diffopts="-M -C"
 
 if $use_worktree; then
@@ -39,9 +61,16 @@ for rev in $allrevs; do
                echo >&2 "Improved to $rev (score: $score)"
                bestrev=$rev
                bestrevscore=$score
+               if [ $score -eq 0 ]; then
+                       break
+               fi
        fi
 done
 echo >&2 "Done."
 
+if [ -z "$bestrevscore" ]; then
+       exit 1
+fi
+
 echo "$bestrev"
 git diff $diffopts --cached "$bestrev" >&2