make 'got clone' pin the fetched branch in got.conf(5) Avoids relying on the server-side HEAD ref by default during future fetches.
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
diff --git a/got/got.1 b/got/got.1
index 0d05ef4..84e6393 100644
--- a/got/got.1
+++ b/got/got.1
@@ -193,6 +193,8 @@ and
.Pa config
files of the cloned repository to store the
.Ar repository-url
+and
+.Ar branch
for future use by
.Cm got fetch
or
diff --git a/got/got.c b/got/got.c
index 992f88f..1a0fbb7 100644
--- a/got/got.c
+++ b/got/got.c
@@ -1163,15 +1163,22 @@ create_wanted_ref(const char *refname, struct got_object_id *id,
static const struct got_error *
create_gotconfig(const char *proto, const char *host, const char *port,
- const char *remote_repo_path, int fetch_all_branches, int mirror_references,
- struct got_repository *repo)
+ const char *remote_repo_path, const char *default_branch,
+ int fetch_all_branches, int mirror_references, struct got_repository *repo)
{
const struct got_error *err = NULL;
char *gotconfig_path = NULL;
char *gotconfig = NULL;
FILE *gotconfig_file = NULL;
+ const char *branchname = NULL;
ssize_t n;
+ if (default_branch) {
+ branchname = default_branch;
+ if (strncmp(branchname, "refs/heads/", 11) == 0)
+ branchname += 11;
+ }
+
/* Create got.conf(5). */
gotconfig_path = got_repo_get_path_gotconfig(repo);
if (gotconfig_path == NULL) {
@@ -1189,11 +1196,15 @@ create_gotconfig(const char *proto, const char *host, const char *port,
"\tprotocol %s\n"
"%s%s%s"
"\trepository \"%s\"\n"
+ "%s%s%s"
"%s"
"}\n",
GOT_FETCH_DEFAULT_REMOTE_NAME, host, proto,
port ? "\tport " : "", port ? port : "", port ? "\n" : "",
remote_repo_path,
+ branchname ? "\tbranch { \"" : "",
+ branchname ? branchname : "",
+ branchname ? "\" }\n" : "",
mirror_references ? "\tmirror-references yes\n" : "") == -1) {
err = got_error_from_errno("asprintf");
goto done;
@@ -1321,7 +1332,7 @@ create_config_files(const char *proto, const char *host, const char *port,
/* Create got.conf(5). */
err = create_gotconfig(proto, host, port, remote_repo_path,
- fetch_all_branches, mirror_references, repo);
+ default_branch, fetch_all_branches, mirror_references, repo);
if (err)
return err;
diff --git a/regress/cmdline/clone.sh b/regress/cmdline/clone.sh
index 090d275..256c4fc 100755
--- a/regress/cmdline/clone.sh
+++ b/regress/cmdline/clone.sh
@@ -94,6 +94,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "master" }
}
EOF
cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
@@ -193,6 +194,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "foo" }
}
EOF
cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
@@ -268,6 +270,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "master" }
}
EOF
cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
@@ -338,6 +341,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "master" }
mirror-references yes
}
EOF
@@ -410,6 +414,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "master" }
mirror-references yes
}
EOF
@@ -486,6 +491,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "master" }
}
EOF
cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
@@ -558,6 +564,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "foo" }
}
EOF
cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
@@ -627,6 +634,7 @@ remote "origin" {
server 127.0.0.1
protocol ssh
repository "$testroot/repo"
+ branch { "master" }
mirror-references yes
}
EOF
diff --git a/regress/cmdline/fetch.sh b/regress/cmdline/fetch.sh
index 86e2e5c..1fc5c95 100755
--- a/regress/cmdline/fetch.sh
+++ b/regress/cmdline/fetch.sh
@@ -874,6 +874,25 @@ test_fetch_update_headref() {
got ref -l -r $testroot/repo-clone > $testroot/stdout
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
+
+ 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 fetch -q -r $testroot/repo-clone -a
+
+ got ref -l -r $testroot/repo-clone > $testroot/stdout
+
+ 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/foo" \