diff --git a/cmd/feature.ab b/cmd/feature.ab index 39dd225..7555bbf 100644 --- a/cmd/feature.ab +++ b/cmd/feature.ab @@ -1,4 +1,5 @@ import * from "../config.ab" +import * from "../git/branch.ab" fun branch(feature: Text): Text { let prefix = get_feature_prefix() @@ -8,20 +9,20 @@ fun branch(feature: Text): Text { fun feature_start(feature: Text, description: Text): Null { let branch = branch(feature) - let base = get_dev_branch() - echo "git switch -c {branch} {base}" - echo "git config --no-add branch.\"{branch}\".description \"{description}\"" + unsafe branch_create(branch, get_dev_branch()) + unsafe branch_set_description(branch, description) } fun feature_checkout(feature: Text): Null { - let branch = branch(feature) - - echo "git checkout \"{branch}\"" + unsafe branch_checkout(branch(feature)) } fun feature_publish(feature: Text): Null { - echo "Publish feature {feature}" + unsafe branch_push( + branch(feature), + get_push_remote() + ) } fun feature_finish(feature: Text): Null { @@ -29,7 +30,14 @@ fun feature_finish(feature: Text): Null { } fun feature_delete(feature: Text): Null { - echo "Delete feature {feature}" + let dev_branch = get_dev_branch() + let branch = branch(feature) + + if branch_get_current() == dev_branch { + branch_checkout(dev_branch) + } + + branch_delete(branch) } fun feature_rebase(feature: Text): Null { diff --git a/git/branch.ab b/git/branch.ab new file mode 100644 index 0000000..4c9407b --- /dev/null +++ b/git/branch.ab @@ -0,0 +1,30 @@ +import * from "../config.ab" + +pub fun branch_get_current(): Text { + return unsafe $git branch --show-current$ +} + +pub fun branch_create(branch: Text, start_point: Text): Null { + echo "git switch -c \"{branch}\" \"{start_point}\"" + // $git switch -c "{branch}" "{start_point}"$? +} + +pub fun branch_checkout(branch: Text): Null { + echo "git checkout \"{branch}\"" + // $git checkout "{branch}$? +} + +pub fun branch_delete(branch: Text): Null { + echo "git branch -d \"{branch}\"" + // $git branch -d "{branch}"$? +} + +pub fun branch_set_description(branch: Text, description: Text): Null { + echo "git config --no-add branch.\"{branch}\".description \"{description}\""4 + // $git config --no-add branch."{branch}".description "{description}"$? +} + +pub fun branch_push(branch: Text, remote: Text): Null { + echo "git push \"{remote}\" \"{branch}\"" + // $git push "{remote}" "{branch}"$? +} \ No newline at end of file