commit 15d3c221e34cad474e87c43111417186822c887c from: Stefan Sperling date: Tue Jan 05 13:47:37 2021 UTC make 'got clone' pin the fetched branch in got.conf(5) Avoids relying on the server-side HEAD ref by default during future fetches. commit - 7a90b6809c18acd607a3ff752bb9a2462317c1f5 commit + 15d3c221e34cad474e87c43111417186822c887c blob - 0d05ef480cf0480004133b98b02d8a976c0dfbfb blob + 84e6393a0ccccffa54f45e6a0864788439cbf871 --- got/got.1 +++ 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 blob - 992f88fac5a3fcebfaabed859563cbf5a8498e4f blob + 1a0fbb720f4427b7c07a93e638a484560ec1d37b --- got/got.c +++ got/got.c @@ -1163,15 +1163,22 @@ create_wanted_ref(const char *refname, struct got_obje 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, "\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 *hos /* 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; blob - 090d275c54ed17e7ed475a292bfd074d1b4cec35 blob + 256c4fc96eab70d803e3a8535f61ceb993785db3 --- regress/cmdline/clone.sh +++ 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 blob - 86e2e5c79aab3d66e535352f2a388f4103e8a551 blob + 1fc5c95a555dfce8b88c9df9c019ea1ae8d57848 --- regress/cmdline/fetch.sh +++ 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" \