Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add branch files shortcut #26

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
subFiles string = "{files}"
subAllFiles string = "{all_files}"
subStagedFiles string = "{staged_files}"
pushFiles string = "{push_files}"
runnerWrapPattern string = "{cmd}"
tagsConfigKey string = "tags"
pipedConfigKey string = "piped"
Expand Down Expand Up @@ -168,19 +169,28 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
return
}

files, _ := context.AllFiles()
files := []string{}
runner := getRunner(hooksGroup, commandsConfigKey, commandName)

if strings.Contains(runner, subStagedFiles) {
files, _ = context.StagedFiles()
} else if strings.Contains(runner, subFiles) || getCommandFiles(hooksGroup, commandName) != "" {
files, _ = context.ExecGitCommand(getCommandFiles(hooksGroup, commandName))
} else if strings.Contains(runner, pushFiles) {
files, _ = context.PushFiles()
} else {
files, _ = context.AllFiles()
}

VerbosePrint("\nFiles before filters: \n", files)

files = FilterGlob(files, getCommandGlobRegexp(hooksGroup, commandName))
files = FilterInclude(files, getCommandIncludeRegexp(hooksGroup, commandName)) // NOTE: confusing option, suppose delete it
files = FilterExclude(files, getCommandExcludeRegexp(hooksGroup, commandName))

VerbosePrint("Files after filters: \n", files)

runner = strings.Replace(runner, pushFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subStagedFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subAllFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subFiles, strings.Join(files, " "), -1)
Expand Down
14 changes: 13 additions & 1 deletion cmd/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd
import (
"errors"
"fmt"

// "io" // win specific
"log"
"os"
Expand All @@ -20,6 +21,7 @@ import (

arrop "github.com/adam-hanna/arrayOperations"
"github.com/gobwas/glob"

// "github.com/kr/pty" //win specific
"github.com/spf13/afero"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,6 +55,7 @@ const (
subFiles string = "{files}"
subAllFiles string = "{all_files}"
subStagedFiles string = "{staged_files}"
pushFiles string = "{push_files}"
runnerWrapPattern string = "{cmd}"
tagsConfigKey string = "tags"
pipedConfigKey string = "piped"
Expand Down Expand Up @@ -162,19 +165,28 @@ func executeCommand(hooksGroup, commandName string, wg *sync.WaitGroup) {
return
}

files, _ := context.AllFiles()
files := []string{}
runner := getRunner(hooksGroup, commandsConfigKey, commandName)

if strings.Contains(runner, subStagedFiles) {
files, _ = context.StagedFiles()
} else if strings.Contains(runner, subFiles) || getCommandFiles(hooksGroup, commandName) != "" {
files, _ = context.ExecGitCommand(getCommandFiles(hooksGroup, commandName))
} else if strings.Contains(runner, pushFiles) {
files, _ = context.PushFiles()
} else {
files, _ = context.AllFiles()
}

VerbosePrint("Files before filters: \n", files)

files = FilterGlob(files, getCommandGlobRegexp(hooksGroup, commandName))
files = FilterInclude(files, getCommandIncludeRegexp(hooksGroup, commandName)) // NOTE: confusing option, suppose delete it
files = FilterExclude(files, getCommandExcludeRegexp(hooksGroup, commandName))

VerbosePrint("Files after filters: \n", files)

runner = strings.Replace(runner, pushFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subStagedFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subAllFiles, strings.Join(files, " "), -1)
runner = strings.Replace(runner, subFiles, strings.Join(files, " "), -1)
Expand Down
4 changes: 4 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func AllFiles() ([]string, error) {
return ExecGitCommand("git ls-files --cached")
}

func PushFiles() ([]string, error) {
return ExecGitCommand("git diff-tree --no-commit-id --name-only -r HEAD --")
}

func ExecGitCommand(command string) ([]string, error) {
commandArg := strings.Split(command, " ")
cmd := exec.Command(commandArg[0], commandArg[1:]...)
Expand Down