Skip to content

Commit

Permalink
generators: add --no-branch option to prevent creating new local branch
Browse files Browse the repository at this point in the history
* useful when regenerating the files locally by hand without planing to submit
  PR with the changes or when some other tool will do additional
  integration before doing the PR (like we plan to do with meta-ros)

Signed-off-by: Martin Jansa <martin.jansa@lge.com>
  • Loading branch information
shr-project committed Nov 19, 2019
1 parent b1ed35b commit 3302c1e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Gentoo Usage:
```
$ superflore-gen-ebuilds --help
usage: Deploy ROS packages into Gentoo Linux [-h] [--ros-distro ROS_DISTRO]
[--all] [--dry-run] [--pr-only]
[--all] [--dry-run] [--pr-only] [--no-branch]
[--output-repository-path OUTPUT_REPOSITORY_PATH]
[--only ONLY [ONLY ...]]
Expand All @@ -48,6 +48,7 @@ optional arguments:
--all regenerate all packages in all distros
--dry-run run without filing a PR to remote
--pr-only ONLY file a PR to remote
--no-branch don't create new local branch
--output-repository-path OUTPUT_REPOSITORY_PATH
location of the Git repo
--only ONLY [ONLY ...]
Expand Down Expand Up @@ -140,7 +141,7 @@ should be followed to generate the OpenEmbedded recipes for `meta-ros`.
$ superflore-gen-oe-recipes --help
usage: Deploy ROS packages into OpenEmbedded Linux [-h]
[--ros-distro ROS_DISTRO]
[--dry-run] [--pr-only]
[--dry-run] [--pr-only] [--no-branch]
[--output-repository-path OUTPUT_REPOSITORY_PATH]
[--only ONLY [ONLY ...]]
[--pr-comment PR_COMMENT]
Expand All @@ -155,6 +156,7 @@ optional arguments:
regenerate packages for the specified distro
--dry-run run without filing a PR to remote
--pr-only ONLY file a PR to remote
--no-branch don't create new local branch
--output-repository-path OUTPUT_REPOSITORY_PATH
location of the Git repo
--only ONLY [ONLY ...]
Expand Down
13 changes: 9 additions & 4 deletions superflore/generators/bitbake/ros_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

class RosMeta(object):
def __init__(
self, dir, do_clone, branch, org='ros', repo='meta-ros', from_branch=''
self, dir, do_clone, branch, org='ros', repo='meta-ros',
from_branch='', branch_name=''
):
self.repo = RepoInstance(
org, repo, dir, do_clone, from_branch=from_branch)
self.branch_name = branch
info('Creating new branch {0}...'.format(self.branch_name))
self.repo.create_branch(self.branch_name)
if branch:
info('Creating new branch {0}...'.format(self.branch_name))
self.repo.create_branch(self.branch_name)

def clean_ros_recipe_dirs(self, distro=None):
if distro:
Expand All @@ -48,7 +50,10 @@ def commit_changes(self, distro, commit_msg):
if self.repo.git.status('--porcelain') == '':
info('Nothing changed; no commit done')
else:
info('Committing to branch {0}...'.format(self.branch_name))
if self.branch_name:
info('Committing to branch {0}...'.format(self.branch_name))
else:
info('Committing to current branch')
self.repo.git.commit(m=commit_msg)

def pull_request(self, message, distro=None, title=''):
Expand Down
3 changes: 2 additions & 1 deletion superflore/generators/bitbake/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def main():
overlay = RosMeta(
_repo,
not args.output_repository_path,
branch='superflore/{}'.format(now),
branch=(('superflore/{}'.format(now)) if not args.no_branch
else None),
org=repo_org,
repo=repo_name,
from_branch=args.upstream_branch,
Expand Down
17 changes: 12 additions & 5 deletions superflore/generators/ebuild/overlay_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@

class RosOverlay(object):
def __init__(
self, repo_dir, do_clone, org='ros', repo='ros-overlay', from_branch=''
self, repo_dir, do_clone, org='ros', repo='ros-overlay',
from_branch='', new_branch=True
):
self.repo = RepoInstance(
org, repo, repo_dir=repo_dir, do_clone=do_clone,
from_branch=from_branch)
self.branch_name = 'gentoo-bot-%s' % rand_ascii_str()
info('Creating new branch {0}...'.format(self.branch_name))
self.repo.create_branch(self.branch_name)
if new_branch:
self.branch_name = 'gentoo-bot-%s' % rand_ascii_str()
info('Creating new branch {0}...'.format(self.branch_name))
self.repo.create_branch(self.branch_name)
else:
self.branch_name = None

def commit_changes(self, distro):
info('Adding changes...')
self.repo.git.add(self.repo.repo_dir)
if self.repo.git.status('--porcelain') == '':
info('Nothing changed; no commit done')
else:
info('Committing to branch {0}...'.format(self.branch_name))
if self.branch_name:
info('Committing to branch {0}...'.format(self.branch_name))
else:
info('Committing to current branch')
if distro == 'all':
commit_msg = 'regenerate all distros, {0}'
elif distro:
Expand Down
1 change: 1 addition & 0 deletions superflore/generators/ebuild/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def main():
org=repo_org,
repo=repo_name,
from_branch=args.upstream_branch,
new_branch=not args.no_branch,
)
if not preserve_existing and not args.only:
pr_comment = pr_comment or (
Expand Down
5 changes: 5 additions & 0 deletions superflore/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def get_parser(tool_tip, is_generator=True, exclude_all=False):
help='ONLY file a PR to remote',
action='store_true'
)
parser.add_argument(
'--no-branch',
help='Do not create new branch automatically',
action='store_true'
)
parser.add_argument(
'--output-repository-path',
help='location of the Git repo',
Expand Down

0 comments on commit 3302c1e

Please sign in to comment.