Skip to content

Commit

Permalink
WIP: subfeature
Browse files Browse the repository at this point in the history
When done, will close #151
  • Loading branch information
jaymzh committed Mar 21, 2024
1 parent 0ba1e66 commit b8bc3d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
13 changes: 8 additions & 5 deletions bin/sj
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ COMMANDS:
Same as "amend" but without changing the message. Alias for
"git commit --amend --no-edit".
bclean
If safe, delete the current branch. Unlike "git branch -d",
bclean can handle squash-merged branches. Think of it as
a smarter "git branch -d".
bclean [<branch>]
If safe, delete the current branch (or the specified branch).
Unlike "git branch -d", bclean can handle squash-merged branches.
Think of it as a smarter "git branch -d".
bcleanall
Walk all branches, and try to delete them if it's safe. See
Expand All @@ -127,7 +127,7 @@ COMMANDS:
br
Verbose branch list. An alias for "git branch -v".
feature
feature <branch_name>
Create a "feature" branch. It's morally equivalent to
"git checkout -b" except it defaults to creating it based on
some form of 'master' instead of your current branch. In order
Expand Down Expand Up @@ -177,6 +177,9 @@ COMMANDS:
A smart wrapper to "git push" that runs whatever is defined in
"on_push" in .sugarjar.yml, and only pushes if they succeed.
subfeature, sj <feature>
An alias for 'sj feature <feature> <current_branch>'
unit
Run any unitests configured in .sugarjar.yaml.
Expand Down
22 changes: 19 additions & 3 deletions lib/sugarjar/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@ def feature(name, base = nil)
name = fprefix(name)
die("#{name} already exists!") if all_local_branches.include?(name)
base ||= most_main
base_pieces = base.split('/')
git('fetch', base_pieces[0]) if base_pieces.length > 1
# If our base is a local branch, don't try to parse it for a remote name
unless all_local_branches.include?(base)
base_pieces = base.split('/')
git('fetch', base_pieces[0]) if base_pieces.length > 1
end
git('checkout', '-b', name, base)
SugarJar::Log.info(
"Created feature branch #{color(name, :green)} based on " +
color(base, :green),
)
end
alias f feature

def subfeature(name)
assert_in_repo
SugarJar::Log.debug("Subfature: #{name}")
feature(name, current_branch)
end
alias sf subfeature

def bclean(name = nil)
assert_in_repo
Expand Down Expand Up @@ -795,13 +806,18 @@ def gitup
fetch_upstream
curr = current_branch
base = tracked_branch
# TODO
# if all_local_branches.include?(base) && first-part-of-base is not remote
# (i.e. we were tracking a local branch that's no longer around)
# then
# prompt to reset tracked branch to be most_main
if !MAIN_BRANCHES.include?(curr) && base == "origin/#{curr}"
SugarJar::Log.warn(
"This branch is tracking origin/#{curr}, which is probably your " +
'downstream (where you push _to_) as opposed to your upstream ' +
'(where you pull _from_). This means that "sj up" is probably ' +
'rebasing on the wrong thing and doing nothing. You probably want ' +
'to do a "git branch -u upstream".',
"to do a 'git branch -u #{most_main}'.",
)
end
SugarJar::Log.debug('Rebasing')
Expand Down

0 comments on commit b8bc3d4

Please sign in to comment.