Skip to content

Commit

Permalink
Use appropriated one-liner if clause and named return parameter
Browse files Browse the repository at this point in the history
Thanks to `wingyplus` for the suggestions. [1]

* Use one-liner if clause for the error checking when appropriated.
* Use the named return parameter for the variable that need to be
  declared at the first of function.

---
[1] neutronth@cfd4d75
  • Loading branch information
neutronth committed Sep 1, 2020
1 parent 8472ddb commit 7d7fb3c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions cmd/git-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ func addWorktreeAndSwap(ctx context.Context, gitRoot, dest, branch, rev string,
// Update submodules
// NOTE: this works for repo with or without submodules.
if submoduleMode != SubmoduleModeOff {
err = updateSubmodules(ctx, worktreePath, depth, submoduleMode)
if err != nil {
if err := updateSubmodules(ctx, worktreePath, depth, submoduleMode); err != nil {
return err
}
}
Expand Down Expand Up @@ -586,8 +585,8 @@ func updateSubmodules(ctx context.Context, worktreePath string, depth int, submo

updateArgs := submoduleUpdateArgs(depth, submoduleMode)
submodulesArgs := append([]string{"submodule", "update", "--init"}, updateArgs...)
_, err := runCommand(ctx, worktreePath, *flGitCmd, submodulesArgs...)
if err != nil {

if _, err := runCommand(ctx, worktreePath, *flGitCmd, submodulesArgs...); err != nil {
return err
}

Expand Down Expand Up @@ -624,8 +623,8 @@ func updateSubmodulesWithRemoteTracking(ctx context.Context, worktreePath string
log.V(0).Info("updating submodule with remote tracking", "submoduleName", submoduleName, "submodulePath", submodulePath)
submoduleRemoteUpdateArgs := append([]string{"submodule", "update", "--remote"}, updateArgs...)
submoduleRemoteUpdateArgs = append(submoduleRemoteUpdateArgs, submodulePath)
_, err = runCommand(ctx, worktreePath, *flGitCmd, submoduleRemoteUpdateArgs...)
if err != nil {

if _, err = runCommand(ctx, worktreePath, *flGitCmd, submoduleRemoteUpdateArgs...); err != nil {
return err
}

Expand All @@ -640,16 +639,15 @@ func updateSubmodulesWithRemoteTracking(ctx context.Context, worktreePath string
return nil
}

func submoduleUpdateArgs(depth int, submoduleMode string) []string {
args := []string{}
func submoduleUpdateArgs(depth int, submoduleMode string) (args []string) {
if submoduleMode == SubmoduleModeRecursive {
args = append(args, "--recursive")
}
if depth != 0 {
args = append(args, "--depth", strconv.Itoa(depth))
}

return args
return
}

func submoduleIsUpToDate(ctx context.Context, worktreePath, submodulePath string) (bool, error) {
Expand Down

0 comments on commit 7d7fb3c

Please sign in to comment.