From 0a1c807a0058fa589cb88fd875e1719de8325b5c Mon Sep 17 00:00:00 2001 From: Alix Fumoleau Date: Fri, 30 Apr 2021 12:19:51 +0200 Subject: [PATCH] Allow custom branch name in config (#3) * Allow custom branch name in config Co-authored-by: Alix Fumoleau Co-authored-by: spouzols --- README.md | 4 ++++ pms | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 224b1bd..1d59700 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ environment-file=something-else.json # Remote repository, optional # Used for load-remote to retrieve files to load into Postman cloud remote-repository=git@somehost.com:repo/project.git + +# Remote repository branch +# Required to use the remote repository +remote-repository-branch=main ``` ## Commands diff --git a/pms b/pms index 0382514..5191ef1 100755 --- a/pms +++ b/pms @@ -12,6 +12,7 @@ PROJECT_CONFIG_COLLECTION_NAME=collection-name PROJECT_CONFIG_ENVIRONMENT_FILE=environment-file PROJECT_CONFIG_ENVIRONMENT_NAME=environment-name PROJECT_CONFIG_REMOTE_REPOSITORY=remote-repository +PROJECT_CONFIG_REMOTE_REPOSITORY_BRANCH=remote-repository-branch configReadItem() { local default_value=${3:-""} @@ -84,10 +85,10 @@ loadEnvironment() { } remoteGitArchive() { - echo "Retrieving from remote repository $REMOTE_REPOSITORY" + echo "Retrieving from remote repository $REMOTE_REPOSITORY (branch $REMOTE_REPOSITORY_BRANCH)" local paths=("$@") if [ ${#paths[@]} -gt 0 ]; then - git archive --remote="$REMOTE_REPOSITORY" master "${paths[@]}" | tar -x + git archive --remote="$REMOTE_REPOSITORY" "$REMOTE_REPOSITORY_BRANCH" "${paths[@]}" | tar -x fi } @@ -115,6 +116,11 @@ loadRemote() { exit 2 fi + if [ -z "$REMOTE_REPOSITORY_BRANCH" ]; then + echo "No '${PROJECT_CONFIG_REMOTE_REPOSITORY_BRANCH}' configuration set." + exit 2 + fi + local paths=() if [ "${COLLECTION_NAME}" ]; then paths+=("${COLLECTION_FILE}") @@ -160,6 +166,7 @@ readProjectConfig() { ENVIRONMENT_FILE="$(projectConfigGet "${PROJECT_CONFIG_ENVIRONMENT_FILE}" "${PROJECT_NAME}.postman_environment.json")" ENVIRONMENT_NAME="$(projectConfigGet "${PROJECT_CONFIG_ENVIRONMENT_NAME}")" REMOTE_REPOSITORY="$(projectConfigGet "${PROJECT_CONFIG_REMOTE_REPOSITORY}")" + REMOTE_REPOSITORY_BRANCH="$(projectConfigGet "${PROJECT_CONFIG_REMOTE_REPOSITORY_BRANCH}")" } initProjectProperty() { @@ -195,6 +202,9 @@ init() { initProjectProperty "${PROJECT_CONFIG_ENVIRONMENT_FILE}" "Environment file name, leave empty to use default file name" "Environment file name: " fi initProjectProperty "${PROJECT_CONFIG_REMOTE_REPOSITORY}" "Enter remote git repository, optional" "Repository: " + if [ -n "${REPLY}" ]; then + initProjectProperty "${PROJECT_CONFIG_REMOTE_REPOSITORY_BRANCH}" "Enter remote git repository branch" "Branch name: " + fi fi echo "All set." }