Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/sample_repoconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ include_from: .sugarjar_local.yaml

overwrite_from: .sugarjar_local_overwrite.yaml

# `primary_branch` allows you to configure a primary branch that is
# non-standard. If your primary branch is `main` or `master`, you do not need
# to set this, sugarjar will figure out out automatically.
#
# This can also be used to force a primary branch in the event you have
# both `main` and `master` around.
primary_branch: somethingweird

# `release_branches` tells SugarJar several things:
# 1. These branches should not be repead when running `bclean`/`bcleanall`.
# 2. When a feature-branch is made from a release branch (e.g. `2.x-branch`),
Expand Down
4 changes: 2 additions & 2 deletions lib/sugarjar/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class SugarJar
# methods are "commands". Anything in private is internal implementation
# details.
class Commands
MAIN_BRANCHES = %w{master main}.freeze

def initialize(options)
SugarJar::Log.debug("Commands.initialize options: #{options}")
@config = options
Expand Down Expand Up @@ -196,6 +194,8 @@ def dirty_check!
end

def determine_main_branch(branches)
return @repo_config['primary_branch'] if @repo_config['primary_branch']

if branches.include?('main')
'main'
elsif branches.include?('master')
Expand Down
12 changes: 8 additions & 4 deletions lib/sugarjar/commands/bclean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class SugarJar
class Commands
# only used for REMOTE branch cleanup. use main_branch() for everything else
MAIN_BRANCHES = %w{master main}.freeze

def lbclean(name = nil)
assert_in_repo!
name ||= current_branch
Expand Down Expand Up @@ -66,7 +69,7 @@ def lbcleanall
all_local_branches.each do |branch|
# skip_branch info will check for MAIN_BRANCHES, but we
# quietly skip them.
next if MAIN_BRANCHES.include?(branch)
next if main_branch == branch

should_skip, why = skip_branch_info(branch)
if should_skip
Expand Down Expand Up @@ -103,7 +106,8 @@ def rbcleanall(remote = nil)
curr = current_branch
remote ||= 'origin'
all_remote_branches(remote).each do |branch|
if (MAIN_BRANCHES + ['HEAD']).include?(branch)
# for remote branches, exclude all POSSIBLE primary branch names
if MAIN_BRANCHES.union([main_branch, 'HEAD']).include?(branch)
SugarJar::Log.debug("Skipping #{branch}")
next
end
Expand Down Expand Up @@ -140,7 +144,7 @@ def gbcleanall(remote = nil)

# rubocop:disable Naming/PredicateMethod
def clean_branch(name, type = :local)
undeleteable = MAIN_BRANCHES.dup
undeleteable = [main_branch]
undeleteable << 'HEAD' if type == :remote
die("Cannot remove #{name} branch") if undeleteable.include?(name)
SugarJar::Log.debug('Fetch relevant remote...')
Expand Down Expand Up @@ -233,7 +237,7 @@ def cleanup_tmp_branch(tmp, backto, tracked = nil)
end

def skip_branch_info(name)
return true, 'main branch' if MAIN_BRANCHES.include?(name)
return true, 'primary branch' if main_branch == name

wt_branches = worktree_branches
rel_branches = release_branches
Expand Down
5 changes: 2 additions & 3 deletions lib/sugarjar/commands/up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def up(branch = nil)
def upall
assert_in_repo!
all_local_branches.each do |branch|
next if MAIN_BRANCHES.include?(branch)
next if main_branch == branch

git('checkout', branch)
result = rebase
Expand Down Expand Up @@ -126,8 +126,7 @@ def rebase(base = nil)
# If this is a subfeature based on a local branch which has since
# been deleted, 'tracked branch' will automatically return <most_main>
# so we don't need any special handling for that
if !MAIN_BRANCHES.include?(curr) && base == "origin/#{curr}" &&
!skip_base_warning
if main_branch != curr && base == "origin/#{curr}" && !skip_base_warning
SugarJar::Log.warn(
"This branch is tracking origin/#{curr}, which is probably your " +
'downstream (where you push _to_) as opposed to your upstream ' +
Expand Down
4 changes: 4 additions & 0 deletions spec/commands/up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
expect(sj).to receive(:current_branch).and_return('foo')
expect(sj).to receive(:tracked_branch).with(:fallback => false).
and_return('upstream/main')
expect(sj).to receive(:all_local_branches).at_least(1).times.
and_return(%w{main foo})
expect(sj).to receive(:git_nofail).with('rebase', 'upstream/main')
sj.send(:rebase)
end
Expand All @@ -20,6 +22,8 @@
expect(sj).to receive(:current_branch).and_return('foo')
expect(sj).to receive(:tracked_branch).with(:fallback => false).
and_return('bar')
expect(sj).to receive(:all_local_branches).at_least(1).times.
and_return(%w{main foo})
expect(sj).to receive(:git_nofail).with('rebase', 'bar')
sj.send(:rebase)
end
Expand Down