summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-10 02:58:14 +0300
committerIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-10 02:58:14 +0300
commit61d514a5ad3c373b48cc6a7713e0d3f46ffb02c3 (patch)
tree852ca843d5a67852d69054f816bb8b746df8b49e
parentadded config file option and some minor bugfixes (diff)
downloadgitbatch-61d514a5ad3c373b48cc6a7713e0d3f46ffb02c3.tar.gz
added recursive option and some minor code formating
-rw-r--r--README.md2
-rw-r--r--main.go13
-rw-r--r--pkg/app/app.go30
-rw-r--r--pkg/app/config.go34
-rw-r--r--pkg/app/files.go78
-rw-r--r--pkg/git/add.go4
-rw-r--r--pkg/git/branch.go14
-rw-r--r--pkg/git/commands.go4
-rw-r--r--pkg/git/fetch.go23
-rw-r--r--pkg/git/merge.go15
-rw-r--r--pkg/git/repository-sort.go4
-rw-r--r--pkg/git/repository.go8
-rw-r--r--pkg/git/reset.go9
-rw-r--r--pkg/git/rev-list.go13
-rw-r--r--pkg/git/stash.go37
-rw-r--r--pkg/git/status.go41
-rw-r--r--pkg/gui/branchview.go2
-rw-r--r--pkg/gui/gui-util.go16
-rw-r--r--pkg/gui/gui.go2
-rw-r--r--pkg/gui/keybindings.go36
-rw-r--r--pkg/gui/mainview.go10
-rw-r--r--pkg/gui/remotebranchview.go6
-rw-r--r--pkg/gui/remotesview.go2
-rw-r--r--pkg/gui/stagedview.go12
-rw-r--r--pkg/gui/stashview.go6
-rw-r--r--pkg/gui/statusview.go8
-rw-r--r--pkg/gui/textstyle.go10
-rw-r--r--pkg/gui/unstagedview.go14
-rw-r--r--pkg/helpers/command.go2
29 files changed, 257 insertions, 198 deletions
diff --git a/README.md b/README.md
index fb88f9f..e3bfdd7 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ For more information;
- select all feature ✔
- arrange repositories to an order e.g. alphabetic, last modified, etc. ✔
- shift keys, i.e. **s** for iterate **alt + s** for reverse iteration ✔
-- recursive repository search from the filesystem
+- recursive repository search from the filesystem ✔
- full src-d/go-git integration (*having some performance issues*)
- implement config file to pre-define repo locations or some settings ✔
- resolve authentication issues
diff --git a/main.go b/main.go
index 5491b97..27cdaaf 100644
--- a/main.go
+++ b/main.go
@@ -11,19 +11,24 @@ import (
var (
// take this as default directory if user does not start app with -d flag
currentDir, err = os.Getwd()
- dir = kingpin.Flag("directory", "Directory to roam for git repositories").Default(currentDir).Short('d').String()
+ dirs = kingpin.Flag("directory", "Directory to roam for git repositories").Default(currentDir).Short('d').Strings()
ignoreConfig = kingpin.Flag("ignore-config", "Ignore config file").Short('i').Bool()
- repoPattern = kingpin.Flag("pattern", "Pattern to filter repositories").Short('p').String()
+ recurseDepth = kingpin.Flag("recursive-depth", "Find directories recursively").Default("1").Short('r').Int()
logLevel = kingpin.Flag("log-level", "Logging level; trace,debug,info,warn,error").Default("error").Short('l').String()
)
func main() {
- kingpin.Version("gitbatch version 0.0.1 (alpha)")
+ kingpin.Version("gitbatch version 0.0.2 (alpha)")
// parse the command line flag and options
kingpin.Parse()
// set the app
- app, err := app.Setup(*dir, *repoPattern, *logLevel, *ignoreConfig)
+ app, err := app.Setup(app.SetupConfig{
+ Directories: *dirs,
+ LogLevel: *logLevel,
+ IgnoreConfig: *ignoreConfig,
+ Depth: *recurseDepth,
+ })
if err != nil {
log.Fatal(err)
}
diff --git a/pkg/app/app.go b/pkg/app/app.go
index e281abc..9082386 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -1,8 +1,6 @@
package app
import (
- "os"
-
"github.com/isacikgoz/gitbatch/pkg/gui"
log "github.com/sirupsen/logrus"
)
@@ -10,16 +8,24 @@ import (
// The App struct is responsible to hold app-wide related entities. Currently
// it has only the gui.Gui pointer for interface entity.
type App struct {
- Gui *gui.Gui
+ Gui *gui.Gui
Config *Config
}
+// SetupConfig is an assembler data to initiate a setup
+type SetupConfig struct {
+ Directories []string
+ LogLevel string
+ IgnoreConfig bool
+ Depth int
+}
+
// Setup will handle pre-required operations. It is designed to be a wrapper for
// main method right now.
-func Setup(directory, repoPattern, logLevel string, ignoreConfig bool) (*App, error) {
+func Setup(setupConfig SetupConfig) (*App, error) {
// initiate the app and give it initial values
app := &App{}
- setLogLevel(logLevel)
+ setLogLevel(setupConfig.LogLevel)
var err error
app.Config, err = LoadConfiguration()
if err != nil {
@@ -27,18 +33,12 @@ func Setup(directory, repoPattern, logLevel string, ignoreConfig bool) (*App, er
log.Error(err)
return app, err
}
- workingDirectory, _ := os.Getwd()
-
directories := make([]string, 0)
- if len(app.Config.Directories) <= 0 || ignoreConfig ||
- (workingDirectory != directory && len(app.Config.Directories) > 0 ){
- directories = generateDirectories(directory, repoPattern)
+
+ if len(app.Config.Directories) <= 0 || setupConfig.IgnoreConfig {
+ directories = generateDirectories(setupConfig.Directories, setupConfig.Depth)
} else {
- for _, dir := range app.Config.Directories {
- for _, d := range generateDirectories(dir, repoPattern) {
- directories = append(directories, d)
- }
- }
+ directories = generateDirectories(app.Config.Directories, setupConfig.Depth)
}
// create a gui.Gui struct and set it as App's gui
diff --git a/pkg/app/config.go b/pkg/app/config.go
index 815b5b0..94052e6 100644
--- a/pkg/app/config.go
+++ b/pkg/app/config.go
@@ -5,36 +5,36 @@ import (
"path/filepath"
"runtime"
- "github.com/spf13/viper"
log "github.com/sirupsen/logrus"
+ "github.com/spf13/viper"
)
// Config type is the configuration entity of the application
type Config struct {
- Mode string
+ Mode string
Directories []string
}
// config file stuff
var (
configFileName = "config"
- configFileExt = ".yml"
- configType = "yaml"
- appName = "gitbatch"
+ configFileExt = ".yml"
+ configType = "yaml"
+ appName = "gitbatch"
configurationDirectory = filepath.Join(osConfigDirectory(), appName)
- configFileAbsPath = filepath.Join(configurationDirectory, configFileName)
+ configFileAbsPath = filepath.Join(configurationDirectory, configFileName)
)
// configuration items
var (
- modeKey = "mode"
- modeKeyDefault = "fetch"
- pathsKey = "paths"
+ modeKey = "mode"
+ modeKeyDefault = "fetch"
+ pathsKey = "paths"
pathsKeyDefault = []string{"."}
)
-// LoadConfiguration returns a Config struct is filled
+// LoadConfiguration returns a Config struct is filled
func LoadConfiguration() (*Config, error) {
if err := initializeConfigurationManager(); err != nil {
return nil, err
@@ -46,7 +46,7 @@ func LoadConfiguration() (*Config, error) {
return nil, err
}
config := &Config{
- Mode: viper.GetString(modeKey),
+ Mode: viper.GetString(modeKey),
Directories: viper.GetStringSlice(pathsKey),
}
return config, nil
@@ -60,13 +60,13 @@ func setDefaults() error {
}
// read configuration from file
-func readConfiguration() error{
+func readConfiguration() error {
err := viper.ReadInConfig() // Find and read the config file
- if err != nil { // Handle errors reading the config file
+ if err != nil { // Handle errors reading the config file
// if file does not exist, simply create one
- if _, err := os.Stat(configFileAbsPath+configFileExt); os.IsNotExist(err) {
+ if _, err := os.Stat(configFileAbsPath + configFileExt); os.IsNotExist(err) {
os.MkdirAll(configurationDirectory, 0755)
- os.Create(configFileAbsPath+configFileExt)
+ os.Create(configFileAbsPath + configFileExt)
} else {
return err
}
@@ -79,7 +79,7 @@ func readConfiguration() error{
}
// write configuration to a file
-func writeConfiguration() error{
+func writeConfiguration() error {
if err := viper.WriteConfig(); err != nil {
return err
}
@@ -109,4 +109,4 @@ func osConfigDirectory() (osConfigDirectory string) {
log.Warn("Operating system couldn't be recognized")
}
return osConfigDirectory
-} \ No newline at end of file
+}
diff --git a/pkg/app/files.go b/pkg/app/files.go
index b210c66..b6ec662 100644
--- a/pkg/app/files.go
+++ b/pkg/app/files.go
@@ -9,50 +9,88 @@ import (
log "github.com/sirupsen/logrus"
)
-// generateDirectories is to find all the files in given path. This method
+// generateDirectories returns poosible git repositories to pipe into git pkg's
+// load function
+func generateDirectories(directories []string, depth int) (gitDirectories []string) {
+ for i := 0; i <= depth; i++ {
+ nonrepos, repos := walkRecursive(directories, gitDirectories)
+ directories = nonrepos
+ gitDirectories = repos
+ }
+ return gitDirectories
+}
+
+// returns given values, first search directories and second stands for possible
+// git repositories. Call this func from a "for i := 0; i<depth; i++" loop
+func walkRecursive(search, appendant []string) ([]string, []string) {
+ max := len(search)
+ for i := 0; i < max; i++ {
+ if i >= len(search) {
+ continue
+ }
+ // find possible repositories and remaining ones, b slice is possible ones
+ a, b, err := seperateDirectories(search[i])
+ if err != nil {
+ log.WithFields(log.Fields{
+ "directory": search[i],
+ }).Trace("Can't read directory")
+ continue
+ }
+ // since we started to search let's get rid of it and remove from search
+ // array
+ search[i] = search[len(search)-1]
+ search = search[:len(search)-1]
+ // lets append what we have found to continue recursion
+ search = append(search, a...)
+ appendant = append(appendant, b...)
+ }
+ return search, appendant
+}
+
+// seperateDirectories is to find all the files in given path. This method
// does not check if the given file is a valid git repositories
-func generateDirectories(directory string, repoPattern string) (directories []string) {
+func seperateDirectories(directory string) (directories, gitDirectories []string, err error) {
files, err := ioutil.ReadDir(directory)
-
// can we read the directory?
if err != nil {
- log.Fatal(err)
+ log.WithFields(log.Fields{
+ "directory": directory,
+ }).Trace("Can't read directory")
+ return directories, gitDirectories, nil
}
-
- // filter according to a pattern
- filteredFiles := filterDirectories(files, repoPattern)
-
- // now let's iterate over the our desired git directories
- for _, f := range filteredFiles {
+ for _, f := range files {
repo := directory + string(os.PathSeparator) + f.Name()
file, err := os.Open(repo)
-
// if we cannot open it, simply continue to iteration and don't consider
if err != nil {
log.WithFields(log.Fields{
"file": file,
- "directory": directory,
+ "directory": repo,
}).Trace("Failed to open file in the directory")
continue
}
dir, err := filepath.Abs(file.Name())
if err != nil {
- log.Fatal(err)
+ return nil, nil, err
+ }
+ // with this approach, we ignore submodule or sub repositoreis in a git repository
+ _, err = os.Open(dir + string(os.PathSeparator) + ".git")
+ if err != nil {
+ directories = append(directories, dir)
+ } else {
+ gitDirectories = append(gitDirectories, dir)
}
-
- // shaping our directory slice
- directories = append(directories, dir)
}
- return directories
+ return directories, gitDirectories, nil
}
// takes a fileInfo slice and returns it with the ones matches with the
-// repoPattern string
-func filterDirectories(files []os.FileInfo, repoPattern string) []os.FileInfo {
+// pattern string
+func filterDirectories(files []os.FileInfo, pattern string) []os.FileInfo {
var filteredRepos []os.FileInfo
for _, f := range files {
// it is just a simple filter
- if strings.Contains(f.Name(), repoPattern) && f.Name() != ".git" {
+ if strings.Contains(f.Name(), pattern) && f.Name() != ".git" {
filteredRepos = append(filteredRepos, f)
} else {
continue
diff --git a/pkg/git/add.go b/pkg/git/add.go
index 73c7d9e..6abb868 100644
--- a/pkg/git/add.go
+++ b/pkg/git/add.go
@@ -11,7 +11,7 @@ var addCommand = "add"
type AddOptions struct {
Update bool
- Force bool
+ Force bool
DryRun bool
}
@@ -49,4 +49,4 @@ func (entity *RepoEntity) AddAll(option AddOptions) error {
return errors.New(out + "\n" + err.Error())
}
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/git/branch.go b/pkg/git/branch.go
index ee01f5d..0fbfdf0 100644
--- a/pkg/git/branch.go
+++ b/pkg/git/branch.go
@@ -6,8 +6,8 @@ import (
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"regexp"
- "strings"
"strconv"
+ "strings"
)
// Branch is the wrapper of go-git's Reference struct. In addition to that, it
@@ -51,7 +51,7 @@ func (entity *RepoEntity) loadLocalBranches() error {
pushables, err := RevList(entity, RevListOptions{
Ref1: "@{u}",
Ref2: "HEAD",
- })
+ })
if err != nil {
push = pushables[0]
} else {
@@ -60,7 +60,7 @@ func (entity *RepoEntity) loadLocalBranches() error {
pullables, err := RevList(entity, RevListOptions{
Ref1: "HEAD",
Ref2: "@{u}",
- })
+ })
if err != nil {
pull = pullables[0]
} else {
@@ -160,7 +160,7 @@ func (entity *RepoEntity) RefreshPushPull() {
pushables, err := RevList(entity, RevListOptions{
Ref1: "@{u}",
Ref2: "HEAD",
- })
+ })
if err != nil {
entity.Branch.Pushables = pushables[0]
} else {
@@ -169,7 +169,7 @@ func (entity *RepoEntity) RefreshPushPull() {
pullables, err := RevList(entity, RevListOptions{
Ref1: "HEAD",
Ref2: "@{u}",
- })
+ })
if err != nil {
entity.Branch.Pullables = pullables[0]
} else {
@@ -184,7 +184,7 @@ func (entity *RepoEntity) pullDiffsToUpstream() ([]*Commit, error) {
pullables, err := RevList(entity, RevListOptions{
Ref1: "HEAD",
Ref2: "@{u}",
- })
+ })
if err != nil {
// possibly found nothing or no upstream set
} else {
@@ -207,7 +207,7 @@ func (entity *RepoEntity) pushDiffsToUpstream() ([]string, error) {
pushables, err := RevList(entity, RevListOptions{
Ref1: "@{u}",
Ref2: "HEAD",
- })
+ })
if err != nil {
return make([]string, 0), nil
}
diff --git a/pkg/git/commands.go b/pkg/git/commands.go
index 825c712..b78b501 100644
--- a/pkg/git/commands.go
+++ b/pkg/git/commands.go
@@ -13,7 +13,7 @@ func GenericGitCommand(repoPath string, args []string) error {
return nil
}
-// GenericGitCommand runs any git command with returning output
+// GenericGitCommandWithOutput runs any git command with returning output
func GenericGitCommandWithOutput(repoPath string, args []string) (string, error) {
out, err := helpers.RunCommandWithOutput(repoPath, "git", args)
if err != nil {
@@ -22,7 +22,7 @@ func GenericGitCommandWithOutput(repoPath string, args []string) (string, error)
return helpers.TrimTrailingNewline(out), nil
}
-// GenericGitCommand runs any git command with returning output
+// GenericGitCommandWithErrorOutput runs any git command with returning output
func GenericGitCommandWithErrorOutput(repoPath string, args []string) (string, error) {
out, err := helpers.RunCommandWithOutput(repoPath, "git", args)
if err != nil {
diff --git a/pkg/git/fetch.go b/pkg/git/fetch.go
index 9733465..5dad021 100644
--- a/pkg/git/fetch.go
+++ b/pkg/git/fetch.go
@@ -6,17 +6,18 @@ import (
var fetchCommand = "fetch"
+// FetchOptions defines the rules for fetch operation
type FetchOptions struct {
- // Name of the remote to fetch from. Defaults to origin.
- RemoteName string
- // Before fetching, remove any remote-tracking references that no longer
- // exist on the remote.
- Prune bool
- // Show what would be done, without making any changes.
- DryRun bool
- // Force allows the fetch to update a local branch even when the remote
- // branch does not descend from it.
- Force bool
+ // Name of the remote to fetch from. Defaults to origin.
+ RemoteName string
+ // Before fetching, remove any remote-tracking references that no longer
+ // exist on the remote.
+ Prune bool
+ // Show what would be done, without making any changes.
+ DryRun bool
+ // Force allows the fetch to update a local branch even when the remote
+ // branch does not descend from it.
+ Force bool
}
// Fetch branches refs from one or more other repositories, along with the
@@ -42,4 +43,4 @@ func Fetch(entity *RepoEntity, options FetchOptions) error {
}
entity.Refresh()
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/git/merge.go b/pkg/git/merge.go
index ebc4ccc..984bc4b 100644
--- a/pkg/git/merge.go
+++ b/pkg/git/merge.go
@@ -6,13 +6,14 @@ import (
var mergeCommand = "merge"
+// MergeOptions defines the rules of a merge operation
type MergeOptions struct {
- // Name of the branch to merge with.
- BranchName string
- // Be verbose.
- Verbose bool
- // With true do not show a diffstat at the end of the merge.
- NoStat bool
+ // Name of the branch to merge with.
+ BranchName string
+ // Be verbose.
+ Verbose bool
+ // With true do not show a diffstat at the end of the merge.
+ NoStat bool
}
// Merge incorporates changes from the named commits or branches into the
@@ -35,4 +36,4 @@ func Merge(entity *RepoEntity, options MergeOptions) error {
}
entity.Refresh()
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/git/repository-sort.go b/pkg/git/repository-sort.go
index 04cd9e7..de5f454 100644
--- a/pkg/git/repository-sort.go
+++ b/pkg/git/repository-sort.go
@@ -9,7 +9,7 @@ import (
type Alphabetical []*RepoEntity
// Len is the interface implementation for Alphabetical sorting function
-func (s Alphabetical) Len() int { return len(s) }
+func (s Alphabetical) Len() int { return len(s) }
// Swap is the interface implementation for Alphabetical sorting function
func (s Alphabetical) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
@@ -48,7 +48,7 @@ func (s Alphabetical) Less(i, j int) bool {
type LastModified []*RepoEntity
// Len is the interface implementation for LastModified sorting function
-func (s LastModified) Len() int { return len(s) }
+func (s LastModified) Len() int { return len(s) }
// Swap is the interface implementation for LastModified sorting function
func (s LastModified) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
diff --git a/pkg/git/repository.go b/pkg/git/repository.go
index 0ec6eaf..b127305 100644
--- a/pkg/git/repository.go
+++ b/pkg/git/repository.go
@@ -2,8 +2,8 @@ package git
import (
"errors"
- "time"
"os"
+ "time"
"github.com/isacikgoz/gitbatch/pkg/helpers"
log "github.com/sirupsen/logrus"
@@ -92,8 +92,10 @@ func InitializeRepository(directory string) (entity *RepoEntity, err error) {
if len(entity.Remotes) > 0 {
// TODO: tend to take origin/master as default
entity.Remote = entity.Remotes[0]
- // TODO: same code on 3 different occasion, maybe something wrong?
- if err = entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err != nil {
+ if entity.Branch == nil {
+ return nil, errors.New("Unable to find a valid branch")
+ }
+ if err = entity.Remote.SyncBranches(entity.Branch.Name); err != nil {
// probably couldn't find, but its ok.
}
} else {
diff --git a/pkg/git/reset.go b/pkg/git/reset.go
index 1a4c71d..f93225c 100644
--- a/pkg/git/reset.go
+++ b/pkg/git/reset.go
@@ -9,12 +9,14 @@ import (
var resetCommand = "reset"
+// ResetOptions defines the rules of git reset command
type ResetOptions struct {
- Hard bool
+ Hard bool
Merge bool
- Keep bool
+ Keep bool
}
+// Reset is the wrapper of "git reset" command
func (file *File) Reset(option ResetOptions) error {
args := make([]string, 0)
args = append(args, resetCommand)
@@ -37,6 +39,7 @@ func (file *File) Reset(option ResetOptions) error {
return nil
}
+// ResetAll resets the changes in a repository, should be used wise
func (entity *RepoEntity) ResetAll(option ResetOptions) error {
args := make([]string, 0)
args = append(args, resetCommand)
@@ -49,4 +52,4 @@ func (entity *RepoEntity) ResetAll(option ResetOptions) error {
return errors.New(out + "\n" + err.Error())
}
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/git/rev-list.go b/pkg/git/rev-list.go
index f9f45da..5debe47 100644
--- a/pkg/git/rev-list.go
+++ b/pkg/git/rev-list.go
@@ -9,11 +9,12 @@ import (
var revlistCommand = "rev-list"
var hashLength = 40
+// RevListOptions defines the rules of rev-list func
type RevListOptions struct {
- // Ref1 is the first reference hash to link
- Ref1 string
- // Ref2 is the second reference hash to link
- Ref2 string
+ // Ref1 is the first reference hash to link
+ Ref1 string
+ // Ref2 is the second reference hash to link
+ Ref2 string
}
// RevList returns the commit hashes that are links from the given commit(s).
@@ -22,7 +23,7 @@ func RevList(entity *RepoEntity, options RevListOptions) ([]string, error) {
args := make([]string, 0)
args = append(args, revlistCommand)
if len(options.Ref1) > 0 && len(options.Ref2) > 0 {
- arg1 := options.Ref1+".."+options.Ref2
+ arg1 := options.Ref1 + ".." + options.Ref2
args = append(args, arg1)
}
out, err := GenericGitCommandWithOutput(entity.AbsPath, args)
@@ -39,4 +40,4 @@ func RevList(entity *RepoEntity, options RevListOptions) ([]string, error) {
}
}
return hashes, nil
-} \ No newline at end of file
+}
diff --git a/pkg/git/stash.go b/pkg/git/stash.go
index 6c647ae..66254c8 100644
--- a/pkg/git/stash.go
+++ b/pkg/git/stash.go
@@ -2,20 +2,21 @@ package git
import (
"regexp"
- "strings"
"strconv"
+ "strings"
log "github.com/sirupsen/logrus"
)
var stashCommand = "stash"
+// StashedItem holds the required fields for a stashed change
type StashedItem struct {
- StashID int
- BranchName string
- Hash string
+ StashID int
+ BranchName string
+ Hash string
Description string
- EntityPath string
+ EntityPath string
}
func stashGet(entity *RepoEntity, option string) string {
@@ -37,12 +38,12 @@ func (entity *RepoEntity) loadStashedItems() error {
stashIDRegexInt := regexp.MustCompile(`[\d]+`)
stashBranchRegex := regexp.MustCompile(`[\w]+: `)
stashHashRegex := regexp.MustCompile(`[\w]{7}`)
-
+
stashlist := strings.Split(output, "\n")
for _, stashitem := range stashlist {
// find id
id := stashIDRegexInt.FindString(stashIDRegex.FindString(stashitem))
- i, err := strconv.Atoi(id)
+ i, err := strconv.Atoi(id)
if err != nil {
// probably something isn't right let's continue over this iteration
log.Trace("cannot initiate stashed item")
@@ -50,29 +51,30 @@ func (entity *RepoEntity) loadStashedItems() error {
}
// trim id section
trimmed := stashIDRegex.Split(stashitem, 2)[1]
-
+
// find branch
- stashBranchRegexMatch :=stashBranchRegex.FindString(trimmed)
+ stashBranchRegexMatch := stashBranchRegex.FindString(trimmed)
branchName := stashBranchRegexMatch[:len(stashBranchRegexMatch)-2]
-
+
// trim branch section
trimmed = stashBranchRegex.Split(trimmed, 2)[1]
hash := stashHashRegex.FindString(trimmed)
-
+
// trim hash
desc := stashHashRegex.Split(trimmed, 2)[1][1:]
entity.Stasheds = append(entity.Stasheds, &StashedItem{
- StashID: i,
- BranchName: branchName,
- Hash: hash,
+ StashID: i,
+ BranchName: branchName,
+ Hash: hash,
Description: desc,
- EntityPath: entity.AbsPath,
- })
+ EntityPath: entity.AbsPath,
+ })
}
return nil
}
+// Stash is the wrapper of convetional "git stash" command
func (entity *RepoEntity) Stash() (output string, err error) {
args := make([]string, 0)
args = append(args, stashCommand)
@@ -82,6 +84,7 @@ func (entity *RepoEntity) Stash() (output string, err error) {
return output, err
}
+// Pop is the wrapper of "git stash pop" command that used for a file
func (stashedItem *StashedItem) Pop() (output string, err error) {
args := make([]string, 0)
args = append(args, stashCommand)
@@ -89,4 +92,4 @@ func (stashedItem *StashedItem) Pop() (output string, err error) {
args = append(args, "stash@{"+strconv.Itoa(stashedItem.StashID)+"}")
output, err = GenericGitCommandWithErrorOutput(stashedItem.EntityPath, args)
return output, err
-} \ No newline at end of file
+}
diff --git a/pkg/git/status.go b/pkg/git/status.go
index 5644a09..8db2ec7 100644
--- a/pkg/git/status.go
+++ b/pkg/git/status.go
@@ -10,25 +10,36 @@ import (
var statusCommand = "status"
+// File represents the status of a file in an index or work tree
type File struct {
- Name string
+ Name string
AbsPath string
- X FileStatus
- Y FileStatus
+ X FileStatus
+ Y FileStatus
}
+// FileStatus is the short representation of state of a file
type FileStatus rune
var (
+ // StatusNotupdated says file not updated
StatusNotupdated FileStatus = ' '
- StatusModified FileStatus = 'M'
- StatusAdded FileStatus = 'A'
- StatusDeleted FileStatus = 'D'
- StatusRenamed FileStatus = 'R'
- StatusCopied FileStatus = 'C'
- StatusUpdated FileStatus = 'U'
+ // StatusModified says file is modifed
+ StatusModified FileStatus = 'M'
+ // StatusAdded says file is added to index
+ StatusAdded FileStatus = 'A'
+ // StatusDeleted says file is deleted
+ StatusDeleted FileStatus = 'D'
+ // StatusRenamed says file is renamed
+ StatusRenamed FileStatus = 'R'
+ // StatusCopied says file is copied
+ StatusCopied FileStatus = 'C'
+ // StatusUpdated says file is updated
+ StatusUpdated FileStatus = 'U'
+ // StatusUntracked says file is untraced
StatusUntracked FileStatus = '?'
- StatusIgnored FileStatus = '!'
+ // StatusIgnored says file is ignored
+ StatusIgnored FileStatus = '!'
)
func shortStatus(entity *RepoEntity, option string) string {
@@ -44,6 +55,8 @@ func shortStatus(entity *RepoEntity, option string) string {
return out
}
+// LoadFiles function simply commands a git status and collects output in a
+// structured way
func (entity *RepoEntity) LoadFiles() ([]*File, error) {
files := make([]*File, 0)
output := shortStatus(entity, "--untracked-files=all")
@@ -58,11 +71,11 @@ func (entity *RepoEntity) LoadFiles() ([]*File, error) {
path := relativePathRegex.FindString(file[2:])
files = append(files, &File{
- Name: path,
+ Name: path,
AbsPath: entity.AbsPath + string(os.PathSeparator) + path,
- X: FileStatus(x),
- Y: FileStatus(y),
- })
+ X: FileStatus(x),
+ Y: FileStatus(y),
+ })
}
return files, nil
}
diff --git a/pkg/gui/branchview.go b/pkg/gui/branchview.go
index b6a2b43..c955cf0 100644
--- a/pkg/gui/branchview.go
+++ b/pkg/gui/branchview.go
@@ -83,4 +83,4 @@ func (gui *Gui) checkoutFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err erro
return err
}
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go
index f9bba41..2462723 100644
--- a/pkg/gui/gui-util.go
+++ b/pkg/gui/gui-util.go
@@ -42,10 +42,10 @@ func (gui *Gui) nextViewOfGroup(g *gocui.Gui, v *gocui.View, group []viewFeature
}
}
if _, err := g.SetCurrentView(focusedViewName); err != nil {
- log.WithFields(log.Fields{
- "view": focusedViewName,
- }).Warn("View cannot be focused.")
- return nil
+ log.WithFields(log.Fields{
+ "view": focusedViewName,
+ }).Warn("View cannot be focused.")
+ return nil
}
gui.updateKeyBindingsView(g, focusedViewName)
return nil
@@ -68,10 +68,10 @@ func (gui *Gui) previousViewOfGroup(g *gocui.Gui, v *gocui.View, group []viewFea
}
}
if _, err := g.SetCurrentView(focusedViewName); err != nil {
- log.WithFields(log.Fields{
- "view": focusedViewName,
- }).Warn("View cannot be focused.")
- return nil
+ log.WithFields(log.Fields{
+ "view": focusedViewName,
+ }).Warn("View cannot be focused.")
+ return nil
}
gui.updateKeyBindingsView(g, focusedViewName)
return nil
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 7fb3019..0cf9458 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -70,7 +70,7 @@ var (
mergeMode = mode{ModeID: MergeMode, DisplayString: "Merge", CommandString: "merge"}
mainViews = []viewFeature{mainViewFeature, remoteViewFeature, remoteBranchViewFeature, branchViewFeature, commitViewFeature}
- modes = []mode{fetchMode, pullMode, mergeMode}
+ modes = []mode{fetchMode, pullMode, mergeMode}
)
// NewGui creates a Gui opject and fill it's state related entites
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index c6e1814..1a6d6c9 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -167,7 +167,7 @@ func (gui *Gui) generateKeybindings() error {
}
}
individualKeybindings := []*KeyBinding{
- // stash view
+ // stash view
{
View: stashViewFeature.Name,
Key: 'p',
@@ -177,7 +177,7 @@ func (gui *Gui) generateKeybindings() error {
Description: "Pop Item",
Vital: true,
},
- // staged view
+ // staged view
{
View: stageViewFeature.Name,
Key: 'r',
@@ -195,7 +195,7 @@ func (gui *Gui) generateKeybindings() error {
Description: "Reset All Items",
Vital: true,
},
- // unstaged view
+ // unstaged view
{
View: unstageViewFeature.Name,
Key: 'a',
@@ -213,7 +213,7 @@ func (gui *Gui) generateKeybindings() error {
Description: "Add All Items",
Vital: true,
},
- // Main view controls
+ // Main view controls
{
View: mainViewFeature.Name,
Key: gocui.KeyArrowUp,
@@ -318,8 +318,8 @@ func (gui *Gui) generateKeybindings() error {
Display: "ctrl + c",
Description: "Force application to quit",
Vital: false,
- },
- // Branch View Controls
+ },
+ // Branch View Controls
{
View: branchViewFeature.Name,
Key: gocui.KeyArrowDown,
@@ -353,7 +353,7 @@ func (gui *Gui) generateKeybindings() error {
Description: "Up",
Vital: false,
},
- // Remote View Controls
+ // Remote View Controls
{
View: remoteViewFeature.Name,
Key: gocui.KeyArrowDown,
@@ -387,7 +387,7 @@ func (gui *Gui) generateKeybindings() error {
Description: "Up",
Vital: false,
},
- // Remote Branch View Controls
+ // Remote Branch View Controls
{
View: remoteBranchViewFeature.Name,
Key: gocui.KeyArrowDown,
@@ -429,7 +429,7 @@ func (gui *Gui) generateKeybindings() error {
Description: "Synch with Remote",
Vital: true,
},
- // Commit View Controls
+ // Commit View Controls
{
View: commitViewFeature.Name,
Key: gocui.KeyArrowDown,
@@ -438,7 +438,7 @@ func (gui *Gui) generateKeybindings() error {
Display: "↓",
Description: "Iterate over commits",
Vital: false,
- },{
+ }, {
View: commitViewFeature.Name,
Key: gocui.KeyArrowUp,
Modifier: gocui.ModNone,
@@ -462,7 +462,7 @@ func (gui *Gui) generateKeybindings() error {
Display: "k",
Description: "Up",
Vital: false,
- },{
+ }, {
View: commitViewFeature.Name,
Key: 'd',
Modifier: gocui.ModNone,
@@ -470,8 +470,8 @@ func (gui *Gui) generateKeybindings() error {
Display: "d",
Description: "Show commit diff",
Vital: true,
- },
- // Diff View Controls
+ },
+ // Diff View Controls
{
View: commitDiffViewFeature.Name,
Key: 'c',
@@ -512,8 +512,8 @@ func (gui *Gui) generateKeybindings() error {
Display: "j",
Description: "Page down",
Vital: false,
- },
- // Application Controls
+ },
+ // Application Controls
{
View: cheatSheetViewFeature.Name,
Key: 'c',
@@ -554,8 +554,8 @@ func (gui *Gui) generateKeybindings() error {
Display: "j",
Description: "Down",
Vital: false,
- },
- // Error View
+ },
+ // Error View
{
View: errorViewFeature.Name,
Key: 'c',
@@ -596,7 +596,7 @@ func (gui *Gui) generateKeybindings() error {
Display: "j",
Description: "Down",
Vital: false,
- },
+ },
}
for _, binding := range individualKeybindings {
gui.KeyBindings = append(gui.KeyBindings, binding)
diff --git a/pkg/gui/mainview.go b/pkg/gui/mainview.go
index f912382..b421775 100644
--- a/pkg/gui/mainview.go
+++ b/pkg/gui/mainview.go
@@ -149,12 +149,12 @@ func (gui *Gui) removeFromQueue(entity *git.RepoEntity) error {
func (gui *Gui) markRepository(g *gocui.Gui, v *gocui.View) error {
r := gui.getSelectedRepository()
if r.State == git.Available || r.State == git.Success {
- if err := gui.addToQueue(r); err !=nil {
+ if err := gui.addToQueue(r); err != nil {
return err
}
} else if r.State == git.Queued {
- if err := gui.removeFromQueue(r); err !=nil {
- return err
+ if err := gui.removeFromQueue(r); err != nil {
+ return err
}
} else {
return nil
@@ -168,7 +168,7 @@ func (gui *Gui) markRepository(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error {
for _, r := range gui.State.Repositories {
if r.State == git.Available || r.State == git.Success {
- if err := gui.addToQueue(r); err !=nil {
+ if err := gui.addToQueue(r); err != nil {
return err
}
} else {
@@ -184,7 +184,7 @@ func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) unmarkAllRepositories(g *gocui.Gui, v *gocui.View) error {
for _, r := range gui.State.Repositories {
if r.State == git.Queued {
- if err := gui.removeFromQueue(r); err !=nil {
+ if err := gui.removeFromQueue(r); err != nil {
return err
}
} else {
diff --git a/pkg/gui/remotebranchview.go b/pkg/gui/remotebranchview.go
index ce44e2c..6c58565 100644
--- a/pkg/gui/remotebranchview.go
+++ b/pkg/gui/remotebranchview.go
@@ -43,14 +43,14 @@ func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
if err = git.Fetch(entity, git.FetchOptions{
RemoteName: entity.Remote.Name,
- Prune: true,
+ Prune: true,
}); err != nil {
return err
}
// have no idea why this works..
// some time need to fix, movement aint bad huh?
- gui.nextRemote(g,v)
- gui.previousRemote(g,v)
+ gui.nextRemote(g, v)
+ gui.previousRemote(g, v)
if err = gui.updateRemoteBranches(g, entity); err != nil {
return err
}
diff --git a/pkg/gui/remotesview.go b/pkg/gui/remotesview.go
index 6f31265..55366b2 100644
--- a/pkg/gui/remotesview.go
+++ b/pkg/gui/remotesview.go
@@ -72,4 +72,4 @@ func (gui *Gui) remoteChangeFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err
return err
}
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/gui/stagedview.go b/pkg/gui/stagedview.go
index 91b0df3..3e83a96 100644
--- a/pkg/gui/stagedview.go
+++ b/pkg/gui/stagedview.go
@@ -29,7 +29,7 @@ func (gui *Gui) openStageView(g *gocui.Gui) error {
return nil
}
-func (gui *Gui) resetChanges(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) resetChanges(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
files, _, err := generateFileLists(entity)
if err != nil {
@@ -40,9 +40,7 @@ func (gui *Gui) resetChanges(g *gocui.Gui, v *gocui.View) error {
}
_, cy := v.Cursor()
_, oy := v.Origin()
- if err := files[cy+oy].Reset(git.ResetOptions{
-
- }); err != nil {
+ if err := files[cy+oy].Reset(git.ResetOptions{}); err != nil {
return err
}
if err := refreshAllStatusView(g, entity); err != nil {
@@ -51,11 +49,9 @@ func (gui *Gui) resetChanges(g *gocui.Gui, v *gocui.View) error {
return nil
}
-func (gui *Gui) resetAllChanges(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) resetAllChanges(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
- if err := entity.ResetAll(git.ResetOptions{
-
- }); err != nil {
+ if err := entity.ResetAll(git.ResetOptions{}); err != nil {
return err
}
if err := refreshAllStatusView(g, entity); err != nil {
diff --git a/pkg/gui/stashview.go b/pkg/gui/stashview.go
index c9c246e..cfdc104 100644
--- a/pkg/gui/stashview.go
+++ b/pkg/gui/stashview.go
@@ -25,7 +25,7 @@ func (gui *Gui) openStashView(g *gocui.Gui) error {
return nil
}
-//
+//
func (gui *Gui) stashChanges(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
output, err := entity.Stash()
@@ -42,7 +42,7 @@ func (gui *Gui) stashChanges(g *gocui.Gui, v *gocui.View) error {
return nil
}
-//
+//
func (gui *Gui) popStash(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
_, oy := v.Origin()
@@ -86,4 +86,4 @@ func refreshStashView(g *gocui.Gui, entity *git.RepoEntity) error {
fmt.Fprintf(stashView, "%s%d %s: %s (%s)\n", prefix, stashedItem.StashID, cyan.Sprint(stashedItem.BranchName), stashedItem.Description, cyan.Sprint(stashedItem.Hash))
}
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/gui/statusview.go b/pkg/gui/statusview.go
index fbc90ee..d95a56f 100644
--- a/pkg/gui/statusview.go
+++ b/pkg/gui/statusview.go
@@ -10,9 +10,9 @@ import (
var (
statusHeaderViewFeature = viewFeature{Name: "status-header", Title: " Status Header "}
// statusViewFeature = viewFeature{Name: "status", Title: " Status "}
- stageViewFeature = viewFeature{Name: "staged", Title: " Staged "}
- unstageViewFeature = viewFeature{Name: "unstaged", Title: " Unstaged "}
- stashViewFeature = viewFeature{Name: "stash", Title: " Stash "}
+ stageViewFeature = viewFeature{Name: "staged", Title: " Staged "}
+ unstageViewFeature = viewFeature{Name: "unstaged", Title: " Unstaged "}
+ stashViewFeature = viewFeature{Name: "stash", Title: " Stash "}
statusViews = []viewFeature{stageViewFeature, unstageViewFeature, stashViewFeature}
)
@@ -90,7 +90,7 @@ func (gui *Gui) statusCursorUp(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) openStatusHeaderView(g *gocui.Gui) error {
maxX, _ := g.Size()
entity := gui.getSelectedRepository()
- v, err := g.SetView(statusHeaderViewFeature.Name, 6, 2, maxX-6, 4)
+ v, err := g.SetView(statusHeaderViewFeature.Name, 6, 2, maxX-6, 4)
if err != nil {
if err != gocui.ErrUnknownView {
return err
diff --git a/pkg/gui/textstyle.go b/pkg/gui/textstyle.go
index 554a590..50bc945 100644
--- a/pkg/gui/textstyle.go
+++ b/pkg/gui/textstyle.go
@@ -45,7 +45,7 @@ var (
keyBindingSeperator = "░"
selectionIndicator = ws + string(green.Sprint("→")) + ws
- tab = ws
+ tab = ws
)
// this function handles the render and representation of the repository
@@ -56,11 +56,11 @@ func (gui *Gui) displayString(entity *git.RepoEntity) string {
repoName := ""
if entity.Branch.Pushables != "?" {
- prefix = prefix + pushable + ws + entity.Branch.Pushables +
- ws + pullable + ws + entity.Branch.Pullables
+ prefix = prefix + pushable + ws + entity.Branch.Pushables +
+ ws + pullable + ws + entity.Branch.Pullables
} else {
- prefix = prefix + pushable + ws + yellow.Sprint(entity.Branch.Pushables) +
- ws + pullable + ws + yellow.Sprint(entity.Branch.Pullables)
+ prefix = prefix + pushable + ws + yellow.Sprint(entity.Branch.Pushables) +
+ ws + pullable + ws + yellow.Sprint(entity.Branch.Pullables)
}
selectedEntity := gui.getSelectedRepository()
diff --git a/pkg/gui/unstagedview.go b/pkg/gui/unstagedview.go
index cf74ce4..93082cc 100644
--- a/pkg/gui/unstagedview.go
+++ b/pkg/gui/unstagedview.go
@@ -25,7 +25,7 @@ func (gui *Gui) openUnStagedView(g *gocui.Gui) error {
return nil
}
-func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
_, files, err := generateFileLists(entity)
if err != nil {
@@ -36,9 +36,7 @@ func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error {
}
_, cy := v.Cursor()
_, oy := v.Origin()
- if err := files[cy+oy].Add(git.AddOptions{
-
- }); err != nil {
+ if err := files[cy+oy].Add(git.AddOptions{}); err != nil {
return err
}
if err := refreshAllStatusView(g, entity); err != nil {
@@ -47,11 +45,9 @@ func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error {
return nil
}
-func (gui *Gui) addAllChanges(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) addAllChanges(g *gocui.Gui, v *gocui.View) error {
entity := gui.getSelectedRepository()
- if err := entity.AddAll(git.AddOptions{
-
- }); err != nil {
+ if err := entity.AddAll(git.AddOptions{}); err != nil {
return err
}
if err := refreshAllStatusView(g, entity); err != nil {
@@ -81,4 +77,4 @@ func refreshUnstagedView(g *gocui.Gui, entity *git.RepoEntity) error {
fmt.Fprintf(stageView, "%s%s%s %s\n", prefix, red.Sprint(string(file.X)), red.Sprint(string(file.Y)), file.Name)
}
return nil
-} \ No newline at end of file
+}
diff --git a/pkg/helpers/command.go b/pkg/helpers/command.go
index 2485b56..b861812 100644
--- a/pkg/helpers/command.go
+++ b/pkg/helpers/command.go
@@ -19,7 +19,7 @@ func RunCommandWithOutput(dir string, command string, args []string) (string, er
}
// GetCommandStatus returns if we supposed to get return value as an int of a command
-// this method can be used. It is practical when you use a command and process a
+// this method can be used. It is practical when you use a command and process a
// failover acoording to a soecific return code
func GetCommandStatus(dir string, command string, args []string) (int, error) {
cmd := exec.Command(command, args...)