Skip to content

Commit

Permalink
PMIPA-5160 Upgrade repo_initialization with optional args
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldsdias authored May 23, 2024
1 parent 2f966f5 commit 20cd4c9
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions tools/repo_initialization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# copy it to your repository and run it to install
# repo_setup and the hooks common to the repositories.
#
# Optional args:
#
# --no-hooks: Don't download and install hooks
# --no-repo-setup-run: Don't run repo_setup.py
# -------------------------------------------------------

# Log and exit with 1
Expand Down Expand Up @@ -32,7 +36,7 @@ function add_to_gitignore() {
if grep -Fxq "$filename" .gitignore; then
echo "$filename already on .gitignore."
else
echo "$filename" >> .gitignore
echo "$filename" >>.gitignore
echo "$filename added to .gitignore."
fi
}
Expand Down Expand Up @@ -63,25 +67,47 @@ function download_from_tools_on_mamba_sdk() {
add_to_gitignore $FILE_TO_DOWNLOAD
}

# Download and install file from tools folder of repo stone-payments/pos-mamba-sdk/tools
# Run file from tools folder of repo stone-payments/pos-mamba-sdk/tools
#
# Usage:
# download_and_install <string1> <string2>
# run_file <string1>
#
# Args:
# string1 - File path to run.
#
# Note: string2 is optional, if it is not passed then "." It will be used.
function run_file() {
if [ "$#" -lt 1 ]; then
log_fatal "Param error: No files were provided"
fi
chmod +x $(git rev-parse --show-toplevel)/$1
$(git rev-parse --show-toplevel)/$1
}

# Download and run file from tools folder of repo stone-payments/pos-mamba-sdk/tools
#
# Usage:
# download_and_run <string1> <string2>
#
# Args:
# string1 - Relative file path on repo to be downloaded.
# string2 (optional) - Relative folder path on repo to be saved.
#
# Note: string2 is optional, if it is not passed then "." It will be used.
function download_and_install() {
function download_and_run() {
if [ "$#" -lt 1 ]; then
log_fatal "Param error: No files were provided"
fi
download_from_tools_on_mamba_sdk $@
chmod +x $(git rev-parse --show-toplevel)/$1
$(git rev-parse --show-toplevel)/$1
run_file $1
}

download_from_tools_on_mamba_sdk _git_hooks/post-checkout _git_hooks
download_and_install _git_hooks/install-hooks.sh _git_hooks
download_and_install repo_setup.py
if [[ "$@" != *"--no-hooks"* ]]; then
download_from_tools_on_mamba_sdk _git_hooks/post-checkout _git_hooks
download_and_run _git_hooks/install-hooks.sh _git_hooks
fi

download_from_tools_on_mamba_sdk repo_setup.py
if [[ "$@" != *"--no-repo-setup-run"* ]]; then
run_file repo_setup.py
fi

0 comments on commit 20cd4c9

Please sign in to comment.