# Diff vs. shelf function diff_vs_shelf { local shelvedChange=${1:-} local workspace= local filesTmpFile= local diffTmpFile= local exitCode=0 if [[ -z "$shelvedChange" ]]; then workspace=$(p4 set -q P4CLIENT|cut -d= -f2) if [[ -n "$workspace" ]]; then shelvedChange=$(p4 -ztag -F %change% changes -s shelved -c "$workspace" -m 1) if [[ -z "$shelvedChange" ]]; then echo "Error: Could not determine shelf to diff against." return 1 fi else echo "Error: Could not determine current workspace." return 1 fi fi filesTmpFile=$(mktemp) p4 -ztag -F %depotFile% files "@=$shelvedChange" > "$filesTmpFile" if [[ -s "$filesTmpFile" ]]; then echo "Showing diffs for files in shelved change @$shelvedChange:" else echo "Error: No files found in change @$shelvedChange." return 1 fi diffTmpFile=$(mktemp) while read -r file; do p4 diff "$file@=$shelvedChange" > "$diffTmpFile" 2>&1 lineCount=$(wc -l "$diffTmpFile"| awk '{print $1}') if [[ "$lineCount" -gt 1 ]]; then if grep -q ^=== "$diffTmpFile"; then cat "$diffTmpFile" else echo "Error: Could not get diffs for $file@=$shelvedChange" exitCode=1 fi else if grep -q ^=== "$diffTmpFile"; then : No diffs. Do nothing. else echo "Error: Could not get diffs for $file@=$shelvedChange" exitCode=1 fi fi done < "$filesTmpFile" rm -f "$filesTmpFile" "$diffsTmpFile" return "$exitCode" } diff_vs_shelf "${1:-}"