Skip to content

Commit 8d1fb9c

Browse files
bherilameta-codesync[bot]
authored andcommitted
Fix sl pull --rebase when default branch is "master"
Summary: When `selectivepulldefault=main,master` and a repo's default branch is actually `"master"` (no `"main"` exists), `sl pull --rebase` would abort with "missing rebase destination" because `bookmarks.mainbookmark()` always returned the first config entry (`"main"`). The fix is in `tweakdefaults.py`: the `pull --rebase` code path now tries each configured `selectivepulldefault` name when the first one doesn't exist in the repo. `mainbookmark()` itself is left unchanged (always returns `names[0]`) since many callers depend on it being a stable, side-effect-free config lookup — changing it to do `name in repo` caused regressions in mutation/visibility behavior (e.g., `test-pushrebase-remotenames.t`, `test-remotenames-pushto.t`). Resolves #1116 Differential Revision: D99509206 fbshipit-source-id: 2bff968e3aee2502ef386616dbd5a73af9145b3f
1 parent 32cb788 commit 8d1fb9c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

eden/scm/sapling/ext/tweakdefaults.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ def pull(orig, ui, repo, *args, **opts):
275275
if isrebase and not dest:
276276
# Not using main bookmark for non-rebase pull. See D38066104 and D38066103.
277277
dest = bookmarks.mainbookmark(repo)
278+
if dest not in repo:
279+
# mainbookmark() returns the first selectivepulldefault entry, which
280+
# may not exist (e.g. config lists "main,master" but only "master"
281+
# exists). Try each configured name before giving up.
282+
for name in repo.ui.configlist("remotenames", "selectivepulldefault"):
283+
if name in repo:
284+
dest = name
285+
break
278286
if dest not in repo:
279287
raise error.Abort(_("missing rebase destination - supply --dest / -d"))
280288

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
#require no-eden
3+
4+
# coding=utf-8
5+
# Copyright (c) Meta Platforms, Inc. and affiliates.
6+
#
7+
# This software may be used and distributed according to the terms of the
8+
# GNU General Public License version 2.
9+
10+
# Test that `sl pull --rebase` works when the default branch is "master"
11+
# and selectivepulldefault lists "main" first.
12+
# Regression test for https://github.com/facebook/sapling/issues/1116
13+
14+
$ export HGIDENTITY=sl
15+
$ cat >> $HGRCPATH << 'EOF'
16+
> [extensions]
17+
> rebase=
18+
> tweakdefaults=
19+
> EOF
20+
21+
# Set up server repo with "master" as the only bookmark (no "main").
22+
# Configure selectivepulldefault=main,master to simulate git-mode default.
23+
24+
$ newclientrepo repo
25+
$ cd ..
26+
$ echo a > repo/a
27+
$ sl -R repo commit -qAm a
28+
$ sl -R repo push -q -r . --to master --create
29+
30+
# Clone with selectivepulldefault=main,master (main listed first, but only master exists)
31+
32+
$ newclientrepo clone repo_server master
33+
$ setconfig remotenames.selectivepulldefault=main,master
34+
35+
# Pull --rebase with no local changes should auto-detect "master" as destination
36+
37+
$ echo b > ../repo/b
38+
$ sl -R ../repo commit -qAm b
39+
$ sl -R ../repo push -q -r . --to master
40+
$ sl pull --rebase
41+
pulling from test:repo_server
42+
searching for changes
43+
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
44+
nothing to rebase - fast-forwarded to master
45+
46+
# Make a local commit and check pull --rebase still works without -d
47+
48+
$ echo x > x
49+
$ sl commit -qAm x
50+
$ echo c > ../repo/c
51+
$ sl -R ../repo commit -qAm c
52+
$ sl -R ../repo push -q -r . --to master
53+
$ sl pull --rebase
54+
pulling from test:repo_server
55+
searching for changes
56+
rebasing * "x" (glob)
57+
$ sl log -G -T '{desc}'
58+
@ x
59+
60+
o c
61+
62+
o b
63+
64+
o a

0 commit comments

Comments
 (0)