Skip to content

Commit

Permalink
new: allow renaming master
Browse files Browse the repository at this point in the history
new: allow changing task and release prefixes
  • Loading branch information
Larry Meadors committed Aug 8, 2021
1 parent a3c7d08 commit c913ec9
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gittyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trunk=master
task_prefix=tasks
release_prefix=releases
31 changes: 16 additions & 15 deletions gitty/gitty_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def bindings_string(self):
@staticmethod
def add_branch_info_to_context(context, current_branch):


# what is the commit hash
if 'git_ref' not in context:
# by default, use the current HEAD
Expand All @@ -134,18 +135,18 @@ def add_branch_info_to_context(context, current_branch):
branch_parts = current_branch.split("/")

# are we on THE master branch or any other master branch?
the_master = current_branch == 'master'
a_master = branch_parts[-1] == 'master'
the_master = current_branch == context['trunk']
a_master = branch_parts[-1] == context['trunk']

# are we on a task branch?
a_task = 'tasks' in branch_parts
a_release = 'releases' in branch_parts
a_task = context['task_prefix'] in branch_parts
a_release = context['release_prefix'] in branch_parts

if not a_task and not a_release:
if the_master:
task_prefix = 'tasks/'
task_prefix = context['task_prefix'] + '/'
else:
task_prefix = branch_parts[0] + '/tasks/'
task_prefix = branch_parts[0] + '/' + context['task_prefix'] + '/'
else:
# we're on a task or release branch - we don't create task branches from those
task_prefix = None
Expand Down Expand Up @@ -333,16 +334,16 @@ def get_version_info(context):
if context['is_stable']:
if context['a_task'] or context['a_release']:
# we're on a task or release branch - the parent is different...
context['parent_version_branch'] = context['branch_parts'][0] + '/master'
context['parent_version_branch'] = context['branch_parts'][0] + '/' + context['trunk']
else:
if len(context['current_version_parts']) <= 4:
# parent is just master
context['parent_version_branch'] = 'master'
context['parent_version_branch'] = context['trunk']
else:
# parent is a shortened version
context['parent_version_branch'] = '.'.join(context['current_version_parts'][:-2]) + '/master'
context['parent_version_branch'] = '.'.join(context['current_version_parts'][:-2]) + '/' + context['trunk']
else:
context['parent_version_branch'] = 'master'
context['parent_version_branch'] = context['trunk']

return context

Expand Down Expand Up @@ -442,10 +443,10 @@ class GitCheckoutMasterCommand(CommandStep):

def describe(self, context):
executor = DescribeExecutor()
return context['git_api'].checkout_existing(context, 'master', False, executor)
return context['git_api'].checkout_existing(context, context['trunk'], False, executor)

def execute(self, context, quiet):
return context['git_api'].checkout_existing(context, 'master', quiet, None)
return context['git_api'].checkout_existing(context, context['trunk'], quiet, None)


class GitShowUnmergedBranchesStep(CommandStep):
Expand Down Expand Up @@ -484,9 +485,9 @@ def execute(self, context, quiet):
branch_name = line.split()[-1]

retain_reason = ''
if branch_name.endswith('/master') or branch_name == 'master':
retain_reason = 'master branches are preserved'
if branch_name.endswith('/releases'):
if branch_name.endswith('/'+context['trunk']) or branch_name == context['trunk']:
retain_reason = context['trunk'] + ' branches are preserved'
if branch_name.endswith('/' + context['release_prefix']):
retain_reason = 'release branches are preserved'
if branch_name == context['current_branch']:
retain_reason = 'current branch is preserved'
Expand Down
16 changes: 8 additions & 8 deletions gitty/gitty_project_type_maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def get_version_info(self, context):
else:
if context['is_stable']:
# we're already on a stabilization branch, so this includes the full version
context['new_stabilization_branch'] = '.'.join(release_version_split) + '/master'
context['new_release_branch'] = '.'.join(release_version_split) + '/releases'
context['new_stabilization_branch'] = '.'.join(release_version_split) + '/' + context['trunk']
context['new_release_branch'] = '.'.join(release_version_split) + '/' + context['release_prefix']
context['new_stabilization_version'] = '.'.join(release_version_split) + '.0-SNAPSHOT'
else:
# we're not in a stabilization ecosystem - this will make one...
context['new_stabilization_branch'] = '.'.join(release_version_split[:-1]) + '/master'
context['new_release_branch'] = '.'.join(release_version_split[:-1]) + '/releases'
context['new_stabilization_branch'] = '.'.join(release_version_split[:-1]) + '/' + context['trunk']
context['new_release_branch'] = '.'.join(release_version_split[:-1]) + '/' + context['release_prefix']
context['new_stabilization_version'] = '.'.join(release_version_split) + '-SNAPSHOT'

if context['is_stable']:
context['current_release_branch'] = '/'.join([
context['branch_parts'][0],
'releases'
context['release_prefix']
])
else:
# we're on THE master branch - so there is not a current release branch
Expand All @@ -79,13 +79,13 @@ def get_version_info(self, context):
release_version_split = context['release_version'].split(".")

