summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-03 01:00:08 +0300
committerIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-03 01:00:08 +0300
commit51d364140f1cd3e9ba09f3380a3e288a11131651 (patch)
treede4e63e07f142d25b1cd250c57a130895f2a82be
parentcode formatting with gofmt (diff)
downloadgitbatch-51d364140f1cd3e9ba09f3380a3e288a11131651.tar.gz
updated code according to lint suggestions
-rw-r--r--pkg/app/app.go6
-rw-r--r--pkg/git/branch.go6
-rw-r--r--pkg/git/commit.go10
-rw-r--r--pkg/git/git-commands.go22
-rw-r--r--pkg/git/load.go5
-rw-r--r--pkg/git/remote.go4
-rw-r--r--pkg/git/remotebranch.go2
-rw-r--r--pkg/git/repository.go28
-rw-r--r--pkg/gui/commitsview.go4
-rw-r--r--pkg/gui/gui-util.go12
-rw-r--r--pkg/gui/gui.go10
-rw-r--r--pkg/gui/keybindings.go2
-rw-r--r--pkg/gui/queuehandler.go9
-rw-r--r--pkg/gui/remotesview.go2
-rw-r--r--pkg/gui/textstyle.go3
-rw-r--r--pkg/helpers/command.go12
-rw-r--r--pkg/helpers/utils.go6
-rw-r--r--pkg/queue/queue.go24
18 files changed, 92 insertions, 75 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
index 53bb34b..d1ab15b 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -11,8 +11,8 @@ type App struct {
Gui *gui.Gui
}
-// If any pre-required operation is needed, setup will handle that task. It is
-// designed to be a wrapper for main method right now.
+// Setup will handle pre-required operations. It is designed to be a wrapper for
+// main method right now.
func Setup(directory, repoPattern, logLevel string) (*App, error) {
// initiate the app and give it initial values
app := &App{}
@@ -32,7 +32,7 @@ func Setup(directory, repoPattern, logLevel string) (*App, error) {
return app, nil
}
-// If any cleanup is required Close method with handle it. e.g. closing streams
+// Close function will handle if any cleanup is required. e.g. closing streams
// or cleaning temproray files so on and so forth
func (app *App) Close() error {
return nil
diff --git a/pkg/git/branch.go b/pkg/git/branch.go
index cd3e3f6..c94ced1 100644
--- a/pkg/git/branch.go
+++ b/pkg/git/branch.go
@@ -55,7 +55,7 @@ func (entity *RepoEntity) loadLocalBranches() error {
return err
}
-// checkouts the next branch
+// NextBranch checkouts the next branch
func (entity *RepoEntity) NextBranch() *Branch {
currentBranch := entity.Branch
currentBranchIndex := 0
@@ -70,7 +70,7 @@ func (entity *RepoEntity) NextBranch() *Branch {
return entity.Branches[currentBranchIndex+1]
}
-// checkout to given branch. If any errors occur, the method returns it instead
+// Checkout to given branch. If any errors occur, the method returns it instead
// of returning nil
func (entity *RepoEntity) Checkout(branch *Branch) error {
if branch.Name == entity.Branch.Name {
@@ -116,7 +116,7 @@ func (entity *RepoEntity) isClean() bool {
return false
}
-// refreshes the active branchs pushable and pullable count
+// RefreshPushPull refreshes the active branchs pushable and pullable count
func (entity *RepoEntity) RefreshPushPull() {
entity.Branch.Pushables, entity.Branch.Pullables = UpstreamDifferenceCount(entity.AbsPath)
}
diff --git a/pkg/git/commit.go b/pkg/git/commit.go
index 974d1b3..b0ba381 100644
--- a/pkg/git/commit.go
+++ b/pkg/git/commit.go
@@ -19,15 +19,17 @@ type Commit struct {
CommitType CommitType
}
-// type of the commit; it can be local or remote (upstream diff)
+// CommitType is the Type of the commit; it can be local or remote (upstream diff)
type CommitType string
const (
+ // LocalCommit is the commit that recorded locally
LocalCommit CommitType = "local"
+ // RemoteCommit is the commit that not merged to local branch
RemoteCommit CommitType = "remote"
)
-// iterate over next commit of a branch
+// NextCommit iterates over next commit of a branch
// TODO: the commits entites can tied to branch instead ot the repository
func (entity *RepoEntity) NextCommit() error {
currentCommitIndex := 0
@@ -90,8 +92,8 @@ func (entity *RepoEntity) loadCommits() error {
return nil
}
-// returns the diff to previous commit detail of the given hash of a specific
-// commit
+// Diff function returns the diff to previous commit detail of the given has
+// of a specific commit
func (entity *RepoEntity) Diff(hash string) (diff string, err error) {
currentCommitIndex := 0
diff --git a/pkg/git/git-commands.go b/pkg/git/git-commands.go
index 37aca64..9518322 100644
--- a/pkg/git/git-commands.go
+++ b/pkg/git/git-commands.go
@@ -23,7 +23,7 @@ func UpstreamDifferenceCount(repoPath string) (string, string) {
return strings.TrimSpace(pushableCount), strings.TrimSpace(pullableCount)
}
-// Instead of returning the count, this method returns the hash list
+// UpstreamPushDiffs returns the hash list
func UpstreamPushDiffs(repoPath string) string {
args := []string{"rev-list", "@{u}..HEAD"}
pushableCount, err := helpers.RunCommandWithOutput(repoPath, "git", args)
@@ -33,7 +33,7 @@ func UpstreamPushDiffs(repoPath string) string {
return pushableCount
}
-// Instead of returning the count, this method returns the hash list
+// UpstreamPullDiffs returns the hash list
func UpstreamPullDiffs(repoPath string) string {
args := []string{"rev-list", "HEAD..@{u}"}
pullableCount, err := helpers.RunCommandWithOutput(repoPath, "git", args)
@@ -43,7 +43,7 @@ func UpstreamPullDiffs(repoPath string) string {
return pullableCount
}
-// Conventional git show command without any argument
+// GitShow is conventional git show command without any argument
func GitShow(repoPath, hash string) string {
args := []string{"show", hash}
diff, err := helpers.RunCommandWithOutput(repoPath, "git", args)
@@ -53,7 +53,7 @@ func GitShow(repoPath, hash string) string {
return diff
}
-// get author's e-mail with git show command
+// GitShowEmail gets author's e-mail with git show command
func GitShowEmail(repoPath, hash string) string {
args := []string{"show", "--quiet", "--pretty=format:%ae", hash}
diff, err := helpers.RunCommandWithOutput(repoPath, "git", args)
@@ -63,7 +63,7 @@ func GitShowEmail(repoPath, hash string) string {
return diff
}
-// get body of the commit with git show
+// GitShowBody gets body of the commit with git show
func GitShowBody(repoPath, hash string) string {
args := []string{"show", "--quiet", "--pretty=format:%B", hash}
diff, err := helpers.RunCommandWithOutput(repoPath, "git", args)
@@ -73,7 +73,7 @@ func GitShowBody(repoPath, hash string) string {
return diff
}
-// get commit's date with git show as string
+// GitShowDate gets commit's date with git show as string
func GitShowDate(repoPath, hash string) string {
args := []string{"show", "--quiet", "--pretty=format:%ai", hash}
diff, err := helpers.RunCommandWithOutput(repoPath, "git", args)
@@ -83,7 +83,7 @@ func GitShowDate(repoPath, hash string) string {
return diff
}
-// wrapper of the git fetch <remote> command
+// FetchWithGit is wrapper of the git fetch <remote> command
func (entity *RepoEntity) FetchWithGit(remote string) error {
args := []string{"fetch", remote}
_, err := helpers.RunCommandWithOutput(entity.AbsPath, "git", args)
@@ -93,7 +93,7 @@ func (entity *RepoEntity) FetchWithGit(remote string) error {
return nil
}
-// wrapper of the git pull <remote>/<branch> command
+// PullWithGit is wrapper of the git pull <remote>/<branch> command
func (entity *RepoEntity) PullWithGit(remote, branch string) error {
args := []string{"pull", remote, branch}
_, err := helpers.RunCommandWithOutput(entity.AbsPath, "git", args)
@@ -103,7 +103,7 @@ func (entity *RepoEntity) PullWithGit(remote, branch string) error {
return nil
}
-// wrapper of the git merge <branch> command
+// MergeWithGit is wrapper of the git merge <branch> command
func (entity *RepoEntity) MergeWithGit(mergeFrom string) error {
args := []string{"merge", mergeFrom}
_, err := helpers.RunCommandWithOutput(entity.AbsPath, "git", args)
@@ -113,7 +113,7 @@ func (entity *RepoEntity) MergeWithGit(mergeFrom string) error {
return nil
}
-// wrapper of the git checkout <branch> command
+// CheckoutWithGit is wrapper of the git checkout <branch> command
func (entity *RepoEntity) CheckoutWithGit(branch string) error {
args := []string{"checkout", branch}
_, err := helpers.RunCommandWithOutput(entity.AbsPath, "git", args)
@@ -123,7 +123,7 @@ func (entity *RepoEntity) CheckoutWithGit(branch string) error {
return nil
}
-// GitStatus returns the plaintext short status of the repo
+// StatusWithGit returns the plaintext short status of the repo
func (entity *RepoEntity) StatusWithGit() string {
args := []string{"status"}
status, err := helpers.RunCommandWithOutput(entity.AbsPath, "git", args)
diff --git a/pkg/git/load.go b/pkg/git/load.go
index dd92ec5..6e1d6c9 100644
--- a/pkg/git/load.go
+++ b/pkg/git/load.go
@@ -4,8 +4,9 @@ import (
"sync"
)
-// initializes the go-git's repository obejcts with given slice of paths. since
-// this job is done parallel, the order of the directories is not kept
+// LoadRepositoryEntities initializes the go-git's repository obejcts with given
+// slice of paths. since this job is done parallel, the order of the directories
+// is not kept
func LoadRepositoryEntities(directories []string) (entities []*RepoEntity, err error) {
entities = make([]*RepoEntity, 0)
diff --git a/pkg/git/remote.go b/pkg/git/remote.go
index 035c68d..bac39d9 100644
--- a/pkg/git/remote.go
+++ b/pkg/git/remote.go
@@ -1,6 +1,6 @@
package git
-// this struct is simply a collection of remote branches and wraps it with the
+// Remote struct is simply a collection of remote branches and wraps it with the
// name of the remote and fetch/push urls. It also holds the *selected* remote
// branch
type Remote struct {
@@ -10,7 +10,7 @@ type Remote struct {
Branches []*RemoteBranch
}
-// iterate over next branch of a remote
+// NextRemote iterates over next branch of a remote
func (entity *RepoEntity) NextRemote() error {
currentRemoteIndex := 0
for i, remote := range entity.Remotes {
diff --git a/pkg/git/remotebranch.go b/pkg/git/remotebranch.go
index 1f46b3d..770b016 100644
--- a/pkg/git/remotebranch.go
+++ b/pkg/git/remotebranch.go
@@ -16,7 +16,7 @@ type RemoteBranch struct {
Reference *plumbing.Reference
}
-// iterates to the next remote branch
+// NextRemoteBranch iterates to the next remote branch
func (remote *Remote) NextRemoteBranch() error {
currentRemoteIndex := 0
for i, rb := range remote.Branches {
diff --git a/pkg/git/repository.go b/pkg/git/repository.go
index f3c76bf..822e820 100644
--- a/pkg/git/repository.go
+++ b/pkg/git/repository.go
@@ -8,9 +8,9 @@ import (
"gopkg.in/src-d/go-git.v4"
)
-// the main entity of the application. The repository name is actually the name
-// of its folder in the host's filesystem. It holds the go-git repository entity
-// along with critic entites such as remote/branches and commits
+// RepoEntity is the main entity of the application. The repository name is
+// actually the name of its folder in the host's filesystem. It holds the go-git
+// repository entity along with critic entites such as remote/branches and commits
type RepoEntity struct {
RepoID string
Name string
@@ -25,18 +25,23 @@ type RepoEntity struct {
State RepoState
}
-// it is the state of the repository for an operation
+// RepoState is the state of the repository for an operation
type RepoState uint8
const (
+ // Available implies repo is ready for the operation
Available RepoState = 0
+ // Queued means repo is queued for a operation
Queued RepoState = 1
+ // Working means an operation is jsut started for this repository
Working RepoState = 2
+ // Success is the expected outcome of the operation
Success RepoState = 3
+ // Fail is the unexpected outcome of the operation
Fail RepoState = 4
)
-// initializee a RepoEntity struct with its belongings.
+// InitializeRepository initializes a RepoEntity struct with its belongings.
func InitializeRepository(directory string) (entity *RepoEntity, err error) {
file, err := os.Open(directory)
if err != nil {
@@ -84,9 +89,9 @@ func InitializeRepository(directory string) (entity *RepoEntity, err error) {
return entity, nil
}
-// Incorporates changes from a remote repository into the current branch. In
-// its default mode, git pull is shorthand for git fetch followed by git merge
-// <branch>
+// Pull incorporates changes from a remote repository into the current branch.
+// In its default mode, git pull is shorthand for git fetch followed by git
+// merge <branch>
func (entity *RepoEntity) Pull() error {
// TODO: Migrate this code to src-d/go-git
// 2018-11-25: tried but it fails, will investigate.
@@ -116,8 +121,8 @@ func (entity *RepoEntity) Fetch() error {
return nil
}
-// Incorporates changes from the named commits or branches into the current
-// branch
+// Merge incorporates changes from the named commits or branches into the
+// current branch
func (entity *RepoEntity) Merge() error {
entity.Checkout(entity.Branch)
if err := entity.MergeWithGit(entity.Remote.Branch.Name); err != nil {
@@ -128,9 +133,10 @@ func (entity *RepoEntity) Merge() error {
return nil
}
-// refresh the belongings of a repositoriy, this function is called right after
+// Refresh the belongings of a repositoriy, this function is called right after
// fetch/pull/merge operations
func (entity *RepoEntity) Refresh() error {
+ var err error
r, err := git.PlainOpen(entity.AbsPath)
if err != nil {
return err
diff --git a/pkg/gui/commitsview.go b/pkg/gui/commitsview.go
index 748126e..0beacce 100644
--- a/pkg/gui/commitsview.go
+++ b/pkg/gui/commitsview.go
@@ -35,7 +35,7 @@ func (gui *Gui) updateCommits(g *gocui.Gui, entity *git.RepoEntity) error {
if err = gui.smartAnchorRelativeToLine(out, currentindex, totalcommits); err != nil {
return err
}
- return nil
+ return err
}
// iteration handler for the commitsview
@@ -51,5 +51,5 @@ func (gui *Gui) nextCommit(g *gocui.Gui, v *gocui.View) error {
if err = gui.updateCommits(g, entity); err != nil {
return err
}
- return nil
+ return err
}
diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go
index c734387..c09ae6c 100644
--- a/pkg/gui/gui-util.go
+++ b/pkg/gui/gui-util.go
@@ -8,20 +8,20 @@ import (
// refreshes the side views of the application for given git.RepoEntity struct
func (gui *Gui) refreshViews(g *gocui.Gui, entity *git.RepoEntity) error {
-
- if err := gui.updateRemotes(g, entity); err != nil {
+ var err error
+ if err = gui.updateRemotes(g, entity); err != nil {
return err
}
- if err := gui.updateBranch(g, entity); err != nil {
+ if err = gui.updateBranch(g, entity); err != nil {
return err
}
- if err := gui.updateRemoteBranches(g, entity); err != nil {
+ if err = gui.updateRemoteBranches(g, entity); err != nil {
return err
}
- if err := gui.updateCommits(g, entity); err != nil {
+ if err = gui.updateCommits(g, entity); err != nil {
return err
}
- return nil
+ return err
}
// siwtch the app mode
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index d420594..7c8f141 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -40,11 +40,15 @@ type mode struct {
CommandString string
}
+// ModeID is the mode indicator for the gui
type ModeID int8
const (
+ // FetchMode puts the gui in fetch state
FetchMode ModeID = 0
- PullMode ModeID = 1
+ // PullMode puts the gui in pull state
+ PullMode ModeID = 1
+ // MergeMode puts the gui in merge state
MergeMode ModeID = 2
)
@@ -66,7 +70,7 @@ var (
mergeMode = mode{ModeID: MergeMode, DisplayString: "Merge", CommandString: "merge"}
)
-// create a Gui opject and fill it's state related entites
+// NewGui creates a Gui opject and fill it's state related entites
func NewGui(directoies []string) (*Gui, error) {
initialState := guiState{
Directories: directoies,
@@ -79,7 +83,7 @@ func NewGui(directoies []string) (*Gui, error) {
return gui, nil
}
-// run the main loop with initial values
+// Run function runs the main loop with initial values
func (gui *Gui) Run() error {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 43916ed..df3e4d8 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -6,7 +6,7 @@ import (
"github.com/jroimartin/gocui"
)
-// keybinding structs is helpful for not re-writinh the same function over and
+// KeyBinding structs is helpful for not re-writinh the same function over and
// over again. it hold useful values to generate a controls view
type KeyBinding struct {
View string
diff --git a/pkg/gui/queuehandler.go b/pkg/gui/queuehandler.go
index af33e21..8801488 100644
--- a/pkg/gui/queuehandler.go
+++ b/pkg/gui/queuehandler.go
@@ -21,11 +21,10 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error {
}
if finished {
return
- } else {
- selectedEntity, _ := gui_go.getSelectedRepository(g, v)
- if job.Entity == selectedEntity {
- gui_go.refreshViews(g, job.Entity)
- }
+ }
+ selectedEntity, _ := gui_go.getSelectedRepository(g, v)
+ if job.Entity == selectedEntity {
+ gui_go.refreshViews(g, job.Entity)
}
}
}(gui, g)
diff --git a/pkg/gui/remotesview.go b/pkg/gui/remotesview.go
index 219b0d7..b762b41 100644
--- a/pkg/gui/remotesview.go
+++ b/pkg/gui/remotesview.go
@@ -53,5 +53,5 @@ func (gui *Gui) nextRemote(g *gocui.Gui, v *gocui.View) error {
if err = gui.updateRemoteBranches(g, entity); err != nil {
return err
}
- return nil
+ return err
}
diff --git a/pkg/gui/textstyle.go b/pkg/gui/textstyle.go
index ef2a184..3f9e7bb 100644
--- a/pkg/gui/textstyle.go
+++ b/pkg/gui/textstyle.go
@@ -105,9 +105,8 @@ func adjustTextLength(text string, maxLength int) (adjusted string) {
if len(text) > maxLength {
adjusted := text[:maxLength-2] + ".."
return adjusted
- } else {
- return text
}
+ return text
}
// the remote link can be too verbose sometimes, so it is good to trim it
diff --git a/pkg/helpers/command.go b/pkg/helpers/command.go
index 7aae7d6..2485b56 100644
--- a/pkg/helpers/command.go
+++ b/pkg/helpers/command.go
@@ -6,9 +6,9 @@ import (
"syscall"
)
-// run the OS command and return its output. If the output returns error it also
-// encapsulates it as a golang.error which is a return code of the command except
-// zero
+// RunCommandWithOutput runs the OS command and return its output. If the output
+// returns error it also encapsulates it as a golang.error which is a return code
+// of the command except zero
func RunCommandWithOutput(dir string, command string, args []string) (string, error) {
cmd := exec.Command(command, args...)
if dir != "" {
@@ -18,9 +18,9 @@ func RunCommandWithOutput(dir string, command string, args []string) (string, er
return string(output), err
}
-// 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 failover acoording
-// to a soecific return code
+// 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
+// failover acoording to a soecific return code
func GetCommandStatus(dir string, command string, args []string) (int, error) {
cmd := exec.Command(command, args...)
if dir != "" {
diff --git a/pkg/helpers/utils.go b/pkg/helpers/utils.go
index 5dfe605..1a3f411 100644
--- a/pkg/helpers/utils.go
+++ b/pkg/helpers/utils.go
@@ -9,8 +9,8 @@ import (
var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
var src = rand.NewSource(time.Now().UnixNano())
-// remove the trailing new line form a string. this method is used mostly on
-// outputs of a command
+// TrimTrailingNewline removes the trailing new line form a string. this method
+// is used mostly on outputs of a command
func TrimTrailingNewline(str string) string {
if strings.HasSuffix(str, "\n") {
return str[:len(str)-1]
@@ -18,7 +18,7 @@ func TrimTrailingNewline(str string) string {
return str
}
-// find the minimum value of two int
+// Min finds the minimum value of two int
func Min(x, y int) int {
if x < y {
return x
diff --git a/pkg/queue/queue.go b/pkg/queue/queue.go
index 511b6ba..b61d43b 100644
--- a/pkg/queue/queue.go
+++ b/pkg/queue/queue.go
@@ -14,20 +14,24 @@ type Job struct {
Entity *git.RepoEntity
}
-// only holds the slice of Jobs
+// JobQueue holds the slice of Jobs
type JobQueue struct {
series []*Job
}
+// JobType is the a git operation supported
type JobType string
const (
+ // Fetch is wrapper of git fetch command
Fetch JobType = "fetch"
- Pull JobType = "pull"
+ // Pull is wrapper of git pull command
+ Pull JobType = "pull"
+ // Merge is wrapper of git merge command
Merge JobType = "merge"
)
-// creates a job struct and return its pointer
+// CreateJob es its name implies creates a job struct and return its pointer
func CreateJob() (j *Job, err error) {
fmt.Println("Job created.")
return j, nil
@@ -68,7 +72,8 @@ func (job *Job) start() error {
return nil
}
-// creates a jobqueue struct and initialize its slice then return its pointer
+// CreateJobQueue creates a jobqueue struct and initialize its slice then return
+// its pointer
func CreateJobQueue() (jobQueue *JobQueue) {
s := make([]*Job, 0)
return &JobQueue{
@@ -76,7 +81,7 @@ func CreateJobQueue() (jobQueue *JobQueue) {
}
}
-// add job to the queue
+// AddJob adds a job to the queue
func (jobQueue *JobQueue) AddJob(j *Job) error {
for _, job := range jobQueue.series {
if job.Entity.RepoID == j.Entity.RepoID && job.JobType == j.JobType {
@@ -87,7 +92,7 @@ func (jobQueue *JobQueue) AddJob(j *Job) error {
return nil
}
-// start the next job of the queue
+// StartNext starts the next job in the queue
func (jobQueue *JobQueue) StartNext() (j *Job, finished bool, err error) {
finished = false
if len(jobQueue.series) < 1 {
@@ -103,7 +108,7 @@ func (jobQueue *JobQueue) StartNext() (j *Job, finished bool, err error) {
return lastJob, finished, nil
}
-// delete it from the queue
+// RemoveFromQueue deletes the given entity and its job from the queue
// TODO: it is not safe if the job has been started
func (jobQueue *JobQueue) RemoveFromQueue(entity *git.RepoEntity) error {
removed := false
@@ -119,8 +124,9 @@ func (jobQueue *JobQueue) RemoveFromQueue(entity *git.RepoEntity) error {
return nil
}
-// since the job and entity is not tied with its own struct, this function
-// returns true if that entity is in the queue along with the jobs type
+// IsInTheQueue function; since the job and entity is not tied with its own
+// struct, this function returns true if that entity is in the queue along with
+// the jobs type
func (jobQueue *JobQueue) IsInTheQueue(entity *git.RepoEntity) (inTheQueue bool, jt JobType) {
inTheQueue = false
for _, job := range jobQueue.series {