mirror of
https://github.com/git/git.git
synced 2026-10-02 19:57:11 +02:00
Reference-related functionality in Git is currently spread across many different commands: git-update-ref(1), git-for-each-ref(1), git-show-ref(1), git-pack-refs(1) and git-symbolic-ref(1). This makes it hard for users to discover what functionality we have available to work with references. We have thus started to consolidate this functionality into git-refs(1), which is a toolbox of everything related to references. Until now, the command doesn't handle functionality of git-update-ref(1). Fix this gap by introducing a new "delete" subcommand, which is the equivalent of `git update-ref -d`. Note that we're intentionally not using a generic "write" subcommand with a "-d" flag. This is rather harder to discover, and subcommands that are implmented as flags tend to be hard to reason about in the code as we'd have to handle mutually-exclusive flags that stem from the other subcommand-like modes. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
153 lines
3.9 KiB
Bash
Executable File
153 lines
3.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='git refs delete'
|
|
|
|
. ./test-lib.sh
|
|
|
|
setup_repo () {
|
|
git init "$1" &&
|
|
test_commit -C "$1" A &&
|
|
test_commit -C "$1" B
|
|
}
|
|
|
|
test_expect_success 'delete without oldvalue verification' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
git refs delete refs/heads/foo &&
|
|
test_must_fail git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete with matching oldvalue' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
git refs delete refs/heads/foo $A &&
|
|
test_must_fail git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete with stale oldvalue fails' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
B=$(git rev-parse B) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
test_must_fail git refs delete refs/heads/foo $B 2>err &&
|
|
test_grep " but expected " err &&
|
|
git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete with null oldvalue fails' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
test_must_fail git refs delete refs/heads/foo $ZERO_OID 2>err &&
|
|
test_grep "null old object ID" err &&
|
|
git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete with invalid oldvalue fails' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
test_must_fail git refs delete refs/heads/foo invalid-oid 2>err &&
|
|
test_grep "invalid old object ID" err &&
|
|
git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete symref with --no-deref leaves target intact' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
git symbolic-ref refs/heads/symref refs/heads/foo &&
|
|
git refs delete --no-deref refs/heads/symref &&
|
|
test_must_fail git refs exists refs/heads/symref &&
|
|
git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete symref with --no-deref verifies target OID' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
B=$(git rev-parse B) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
git symbolic-ref refs/heads/symref refs/heads/foo &&
|
|
|
|
test_must_fail git refs delete --no-deref refs/heads/symref $B &&
|
|
git refs exists refs/heads/symref &&
|
|
|
|
git refs delete --no-deref refs/heads/symref $A &&
|
|
test_must_fail git refs exists refs/heads/symref &&
|
|
git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete with message records reason in reflog' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
git symbolic-ref HEAD refs/heads/foo &&
|
|
git refs delete --message=delete-reason refs/heads/foo &&
|
|
test_must_fail git refs exists refs/heads/foo &&
|
|
test-tool ref-store main for-each-reflog-ent HEAD >actual &&
|
|
test_grep "delete-reason$" actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete with empty message fails' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
(
|
|
cd repo &&
|
|
A=$(git rev-parse A) &&
|
|
git update-ref refs/heads/foo $A &&
|
|
test_must_fail git refs delete --message= refs/heads/foo 2>err &&
|
|
test_grep "empty message" err &&
|
|
git refs exists refs/heads/foo
|
|
)
|
|
'
|
|
|
|
test_expect_success 'delete without arguments fails' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
test_must_fail git -C repo refs delete 2>err &&
|
|
test_grep "requires reference name" err
|
|
'
|
|
|
|
test_expect_success 'delete with too many arguments fails' '
|
|
test_when_finished "rm -rf repo" &&
|
|
setup_repo repo &&
|
|
test_must_fail git refs delete one two three 2>err &&
|
|
test_grep "requires reference name" err
|
|
'
|
|
|
|
test_done
|