forked from git-town/git-town
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diff parent command (git-town#1385)
- Loading branch information
Showing
17 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
features/git-town-diff-parent/current_branch/on_feature_branch/no_parent_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Feature: git town-parent-diff: diffing the current feature branch | ||
|
||
As a user running parent-diff | ||
With no arguments | ||
On a feature branch that has no parent branch defined | ||
I should see a prompt to supply a parent branch | ||
So that the command can work as I expect | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature" with no parent | ||
And I am on the "feature" branch | ||
When I run "git-town diff-parent" and answer the prompts: | ||
| PROMPT | ANSWER | | ||
| Please specify the parent branch of 'feature' | [ENTER] | | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| feature | git diff main..feature | | ||
And I am still on the "feature" branch | ||
And Git Town is now aware of this branch hierarchy | ||
| BRANCH | PARENT | | ||
| feature | main | |
17 changes: 17 additions & 0 deletions
17
features/git-town-diff-parent/current_branch/on_feature_branch/with_parent_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: git town-parent-diff: diffing the current feature branch | ||
|
||
As a developer makeing changes to a feature branched created with Git Town | ||
I want that Git Town tells me which changes this feature branch contains | ||
So that I know what work is left to do | ||
And which work will be merged into the parent branch | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature-1" | ||
And my repository has a feature branch named "feature-2" as a child of "feature-1" | ||
And I am on the "feature-2" branch | ||
When I run "git-town diff-parent" | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| feature-2 | git diff feature-1..feature-2 | | ||
And I am still on the "feature-2" branch |
17 changes: 17 additions & 0 deletions
17
features/git-town-diff-parent/current_branch/on_main_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: git town-diff-parent: errors when trying to diff the main branch | ||
|
||
As a developer accidentally trying to diff the main branch | ||
I should see an error that I cannot diff the main branch | ||
Because the master branch cannot have a parent branch | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature" | ||
And I am on the "main" branch | ||
When I run "git-town diff-parent" | ||
Then it runs no commands | ||
And it prints the error: | ||
""" | ||
You can only diff-parent feature branches | ||
""" | ||
And I am still on the "main" branch |
17 changes: 17 additions & 0 deletions
17
features/git-town-diff-parent/current_branch/on_non_feature_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: git town-diff-parent: errors when trying to diff a perennial branch | ||
|
||
As a developer accidentally trying to diff a perennial branch | ||
I should see an error that I cannot diff perennial branches | ||
Because perennial branches cannot have parent branches | ||
|
||
|
||
Scenario: result | ||
Given my repository has the perennial branch "qa" | ||
And I am on the "qa" branch | ||
When I run "git-town diff-parent" | ||
Then it runs no commands | ||
And it prints the error: | ||
""" | ||
You can only diff-parent feature branches | ||
""" | ||
And I am still on the "qa" branch |
15 changes: 15 additions & 0 deletions
15
features/git-town-diff-parent/supplied_branch/branch_does_not_exist.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: git town-diff-parent: errors if supplied branch does not exist | ||
|
||
As a developer mistyping the branch name to diff against its parent | ||
I should get an error that the given branch does not exist | ||
So that I can diff the correct branch | ||
|
||
Scenario: result | ||
Given I am on the "main" branch | ||
When I run "git-town diff-parent non-existing-feature" | ||
Then it runs no commands | ||
And it prints the error: | ||
""" | ||
There is no local branch named 'non-existing-feature' | ||
""" | ||
And I end up on the "main" branch |
14 changes: 14 additions & 0 deletions
14
features/git-town-diff-parent/supplied_branch/feature_branch/on_main_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: git town-diff-parent: diffing a given feature branch | ||
|
||
(see ../../current_branch/on_feature_branch/with_parent_branches.feature) | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature-1" | ||
And my repository has a feature branch named "feature-2" as a child of "feature-1" | ||
And I am on the "main" branch | ||
When I run "git-town diff-parent feature-2" | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| main | git diff feature-1..feature-2 | | ||
And I am still on the "main" branch |
22 changes: 22 additions & 0 deletions
22
...ures/git-town-diff-parent/supplied_branch/feature_branch/on_main_branch_no_parent.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Feature: git town-parent-diff: diffing the current feature branch | ||
|
||
As a user running parent-diff | ||
With a supplied branch | ||
On the main branch | ||
I should see a prompt to identify a parent branch | ||
So that the command can work as I expect | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature" with no parent | ||
And I am on the "main" branch | ||
When I run "git-town diff-parent feature" and answer the prompts: | ||
| PROMPT | ANSWER | | ||
| Please specify the parent branch of 'feature' | [ENTER] | | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| main | git diff main..feature | | ||
And I am still on the "main" branch | ||
And Git Town is now aware of this branch hierarchy | ||
| BRANCH | PARENT | | ||
| feature | main | |
14 changes: 14 additions & 0 deletions
14
features/git-town-diff-parent/supplied_branch/feature_branch/on_parent_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: git town-diff-parent: diffing a given feature branch | ||
|
||
(see ../../current_branch/on_feature_branch/with_parent_branches.feature) | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature-1" | ||
And my repository has a feature branch named "feature-2" as a child of "feature-1" | ||
And I am on the "feature-1" branch | ||
When I run "git-town diff-parent feature-2" | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| feature-1 | git diff feature-1..feature-2 | | ||
And I am still on the "feature-1" branch |
15 changes: 15 additions & 0 deletions
15
features/git-town-diff-parent/supplied_branch/main_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Feature: git town-diff-parent: errors when trying to diff the main branch | ||
|
||
(see ../current_branch/on_main_branch.feature) | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature" | ||
And I am on the "feature" branch | ||
When I run "git-town diff-parent main" | ||
Then it runs no commands | ||
And it prints the error: | ||
""" | ||
You can only diff-parent feature branches | ||
""" | ||
And I am still on the "feature" branch |
14 changes: 14 additions & 0 deletions
14
features/git-town-diff-parent/supplied_branch/on_supplied_feature_branch/has_parent.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: git town-diff-parent: diffing a given feature branch | ||
|
||
(see ../../current_branch/on_feature_branch/with_parent_branch.feature) | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature-1" | ||
And my repository has a feature branch named "feature-2" as a child of "feature-1" | ||
And I am on the "feature-2" branch | ||
When I run "git-town diff-parent feature-2" | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| feature-2 | git diff feature-1..feature-2 | | ||
And I am still on the "feature-2" branch |
22 changes: 22 additions & 0 deletions
22
.../git-town-diff-parent/supplied_branch/on_supplied_feature_branch/no_parent_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Feature: git town-parent-diff: diffing the current feature branch | ||
|
||
As a user running parent-diff | ||
With a supplied branch that matches my current branch | ||
On a branch that has no parent branch defined | ||
I should see a prompt to supply a parent branch | ||
So that the command can work as I expect | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature" with no parent | ||
And I am on the "feature" branch | ||
When I run "git-town diff-parent feature" and answer the prompts: | ||
| PROMPT | ANSWER | | ||
| Please specify the parent branch of 'feature' | [ENTER] | | ||
Then it runs the commands | ||
| BRANCH | COMMAND | | ||
| feature | git diff main..feature | | ||
And I am still on the "feature" branch | ||
And Git Town is now aware of this branch hierarchy | ||
| BRANCH | PARENT | | ||
| feature | main | |
16 changes: 16 additions & 0 deletions
16
features/git-town-diff-parent/supplied_branch/perennial_branch.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Feature: git town-diff-parent: errors when trying to diff a perennial branch | ||
|
||
(see ../current_branch/on_perennial_branch.feature) | ||
|
||
|
||
Scenario: result | ||
Given my repository has a feature branch named "feature" | ||
And my repository has the perennial branch "qa" | ||
And I am on the "feature" branch | ||
When I run "git-town diff-parent qa" | ||
Then it runs no commands | ||
And it prints the error: | ||
""" | ||
You can only diff-parent feature branches | ||
""" | ||
And I am still on the "feature" branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/git-town/git-town/src/git" | ||
"github.com/git-town/git-town/src/prompt" | ||
"github.com/git-town/git-town/src/script" | ||
"github.com/git-town/git-town/src/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type diffParentConfig struct { | ||
branch string | ||
parentBranch string | ||
} | ||
|
||
var diffParentCommand = &cobra.Command{ | ||
Use: "diff-parent [<branch>]", | ||
Short: "Shows the changes committed to a feature branch", | ||
Long: `Shows the changes committed to a feature branch | ||
Works on either the current branch or the branch name provided. | ||
Exits with error code 1 if the given branch is a perennial branch or the main branch.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config := getDiffParentConfig(args) | ||
script.RunCommandSafe("git", "diff", config.parentBranch+".."+config.branch) | ||
}, | ||
Args: cobra.MaximumNArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return util.FirstError( | ||
git.ValidateIsRepository, | ||
validateIsConfigured, | ||
) | ||
}, | ||
} | ||
|
||
// Does not return error because "Ensure" functions will call exit directly | ||
func getDiffParentConfig(args []string) (config diffParentConfig) { | ||
initialBranch := git.GetCurrentBranchName() | ||
|
||
if len(args) == 0 { | ||
config.branch = initialBranch | ||
} else { | ||
config.branch = args[0] | ||
} | ||
|
||
if initialBranch != config.branch { | ||
git.EnsureHasLocalBranch(config.branch) | ||
} | ||
|
||
git.Config().EnsureIsFeatureBranch(config.branch, "You can only diff-parent feature branches.") | ||
|
||
prompt.EnsureKnowsParentBranches([]string{config.branch}) | ||
config.parentBranch = git.Config().GetParentBranch(config.branch) | ||
return | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(diffParentCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters