git: respect 'default-push' path if present (#469)

Summary:
git: respect 'default-push' path if present
In non-Git mode, 'hg push' (without an explicit path) pushes to the
'default-push' path if present, falling back to the 'default' path.

In Git mode, 'sl push' (without an explicit path) always pushes to the 'default'
path. 'default-push' is ignored.

Teach Git mode to push to 'default-push' if present, similar to how it works in
non-Git mode.

This commit only affects 'sl push'. 'sl pr submit' still ignores the
'default-push' path.

Pull Request resolved: https://github.com/facebook/sapling/pull/469

Test Plan: $ (cd tests && python run-tests.py test-git-push-default-push.t)

Reviewed By: muirdm

Differential Revision: D43336914

Pulled By: quark-zju

fbshipit-source-id: f11c45fb2bd8678b6be7294bf15359131db0ee2e
This commit is contained in:
Mark Shroyer 2023-02-17 12:04:00 -08:00 committed by Facebook GitHub Bot
parent 1abfcbc16c
commit ac6d40c320
3 changed files with 45 additions and 1 deletions

1
eden/scm/.gitignore vendored
View File

@ -30,6 +30,7 @@ fb/tests/*.err
tests/htmlcov
tests/getdb.sh
tests/testutil/getdb.py
tests/__pycache__/
contrib/chg/chg
contrib/chg/libchg.a
contrib/hgsh/hgsh

View File

@ -854,7 +854,9 @@ def expushcmd(orig, ui, repo, dest=None, **opts):
dest, opts = adjust_push_dest_opts(ui, dest, opts)
if git.isgitpeer(repo):
if dest is None:
dest = "default"
dest = "default-push"
if dest not in ui.paths:
dest = "default"
force = opts.get("force")
delete = opts.get("delete")
if delete:

View File

@ -0,0 +1,41 @@
#require git no-windows
#debugruntest-compatible
$ . $TESTDIR/git.sh
Initialize the server repos.
$ git init -q --bare -b main repo-1.git
$ git init -q --bare -b main repo-2.git
Initialize the Sapling repo.
$ hg clone -q --git "$TESTTMP/repo-1.git" client-repo
$ cd client-repo
$ hg paths --add default-push "$TESTTMP/repo-2.git"
$ touch testfile
$ hg add testfile
$ hg commit testfile -m testcommit
Pushing without specifying a path pushes to the 'default-push' path.
$ hg push -q -r . --to main --create
$ GIT_DIR="$TESTTMP/repo-1.git" git log --pretty=format:%s%n
fatal: your current branch 'main' does not have any commits yet
[128]
$ GIT_DIR="$TESTTMP/repo-2.git" git log --pretty=format:%s%n
testcommit
After deleting the 'default-push' path,
pushing without specifying a path pushes to the 'default' path
$ hg paths --delete default-push
$ hg push -q -r . --to main --create
$ GIT_DIR="$TESTTMP/repo-1.git" git log --pretty=format:%s%n
testcommit
$ GIT_DIR="$TESTTMP/repo-2.git" git log --pretty=format:%s%n
testcommit