Skip to content

Commit 42bb75e

Browse files
authored
Use bare git for dry run (#356)
1 parent 7a604c7 commit 42bb75e

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

jupyter_releaser/lib.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,13 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F
164164
# Make a new branch with a uuid suffix
165165
pr_branch = f"changelog-{uuid.uuid1().hex}"
166166

167-
if not dry_run:
168-
dirty = util.run("git --no-pager diff --stat") != ""
169-
if dirty:
170-
util.run("git stash")
171-
util.run(f"{util.GIT_FETCH_CMD} {branch}")
172-
util.run(f"git checkout -b {pr_branch} origin/{branch}")
173-
if dirty:
174-
util.run("git stash apply")
167+
dirty = util.run("git --no-pager diff --stat") != ""
168+
if dirty:
169+
util.run("git stash")
170+
util.run(f"{util.GIT_FETCH_CMD} {branch}")
171+
util.run(f"git checkout -b {pr_branch} origin/{branch}")
172+
if dirty:
173+
util.run("git stash apply")
175174

176175
# Add a commit with the message
177176
try:
@@ -188,8 +187,8 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F
188187
head = pr_branch
189188
maintainer_can_modify = True
190189

191-
if not dry_run:
192-
util.run(f"git push origin {pr_branch}")
190+
remote_name = util.get_remote_name(dry_run)
191+
util.run(f"git push {remote_name} {pr_branch}")
193192

194193
# title, head, base, body, maintainer_can_modify, draft, issue
195194
pull = gh.pulls.create(title, head, base, body, maintainer_can_modify, False, None)
@@ -265,9 +264,10 @@ def draft_release(
265264
if delta.days > 0:
266265
gh.repos.delete_release(release.id)
267266

268-
remote_url = util.run("git config --get remote.origin.url")
269-
if not dry_run and not os.path.exists(remote_url):
270-
util.run(f"git push origin HEAD:{branch} --follow-tags --tags")
267+
remote_name = util.get_remote_name(dry_run)
268+
remote_url = util.run(f"git config --get remote.{remote_name}.url")
269+
if not os.path.exists(remote_url):
270+
util.run(f"git push {remote_name} HEAD:{branch} --follow-tags --tags")
271271

272272
util.log(f"Creating release for {version}")
273273
util.log(f"With assets: {assets}")

jupyter_releaser/util.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,30 @@ def get_gh_object(dry_run=False, **kwargs):
432432
return core.GhApi(**kwargs)
433433

434434

435+
_local_remote = None
436+
437+
438+
def get_remote_name(dry_run):
439+
"""Get the appropriate remote git name."""
440+
global _local_remote
441+
if not dry_run:
442+
return "origin"
443+
444+
if _local_remote:
445+
try:
446+
run(f"git remote add test {_local_remote}")
447+
except Exception:
448+
pass
449+
return "test"
450+
451+
tfile = tempfile.NamedTemporaryFile(suffix=".git")
452+
tfile.close()
453+
_local_remote = tfile.name.replace(os.sep, "/")
454+
run(f"git init --bare {_local_remote}")
455+
run(f"git remote add test {_local_remote}")
456+
return "test"
457+
458+
435459
def ensure_mock_github():
436460
"""Check for or start a mock github server."""
437461
core.GH_HOST = MOCK_GITHUB_URL

0 commit comments

Comments
 (0)