make 'got clone' create refs/remotes/origin/HEAD, as 'git clone' does
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
diff --git a/got/got.c b/got/got.c
index 88e0035..b02072b 100644
--- a/got/got.c
+++ b/got/got.c
@@ -885,13 +885,13 @@ fetch_progress(void *arg, const char *message, off_t packfile_size,
}
static const struct got_error *
-create_head_ref(struct got_reference *target_ref, int verbosity,
- struct got_repository *repo)
+create_symref(const char *refname, struct got_reference *target_ref,
+ int verbosity, struct got_repository *repo)
{
const struct got_error *err;
struct got_reference *head_symref;
- err = got_ref_alloc_symref(&head_symref, GOT_REF_HEAD, target_ref);
+ err = got_ref_alloc_symref(&head_symref, refname, target_ref);
if (err)
return err;
@@ -1243,6 +1243,7 @@ cmd_clone(int argc, char *argv[])
goto done;
}
error = create_ref(remote_refname, id, verbosity - 1, repo);
+ free(remote_refname);
if (error)
goto done;
}
@@ -1252,6 +1253,7 @@ cmd_clone(int argc, char *argv[])
struct got_reference *target_ref;
const char *refname = pe->path;
const char *target = pe->data;
+ char *remote_refname = NULL, *remote_target = NULL;
if (strcmp(refname, GOT_REF_HEAD) != 0)
continue;
@@ -1265,7 +1267,44 @@ cmd_clone(int argc, char *argv[])
goto done;
}
- error = create_head_ref(target_ref, verbosity, repo);
+ error = create_symref(refname, target_ref, verbosity, repo);
+ got_ref_close(target_ref);
+ if (error)
+ goto done;
+
+ if (mirror_references)
+ continue;
+
+ if (strncmp("refs/heads/", target, 11) != 0)
+ continue;
+
+ if (asprintf(&remote_refname,
+ "refs/remotes/%s/%s", GOT_FETCH_DEFAULT_REMOTE_NAME,
+ refname) == -1) {
+ error = got_error_from_errno("asprintf");
+ goto done;
+ }
+ if (asprintf(&remote_target,
+ "refs/remotes/%s/%s", GOT_FETCH_DEFAULT_REMOTE_NAME,
+ target + 11) == -1) {
+ error = got_error_from_errno("asprintf");
+ free(remote_refname);
+ goto done;
+ }
+ error = got_ref_open(&target_ref, repo, remote_target, 0);
+ if (error) {
+ free(remote_refname);
+ free(remote_target);
+ if (error->code == GOT_ERR_NOT_REF) {
+ error = NULL;
+ continue;
+ }
+ goto done;
+ }
+ error = create_symref(remote_refname, target_ref,
+ verbosity - 1, repo);
+ free(remote_refname);
+ free(remote_target);
got_ref_close(target_ref);
if (error)
goto done;
@@ -1289,7 +1328,8 @@ cmd_clone(int argc, char *argv[])
goto done;
}
- error = create_head_ref(target_ref, verbosity, repo);
+ error = create_symref(GOT_REF_HEAD, target_ref,
+ verbosity, repo);
got_ref_close(target_ref);
if (error)
goto done;
diff --git a/regress/cmdline/clone.sh b/regress/cmdline/clone.sh
index 446d7b7..b188613 100755
--- a/regress/cmdline/clone.sh
+++ b/regress/cmdline/clone.sh
@@ -76,6 +76,8 @@ function test_clone_basic {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
@@ -175,6 +177,8 @@ function test_clone_all {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
@@ -282,6 +286,8 @@ function test_clone_reference {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
>> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
diff --git a/regress/cmdline/fetch.sh b/regress/cmdline/fetch.sh
index fb811d1..404c994 100755
--- a/regress/cmdline/fetch.sh
+++ b/regress/cmdline/fetch.sh
@@ -106,6 +106,8 @@ function test_fetch_basic {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id2" \
>> $testroot/stdout.expected
@@ -205,6 +207,8 @@ function test_fetch_branch {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
# refs/remotes/origin/master is umodified because it wasn't fetched
echo "refs/remotes/origin/master: $commit_id" \
@@ -243,6 +247,8 @@ function test_fetch_branch {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id2" \
>> $testroot/stdout.expected
@@ -280,6 +286,8 @@ function test_fetch_all {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
# refs/hoo/boo/zoo is missing because it is outside of refs/heads
@@ -305,6 +313,8 @@ function test_fetch_all {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
@@ -343,6 +353,8 @@ function test_fetch_empty_packfile {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
# refs/hoo/boo/zoo is missing because it is outside of refs/heads
@@ -369,6 +381,8 @@ function test_fetch_empty_packfile {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
@@ -408,6 +422,8 @@ function test_fetch_delete_branch {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" \
>> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
@@ -438,6 +454,8 @@ function test_fetch_delete_branch {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
@@ -475,6 +493,8 @@ function test_fetch_delete_branch {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
# refs/heads/foo is now deleted
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
>> $testroot/stdout.expected
@@ -524,6 +544,8 @@ function test_fetch_update_tag {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" \
>> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id" \
@@ -552,6 +574,8 @@ function test_fetch_update_tag {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id2" \
>> $testroot/stdout.expected
@@ -591,6 +615,8 @@ function test_fetch_update_tag {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id2" \
>> $testroot/stdout.expected
@@ -628,6 +654,8 @@ function test_fetch_update_tag {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id2" \
>> $testroot/stdout.expected
@@ -713,6 +741,8 @@ function test_fetch_reference {
echo "HEAD: refs/heads/master" > $testroot/stdout.expected
echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+ echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
+ >> $testroot/stdout.expected
echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
>> $testroot/stdout.expected
echo "refs/remotes/origin/master: $commit_id2" \