From b1db1e3e6fde191b65222097fb117dd1f77e8fe5 Mon Sep 17 00:00:00 2001 From: arturs Date: Sun, 7 Mar 2021 12:28:03 +0200 Subject: [PATCH 01/21] add git:unlock functionality --- docs/deployment/methods/git.md | 1 + plugins/git/help-functions | 1 + plugins/git/internal-functions | 38 ++++++++++++++++++++++++++++++---- plugins/git/subcommands/unlock | 6 ++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 plugins/git/subcommands/unlock diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index fdcfecb97..1a7678917 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -12,6 +12,7 @@ git:initialize # Initialize a git repository git:public-key # Outputs the dokku public deploy key git:report [] [] # Displays a git report for one or more apps git:set () # Set or clear a git property for an app +git:unlock # Removes previous git clone folder for new deployment ``` Git-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`. A Git-based deployment currently supports building applications via: diff --git a/plugins/git/help-functions b/plugins/git/help-functions index 42f64c255..2dcb432c5 100755 --- a/plugins/git/help-functions +++ b/plugins/git/help-functions @@ -36,5 +36,6 @@ fn-help-content() { git:public-key, Outputs the dokku public deploy key git:report [] [], Displays a git report for one or more apps git:set (), Set or clear a git property for an app + git:unlock , Removes previous git clone folder for new deployment help_content } diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index c3b05c7ae..e5297f15a 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -193,6 +193,20 @@ cmd-git-sync() { verify_app_name "$APP" + if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then + if [[ has_tty ]]; then + cmd-git-unlock "$APP" + if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then + dokku_log_fail "Failed to delete existing clone folder" + exit 15 + fi + else + dokku_log_fail "Missing tty, try running ssh -t which will allocate new tty for you" + fi + else + dokku_log_info1 "No need to unlock app, carrying on with build" + fi + if [[ -z "$GIT_REMOTE" ]]; then dokku_log_fail "Missing GIT_REMOTE parameter" return @@ -215,6 +229,26 @@ cmd-git-sync() { fi } +cmd-git-unlock() { + declare desc="removes the clone folder for an app" + local cmd="git:unlock" + [[ "$1" == "$cmd" ]] && shift 1 + declare APP + + APP="${ARGS[0]}" + + local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" + + if [[ -d "$APP_CLONE_ROOT" ]]; then + dokku_log_info1 "About to delete $APP_CLONE_ROOT" + rm -rf "$APP_CLONE_ROOT" + else + dokku_log_info1 "No clone folder exists app already unlocked" + fi + + dokku_log_info1 "Successfully unlocked $APP" +} + cmd-git-public-key() { declare desc="outputs the dokku public deploy key" local cmd="git:public-key" @@ -331,10 +365,6 @@ fn-git-clone() { dokku_log_fail "The clone subcommand can only be executed for new applications" fi - if [[ -d "$APP_CLONE_ROOT" ]]; then - dokku_log_fail "Clone in progress" - fi - if [[ -z "$GIT_REF" ]]; then GIT_REF="$(fn-git-deploy-branch "$APP")" fi diff --git a/plugins/git/subcommands/unlock b/plugins/git/subcommands/unlock new file mode 100644 index 000000000..ca256e1cc --- /dev/null +++ b/plugins/git/subcommands/unlock @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +cmd-git-unlock "$@" From 58dca68fb4e031debf02e0417a791558d6942ca9 Mon Sep 17 00:00:00 2001 From: arturs Date: Sun, 7 Mar 2021 15:29:07 +0200 Subject: [PATCH 02/21] fix has_tty if condition --- plugins/git/internal-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index e5297f15a..7c24f4652 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -194,7 +194,7 @@ cmd-git-sync() { verify_app_name "$APP" if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then - if [[ has_tty ]]; then + if has_tty eq 0 ; then cmd-git-unlock "$APP" if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then dokku_log_fail "Failed to delete existing clone folder" From 741ea68cac023ff6eee73115c0f4e108d959bb4a Mon Sep 17 00:00:00 2001 From: arturs Date: Sun, 7 Mar 2021 15:37:40 +0200 Subject: [PATCH 03/21] fix formatting according to shfmt --- plugins/git/internal-functions | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 7c24f4652..d571b185e 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -193,17 +193,17 @@ cmd-git-sync() { verify_app_name "$APP" - if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then - if has_tty eq 0 ; then - cmd-git-unlock "$APP" + if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then + if has_tty eq 0; then + cmd-git-unlock "$APP" if [[ -d "$DOKKU_LIB_ROOT/data/git/$APP" ]]; then - dokku_log_fail "Failed to delete existing clone folder" - exit 15 + dokku_log_fail "Failed to delete existing clone folder" + exit 15 fi - else - dokku_log_fail "Missing tty, try running ssh -t which will allocate new tty for you" + else + dokku_log_fail "Missing tty, try running ssh -t which will allocate new tty for you" fi - else + else dokku_log_info1 "No need to unlock app, carrying on with build" fi @@ -241,8 +241,8 @@ cmd-git-unlock() { if [[ -d "$APP_CLONE_ROOT" ]]; then dokku_log_info1 "About to delete $APP_CLONE_ROOT" - rm -rf "$APP_CLONE_ROOT" - else + rm -rf "$APP_CLONE_ROOT" + else dokku_log_info1 "No clone folder exists app already unlocked" fi From c05f220d14ae55942dd0fcef0d7afcf8927e02ea Mon Sep 17 00:00:00 2001 From: arturs Date: Tue, 9 Mar 2021 18:49:42 +0200 Subject: [PATCH 04/21] make unlock file exec --- plugins/git/subcommands/unlock | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 plugins/git/subcommands/unlock diff --git a/plugins/git/subcommands/unlock b/plugins/git/subcommands/unlock old mode 100644 new mode 100755 From 99bc51f106cd39fc82b39166a1d40643103de178 Mon Sep 17 00:00:00 2001 From: arturs Date: Wed, 10 Mar 2021 19:29:23 +0200 Subject: [PATCH 05/21] fix unlock command --- plugins/git/internal-functions | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index d571b185e..66ebdb20b 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -201,7 +201,7 @@ cmd-git-sync() { exit 15 fi else - dokku_log_fail "Missing tty, try running ssh -t which will allocate new tty for you" + dokku_log_fail "Missing tty, please run git:unlock command" fi else dokku_log_info1 "No need to unlock app, carrying on with build" @@ -233,20 +233,21 @@ cmd-git-unlock() { declare desc="removes the clone folder for an app" local cmd="git:unlock" [[ "$1" == "$cmd" ]] && shift 1 - declare APP - - APP="${ARGS[0]}" + declare APP="$1" local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" if [[ -d "$APP_CLONE_ROOT" ]]; then dokku_log_info1 "About to delete $APP_CLONE_ROOT" + chown dokku:dokku -R "$APP_CLONE_ROOT" + chmod 755 "$APP_CLONE_ROOT" rm -rf "$APP_CLONE_ROOT" + dokku_log_info1 "Successfully unlocked $APP" else dokku_log_info1 "No clone folder exists app already unlocked" fi - dokku_log_info1 "Successfully unlocked $APP" + } cmd-git-public-key() { From 642dc83702248c8718c08c7080be95528213062f Mon Sep 17 00:00:00 2001 From: arturs Date: Wed, 10 Mar 2021 20:31:44 +0200 Subject: [PATCH 06/21] fix lint issue --- plugins/git/internal-functions | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 66ebdb20b..6c558cbaa 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -247,7 +247,6 @@ cmd-git-unlock() { dokku_log_info1 "No clone folder exists app already unlocked" fi - } cmd-git-public-key() { From 5debadfde1ccff80be6db8a1cb5e3fb5ab55089a Mon Sep 17 00:00:00 2001 From: arturs Date: Wed, 10 Mar 2021 22:10:44 +0200 Subject: [PATCH 07/21] remove redundant code --- plugins/git/internal-functions | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 6c558cbaa..e2ec08af1 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -201,10 +201,8 @@ cmd-git-sync() { exit 15 fi else - dokku_log_fail "Missing tty, please run git:unlock command" + dokku_log_fail "Run 'git:unlock' to remove the existing temporary clone" fi - else - dokku_log_info1 "No need to unlock app, carrying on with build" fi if [[ -z "$GIT_REMOTE" ]]; then @@ -246,9 +244,7 @@ cmd-git-unlock() { else dokku_log_info1 "No clone folder exists app already unlocked" fi - } - cmd-git-public-key() { declare desc="outputs the dokku public deploy key" local cmd="git:public-key" From 5ae531ca2585e26802960806d3c77840ca0d55e7 Mon Sep 17 00:00:00 2001 From: arturs Date: Wed, 10 Mar 2021 22:58:40 +0200 Subject: [PATCH 08/21] remove unnecessary code --- plugins/git/internal-functions | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index e2ec08af1..a16dfb5a1 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -237,8 +237,6 @@ cmd-git-unlock() { if [[ -d "$APP_CLONE_ROOT" ]]; then dokku_log_info1 "About to delete $APP_CLONE_ROOT" - chown dokku:dokku -R "$APP_CLONE_ROOT" - chmod 755 "$APP_CLONE_ROOT" rm -rf "$APP_CLONE_ROOT" dokku_log_info1 "Successfully unlocked $APP" else From 8d11789566e8dc0c0e114c401e0a08caf3783783 Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 17:41:39 +0200 Subject: [PATCH 09/21] add tests and prompt to unlock --- plugins/git/internal-functions | 28 ++++++++++++++++++++++++---- tests/unit/git_6.bats | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 tests/unit/git_6.bats diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index a16dfb5a1..7b3a10d1c 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -231,14 +231,34 @@ cmd-git-unlock() { declare desc="removes the clone folder for an app" local cmd="git:unlock" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1" + declare APP="$1" FLAG + + for arg in "$@"; do + if [[ "$arg" == "--force" ]]; then + FLAG="--force" + continue + fi + + ARGS+=("$arg") + done local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" if [[ -d "$APP_CLONE_ROOT" ]]; then - dokku_log_info1 "About to delete $APP_CLONE_ROOT" - rm -rf "$APP_CLONE_ROOT" - dokku_log_info1 "Successfully unlocked $APP" + if [[ "$FLAG" == "--force" ]]; then + dokku_log_info1 "About to delete $APP_CLONE_ROOT" + rm -rf "$APP_CLONE_ROOT" + dokku_log_info1 "Successfully unlocked $APP" + else + read -rp "Are you sure that want to delete clone folder (y/n)?" choice + case "$choice" in + y|Y ) dokku_log_info1 "About to delete $APP_CLONE_ROOT" + rm -rf "$APP_CLONE_ROOT" + dokku_log_info1 "Successfully unlocked $APP";; + n|N ) echo "no";; + * ) echo "please answer with yes or no";; + esac + fi else dokku_log_info1 "No clone folder exists app already unlocked" fi diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats new file mode 100644 index 000000000..0635e662e --- /dev/null +++ b/tests/unit/git_6.bats @@ -0,0 +1,32 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app + touch /home/dokku/.ssh/known_hosts + chown dokku:dokku /home/dokku/.ssh/known_hosts + touch /home/dokku/data/git/$TEST_APP + +} + +teardown() { + rm -f /home/dokku/.ssh/id_rsa.pub || true + destroy_app + global_teardown +} + +@test "(git) git:unlock [succes]" { + run /bin/bash -c "dokku git:unlock $TEST_APP --force" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(git) git:unlock [missing]" { + run /bin/bash -c "dokku git:unlock + echo "output: $output" + echo "status: $status" + assert_failure +} \ No newline at end of file From 5a002f9007bc97ee22ba83d8f60188f60c48298f Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 17:45:41 +0200 Subject: [PATCH 10/21] update docs --- docs/deployment/methods/git.md | 2 +- plugins/git/help-functions | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index 1a7678917..53bd39506 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -12,7 +12,7 @@ git:initialize # Initialize a git repository git:public-key # Outputs the dokku public deploy key git:report [] [] # Displays a git report for one or more apps git:set () # Set or clear a git property for an app -git:unlock # Removes previous git clone folder for new deployment +git:unlock [--force] # Removes previous git clone folder for new deployment ``` Git-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`. A Git-based deployment currently supports building applications via: diff --git a/plugins/git/help-functions b/plugins/git/help-functions index 2dcb432c5..577239793 100755 --- a/plugins/git/help-functions +++ b/plugins/git/help-functions @@ -36,6 +36,6 @@ fn-help-content() { git:public-key, Outputs the dokku public deploy key git:report [] [], Displays a git report for one or more apps git:set (), Set or clear a git property for an app - git:unlock , Removes previous git clone folder for new deployment + git:unlock [--force], Removes previous git clone folder for new deployment help_content } From ebcacdb5af91b08d6b5ead45e1cde0bda74d2c8d Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 17:46:20 +0200 Subject: [PATCH 11/21] add new line at the end of the file --- tests/unit/git_6.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index 0635e662e..47b41bc11 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -29,4 +29,4 @@ teardown() { echo "output: $output" echo "status: $status" assert_failure -} \ No newline at end of file +} From 888f45254a9b0fac4c42de28ed737478da11344f Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 17:59:46 +0200 Subject: [PATCH 12/21] fix shfmt --- plugins/git/internal-functions | 30 ++++++++++++++++-------------- tests/unit/git_6.bats | 1 - 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 7b3a10d1c..f78eaa889 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -245,20 +245,22 @@ cmd-git-unlock() { local APP_CLONE_ROOT="$DOKKU_LIB_ROOT/data/git/$APP" if [[ -d "$APP_CLONE_ROOT" ]]; then - if [[ "$FLAG" == "--force" ]]; then - dokku_log_info1 "About to delete $APP_CLONE_ROOT" - rm -rf "$APP_CLONE_ROOT" - dokku_log_info1 "Successfully unlocked $APP" - else - read -rp "Are you sure that want to delete clone folder (y/n)?" choice - case "$choice" in - y|Y ) dokku_log_info1 "About to delete $APP_CLONE_ROOT" - rm -rf "$APP_CLONE_ROOT" - dokku_log_info1 "Successfully unlocked $APP";; - n|N ) echo "no";; - * ) echo "please answer with yes or no";; - esac - fi + if [[ "$FLAG" == "--force" ]]; then + dokku_log_info1 "About to delete $APP_CLONE_ROOT" + rm -rf "$APP_CLONE_ROOT" + dokku_log_info1 "Successfully unlocked $APP" + else + read -rp "Are you sure that want to delete clone folder (y/n)?" choice + case "$choice" in + y | Y) + dokku_log_info1 "About to delete $APP_CLONE_ROOT" + rm -rf "$APP_CLONE_ROOT" + dokku_log_info1 "Successfully unlocked $APP" + ;; + n | N) echo "no" ;; + *) echo "please answer with yes or no" ;; + esac + fi else dokku_log_info1 "No clone folder exists app already unlocked" fi diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index 47b41bc11..20e83d1cc 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -8,7 +8,6 @@ setup() { touch /home/dokku/.ssh/known_hosts chown dokku:dokku /home/dokku/.ssh/known_hosts touch /home/dokku/data/git/$TEST_APP - } teardown() { From dff21e1d36a25492ac8511c4470364fd93032259 Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 18:58:50 +0200 Subject: [PATCH 13/21] fix test --- tests/unit/git_6.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index 20e83d1cc..bfea83adf 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -24,7 +24,7 @@ teardown() { } @test "(git) git:unlock [missing]" { - run /bin/bash -c "dokku git:unlock + run /bin/bash -c "dokku git:unlock" echo "output: $output" echo "status: $status" assert_failure From 76d9b37b2200372d74f8dd5dcdaa7b83156896bb Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 19:19:59 +0200 Subject: [PATCH 14/21] fix typo --- tests/unit/git_6.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index bfea83adf..97ad0a749 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -16,14 +16,14 @@ teardown() { global_teardown } -@test "(git) git:unlock [succes]" { +@test "(git) git:unlock [success]" { run /bin/bash -c "dokku git:unlock $TEST_APP --force" echo "output: $output" echo "status: $status" assert_success } -@test "(git) git:unlock [missing]" { +@test "(git) git:unlock [missing arg]" { run /bin/bash -c "dokku git:unlock" echo "output: $output" echo "status: $status" From b061843eb1304a27889d87ee9a94c65b49aa18e1 Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 20:46:06 +0200 Subject: [PATCH 15/21] fix formatting issue --- docs/deployment/methods/git.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deployment/methods/git.md b/docs/deployment/methods/git.md index 53bd39506..b34897d59 100644 --- a/docs/deployment/methods/git.md +++ b/docs/deployment/methods/git.md @@ -12,7 +12,7 @@ git:initialize # Initialize a git repository git:public-key # Outputs the dokku public deploy key git:report [] [] # Displays a git report for one or more apps git:set () # Set or clear a git property for an app -git:unlock [--force] # Removes previous git clone folder for new deployment +git:unlock [--force] # Removes previous git clone folder for new deployment ``` Git-based deployment has been the traditional method of deploying applications in Dokku. As of v0.12.0, Dokku introduces a few ways to customize the experience of deploying via `git push`. A Git-based deployment currently supports building applications via: From 5c27ec31b7113e4ee54d56e5aa5addb89c29b549 Mon Sep 17 00:00:00 2001 From: arturs Date: Thu, 11 Mar 2021 21:55:32 +0200 Subject: [PATCH 16/21] add deploy command to tests --- tests/unit/git_6.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index 97ad0a749..7a0ddec69 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -5,6 +5,7 @@ load test_helper setup() { global_setup create_app + deploy_app touch /home/dokku/.ssh/known_hosts chown dokku:dokku /home/dokku/.ssh/known_hosts touch /home/dokku/data/git/$TEST_APP From 4e50214b80635158aaf0908cb37d425ca9fd1d89 Mon Sep 17 00:00:00 2001 From: arturs Date: Fri, 12 Mar 2021 08:25:55 +0200 Subject: [PATCH 17/21] remove redundant commands from test --- tests/unit/git_6.bats | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index 7a0ddec69..2683c5a4b 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -4,8 +4,6 @@ load test_helper setup() { global_setup - create_app - deploy_app touch /home/dokku/.ssh/known_hosts chown dokku:dokku /home/dokku/.ssh/known_hosts touch /home/dokku/data/git/$TEST_APP @@ -13,7 +11,6 @@ setup() { teardown() { rm -f /home/dokku/.ssh/id_rsa.pub || true - destroy_app global_teardown } From f9be3dd974f50a30306e8c8324a6b67bc207ea54 Mon Sep 17 00:00:00 2001 From: arturs Date: Fri, 12 Mar 2021 09:24:41 +0200 Subject: [PATCH 18/21] clean up remove clone folder fn --- plugins/git/internal-functions | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index f78eaa889..8ee375a93 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -246,16 +246,12 @@ cmd-git-unlock() { if [[ -d "$APP_CLONE_ROOT" ]]; then if [[ "$FLAG" == "--force" ]]; then - dokku_log_info1 "About to delete $APP_CLONE_ROOT" - rm -rf "$APP_CLONE_ROOT" - dokku_log_info1 "Successfully unlocked $APP" + fn-git-remove-clone-folder "$APP_CLONE_ROOT" else read -rp "Are you sure that want to delete clone folder (y/n)?" choice case "$choice" in y | Y) - dokku_log_info1 "About to delete $APP_CLONE_ROOT" - rm -rf "$APP_CLONE_ROOT" - dokku_log_info1 "Successfully unlocked $APP" + fn-git-remove-clone-folder "$APP_CLONE_ROOT" ;; n | N) echo "no" ;; *) echo "please answer with yes or no" ;; @@ -351,6 +347,13 @@ fn-git-auth-error() { dokku_log_fail "As an alternative, configure the netrc authentication via the git:auth command" } +fn-git-remove-clone-folder() { + declare APP_CLONE_ROOT="$1" + dokku_log_info1 "About to delete $APP_CLONE_ROOT" + rm -rf "$APP_CLONE_ROOT" + dokku_log_info1 "Successfully deleted $APP_CLONE_ROOT" +} + fn-git-create-hook() { declare APP="$1" local APP_PATH="$DOKKU_ROOT/$APP" From 4cd064f76cec0e7d242b22b60cd20ccc142ce14f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Mar 2021 02:53:28 -0500 Subject: [PATCH 19/21] chore: run shfmt against file --- plugins/git/internal-functions | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 8ee375a93..a803d7f5e 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -250,11 +250,11 @@ cmd-git-unlock() { else read -rp "Are you sure that want to delete clone folder (y/n)?" choice case "$choice" in - y | Y) - fn-git-remove-clone-folder "$APP_CLONE_ROOT" - ;; - n | N) echo "no" ;; - *) echo "please answer with yes or no" ;; + y | Y) + fn-git-remove-clone-folder "$APP_CLONE_ROOT" + ;; + n | N) echo "no" ;; + *) echo "please answer with yes or no" ;; esac fi else From 9781a905a7a94ef0142e244ed59abe983c3ab6aa Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Mar 2021 02:55:22 -0500 Subject: [PATCH 20/21] fix: create correct clone directory --- tests/unit/git_6.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index 2683c5a4b..fb0776649 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -6,7 +6,7 @@ setup() { global_setup touch /home/dokku/.ssh/known_hosts chown dokku:dokku /home/dokku/.ssh/known_hosts - touch /home/dokku/data/git/$TEST_APP + mkdir -p "$DOKKU_LIB_ROOT/data/git/$TEST_APP" } teardown() { @@ -15,7 +15,7 @@ teardown() { } @test "(git) git:unlock [success]" { - run /bin/bash -c "dokku git:unlock $TEST_APP --force" + run /bin/bash -c "dokku git:unlock $TEST_APP --force" echo "output: $output" echo "status: $status" assert_success From a901661e916955020894e915adf63644aab9550a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 12 Mar 2021 02:55:33 -0500 Subject: [PATCH 21/21] chore: set perms on tmp git directory --- tests/unit/git_6.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/git_6.bats b/tests/unit/git_6.bats index fb0776649..ab706a575 100644 --- a/tests/unit/git_6.bats +++ b/tests/unit/git_6.bats @@ -7,6 +7,7 @@ setup() { touch /home/dokku/.ssh/known_hosts chown dokku:dokku /home/dokku/.ssh/known_hosts mkdir -p "$DOKKU_LIB_ROOT/data/git/$TEST_APP" + chown dokku:dokku "$DOKKU_LIB_ROOT/data/git/$TEST_APP" } teardown() {