Skip to content

Instantly share code, notes, and snippets.

@in8finity
Created April 7, 2017 15:51
Show Gist options
  • Save in8finity/5b6554d64f256d39b4b3cfbbc8b253c9 to your computer and use it in GitHub Desktop.
Save in8finity/5b6554d64f256d39b4b3cfbbc8b253c9 to your computer and use it in GitHub Desktop.
BRANCH_NAME=feature/BACK-581-automatic-bills-generation-sverka
BASE_BRANCH=develop
TMP_DIR=/tmp/extractor/
EXTRACTED_FILES_LIST_FILE=$TMP_DIR/extracted_files.list
FULL_FILES_LIST_FILE=$TMP_DIR/full_files.list
TMP_FILES_LIST_FILE=$TMP_DIR/tmp_files.list
# creating and clening the temp folder
mkdir -p $TMP_DIR
rm -rf $TMP_DIR/*
echo -n "" > $FULL_FILES_LIST_FILE # позднее используется, для оставшихся файлов
echo -n "" > $EXTRACTED_FILES_LIST_FILE
# saving full files list in temporary file
git diff --name-only $BRANCH_NAME $BASE_BRANCH > $FULL_FILES_LIST_FILE
function extract(){
PATCH_NAME=$2
# extracting files by inclusive and exclusive regexps
FILES_FILTER_REGEX=$1
if [[ -z $3 ]] then
FILES_LIST=$(git diff --name-only $BASE_BRANCH $BRANCH_NAME | grep -e $FILES_FILTER_REGEX | grep -v $FILES_FILTER_REGEX )
else
FILES_LIST=$(git diff --name-only $BASE_BRANCH $BRANCH_NAME | grep -e $FILES_FILTER_REGEX )
fi
echo $FILES_LIST > $TMP_FILES_LIST_FILE # saving files list to temp file
# excluding files that already have been extracted
# echo $FILES_LIST # could be convenient to check files list
if [[ -s $EXTRACTED_FILES_LIST_FILE ]] then
FILES_LIST=$(grep -vxF -f $EXTRACTED_FILES_LIST_FILE $TMP_FILES_LIST_FILE)
fi
echo $FILES_LIST >> $EXTRACTED_FILES_LIST_FILE
echo "=== Extracted files ==="
echo $FILES_LIST
git log --pretty=email --patch-with-stat --reverse --full-index --binary $BASE_BRANCH..$BRANCH_NAME -- $(echo $FILES_LIST) > $TMP_DIR/$PATCH_NAME.patch
}
# extracting patches with args ( regex to include, patch name, regex to exclude )
extract 'locale' 'locale'
extract 'send' 'send'
extract 'collector' 'collector'
extract 'worker' 'worker' '.yml'
# setting FILES_LIST to list of files left after extraction
EXCLUDE_PATTERN=".yml"
FILES_LIST=$(sort $EXTRACTED_FILES_LIST_FILE $FULL_FILES_LIST_FILE | uniq -u | grep -v $EXCLUDE_PATTERN | grep '/')
git log --pretty=email --patch-with-stat --reverse --full-index --binary develop..HEAD -- $(echo $FILES_LIST) > $TMP_DIR/base.patch
echo "-------------------------------------------------------------------------"
echo "Results:"
echo $FILES_LIST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment