fix deletion of branches stored in packed-refs broken since 29606af7a3a58767bf817a38035490899609d13e
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
diff --git a/lib/reference.c b/lib/reference.c
index c4723d5..c175b73 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -793,6 +793,7 @@ got_ref_list(struct got_reflist_head *refs, struct got_repository *repo,
{
const struct got_error *err;
char *packed_refs_path, *path_refs = NULL;
+ const char *ondisk_ref_namespace = NULL;
FILE *f = NULL;
struct got_reference *ref;
struct got_reflist_entry *new;
@@ -814,8 +815,9 @@ got_ref_list(struct got_reflist_head *refs, struct got_repository *repo,
goto done;
}
+ ondisk_ref_namespace = ref_namespace;
if (ref_namespace && strncmp(ref_namespace, "refs/", 5) == 0)
- ref_namespace += 5;
+ ondisk_ref_namespace += 5;
/* Gather on-disk refs before parsing packed-refs. */
free(path_refs);
@@ -825,7 +827,8 @@ got_ref_list(struct got_reflist_head *refs, struct got_repository *repo,
goto done;
}
err = gather_on_disk_refs(refs, path_refs,
- ref_namespace ? ref_namespace : "", repo, cmp_cb, cmp_arg);
+ ondisk_ref_namespace ? ondisk_ref_namespace : "", repo,
+ cmp_cb, cmp_arg);
if (err)
goto done;
diff --git a/regress/cmdline/branch.sh b/regress/cmdline/branch.sh
index 3b0f39a..1b883c4 100755
--- a/regress/cmdline/branch.sh
+++ b/regress/cmdline/branch.sh
@@ -248,6 +248,19 @@ function test_branch_delete {
return 1
fi
+ got ref -l -r $testroot/repo > $testroot/stdout
+ echo "HEAD: refs/heads/master" > $testroot/stdout.expected
+ echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
+ echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
+ echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
got branch -d bogus_branch_name -r $testroot/repo \
> $testroot/stdout 2> $testroot/stderr
ret="$?"
@@ -292,7 +305,76 @@ function test_branch_delete_current_branch {
test_done "$testroot" "$ret"
}
+function test_branch_delete_packed {
+ local testroot=`test_init branch_delete_packed`
+ local commit_id=`git_show_head $testroot/repo`
+
+ for b in branch1 branch2 branch3; do
+ got branch -r $testroot/repo $b
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got branch command failed unexpectedly"
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ done
+
+ (cd $testroot/repo && git pack-refs --all)
+
+ got branch -d branch2 -r $testroot/repo > $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got update command failed unexpectedly"
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got branch -l -r $testroot/repo > $testroot/stdout
+ echo " branch1: $commit_id" > $testroot/stdout.expected
+ echo " branch3: $commit_id" >> $testroot/stdout.expected
+ echo " master: $commit_id" >> $testroot/stdout.expected
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got ref -l -r $testroot/repo > $testroot/stdout
+ echo "HEAD: refs/heads/master" > $testroot/stdout.expected
+ echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
+ echo "refs/heads/branch3: $commit_id" >> $testroot/stdout.expected
+ echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ got branch -d bogus_branch_name -r $testroot/repo \
+ > $testroot/stdout 2> $testroot/stderr
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got update succeeded unexpectedly"
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "got: reference refs/heads/bogus_branch_name not found" \
+ > $testroot/stderr.expected
+ cmp -s $testroot/stderr $testroot/stderr.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_branch_create
run_test test_branch_list
run_test test_branch_delete
run_test test_branch_delete_current_branch
+run_test test_branch_delete_packed