|
|
#!/bin/sh # --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: bin/sde-commit # Copyright (C) 2006 - 2009 The OpenSDE Project # Copyright (C) 2004 - 2006 The T2 SDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END ---
#Description: Commits into svn the changes on the given locations #Alias: ci
[ -n "$SDEROOT" ] || export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
. $SDEROOT/lib/libsde.in
commit_usage() { local progname=${0##*/} cat <<EOT Usage: $progname [--file <message file>] [-m <message>] [FILES...] EOT }
commit_abort() { echo_error "Got SIGINT (Crtl-C)." rm -f $tmpfile.status $tmpfile.diff
[ -n "$logfile" -a "$logfile" != "$tmpfile.log" ] || rm -f "$logfile" exit 1 }
shortopts='F:m:s' longopts='file:' options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" ) if [ $? -ne 0 ]; then commit_usage exit -1 fi
# load new arguments list eval set -- "$options"
logfile= message= signed= tmpfile=$SDEROOT/tmp/$$
mkdir -p "$SDEROOT/tmp"
while [ $# -gt 0 ]; do case "$1" in -F|--file) logfile="`readlink -f $2 2> /dev/null`"; shift ;; -m) message="$2"; shift ;; -s) signed=true; shift ;;
--) shift; break ;; -*) echo_abort 1 "Unknown argument '$1', aborting." ;; *) break ;; esac shift done
if [ -n "$logfile" -a ! -r "$logfile" ]; then echo_abort 2 "File '$logfile' not found." fi
# validate locations # [ $# -gt 0 ] || set -- . # extract roots at root relative paths of the given locations locations=$( $SDEROOT/bin/sde-list-files --roots "$@" )
# we only accept one root at the time roots=$( echo "$locations" | cut -d' ' -f1 | sort -u ) root=$( echo "$roots" | head -n 1 ) [ "$root" = "$roots" ] || echo_abort 1 "Locations from multiple repositories given, aborting."
# $root relative locations locations=$( echo "$locations" | cut -d' ' -f2 ) [ -n "$locations" ] || echo_abort 1 "No locations, aborting."
# and here we go # trap 'commit_abort' INT
# on git we need an empty index # [ ! -d "$SDEROOT/$root/.git" ] || ( cd "$SDEROOT/$root/"; git reset > /dev/null )
# find changes on these locations, and apply copyright patch # - in the case of git working trees we populate the index # $SDEROOT/bin/sde-list-changes -C "$SDEROOT/$root" --status $locations | ( while read status file; do # work sitting on the root of the working tree cd "$SDEROOT/$root"
if [ -d ".git" ]; then # git status case "$status" in D) # deleted, tell the index git rm --quiet -- "$file" ;; M|?) # modified, update copyright note and add to the index $SDEROOT/bin/sde-patch-copyright -- "$file" git add -- "$file" ;; *) # unknown echo_warning "$file: has an unknown status ($status)" ;; esac elif [ -d ".svn" ]; then # svn status case "$status" in ?) # new file, add copyright note and `svn add` $SDEROOT/bin/sde-patch-copyright -- "$file" svn add -q -- "$file" ;; A|M) # modified or already added, update copyright note $SDEROOT/bin/sde-patch-copyright -- "$file" ;; *) # unknown echo_warning "$file: has an unknown status ($status)" ;; esac
fi done )
# and finally move to the root of the working tree cd "$SDEROOT/$root"
# cache stats and diff if [ -d ".git" ]; then # git status git diff-index -M --color --cached --stat=80,65 HEAD > $tmpfile.status git diff-index -M --color --cached -p HEAD | sed -e "s,^\(.\[1m\|\)\(---\|\+\+\+\) [ab]/,\1\2 $root/," > $tmpfile.diff
if [ -z "$logfile" -a -z "$message" ]; then logfile=$tmpfile.log git diff-index -M --cached -p HEAD | sed -e "s,^\(---\|\+\+\+\) [ab]/,\1 $root/," | gawk -f $SDEROOT/lib/sde-commit/commit-message.awk > $logfile fi elif [ -d ".svn" ]; then # svn status svn status -- $locations > $tmpfile.status svn diff -- $locations > $tmpfile.diff
if [ -z "$logfile" -a -z "$message" ]; then logfile=$tmpfile.log cat $tmpfile.diff | sed -e "s,^\(---\|\+\+\+\) [ab]/,\1 $root/," | gawk -f $SDEROOT/lib/sde-commit/commit-message.awk > $logfile fi else echo_abort 3 "$root: unknown version control system." fi
if [ -n "$message" ]; then logfile=$tmpfile.log echo "$message" > $logfile fi
if [ -s $tmpfile.diff -o -s $tmpfile.status ]; then
echo_msg "Changes:" cat $tmpfile.diff
echo_msg "Status:" cat $tmpfile.status
if [ -s "$logfile" -a -n "${signed:-}" -a -e '.git' ]; then cat <<-EOT >> $logfile
Signed-off-by: $(git config user.name) <$(git config user.email)> EOT fi
quit=0 until [ $quit -ne 0 ]; do
echo_msg "Commit Message:" if [ -s $logfile ]; then cat $logfile commit=",${COLOR_MESSAGE}c${COLOR_NORMAL}:commit" else echo_warning "\tEmpty Log File!" commit= fi
$ECHO_E -n "\n${COLOR_MESSAGE}Is the message ok?${COLOR_NORMAL}" $ECHO_E -n " (${COLOR_MESSAGE}q${COLOR_NORMAL}:quit,${COLOR_MESSAGE}e${COLOR_NORMAL}:edit,${COLOR_MESSAGE}d${COLOR_NORMAL}:diff,${COLOR_MESSAGE}s${COLOR_NORMAL}:status$commit)${COLOR_MESSAGE}:${COLOR_NORMAL} " read opt
case "$opt" in c*) if [ -z "$commit" ]; then # don't commit yet continue elif [ -d ".git" ]; then # git commit git commit ${signed:+-s} --file $logfile && rm "$logfile" ; quit=1 elif [ -d ".svn" ]; then # svn commit svn commit --file $logfile -- $locations && rm "$logfile" ; quit=1 fi ;; d*) ${PAGER:-less -R} $tmpfile.diff ;; s*) cat $tmpfile.status ;; e*) ${EDITOR:-vi} $logfile ;; q*) quit=1 ;; *) echo "Excuse me?" esac done else echo_warning "No changes detected." fi
rm -f $tmpfile.status $tmpfile.diff [ "$logfile" != "$tmpfile.log" ] || rm -f "$logfile"
|