Skip to content

Commit

Permalink
Handle parent feature going away (#159)
Browse files Browse the repository at this point in the history
When the parent branch goes away, set the tracking to 'most_main'

Signed-off-by: Phil Dibowitz <phil@ipom.com>
  • Loading branch information
jaymzh authored Apr 26, 2024
1 parent 67a0190 commit 13cd7d4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/sugarjar/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,18 @@ def gitup
SugarJar::Log.debug('Fetching upstream')
fetch_upstream
curr = current_branch
base = tracked_branch
# this isn't a hash, it's a named param, silly rubocop
# rubocop:disable Style/HashSyntax
base = tracked_branch(fallback: false)
# rubocop:enable Style/HashSyntax
unless base
SugarJar::Log.info(
'The brach we were tracking is gone, resetting tracking to ' +
most_main,
)
git('branch', '-u', most_main)
base = most_main
end
# 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
Expand Down Expand Up @@ -886,12 +897,13 @@ def rebase_in_progress?
File.exist?(rebase_file) || File.exist?(rebase_merge_file)
end

def tracked_branch
def tracked_branch(fallback: true)
s = git_nofail(
'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'
)
if s.error?
most_main
fallback ? most_main : nil

else
s.stdout.strip
end
Expand Down

0 comments on commit 13cd7d4

Please sign in to comment.