From 88615ce19a85f0a9e76d3d0fa0a7b984faae9469 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Thu, 3 Oct 2024 01:09:24 -0700 Subject: [PATCH 1/9] Initial scaffold --- .gitmodules | 3 +++ tests/git-abort.bats | 63 ++++++++++++++++++++++++++++++++++++++++++++ tests/git-alias.bats | 21 +++++++++++++++ tests/test_util.sh | 33 +++++++++++++++++++++++ vendor/bats-all | 1 + 5 files changed, 121 insertions(+) create mode 100644 .gitmodules create mode 100644 tests/git-abort.bats create mode 100644 tests/git-alias.bats create mode 100644 tests/test_util.sh create mode 160000 vendor/bats-all diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..33dec902b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/bats-all"] + path = vendor/bats-all + url = https://github.com/hyperupcall/bats-all diff --git a/tests/git-abort.bats b/tests/git-abort.bats new file mode 100644 index 000000000..15b120d6b --- /dev/null +++ b/tests/git-abort.bats @@ -0,0 +1,63 @@ +# shellcheck shell=bash + +source "$BATS_TEST_DIRNAME/test_util.sh" + +setup_file() { + test_util.setup_file +} + +# This is ran before each "@test". +setup() { + # cd's to a temporary directory that is unique for each "@test". + test_util.cd_test + + # Do initialization (this code is copied from test_git_alias.py) + git init + git config --global alias.globalalias status + git config --global alias.x status + git config --local alias.localalias status + git config --local alias.y status +} + +@test "list all works" { + run git alias + + # This is one way to do it, most similar to the "test_list_all" test in + # test_git_alias.py. It's slightly more accurate because each substring + # must match a particular line of output (rather than matching any part of the output) + assert_line 'globalalias = status' + assert_line 'x = status' + assert_line 'localalias = status' + assert_line 'y = status' + + # To test the full output, this is one way: + assert_output 'globalalias = status +localalias = status +x = status +y = status' + + # One can use heredocs to also achieve this, which makes the test look a little nicer. Note that the indentation MUST BE DONE WITH TABS. + assert_output - <<-"EOF" + globalalias = status + localalias = status + x = status + y = status +EOF + + # I tend to put 'assert_success' at the bottom. This usually makes debugging easier because an "assert_output" written above will usuall fail first. This will cause the the output of the run command to be printed (instead of just the exit code). + # The downside to this is that sometimes there is a bug: An error "lines: parameter not set" will be shown instead (which is a Bats issue). + assert_success +} + +@test "list all global works" { + run git alias --global + + # One debugging technique for bats test I've found useful is to redirect to + # fd3. The variable "$output" is set by Bats, and it is the output of the previous "run" command (in this case, `git alias --global`). Here, we are printing it to fd3 for debugging. Naturally, be sure to run `exec 3>&1` (assuming you are running Bash or Zsh shell) in the terminal before running Bats. +# echo "$output" >&3 + + + assert_output 'globalalias = status +x = status' + assert_success +} diff --git a/tests/git-alias.bats b/tests/git-alias.bats new file mode 100644 index 000000000..d6d57ef82 --- /dev/null +++ b/tests/git-alias.bats @@ -0,0 +1,21 @@ +# shellcheck shell=bash + +source "$BATS_TEST_DIRNAME/test_util.sh" + +setup_file() { + test_util.setup_file +} + +setup() { + test_util.cd_test + + # Any extra setup goes here. +} + +@test "blah 1" { + : +} + +@test "blah 2" { + : +} diff --git a/tests/test_util.sh b/tests/test_util.sh new file mode 100644 index 000000000..4b2fed750 --- /dev/null +++ b/tests/test_util.sh @@ -0,0 +1,33 @@ +# shellcheck shell=bash + +# Bats has some very (official) nifty utility libraries to make testing easier. +# For example, `bats-support` adds `fail()` +# For example, `bats-assert` adds `assert()`, `assert_success`, `assert_output`. +# These helper functions: +# - _Significantly_ improve error messages (this is the main reason why I like to use these) +# - Make the test more semantic and readable (ex. assert_success reads better than [ $? == 0 ]) +# I created a repository that combines each of the three Bats utility libraries. This makes testing easier, but separate submodules for each Bats utility library can be crated (ex. vendor/bats-all, vendor/bats-support, vendor/bats-assert) +# This `load.bash` sources all Bats utility libraries +source "$BATS_TEST_DIRNAME/../vendor/bats-all/load.bash" + +# Various helper functions. I always prefix them with "test_util" so their intent and +# location of definition (this file) is obvious wherever they are used. + +test_util.setup_file() { + # Bats automatically sets 'set -e', so we don't have to do any "|| exit 1" stuff + cd "$BATS_FILE_TMPDIR" + + # Export some variables so Git neither reads nor mutates the users' Git config. + export GIT_CONFIG_NOSYSTEM=1 + export GIT_CONFIG_GLOBAL="$PWD/git_config" + # This removes default warning about default "master" branch on some Git versions. + git config --global init.defaultBranch main + + # Append to path so that we can access all commands included from git-extras + # TODO: This currently breaks with commands that are included in "not_needed_git_repo" etc. + PATH="$BATS_TEST_DIRNAME/../bin:$PATH" +} + +test_util.cd_test() { + cd "$BATS_TEST_TMPDIR" +} diff --git a/vendor/bats-all b/vendor/bats-all new file mode 160000 index 000000000..a16a4a2cf --- /dev/null +++ b/vendor/bats-all @@ -0,0 +1 @@ +Subproject commit a16a4a2cfa744878992a5f5d3f206319dba54158 From de552759ce3d01b8bffef9287acfd8155f08312c Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Thu, 28 Nov 2024 22:06:37 -0800 Subject: [PATCH 2/9] Finish first half of Bats tests --- .editorconfig | 8 +++ tests/git-abort.bats | 124 ++++++++++++++++++++++-------------- tests/git-alias.bats | 99 ++++++++++++++++++++++++++-- tests/git-archive-file.bats | 66 +++++++++++++++++++ tests/git-authors.bats | 52 +++++++++++++++ tests/test_util.sh | 31 +++------ 6 files changed, 304 insertions(+), 76 deletions(-) create mode 100644 tests/git-archive-file.bats create mode 100644 tests/git-authors.bats diff --git a/.editorconfig b/.editorconfig index bc1a4e7c0..b715678da 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,3 +20,11 @@ trim_trailing_whitespace = false [*.py] indent_size = 4 + +[*.bats] +indent_style = tab +indent_size = 4 + +[tests/*.sh] +indent_style = tab +indent_size = 4 diff --git a/tests/git-abort.bats b/tests/git-abort.bats index 15b120d6b..94f9f8d67 100644 --- a/tests/git-abort.bats +++ b/tests/git-abort.bats @@ -3,61 +3,91 @@ source "$BATS_TEST_DIRNAME/test_util.sh" setup_file() { - test_util.setup_file + test_util.setup_file } -# This is ran before each "@test". setup() { - # cd's to a temporary directory that is unique for each "@test". - test_util.cd_test - - # Do initialization (this code is copied from test_git_alias.py) - git init - git config --global alias.globalalias status - git config --global alias.x status - git config --local alias.localalias status - git config --local alias.y status + test_util.cd_test + + git init + git commit --allow-empty -m "Initial commit" + git branch A + git branch B + git checkout A + printf '%s\n' 'a' > tmpfile + git add . + git commit -m A + git checkout B + printf '%s\n' 'b' > tmpfile + git add . + git commit -m B + git status +} + +@test "cherry pick" { + run git cherry-pick A + assert_failure + + run git status + assert_line -p 'You are currently cherry-picking commit' + assert_line -p 'Unmerged paths:' + assert_success + + run git abort + assert_success + + run git status + assert_line -p 'nothing to commit, working tree clean' + assert_success +} + +@test "merge" { + run git merge A + assert_failure + + run git status + assert_line -p 'You have unmerged paths' + assert_line -p 'Unmerged paths:' + assert_success + + run git abort + assert_success + + run git status + assert_line -p 'nothing to commit, working tree clean' + assert_success } -@test "list all works" { - run git alias - - # This is one way to do it, most similar to the "test_list_all" test in - # test_git_alias.py. It's slightly more accurate because each substring - # must match a particular line of output (rather than matching any part of the output) - assert_line 'globalalias = status' - assert_line 'x = status' - assert_line 'localalias = status' - assert_line 'y = status' - - # To test the full output, this is one way: - assert_output 'globalalias = status -localalias = status -x = status -y = status' - - # One can use heredocs to also achieve this, which makes the test look a little nicer. Note that the indentation MUST BE DONE WITH TABS. - assert_output - <<-"EOF" - globalalias = status - localalias = status - x = status - y = status -EOF - - # I tend to put 'assert_success' at the bottom. This usually makes debugging easier because an "assert_output" written above will usuall fail first. This will cause the the output of the run command to be printed (instead of just the exit code). - # The downside to this is that sometimes there is a bug: An error "lines: parameter not set" will be shown instead (which is a Bats issue). - assert_success +@test "rebase" { + run git rebase A + assert_failure + + run git status + assert_line -p 'You are currently rebasing branch' + assert_line -p 'Unmerged paths:' + assert_success + + run git abort + assert_success + + run git status + assert_line -p 'nothing to commit, working tree clean' + assert_success } -@test "list all global works" { - run git alias --global +@test "revert" { + run git revert A + assert_failure - # One debugging technique for bats test I've found useful is to redirect to - # fd3. The variable "$output" is set by Bats, and it is the output of the previous "run" command (in this case, `git alias --global`). Here, we are printing it to fd3 for debugging. Naturally, be sure to run `exec 3>&1` (assuming you are running Bash or Zsh shell) in the terminal before running Bats. -# echo "$output" >&3 + run git status + assert_line -p 'You are currently reverting commit' + assert_line -p 'Unmerged paths:' + assert_success + run git abort + assert_success - assert_output 'globalalias = status -x = status' - assert_success + run git status + assert_line -p 'nothing to commit, working tree clean' + assert_success } diff --git a/tests/git-alias.bats b/tests/git-alias.bats index d6d57ef82..fa210a707 100644 --- a/tests/git-alias.bats +++ b/tests/git-alias.bats @@ -3,19 +3,104 @@ source "$BATS_TEST_DIRNAME/test_util.sh" setup_file() { - test_util.setup_file + test_util.setup_file } setup() { - test_util.cd_test + test_util.cd_test - # Any extra setup goes here. + git init + git config --global alias.globalalias status + git config --global alias.x status + git config --local alias.localalias status + git config --local alias.y status } -@test "blah 1" { - : +@test "list all works" { + run git alias + assert_output - <<-'EOF' + globalalias = status + localalias = status + x = status + y = status +EOF + assert_success } -@test "blah 2" { - : +@test "list all globally works" { + run git alias --global + assert_output - <<-'EOF' + globalalias = status + x = status +EOF + assert_success +} + +@test "list all locally works" { + run git alias --local + assert_output - <<-'EOF' + localalias = status + y = status +EOF + assert_success +} + +@test "search globally works" { + run git alias --global global + assert_output - <<-'EOF' + globalalias = status +EOF + assert_success + + run git alias --global local + assert_output '' + assert_failure +} + +@test "search locally works" { + run git alias --local local + assert_output - <<-'EOF' + localalias = status +EOF + assert_success + + run git alias --local global + assert_output '' + assert_failure +} + +@test "get alias globally and defaultly" { + run git alias globalalias + assert_output - <<-'EOF' + globalalias = status +EOF + assert_success +} + +@test "set alias globally and defaultly" { + git alias globalalias diff + run git alias diff + assert_output - <<-'EOF' + globalalias = diff +EOF + assert_success +} + +@test "get alias locally" { + run git alias --local localalias + assert_output - <<-'EOF' + localalias = status +EOF + assert_success +} + +@test "set alias locally" { + git alias --local localalias diff + run git alias + assert_output - <<-'EOF' + globalalias = status + localalias = diff + x = status + y = status +EOF } diff --git a/tests/git-archive-file.bats b/tests/git-archive-file.bats new file mode 100644 index 000000000..76cffd6eb --- /dev/null +++ b/tests/git-archive-file.bats @@ -0,0 +1,66 @@ +# shellcheck shell=bash + +source "$BATS_TEST_DIRNAME/test_util.sh" + +setup_file() { + test_util.setup_file +} + +setup() { + test_util.cd_test + + git init + printf '%s\n' 'data' > tmpfile + git add . + git commit -m 'test: add data' + git tag 0.1.0 -m 'bump: 0.1.0' +} + +@test "archive file on tags branch" { + git checkout -b tags0.1.0 + run git archive-file + assert_success + + local describe_output= + describe_output=$(git describe) + assert_file_exists "${PWD##*/}.$describe_output.zip" +} + +@test "archive file on any not tags branch without default branch" { + git checkout -b not-tags-branch + run git archive-file + assert_success + + local describe_output= + describe_output=$(git describe --always --long) + assert_file_exists "${PWD##*/}.$describe_output.not-tags-branch.zip" +} + +@test "archive file on any not tags branch with default branch" { + skip "Not working as expected" + + run git archive-file + assert_success + + local describe_output= + describe_output=$(git describe --always --long) + assert_file_exists "${PWD##*/}.$describe_output.zip" +} + +@test "archive file on branch name has slash" { + git checkout -b feature/slash + run git archive-file + assert_success + + local describe_output= + describe_output=$(git describe --always --long) + assert_file_exists "${PWD##*/}.$describe_output.feature-slash.zip" +} + +@test "archive file on dirname has backslash" { + skip +} + +@test "archive file on tag name has slash" { + skip +} diff --git a/tests/git-authors.bats b/tests/git-authors.bats new file mode 100644 index 000000000..16425db40 --- /dev/null +++ b/tests/git-authors.bats @@ -0,0 +1,52 @@ +# shellcheck shell=bash + +source "$BATS_TEST_DIRNAME/test_util.sh" + + +setup_file() { + test_util.setup_file +} + +setup() { + test_util.cd_test + + git init + git config --local user.name test + git config --local user.email test@example.com + printf '%s\n' 'A' > tmpfile + git add . + git commit -m 'test: add data A' + git config --local user.name testagain + git config --local user.email testagain@example.com + printf '%s\n' 'B' > tmpfile + git add . + git commit -m 'test: add data B' +} + +@test "output authors has email without any parameter" { + run git authors + assert_success + + local content=$(\ntestagain ' +} + +@test "list authors has email defaultly" { + run git authors --list + assert_output $'test \ntestagain ' + assert_success + + run git authors -l + assert_output $'test \ntestagain ' + assert_success +} + +@test "list authors has no email" { + run git authors --list --no-email + assert_output $'test\ntestagain' + assert_success + + run git authors -l --no-email + assert_output $'test\ntestagain' + assert_success +} diff --git a/tests/test_util.sh b/tests/test_util.sh index 4b2fed750..a34054342 100644 --- a/tests/test_util.sh +++ b/tests/test_util.sh @@ -1,33 +1,20 @@ # shellcheck shell=bash -# Bats has some very (official) nifty utility libraries to make testing easier. -# For example, `bats-support` adds `fail()` -# For example, `bats-assert` adds `assert()`, `assert_success`, `assert_output`. -# These helper functions: -# - _Significantly_ improve error messages (this is the main reason why I like to use these) -# - Make the test more semantic and readable (ex. assert_success reads better than [ $? == 0 ]) -# I created a repository that combines each of the three Bats utility libraries. This makes testing easier, but separate submodules for each Bats utility library can be crated (ex. vendor/bats-all, vendor/bats-support, vendor/bats-assert) -# This `load.bash` sources all Bats utility libraries source "$BATS_TEST_DIRNAME/../vendor/bats-all/load.bash" -# Various helper functions. I always prefix them with "test_util" so their intent and -# location of definition (this file) is obvious wherever they are used. - test_util.setup_file() { - # Bats automatically sets 'set -e', so we don't have to do any "|| exit 1" stuff - cd "$BATS_FILE_TMPDIR" + cd "$BATS_FILE_TMPDIR" - # Export some variables so Git neither reads nor mutates the users' Git config. - export GIT_CONFIG_NOSYSTEM=1 - export GIT_CONFIG_GLOBAL="$PWD/git_config" - # This removes default warning about default "master" branch on some Git versions. - git config --global init.defaultBranch main + export GIT_CONFIG_NOSYSTEM=1 + export GIT_CONFIG_GLOBAL="$PWD/git_config" + # This removes default warning about default "master" branch on some Git versions. + git config --global init.defaultBranch main - # Append to path so that we can access all commands included from git-extras - # TODO: This currently breaks with commands that are included in "not_needed_git_repo" etc. - PATH="$BATS_TEST_DIRNAME/../bin:$PATH" + # Append to path so that we can access all commands included from git-extras + # TODO: This currently breaks with commands that are included in "not_needed_git_repo" etc. + PATH="$BATS_TEST_DIRNAME/../bin:$PATH" } test_util.cd_test() { - cd "$BATS_TEST_TMPDIR" + cd "$BATS_TEST_TMPDIR" } From 505c57b3f7ea8dd3b54c3ed85cabd62932eee254 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Fri, 7 Mar 2025 00:40:07 -0800 Subject: [PATCH 3/9] Add Bats to CI --- .github/workflows/ci.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbe0153f5..70fcd4031 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,12 +47,20 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.12' - - name: Install dependencies + - name: Install Python Dependencies run: | python -m pip install --upgrade pip pip install pytest==8.1.2 GitPython==3.1.43 testpath==0.6.0 - - name: Unit test + - name: Setup Bats and bats libs + id: setup-bats + uses: bats-core/bats-action@3.0.0 + - name: Test with Pytest run: make test + - name: Test with Bats + env: + BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }} + TERM: xterm + run: bats ./tests build: strategy: From bc946fd98c230bbae2daf4e9bc7e835904d3538e Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Fri, 7 Mar 2025 00:45:45 -0800 Subject: [PATCH 4/9] Fix CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1304aed1a..403ee70e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,7 @@ jobs: steps: - uses: actions/checkout@v4 + submodules: recursive - name: Install poetry run: pip install poetry - name: Set up Python From 2a9fed3ada18eea4756fe3187bee676c1ce93aa8 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 9 Mar 2025 23:15:58 -0700 Subject: [PATCH 5/9] Fix CI --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 403ee70e5..b0257c95b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,8 @@ jobs: steps: - uses: actions/checkout@v4 - submodules: recursive + with: + submodules: recursive - name: Install poetry run: pip install poetry - name: Set up Python From ddf23713b1bf81f6962ab06c16986a9156c84669 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 9 Mar 2025 23:26:56 -0700 Subject: [PATCH 6/9] Fix configuration to set git name and email --- tests/test_util.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_util.sh b/tests/test_util.sh index a34054342..c92cb3749 100644 --- a/tests/test_util.sh +++ b/tests/test_util.sh @@ -7,8 +7,14 @@ test_util.setup_file() { export GIT_CONFIG_NOSYSTEM=1 export GIT_CONFIG_GLOBAL="$PWD/git_config" + export GIT_CONFIG_COUNT=3 + export GIT_CONFIG_KEY_2="user.email" + export GIT_CONFIG_VALUE_2="name@example.com" + export GIT_CONFIG_KEY_3="user.name" + export GIT_CONFIG_VALUE_3="Name" # This removes default warning about default "master" branch on some Git versions. - git config --global init.defaultBranch main + export GIT_CONFIG_KEY_1="init.defaultBranch" + export GIT_CONFIG_VALUE_1="main" # Append to path so that we can access all commands included from git-extras # TODO: This currently breaks with commands that are included in "not_needed_git_repo" etc. From cc3141b73332f1ff47b3b588445bdaedeb4c0ea2 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 9 Mar 2025 23:28:39 -0700 Subject: [PATCH 7/9] Fix `GIT_CONFIG_{KEY,VALUE}` indexing --- tests/test_util.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_util.sh b/tests/test_util.sh index c92cb3749..73ca915ad 100644 --- a/tests/test_util.sh +++ b/tests/test_util.sh @@ -8,13 +8,13 @@ test_util.setup_file() { export GIT_CONFIG_NOSYSTEM=1 export GIT_CONFIG_GLOBAL="$PWD/git_config" export GIT_CONFIG_COUNT=3 - export GIT_CONFIG_KEY_2="user.email" - export GIT_CONFIG_VALUE_2="name@example.com" - export GIT_CONFIG_KEY_3="user.name" - export GIT_CONFIG_VALUE_3="Name" + export GIT_CONFIG_KEY_0="user.email" + export GIT_CONFIG_VALUE_0="name@example.com" + export GIT_CONFIG_KEY_1="user.name" + export GIT_CONFIG_VALUE_1="Name" # This removes default warning about default "master" branch on some Git versions. - export GIT_CONFIG_KEY_1="init.defaultBranch" - export GIT_CONFIG_VALUE_1="main" + export GIT_CONFIG_KEY_2="init.defaultBranch" + export GIT_CONFIG_VALUE_2="main" # Append to path so that we can access all commands included from git-extras # TODO: This currently breaks with commands that are included in "not_needed_git_repo" etc. From e48665ec24a5dd87a1d01d59293a589241aa2dfd Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 9 Mar 2025 23:48:21 -0700 Subject: [PATCH 8/9] Fix Git config override precedence --- tests/git-authors.bats | 8 ++++---- tests/test_util.sh | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/git-authors.bats b/tests/git-authors.bats index 16425db40..203a88275 100644 --- a/tests/git-authors.bats +++ b/tests/git-authors.bats @@ -11,13 +11,13 @@ setup() { test_util.cd_test git init - git config --local user.name test - git config --local user.email test@example.com + GIT_CONFIG_VALUE_0='test@example.com' + GIT_CONFIG_VALUE_1='test' printf '%s\n' 'A' > tmpfile git add . git commit -m 'test: add data A' - git config --local user.name testagain - git config --local user.email testagain@example.com + GIT_CONFIG_VALUE_0='testagain@example.com' + GIT_CONFIG_VALUE_1='testagain' printf '%s\n' 'B' > tmpfile git add . git commit -m 'test: add data B' diff --git a/tests/test_util.sh b/tests/test_util.sh index 73ca915ad..865a9ab12 100644 --- a/tests/test_util.sh +++ b/tests/test_util.sh @@ -24,3 +24,22 @@ test_util.setup_file() { test_util.cd_test() { cd "$BATS_TEST_TMPDIR" } + +test_util.set_git_config_env() { + local -a varkeys=() + readarray -t varkeys <(POSIXLY_CORRECT=1 set) + for line in "${varkeys[@]}"; do + if [[ $line =~ ^(GIT_CONFIG_KEY|GIT_CONFIG_VALUE) ]]; then + unset -v "${line%%=*}" + fi + done + + local -n configobj="$1" + local idx=0 + for key in "${!configobj[@]}"; do + export "GIT_CONFIG_KEY_$idx=$key" + export "GIT_CONFIG_VALUE_$idx=${configobj[$key]}" + ((idx += 1)) + done + export GIT_CONFIG_COUNT="${#configobj[@]}" +} From efb804d0bc3e9a5ca35e346fe5ab3cf57950c724 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 9 Mar 2025 23:50:01 -0700 Subject: [PATCH 9/9] Remove unused and untested function --- tests/test_util.sh | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/test_util.sh b/tests/test_util.sh index 865a9ab12..73ca915ad 100644 --- a/tests/test_util.sh +++ b/tests/test_util.sh @@ -24,22 +24,3 @@ test_util.setup_file() { test_util.cd_test() { cd "$BATS_TEST_TMPDIR" } - -test_util.set_git_config_env() { - local -a varkeys=() - readarray -t varkeys <(POSIXLY_CORRECT=1 set) - for line in "${varkeys[@]}"; do - if [[ $line =~ ^(GIT_CONFIG_KEY|GIT_CONFIG_VALUE) ]]; then - unset -v "${line%%=*}" - fi - done - - local -n configobj="$1" - local idx=0 - for key in "${!configobj[@]}"; do - export "GIT_CONFIG_KEY_$idx=$key" - export "GIT_CONFIG_VALUE_$idx=${configobj[$key]}" - ((idx += 1)) - done - export GIT_CONFIG_COUNT="${#configobj[@]}" -}