Skip to content

Commit

Permalink
[gareth] Add support for updating the dev env
Browse files Browse the repository at this point in the history
This commit adds the code which can update the forks
with gareth. It fetches the latest changes in the
upstream and rebases the `master` branch accordingly.

Usage:
```
$ gareth -s sources --update
```

Signed-off-by: Venu Vardhan Reddy Tekula <[email protected]>
  • Loading branch information
vchrombie committed Apr 26, 2021
1 parent 2721b6a commit 67b6594
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
36 changes: 36 additions & 0 deletions gareth/gareth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"""

import os
import subprocess

import click
import git.repo.base as grb
Expand Down Expand Up @@ -53,6 +54,10 @@

GITHUB_URL = "https://github.com/"

CHECKOUT_MASTER_CMD = ['git', 'checkout', 'master']
FETCH_UPSTREAM_CMD = ['git', 'fetch', 'upstream']
REBASE_UPSTREAM_CMD = ['git', 'rebase', 'upstream/master']


def source_prompt():
"""Prompt source to read the folder name"""
Expand Down Expand Up @@ -172,6 +177,14 @@ def set_upstream(local_repo_path, org, repo):
click.ClickException(msg)


def sync_with_upstream():
"""Rebase the fork with upstream"""

subprocess.call(CHECKOUT_MASTER_CMD)
subprocess.call(FETCH_UPSTREAM_CMD)
subprocess.call(REBASE_UPSTREAM_CMD)


def create_dev_setup(token, source):
"""Create the developer setup"""

Expand Down Expand Up @@ -202,5 +215,28 @@ def create_dev_setup(token, source):
click.echo("The dev setup is created.")


def update_dev_setup(source):
"""Update the developer setup"""

click.echo("Updating the developer setup.\n")

source_path = os.path.join(os.getcwd(), source)

for repository in REPOS:
click.echo("{}...".format(repository))

org, repo = repository.split('/')
dirpath = os.path.join(source_path, repo)

change_the_directory(dirpath)

sync_with_upstream()

click.echo("done\n")

click.echo()
click.echo("The dev setup is updated.")


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Add support for updating the dev environment
category: added
author: Venu Vardhan Reddy Tekula <[email protected]>
issue: null
notes: >
The support for updating the developer environment
is added. This would be needed to update the repos
by rebasing the latest changes with the upstream.
It would open each folder, changes to `master` branch,
and rebase the changes with the upstream.
Usage:
```
$ gareth -s sources --update
```

0 comments on commit 67b6594

Please sign in to comment.