Download raw body.
change got clone's got.conf default branch setting
The 'got clone' command generates a default configuration file which currently looks something like this: remote "origin" { server git.example.com protocol ssh repository "/repo.git" branch { "main" } } Where the "branch" directive applies to both 'got fetch' and 'got send'. This can result in the default branch being sent even when that is not what the user intended. For example, when 'got send -d foo' is used to delete branch "foo", the above config file makes this command equivalent to 'got send -d foo -b main'. The patch below avoids this issue in fresh clones by writing a got.conf like this instead: remote "origin" { server git.example.com protocol ssh repository "/repo.git" fetch { branch { "main" } } } If 'got send -d foo' is used with the above got.conf then it will really only delete branch "foo" and not send anything else. This is because we only get a default branch from the work tree or the repository if the -d option is not used. ok? make 'got clone' set a got.conf default branch for fetching only, not sending This will make 'got send' default to the work tree's current branch or the HEAD reference if not invokved in a work tree, rather than defaulting to sending the default branch found while cloning. M got/got.c | 8+ 2- M regress/cmdline/clone.sh | 27+ 9- M regress/cmdline/fetch.sh | 2+ 0- 3 files changed, 37 insertions(+), 11 deletions(-) commit - f4dfd849913b7ada5a3f441160a74efb8fc9978f commit + f22be008b3bcfcb429c4d49b10a76302b1d45110 blob - 80379bddab5170afe5c0e8cbb9bd21f4d8362982 blob + bd5af8c0b0571f83a5818af322e15e0785dee8f9 --- got/got.c +++ got/got.c @@ -1397,15 +1397,21 @@ create_gotconfig(const char *proto, const char *host, "\tprotocol %s\n" "%s%s%s" "\trepository \"%s\"\n" + "%s" "%s%s%s" + "%s" "%s%s%s" "%s" "%s" "}\n", GOT_FETCH_DEFAULT_REMOTE_NAME, host, proto, port ? "\tport " : "", port ? port : "", port ? "\n" : "", - remote_repo_path, branches ? "\tbranch { " : "", - branches ? branches : "", branches ? "}\n" : "", + remote_repo_path, + branches ? "\tfetch {\n" : "", + branches ? "\t\tbranch { " : "", + branches ? branches : "", + branches ? "}\n" : "", + branches ? "\t}\n" : "", refs ? "\treference { " : "", refs ? refs : "", refs ? "}\n" : "", mirror_references ? "\tmirror_references yes\n" : "", fetch_all_branches ? "\tfetch_all_branches yes\n" : "") == -1) { blob - 184a0cab35d28783c255c1494d78b1695189a105 blob + e9daec23e99eaee20166b09dfb7ebbde29181db1 --- regress/cmdline/clone.sh +++ regress/cmdline/clone.sh @@ -95,7 +95,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "master" } + fetch { + branch { "master" } + } } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected @@ -226,7 +228,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "foo" } + fetch { + branch { "foo" } + } } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected @@ -375,7 +379,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "master" } + fetch { + branch { "master" } + } mirror_references yes } EOF @@ -525,7 +531,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "master" } + fetch { + branch { "master" } + } reference { "hoo" } } EOF @@ -601,7 +609,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "foo" } + fetch { + branch { "foo" } + } reference { "hoo/boo/zoo" } } EOF @@ -674,7 +684,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "master" } + fetch { + branch { "master" } + } reference { "hoo" } mirror_references yes } @@ -748,7 +760,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "bar" "foo" } + fetch { + branch { "bar" "foo" } + } } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected @@ -830,7 +844,9 @@ remote "origin" { server 127.0.0.1 protocol ssh repository "$testroot/repo" - branch { "foo" } + fetch { + branch { "foo" } + } } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected @@ -975,7 +991,9 @@ remote "origin" { protocol http port $GOT_TEST_HTTP_PORT repository "/repo" - branch { "master" } + fetch { + branch { "master" } + } } EOF cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected blob - 9bda4d3b425e3cfc1eaf1893388d1c2ad82c2065 blob + aac6a219e2b443b516724c8444a2c326b6bdcf49 --- regress/cmdline/fetch.sh +++ regress/cmdline/fetch.sh @@ -485,9 +485,11 @@ test_fetch_all() { # remove default branch from got.conf, fetch all branches ed -s $testroot/repo-clone/got.conf <<-EOF + /fetch {/d /branch {/c fetch_all_branches yes . + /}/d w EOF
change got clone's got.conf default branch setting