Skip to content

Commit 2252e55

Browse files
committed
Merge branch 'test-tool-git-dir'
2 parents c0d2322 + feb9dbe commit 2252e55

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

t/helper/test-tool.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include "test-tool-utils.h"
44
#include "trace2.h"
55
#include "parse-options.h"
6+
#include "environment.h"
67

78
static const char * const test_tool_usage[] = {
8-
"test-tool [-C <directory>] <command [<arguments>...]]",
9+
"test-tool [-C <directory>] [--git-dir=<path>] <command [<arguments>...]]",
910
NULL
1011
};
1112

@@ -107,9 +108,12 @@ static NORETURN void die_usage(void)
107108
int cmd_main(int argc, const char **argv)
108109
{
109110
const char *working_directory = NULL;
111+
const char *git_dir = NULL;
110112
struct option options[] = {
111113
OPT_STRING('C', NULL, &working_directory, "directory",
112114
"change the working directory"),
115+
OPT_STRING(0, "git-dir", &git_dir, "path",
116+
"set the path to the repository"),
113117
OPT_END()
114118
};
115119

@@ -123,6 +127,8 @@ int cmd_main(int argc, const char **argv)
123127

124128
if (working_directory && chdir(working_directory) < 0)
125129
die("Could not cd to '%s'", working_directory);
130+
if (git_dir)
131+
setenv(GIT_DIR_ENVIRONMENT, git_dir, 1);
126132

127133
for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) {
128134
if (!strcmp(cmds[i].name, argv[1])) {

t/t1460-refs-migrate.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,32 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
88
. ./test-lib.sh
99

1010
print_all_reflog_entries () {
11-
repo=$1 &&
12-
test-tool -C "$repo" ref-store main for-each-reflog >reflogs &&
11+
repo_flag=$1 &&
12+
repo=$2 &&
13+
test-tool "$repo_flag" "$repo" ref-store main for-each-reflog >reflogs &&
1314
while read reflog
1415
do
1516
echo "REFLOG: $reflog" &&
16-
test-tool -C "$repo" ref-store main for-each-reflog-ent "$reflog" ||
17+
test-tool "$repo_flag" "$repo" ref-store main for-each-reflog-ent "$reflog" ||
1718
return 1
1819
done <reflogs
1920
}
2021

2122
# Migrate the provided repository from one format to the other and
2223
# verify that the references and logs are migrated over correctly.
23-
# Usage: test_migration <repo> <format> [<skip_reflog_verify> [<options...>]]
24+
# Usage: test_migration [--git-dir] <repo> <format> [<skip_reflog_verify> [<options...>]]
25+
# --git-dir: treat <repo> as a git directory (for bare repositories).
2426
# <repo> is the relative path to the repo to be migrated.
2527
# <format> is the ref format to be migrated to.
2628
# <skip_reflog_verify> (default: false) whether to skip reflog verification.
2729
# <options...> are other options be passed directly to 'git refs migrate'.
2830
test_migration () {
31+
repo_flag=-C &&
32+
if test "$1" = "--git-dir"
33+
then
34+
repo_flag=--git-dir &&
35+
shift
36+
fi &&
2937
repo=$1 &&
3038
format=$2 &&
3139
shift 2 &&
@@ -35,25 +43,25 @@ test_migration () {
3543
skip_reflog_verify=$1
3644
shift
3745
fi &&
38-
git -C "$repo" for-each-ref --include-root-refs \
46+
git "$repo_flag" "$repo" for-each-ref --include-root-refs \
3947
--format='%(refname) %(objectname) %(symref)' >expect &&
4048
if ! $skip_reflog_verify
4149
then
42-
print_all_reflog_entries "$repo" >expect_logs
50+
print_all_reflog_entries "$repo_flag" "$repo" >expect_logs
4351
fi &&
4452

45-
git -C "$repo" refs migrate --ref-format="$format" "$@" &&
53+
git "$repo_flag" "$repo" refs migrate --ref-format="$format" "$@" &&
4654

47-
git -C "$repo" for-each-ref --include-root-refs \
55+
git "$repo_flag" "$repo" for-each-ref --include-root-refs \
4856
--format='%(refname) %(objectname) %(symref)' >actual &&
4957
test_cmp expect actual &&
5058
if ! $skip_reflog_verify
5159
then
52-
print_all_reflog_entries "$repo" >actual_logs &&
60+
print_all_reflog_entries "$repo_flag" "$repo" >actual_logs &&
5361
test_cmp expect_logs actual_logs
5462
fi &&
5563

56-
git -C "$repo" rev-parse --show-ref-format >actual &&
64+
git "$repo_flag" "$repo" rev-parse --show-ref-format >actual &&
5765
echo "$format" >expect &&
5866
test_cmp expect actual
5967
}
@@ -144,7 +152,7 @@ do
144152
git init --ref-format=$from_format repo &&
145153
test_commit -C repo initial &&
146154
git clone --ref-format=$from_format --mirror repo repo.git &&
147-
test_migration repo.git "$to_format"
155+
test_migration --git-dir repo.git "$to_format"
148156
'
149157

150158
test_expect_success "$from_format -> $to_format: dangling symref" '

0 commit comments

Comments
 (0)