I've a script to perform git operations.
- Parse the file for the repo, source and new branch
- Clone the repo
- check if the new branch already exists. skip this repo if it does
- create new branch:
- cd into the folder
- git branch new_branch
- git checkout new_branch origin/source_branch
- git push origin new_branch
- print the status piping with tee (stdout and file)
- reset: cd out of the folder and delete the folder.
- next entry
The print to the file works only if I remove the 'cd' command. It print fine onto the stdout but not the file. Any idea why is 'cd' affecting the 'tee' ?
input.csv: repo,branch1,branch2, git@github.com/myproject/test-1.git, feature1, feature2, git@github.com/myproject/test-2.git, feature1, feature2,
Simplified script:
#!/bin/bash
BASE_DIR=`pwd`
INPUT_FILE_CSV=input.csv
OUTFILE="output.txt"
[ -e $OUTFILE ] && rm -f $OUTFILE
while IFS="," read -r REPO SRC_BRANCH NEW_BRANCH
do
echo "**********************Repo: ${REPO} **********************"
REPO_NAME=`echo $REPO | rev |cut -d '/' -f1 |rev | sed 's|.git||g'`
rm -rf $REPO_NAME
ERR=$(git clone -q $REPO)
if [ $? -eq 0 ]; then
#Logic to check if the branch exists
# cd $REPO_NAME
# Run few other git commands
echo "${REPO_NAME}; Success;" | tee -a $OUTFILE
cd $BASE_DIR
rm -rf $REPO_NAME
else
echo "${REPO_NAME}; Failure; ERR: ${ERR}" | tee -a $OUTFILE
fi
done < <(cut -d "," -f1,2,3 $INPUT_FILE_CSV | tail -n +2)
Expected output:
test1;Success;
test2;Failure;Err: $ERR
Current output:
test-1; Failure; ERR:
NOTE: The git URL in the input.csv aren't real/valid.