Skip to content

Commit

Permalink
Use a more efficient fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Feb 12, 2022
1 parent 0082d05 commit e476a10
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F
dirty = util.run("git --no-pager diff --stat") != ""
if dirty:
util.run("git stash")
util.run(f"git fetch origin {branch}")
util.run(f"{util.GIT_FETCH_CMD} {branch}")
util.run(f"git checkout -b {pr_branch} origin/{branch}")
if dirty:
util.run("git stash apply")
Expand Down Expand Up @@ -530,7 +530,7 @@ def prep_git(ref, branch, repo, auth, username, url):
ref = ref or ""

# Make sure we have *all* tags
util.run("git fetch origin --tags --force --quiet")
util.run(f"{util.GIT_FETCH_CMD} --tags --force ")

# Handle the ref
if ref.startswith("refs/pull/"):
Expand All @@ -541,11 +541,11 @@ def prep_git(ref, branch, repo, auth, username, url):

# Reuse existing branch if possible
if ref:
util.run(f"git fetch origin +{ref}:{ref_alias}")
util.run(f"git fetch origin {ref}")
util.run(f"{util.GIT_FETCH_CMD} +{ref}:{ref_alias}")
util.run(f"{util.GIT_FETCH_CMD} {ref}")
checkout_cmd = f"git checkout -B {branch} {ref_alias}"
else:
util.run(f"git fetch origin {branch}")
util.run(f"{util.GIT_FETCH_CMD} {branch}")
checkout_cmd = f"git checkout {branch}"

if checkout_exists:
Expand Down Expand Up @@ -597,7 +597,7 @@ def forwardport_changelog(

# switch to main branch here
branch = branch or util.get_default_branch()
util.run(f"git fetch origin {branch}")
util.run(f" {branch}")
util.run(f"git checkout {branch}")

# Bail if the tag has been merged to the branch
Expand Down
7 changes: 4 additions & 3 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from jupyter_releaser.tests.util import REPO_DATA
from jupyter_releaser.tests.util import VERSION_SPEC
from jupyter_releaser.util import bump_version
from jupyter_releaser.util import GIT_FETCH_CMD
from jupyter_releaser.util import normalize_path
from jupyter_releaser.util import run

Expand Down Expand Up @@ -107,9 +108,9 @@ def test_prep_git_full(py_package, tmp_path, mocker, runner):
call('git config --global user.name "GitHub Action"'),
call("git init .jupyter_releaser_checkout"),
call("git remote add origin https://snuffy:[email protected]/baz/bar.git"),
call("git fetch origin --tags --force --quiet"),
call("git fetch origin +refs/pull/42:refs/pull/42"),
call("git fetch origin refs/pull/42"),
call(f"{GIT_FETCH_CMD} --tags --force"),
call(f"{GIT_FETCH_CMD} +refs/pull/42:refs/pull/42"),
call(" refs/pull/42"),
call("git checkout -B foo refs/pull/42"),
]
)
Expand Down
2 changes: 2 additions & 0 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
SCHEMA = files("jupyter_releaser").joinpath("schema.json").read_text()
SCHEMA = json.loads(SCHEMA)

GIT_FETCH_CMD = "git fetch origin --filter=blob:none --quiet"


def run(cmd, **kwargs):
"""Run a command as a subprocess and get the output as a string"""
Expand Down

0 comments on commit e476a10

Please sign in to comment.