提交 3021e584 编写于 作者: M Mislav Marohnić

Merge branch 'akshatgoel-issue1305'

Closes #1332, fixes #1305
......@@ -90,7 +90,9 @@ func (r *Runner) Execute() ExecError {
utils.Check(err)
git.GlobalFlags = args.GlobalFlags // preserve git global flags
expandAlias(args)
if !isBuiltInHubCommand(args.Command) {
expandAlias(args)
}
cmd := r.Lookup(args.Command)
if cmd != nil && cmd.Runnable() {
......@@ -163,7 +165,8 @@ func executeCommands(cmds []*cmd.Cmd, execFinal bool) error {
func expandAlias(args *Args) {
cmd := args.Command
expandedCmd, err := git.Alias(cmd)
if err == nil && expandedCmd != "" {
if err == nil && expandedCmd != "" && !git.IsBuiltInGitCommand(cmd) {
words, e := splitAliasCmd(expandedCmd)
if e == nil {
args.Command = words[0]
......@@ -172,6 +175,15 @@ func expandAlias(args *Args) {
}
}
func isBuiltInHubCommand(command string) bool {
for hubCommand, _ := range CmdRunner.All() {
if hubCommand == command {
return true
}
}
return false
}
func splitAliasCmd(cmd string) ([]string, error) {
if cmd == "" {
return nil, fmt.Errorf("alias can't be empty")
......
......@@ -96,3 +96,11 @@ Feature: hub ci-status
Given the remote commit state of "git.my.org/michiels/pencilbox" "the_sha" is "success"
When I successfully run `hub ci-status the_sha`
Then the output should contain exactly "success\n"
Scenario: If alias named ci-status exists, it should not be expanded.
Given there is a commit named "the_sha"
Given the remote commit state of "michiels/pencilbox" "the_sha" is "success"
When I successfully run `git config --global alias.ci-status "ci-status -v"`
When I run `hub ci-status the_sha`
Then the output should contain exactly "success\n"
And the exit status should be 0
Feature: git-hub compatibility
Scenario: If alias named branch exists, it should not be expanded.
Given I am in "git://github.com/rtomayko/ronn.git" git repo
And the default branch for "origin" is "master"
When I successfully run `git config --global alias.branch "branch -a"`
When I run `hub branch`
Then the stdout should contain exactly "* master\n"
......@@ -305,6 +305,7 @@ func LocalBranches() ([]string, error) {
if err == nil {
for i, line := range lines {
lines[i] = strings.TrimPrefix(line, "* ")
lines[i] = strings.TrimPrefix(lines[i], " ")
}
}
return lines, err
......@@ -315,8 +316,7 @@ func gitOutput(input ...string) (outputs []string, err error) {
out, err := cmd.CombinedOutput()
for _, line := range strings.Split(out, "\n") {
line = strings.TrimSpace(line)
if line != "" {
if strings.TrimSpace(line) != "" {
outputs = append(outputs, string(line))
}
}
......@@ -337,3 +337,20 @@ func gitCmd(args ...string) *cmd.Cmd {
return cmd
}
func IsBuiltInGitCommand(command string) bool {
helpCommandOutput, err := gitOutput("help", "-a")
if err != nil {
return false
}
for _, helpCommandOutputLine := range helpCommandOutput {
if strings.HasPrefix(helpCommandOutputLine, " ") {
for _, gitCommand := range strings.Split(helpCommandOutputLine, " ") {
if gitCommand == command {
return true
}
}
}
}
return false
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册