# we're on an actual release branch, so this includes the full version
context['new_release_branch'] = '.'.join(release_version_split) + '/releases'
context['new_stabilization_branch'] = '.'.join(release_version_split) + '/master'
context['new_release_branch'] = '.'.join(release_version_split) + '/' + context['release_prefix']
context['new_stabilization_branch'] = '.'.join(release_version_split) + '/' + context['trunk']
context['new_stabilization_version'] = '.'.join(release_version_split) + '.0-SNAPSHOT'

context['current_release_branch'] = '/'.join([
context['branch_parts'][0],
'releases'
context['release_prefix']
])

self.build_next_version_numbers(context, release_version_split)
Expand Down
10 changes: 5 additions & 5 deletions gitty/gitty_project_type_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def get_version_info(self, context):
release_version_split = context['release_version'].split(".")

if context['is_stable']:
context['current_release_branch'] = '.'.join(release_version_split[:-1]) + '/releases'
context['current_release_branch'] = '.'.join(release_version_split[:-1]) + '/' + context['release_prefix']
if context['a_task']:
context['new_release_branch'] = None
context['new_stabilization_branch'] = None
context['new_stabilization_version'] = None
else:
context['new_release_branch'] = '.'.join(release_version_split) + '/releases'
context['new_stabilization_branch'] = '.'.join(release_version_split) + '/master'
context['new_release_branch'] = '.'.join(release_version_split) + '/' + context['release_prefix']
context['new_stabilization_branch'] = '.'.join(release_version_split) + '/' + context['trunk']
context['new_stabilization_version'] = '.'.join(release_version_split) + '.0'
else:
context['current_release_branch'] = None
Expand All @@ -46,8 +46,8 @@ def get_version_info(self, context):
context['new_stabilization_branch'] = None
context['new_stabilization_version'] = None
else:
context['new_release_branch'] = '.'.join(release_version_split[:-1]) + '/releases'
context['new_stabilization_branch'] = '.'.join(release_version_split[:-1]) + '/master'
context['new_release_branch'] = '.'.join(release_version_split[:-1]) + '/' + context['release_prefix']
context['new_stabilization_branch'] = '.'.join(release_version_split[:-1]) + '/' + context['trunk']
context['new_stabilization_version'] = '.'.join(release_version_split)

# increment the patch
Expand Down
10 changes: 5 additions & 5 deletions gitty/gitty_project_type_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def get_version_info(self, context):
stable_branch_version = '.'.join(current_version_split[:-2])
if context['is_stable']:
# this means we're NOT on THE master branch or a task branch
context['new_stabilization_branch'] = release_version + '/master'
context['new_release_branch'] = release_version + '/releases'
context['new_stabilization_branch'] = release_version + '/' + context['trunk']
context['new_release_branch'] = release_version + '/' + context['release_prefix']
context['new_stabilization_version'] = release_version + '.0.dev0'
else:
# this means we're on a branch like 1.0/master
context['new_stabilization_branch'] = stable_branch_version + '/master'
context['new_release_branch'] = stable_branch_version + '/releases'
context['new_stabilization_branch'] = stable_branch_version + '/' + context['trunk']
context['new_release_branch'] = stable_branch_version + '/' + context['release_prefix']
context['release_version'] = stable_branch_version + '.0'

if context['the_master']:
Expand All @@ -67,7 +67,7 @@ def get_version_info(self, context):
context['next_stable_version'] = next_stable_version + '.dev0'

if len(context['branch_parts']) > 1:
context['current_release_branch'] = stable_branch_version + '/releases'
context['current_release_branch'] = stable_branch_version + '/' + context['release_prefix']
else:
context['current_release_branch'] = None

Expand Down
37 changes: 37 additions & 0 deletions gitty/gitty_support.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
import os
from pathlib import Path

from gitty.gitty_command import *
import sys


def setup(context):

# look for .gittyrc files - they can live in 2 places:
# - the user's home directory
# - the current working directory (CWD)
# if both exist and define overlapping values, the one in the CWD is used
# these are the global defaults
grc_config = {
'trunk': 'master',
'task_prefix': 'tasks',
'release_prefix': 'releases'
}
home_config_location = os.path.join(Path.home(), ".gittyrc")
local_config_location = ".gittyrc"
if os.path.exists(home_config_location):
with open(home_config_location) as f:
for line in f:
(key, val) = line.split("=")
grc_config[key] = val.strip()

if os.path.exists(local_config_location):
with open(local_config_location) as f:
for line in f:
(key, val) = line.split("=")
grc_config[key] = val.strip()

# if len(grc_config) == 0:
# print(
# "no config files found at '{}' or '{}', using defaults.".format(
# home_config_location, local_config_location
# )
# )

context.update(grc_config)
# print(context)

# get any CLI switches in the context:
# look at any parameter that starts with '--', and if the NEXT parameter doesn't
# start with '--', assume it's the value for this parameter
Expand Down
12 changes: 12 additions & 0 deletions lifecycle.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@startuml
'https://plantuml.com/sequence-diagram
autonumber
participant gitty
participant setup as "setup()\n(gitty_support.py)"

gitty -> setup: init config
setup -> command_handler: find and execute\ncommand
command_handler --> setup
setup --> gitty: exit value

@enduml

0 comments on commit c913ec9

Please sign in to comment.