2017-04-18 09:29:05 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git rebase --signoff
|
|
|
|
|
|
|
|
This test runs git rebase --signoff and make sure that it works.
|
|
|
|
'
|
|
|
|
|
built-ins & libs & helpers: add/move destructors, fix leaks
Fix various leaks in built-ins, libraries and a test helper here we
were missing a call to strbuf_release(), string_list_clear() etc, or
were calling them after a potential "return".
Comments on individual changes:
- builtin/checkout.c: Fix a memory leak that was introduced in [1]. A
sibling leak introduced in [2] was recently fixed in [3]. As with [3]
we should be using the wt_status_state_free_buffers() API introduced
in [4].
- builtin/repack.c: Fix a leak that's been here since this use of
"strbuf_release()" was added in a1bbc6c0176 (repack: rewrite the shell
script in C, 2013-09-15). We don't use the variable for anything
except this loop, so we can instead free it right afterwards.
- builtin/rev-parse: Fix a leak that's been here since this code was
added in 21d47835386 (Add a parseopt mode to git-rev-parse to bring
parse-options to shell scripts., 2007-11-04).
- builtin/stash.c: Fix a couple of leaks that have been here since
this code was added in d4788af875c (stash: convert create to builtin,
2019-02-25), we strbuf_release()'d only some of the "struct strbuf" we
allocated earlier in the function, let's release all of them.
- ref-filter.c: Fix a leak in 482c1191869 (gpg-interface: improve
interface for parsing tags, 2021-02-11), we don't use the "payload"
variable that we ask parse_signature() to populate for us, so let's
free it.
- t/helper/test-fake-ssh.c: Fix a leak that's been here since this
code was added in 3064d5a38c7 (mingw: fix t5601-clone.sh,
2016-01-27). Let's free the "struct strbuf" as soon as we don't need
it anymore.
1. c45f0f525de (switch: reject if some operation is in progress,
2019-03-29)
2. 2708ce62d21 (branch: sort detached HEAD based on a flag,
2021-01-07)
3. abcac2e19fa (ref-filter.c: fix a leak in get_head_description,
2022-09-25)
4. 962dd7ebc3e (wt-status: introduce wt_status_state_free_buffers(),
2020-09-27).
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-11-08 18:17:42 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2017-04-18 09:29:05 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
git commit --allow-empty -m "Initial empty commit" &&
|
|
|
|
test_commit first file a &&
|
|
|
|
|
|
|
|
ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
|
2017-04-18 09:29:05 +00:00
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
# Expected commit message for initial commit after rebase --signoff
|
|
|
|
cat >expected-initial-signed <<-EOF &&
|
|
|
|
Initial empty commit
|
2018-03-20 11:10:55 +00:00
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
Signed-off-by: $ident
|
|
|
|
EOF
|
2018-03-20 11:10:55 +00:00
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
# Expected commit message after rebase --signoff
|
|
|
|
cat >expected-signed <<-EOF &&
|
|
|
|
first
|
2017-04-18 09:29:05 +00:00
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
Signed-off-by: $ident
|
|
|
|
EOF
|
2017-04-18 09:29:05 +00:00
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
# Expected commit message after rebase without --signoff (or with --no-signoff)
|
|
|
|
cat >expected-unsigned <<-EOF &&
|
|
|
|
first
|
|
|
|
EOF
|
2017-04-18 09:29:05 +00:00
|
|
|
|
2024-04-09 15:27:22 +00:00
|
|
|
git config alias.rbs "rebase --signoff"
|
|
|
|
'
|
2017-04-18 09:29:05 +00:00
|
|
|
|
|
|
|
# We configure an alias to do the rebase --signoff so that
|
|
|
|
# on the next subtest we can show that --no-signoff overrides the alias
|
|
|
|
test_expect_success 'rebase --signoff adds a sign-off line' '
|
|
|
|
git rbs HEAD^ &&
|
2024-04-09 15:27:23 +00:00
|
|
|
test_commit_message HEAD expected-signed
|
2017-04-18 09:29:05 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase --no-signoff does not add a sign-off line' '
|
|
|
|
git commit --amend -m "first" &&
|
|
|
|
git rbs --no-signoff HEAD^ &&
|
2024-04-09 15:27:23 +00:00
|
|
|
test_commit_message HEAD expected-unsigned
|
2017-04-18 09:29:05 +00:00
|
|
|
'
|
|
|
|
|
2018-03-20 11:10:55 +00:00
|
|
|
test_expect_success 'rebase --exec --signoff adds a sign-off line' '
|
|
|
|
test_when_finished "rm exec" &&
|
|
|
|
git commit --amend -m "first" &&
|
|
|
|
git rebase --exec "touch exec" --signoff HEAD^ &&
|
|
|
|
test_path_is_file exec &&
|
2024-04-09 15:27:23 +00:00
|
|
|
test_commit_message HEAD expected-signed
|
2018-03-20 11:10:55 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase --root --signoff adds a sign-off line' '
|
|
|
|
git commit --amend -m "first" &&
|
|
|
|
git rebase --root --keep-empty --signoff &&
|
2024-04-09 15:27:23 +00:00
|
|
|
test_commit_message HEAD^ expected-initial-signed &&
|
|
|
|
test_commit_message HEAD expected-signed
|
2018-03-20 11:10:55 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase -i --signoff fails' '
|
|
|
|
git commit --amend -m "first" &&
|
|
|
|
git rebase -i --signoff HEAD^ &&
|
2024-04-09 15:27:23 +00:00
|
|
|
test_commit_message HEAD expected-signed
|
2018-03-20 11:10:55 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase -m --signoff fails' '
|
|
|
|
git commit --amend -m "first" &&
|
|
|
|
git rebase -m --signoff HEAD^ &&
|
2024-04-09 15:27:23 +00:00
|
|
|
test_commit_message HEAD expected-signed
|
2018-03-20 11:10:55 +00:00
|
|
|
'
|
2017-04-18 09:29:05 +00:00
|
|
|
test_done
|