commit - 5e08262609e4b99fae21c63ff12d7c9cbfc981e2
commit + a9c2d4c277afebe2aff309e7b43a32185fc37cd1
blob - 16044da028a60088852c19c49c0f5e341d3658b2
blob + 3cdf1de314061058b3bc30f1516b7688040143bf
--- got/got.c
+++ got/got.c
}
static const struct got_error *
-create_symref(const char *refname, struct got_reference *target_ref,
- int verbosity, struct got_repository *repo)
+create_symref(struct got_reference **head_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, refname, target_ref);
+ err = got_ref_alloc_symref(head_symref, refname, target_ref);
if (err)
return err;
- err = got_ref_write(head_symref, repo);
- got_ref_close(head_symref);
+ err = got_ref_write(*head_symref, repo);
if (err == NULL && verbosity > 0) {
printf("Created reference %s: %s\n", GOT_REF_HEAD,
got_ref_get_name(target_ref));
const char *uri, *dirname;
char *proto, *host, *port, *repo_name, *server_path;
char *default_destdir = NULL, *id_str = NULL;
- const char *repo_path, *remote_repo_path;
+ const char *repo_path;
struct got_repository *repo = NULL;
struct got_pathlist_head refs, symrefs, wanted_branches, wanted_refs;
struct got_pathlist_entry *pe;
ssize_t n;
int verbosity = 0, fetch_all_branches = 0, mirror_references = 0;
int list_refs_only = 0;
- struct got_reference *head_symref = NULL;
+ struct got_reference *default_head = NULL;
TAILQ_INIT(&refs);
TAILQ_INIT(&symrefs);
const char *refname = pe->path;
const char *target = pe->data;
char *remote_refname = NULL, *remote_target = NULL;
+ struct got_reference *head_symref;
if (strcmp(refname, GOT_REF_HEAD) != 0)
continue;
goto done;
}
- error = create_symref(refname, target_ref, verbosity, repo);
+ error = create_symref(&head_symref, refname, target_ref,
+ verbosity, repo);
got_ref_close(target_ref);
if (error)
goto done;
+ /* First HEAD reference listed is the default branch. */
+ if (default_head == NULL)
+ default_head = head_symref;
+ else
+ got_ref_close(head_symref);
+
if (mirror_references)
continue;
}
goto done;
}
- error = create_symref(remote_refname, target_ref,
- verbosity - 1, repo);
+ error = create_symref(&head_symref, remote_refname,
+ target_ref, verbosity - 1, repo);
free(remote_refname);
free(remote_target);
got_ref_close(target_ref);
+ got_ref_close(head_symref);
if (error)
goto done;
}
goto done;
}
- error = create_symref(GOT_REF_HEAD, target_ref,
- verbosity, repo);
+ error = create_symref(&default_head, GOT_REF_HEAD,
+ target_ref, verbosity, repo);
got_ref_close(target_ref);
if (error)
goto done;
goto done;
}
got_path_strip_trailing_slashes(server_path);
- remote_repo_path = server_path;
- while (remote_repo_path[0] == '/')
- remote_repo_path++;
if (asprintf(&gotconfig,
"remote \"%s\" {\n"
"\tserver %s\n"
"}\n",
GOT_FETCH_DEFAULT_REMOTE_NAME, host, proto,
port ? "\tport " : "", port ? port : "", port ? "\n" : "",
- remote_repo_path,
+ server_path,
mirror_references ? "\tmirror-references yes\n" : "") == -1) {
error = got_error_from_errno("asprintf");
goto done;
* If the server specified a default branch, use just that one.
* Otherwise fall back to fetching all branches on next fetch.
*/
- if (head_symref) {
- branchname = got_ref_get_symref_target(head_symref);
+ if (default_head) {
+ branchname = got_ref_get_symref_target(default_head);
if (strncmp(branchname, "refs/heads/", 11) == 0)
branchname += 11;
} else
error = got_error_from_errno("fclose");
if (repo)
got_repo_close(repo);
- if (head_symref)
- got_ref_close(head_symref);
+ if (default_head)
+ got_ref_close(default_head);
TAILQ_FOREACH(pe, &refs, entry) {
free((void *)pe->path);
free(pe->data);
blob - 7ad2a2f1a59a577580c1f8c552f7c07b5cbd9b76
blob + 090d275c54ed17e7ed475a292bfd074d1b4cec35
--- regress/cmdline/clone.sh
+++ regress/cmdline/clone.sh
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/heads/master:refs/remotes/origin/master
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/heads/foo:refs/remotes/origin/foo
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/heads/*:refs/remotes/origin/*
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+ mirror-references yes
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/*:refs/*
+ mirror = true
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+ mirror-references yes
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/*:refs/*
+ mirror = true
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/heads/master:refs/remotes/origin/master
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/heads/foo:refs/remotes/origin/foo
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
fi
+
+ cat > $testroot/got.conf.expected <<EOF
+remote "origin" {
+ server 127.0.0.1
+ protocol ssh
+ repository "$testroot/repo"
+ mirror-references yes
+}
+EOF
+ cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/got.conf.expected \
+ $testroot/repo-clone/got.conf
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cat > $testroot/config.expected <<EOF
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
+
+[remote "origin"]
+ url = ssh://127.0.0.1$testroot/repo
+ fetch = +refs/*:refs/*
+ mirror = true
+EOF
+ cmp -s $testroot/repo-clone/config $testroot/config.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/config.expected \
+ $testroot/repo-clone/config
+ fi
test_done "$testroot" "$ret"
}