mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
Some checks failed
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-latest) (push) Has been cancelled
ci / commitlint (push) Has been cancelled
ci / format (push) Has been cancelled
ci / rumdl-check (push) Has been cancelled
ci / actionlint (push) Has been cancelled
Adds `$FORGIT_SWITCH_AUTO_CREATE_BRANCH` and `$FORGIT_CHECKOUT_BRANCH_AUTO_CREATE_BRANCH` environment variables that can be set to `false` to prevent `checkout_branch <BRANCH_NAME>` and `switch_brach <BRANCH_NAME>` from creating new branches when they do not exist. With the environment variables set to `false`, new branches can still be created explicitly using `switch_branch -c <BRANCH_NAME>` and `<checkout_branch> -c <BRANCH_NAME>` respectively.
51 lines
1.8 KiB
Bash
51 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
function set_up_before_script() {
|
|
source bin/git-forgit
|
|
|
|
# Ignore global git config files
|
|
export GIT_CONFIG_SYSTEM=/dev/null
|
|
export GIT_CONFIG_GLOBAL=/dev/null
|
|
|
|
# Create a temporary git repository for testing
|
|
cd "$(bashunit::temp_dir)" || return 1
|
|
git init -q
|
|
git config user.email "test@example.com"
|
|
git config user.name "Test User"
|
|
git commit -q --allow-empty -m "initial commit"
|
|
git branch existing-branch
|
|
}
|
|
|
|
function test_checkout_branch_creates_branch_when_it_does_not_exist() {
|
|
_forgit_checkout_branch auto-created-branch &>/dev/null
|
|
assert_exit_code "0"
|
|
assert_same "auto-created-branch" "$(git branch --show-current)"
|
|
}
|
|
|
|
function test_checkout_branch_does_not_create_branch_when_auto_create_is_disabled() {
|
|
FORGIT_CHECKOUT_BRANCH_AUTO_CREATE_BRANCH=false
|
|
_forgit_checkout_branch not-created-branch &>/dev/null
|
|
assert_exit_code "128"
|
|
assert_not_same "not-created-branch" "$(git branch --show-current)"
|
|
}
|
|
|
|
function test_checkout_branch_switches_to_existing_branch() {
|
|
_forgit_checkout_branch existing-branch &>/dev/null
|
|
assert_exit_code "0"
|
|
assert_same "existing-branch" "$(git branch --show-current)"
|
|
}
|
|
|
|
function test_checkout_branch_switches_to_existing_branch_when_auto_create_is_disabled() {
|
|
FORGIT_CHECKOUT_BRANCH_AUTO_CREATE_BRANCH=false
|
|
_forgit_checkout_branch existing-branch &>/dev/null
|
|
assert_exit_code "0"
|
|
assert_same "existing-branch" "$(git branch --show-current)"
|
|
}
|
|
|
|
function test_checkout_branch_creates_branch_when_requested_when_auto_create_is_disabled() {
|
|
FORGIT_CHECKOUT_BRANCH_AUTO_CREATE_BRANCH=false
|
|
_forgit_checkout_branch -c explicitly-created-branch &>/dev/null
|
|
assert_exit_code "0"
|
|
assert_same "explicitly-created-branch" "$(git branch --show-current)"
|
|
}
|