From b525c785b4ca4218f3db8c7a8ead916e733b8b6d Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Sun, 31 Mar 2024 20:22:51 -0700 Subject: [PATCH] feat: used -b for clone --- git-clone/main.test.ts | 10 ++-------- git-clone/run.sh | 21 ++++++--------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/git-clone/main.test.ts b/git-clone/main.test.ts index cf11de5..8370e50 100644 --- a/git-clone/main.test.ts +++ b/git-clone/main.test.ts @@ -111,10 +111,7 @@ describe("git-clone", async () => { expect(output.exitCode).toBe(0); expect(output.stdout).toEqual([ "Creating directory ~/repo-tests.log...", - "Cloning https://github.com/michaelbrewer/repo-tests.log to ~/repo-tests.log...", - "Switch to branch feat/branch...", - "branch 'feat/branch' set up to track 'origin/feat/branch'.", - "/git", + "Cloning https://github.com/michaelbrewer/repo-tests.log to ~/repo-tests.log on branch feat/branch...", ]); }); @@ -127,10 +124,7 @@ describe("git-clone", async () => { expect(output.exitCode).toBe(0); expect(output.stdout).toEqual([ "Creating directory ~/repo-tests.log...", - "Cloning https://gitlab.com/mike.brew/repo-tests.log to ~/repo-tests.log...", - "Switch to branch feat/branch...", - "branch 'feat/branch' set up to track 'origin/feat/branch'.", - "/git", + "Cloning https://gitlab.com/mike.brew/repo-tests.log to ~/repo-tests.log on branch feat/branch...", ]); }); }); diff --git a/git-clone/run.sh b/git-clone/run.sh index ffb305a..bd80717 100755 --- a/git-clone/run.sh +++ b/git-clone/run.sh @@ -34,21 +34,12 @@ fi # Check if the directory is empty # and if it is, clone the repo, otherwise skip cloning if [ -z "$(ls -A "$CLONE_PATH")" ]; then - echo "Cloning $REPO_URL to $CLONE_PATH..." - git clone "$REPO_URL" "$CLONE_PATH" - - # Return the exit code of the last command - exit_code=$? - if [ $exit_code -ne 0 ]; then - exit $exit_code - fi - - # If BRANCH_NAME is set of a non-blank value, switch to that branch - if [ -n "$BRANCH_NAME" ]; then - echo "Switch to branch $BRANCH_NAME..." - cd "$CLONE_PATH" || exit 1 - git switch "$BRANCH_NAME" - cd - || exit 1 + if [ -z "$BRANCH_NAME" ]; then + echo "Cloning $REPO_URL to $CLONE_PATH..." + git clone "$REPO_URL" "$CLONE_PATH" + else + echo "Cloning $REPO_URL to $CLONE_PATH on branch $BRANCH_NAME..." + git clone "$REPO_URL" -b "$BRANCH_NAME" "$CLONE_PATH" fi else echo "$CLONE_PATH already exists and isn't empty, skipping clone!"