Skip to content

Commit

Permalink
When cloning a repo where contributions go through a fork, configure …
Browse files Browse the repository at this point in the history
…that checkout to use the fork and to pull from upstream main.
  • Loading branch information
jaraco committed Sep 11, 2022
1 parent 6d89385 commit 21350ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
17 changes: 16 additions & 1 deletion jaraco/develop/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,26 @@ def target_for_root(project, root: path.Path = path.Path()):
return root / prefix


def configure_fork(project, repo):
if 'fork' not in project.tags:
return
cmd = ['gh', 'repo', 'fork', '--remote']
subprocess.check_call(cmd, cwd=repo)
cmd = ['git', 'config', '--local', 'branch.main.remote', 'upstream']
subprocess.check_call(cmd, cwd=repo)
cmd = ['git', 'remote', 'get-url', 'origin']
origin = subprocess.check_output(cmd, cwd=repo)
cmd = ['git', 'remote', 'set-url', '--push', 'upstream', origin]
subprocess.check_output(cmd, cwd=repo)


def checkout(project, target: path.Path = path.Path()):
url = resolve(project)
cmd = ['git', '-C', target, 'clone', url]
subprocess.check_call(cmd)
return target / posixpath.basename(project)
repo = target / posixpath.basename(project)
configure_fork(project, repo)
return repo


def projects():
Expand Down
24 changes: 12 additions & 12 deletions jaraco/develop/projects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ compilers
jaraco.pghfreethought
multipy-tox
skeleton
/martinvonz/jj
/martinvonz/jj [fork]
/pypa/distutils
/cherrypy/cherrypy
/cherrypy/cheroot
/python/cpython
/python/bedevere
/python/devguide
/xonsh/xonsh
/jsonpickle/jsonpickle
/StefanScherer/windows-docker-machine
/pypa/pep517
/python/cpython [fork]
/python/bedevere [fork]
/python/devguide [fork]
/xonsh/xonsh [fork]
/jsonpickle/jsonpickle [fork]
/StefanScherer/windows-docker-machine [fork]
/pypa/pep517 [fork]
/pypa/twine
/pypa/setuptools_scm
/pypa/packaging
/pypa/get-pip
/pypa/pip
/pypa/setuptools_scm [fork]
/pypa/packaging [fork]
/pypa/get-pip [fork]
/pypa/pip [fork]

0 comments on commit 21350ae

Please sign in to comment.