diff --git a/eden/scm/edenscm/git.py b/eden/scm/edenscm/git.py index 917513fb01cea..c8506956dc5b1 100644 --- a/eden/scm/edenscm/git.py +++ b/eden/scm/edenscm/git.py @@ -21,7 +21,7 @@ import bindings from edenscm import tracing -from . import bookmarks as bookmod, error, identity, progress, util +from . import bookmarks as bookmod, error, identity, progress, util, rcutil from .i18n import _ from .node import bin, hex, nullid @@ -153,6 +153,16 @@ def clone(ui, url, destpath=None, update=True, pullnames=None): # If `git ls-remote --symref HEAD` failed to yield a name, # fall back to the using the names in the config. pullnames = bookmod.selectivepullbookmarknames(repo) + default_publicheads = repo.ui.config('remotenames', + 'publicheads').split(',') # ['remote/master', 'remote/main'] + remote_publicheads = ['remote/' + path for path in pullnames] + all_publicheads = ','.join(sorted(set(default_publicheads + remote_publicheads))) + + configfilename = repo.ui.identity.configrepofile() + rcutil.editconfig(repo.ui, + repo.localvfs.join(configfilename), + 'remotenames', 'publicheads', + all_publicheads) # Make sure we pull "update". If it looks like a hash, add to # "nodes", otherwise to "names". diff --git a/eden/scm/tests/test-git-clone-sets-publicheads.t b/eden/scm/tests/test-git-clone-sets-publicheads.t new file mode 100644 index 0000000000000..bb32ed6eb97d7 --- /dev/null +++ b/eden/scm/tests/test-git-clone-sets-publicheads.t @@ -0,0 +1,29 @@ +#chg-compatible +#require git no-windows + + $ . $TESTDIR/git.sh + +Prepare a git repo: + + $ git init -q gitrepo + $ cd gitrepo + $ git config core.autocrlf false + $ echo 1 > alpha + $ git add alpha + $ git commit -q -malpha + + $ git switch -c foo + Switched to a new branch 'foo' + + $ echo 2 > beta + $ git add beta + $ git commit -q -mbeta + +Test git clone sets publicheads + $ hg clone --git "$TESTTMP/gitrepo" cloned + From $TESTTMP/gitrepo + * [new ref] 3f5848713286c67b8a71a450e98c7fa66787bde2 -> remote/foo + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ cd cloned + $ hg config remotenames.publicheads + remote/foo,remote/main,remote/master diff --git a/eden/scm/tests/test-git.t b/eden/scm/tests/test-git.t index 745ba6c47a793..d235f1f7e3a55 100644 --- a/eden/scm/tests/test-git.t +++ b/eden/scm/tests/test-git.t @@ -260,6 +260,9 @@ Test clone with flags (--noupdate, --updaterev): remote/master 3f5848713286 $ cd .. + # This test is VERY suspicious. It's supposed to test `ls-remote` symref HEAD + # parsing, but it passes `--updaterev` that totally circumvents all the code + # it's supposed to test $ hg clone --git "$TESTTMP/gitrepo" -u foo cloned1 From $TESTTMP/gitrepo * [new ref] 3f5848713286c67b8a71a450e98c7fa66787bde2 -> remote/master