#!/bin/bash
set -u
export TestID=${1:-1}
export P4BIN=${2:-p4}
export P4PORT=${3:-1666}
export P4USER=${4:-bruno}
export P4CLIENT=TestWS.$TestID
export P4CONFIG=/tmp/.p4config.$TestID
declare ExitCode=
echo -e "Running Test $TestID\n$0 $*\n"
/bin/rm -f "$P4CONFIG"
echo -e "P4PORT=$P4PORT\nP4USER=$P4USER\nP4CLIENT=$P4CLIENT\nP4IGNORE=.p4ignore\nP4TICKETS=$PWD/.p4tickets\nP4ENVIRO=$PWD/.p4enviro\nP4TRUST=$PWD/.p4trust" > $P4CONFIG
echo -e "Wrote this P4CONFIG file $P4CONFIG:\n$(cat $P4CONFIG)"
RootDir=/tmp/$P4CLIENT
Stream="//jam/rel2.1"
TmpFile=/tmp/tmpFile.$TestID.$$.$RANDOM
/bin/rm -rf $RootDir
Cmd="$P4BIN client -df -Fs $P4CLIENT"
echo "Running: $Cmd"
$Cmd > /dev/null 2>&1 ||:
echo "Creating Workspace $P4CLIENT"
echo -e "Client: $P4CLIENT\n\nOwner: $P4USER\n\nDescription:\n\tCreated by $P4USER.\n\nRoot: $RootDir\n\nOptions: allwrite noclobber compress locked modtime normdir\n\nSubmitOptions: leaveunchanged\n\nLineEnd: local\n\nStream: $Stream\n\n" > $TmpFile
$P4BIN -s client -i < $TmpFile
if [[ $? -ne 0 ]]; then
echo -e "Failed to create workspace with this spec:\n$(cat $TmpFile)\n"
cat $TmpFile
exit 2
fi
mkdir -p $RootDir || exit 2
echo "Operating in: $PWD"
cd $RootDir || exit 2
Cmd="$P4BIN -s sync -f jam.cbdsst"
echo "Running: $Cmd"
$Cmd || exit 2
Cmd="$P4BIN -s edit jam.cbdsst"
echo "Running: $Cmd"
$Cmd || exit 2
Cmd="$P4BIN -s submit -d UPDATE_UNMODIFIED_FILE jam.cbdsst"
echo -e "Attempting to submit unmodified jam.cbdsst file.\nRunning: $Cmd"
$Cmd
ExitCode=$?
Cmd="$P4BIN -s revert jam.cbdsst"
echo -e "Silently reverting jam.cbdsst so a lock won't break the next test.\nRunning: $Cmd"
$Cmd > /dev/null 2>&1 ||:
# The exit code is for the 'p4 submit' command; that's what matters for this test.
exit $ExitCode