#!/bin/bash
#------------------------------------------------------------------------------
# Repro for: jobNNNNN
set -u
# Usage:
# ./repro.sh [-f] 2>&1 | tee repro.log
#
# Scenario: Rename And ReAdd Hell
export P4CONFIG=.p4config
export P4ENVIRO=/dev/null/.p4enviro
declare Version=1.0.0
# Micro functions.
function msg () { echo -e "${1:-Hi}"; }
function bail () { msg "Error: ${1:-Unknown Error}"; exit ${2:-1}; }
function cmd () { msg "${2:-Executing command: $1}"; $1; return $?; }
declare -i shiftArgs=0
declare -i Force=0
declare -i Scenario=1
declare ScenarioTitle=
declare StartPointD1=
declare StartPointD2=
#------------------------------------------------------------------------------
# Command Line Args
set +u; while [[ $# -gt 0 ]]; do
case $1 in
(-f) Force=1;;
(*) usageError "Unknown arg ($1).";;
esac
# Shift (modify $#) the appropriate number of times.
shift; while [[ $shiftArgs -gt 0 ]]; do
[[ $# -eq 0 ]] && usageError "Bad usage."
shiftArgs=$shiftArgs-1
shift
done
done
set -u
ReproDir=/tmp/repro
msg "Started ${0##*/} v$Version at $(date)."
msg "ReproDir=$ReproDir"
[[ -d $ReproDir && $Force -eq 1 ]] && /bin/rm -rf "$ReproDir"
[[ -d $ReproDir ]] && bail "Old repro dir [$ReproDir] exists."
mkdir $ReproDir
cd $ReproDir
msg "==============================================================================\nScenario $Scenario: $ScenarioTitle\n"
msg "\nPreliminary info: Show versions of p4/p4d on the PATH:"
cmd "p4 -V"
cmd "p4d -V"
msg "\nPreliminary setup: Spin up a local repo."
cmd "p4 init"
msg "\nAdd some files."
echo -e "// ONE_H\n#ifndef ONE_H\n#define ONE_H 1\n\n//Stuff goes here\n\n#endif //ONE_H\n" > One.h
echo -e "// TWO_H\n#ifndef TWO_H\n#define TWO_H 1\n\n//Stuff goes here\n\n#endif //TWO_H\n" > Two.h
cmd "p4 status"
msg "Reconcile and submit."
p4 rec && p4 submit -d "Added One.h and Two.h in main."
msg "\n== Dev Stream d1 =="
p4 stream -t development -P //stream/main -o //stream/d1 | p4 stream -i
cmd "p4 populate -f -r -S //stream/d1"
msg "\n== Dev Stream d2 =="
p4 stream -t development -P //stream/main -o //stream/d2 | p4 stream -i
cmd "p4 populate -f -r -S //stream/d2"
StartPointD1=$(p4 -ztag -F %change% changes -m 1 //stream/main/...)
msg "Start point of d1 on main is change @$StartPointD1."
cmd "p4 switch d1"
cmd "p4 switch"
msg "\nRename Two.h in d1 stream."
cmd "p4 move -r Two.h TheNumberTwo.h"
msg "Submitting."
p4 submit -d "Rename Two.h to TheNumberTwo.h in d1."
echo -e "// TWO_H\n#ifndef TWO_H\n#define TWO_H 1\n\n//Different Stuff goes here\n\n#endif //TWO_H\n" > Two.h
cmd "p4 add Two.h"
msg "Submitting."
p4 submit -d "Submitting Re-Add of new file."
msg "\nCopy to main\n"
cmd "p4 switch main"
cmd "p4 switch"
#cmd "p4 copy -S //stream/d1"
cmd "p4 integ //stream/d1/... //stream/main/..."
cmd "p4 resolve -as //stream/main/..."
msg "Submitting."
p4 submit -d "Submitting copy of up a \"double-dolby\" action, with a move/delete and re-add of a file."
cmd "p4 integ //stream/d1/... //stream/main/..."
cmd "p4 resolve -as"
cmd "p4 submit -d Part2."
cmd "ls" "What is here now:"
cmd "p4 switch d2"
cmd "p4 switch"
msg "Now for the Hell part, we merge to d2."
cmd "p4 merge"
cmd "p4 resolve -am"
cmd "p4 submit d3"
cmd "ls" "What is here now:"
msg "YIKES! Second merge after submit of first needed to get re-added file."
exit 0