Skip to content
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
84 changes: 43 additions & 41 deletions gitcmds/gitcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,62 +611,64 @@ func Release(wd string) error {
}

// Upload uploads sources to git repo
func Upload(cmd *cobra.Command, wd string) error {
commitMessageParts := cmd.Context().Value(contextPkg.CtxKeyCommitMessage).([]string)
func Upload(cmd *cobra.Command, wd string, needToCommit bool) error {
if needToCommit {
commitMessageParts := cmd.Context().Value(contextPkg.CtxKeyCommitMessage).([]string)

stdout, stderr, err := new(exec.PipedExec).
Command(git, "add", ".").
WorkingDir(wd).
RunToStrings()
if err != nil {
logger.Verbose(stderr)

if len(stderr) > 0 {
return errors.New(stderr)
}
stdout, stderr, err := new(exec.PipedExec).
Command(git, "add", ".").
WorkingDir(wd).
RunToStrings()
if err != nil {
logger.Verbose(stderr)

return fmt.Errorf("git add failed: %w", err)
}
logger.Verbose(stdout)
if len(stderr) > 0 {
return errors.New(stderr)
}

params := []string{"commit", "-a"}
for _, m := range commitMessageParts {
params = append(params, mimm, m)
}
return fmt.Errorf("git add failed: %w", err)
}
logger.Verbose(stdout)

_, stderr, err = new(exec.PipedExec).
Command(git, params...).
WorkingDir(wd).
RunToStrings()
if strings.Contains(stderr, MsgPreCommitError) {
var response string
fmt.Println("")
printLn(strings.TrimSpace(stderr))
fmt.Print("Do you want to commit anyway(y/n)?")
_, _ = fmt.Scanln(&response)

if response != "y" {
return nil
params := []string{"commit", "-a"}
for _, m := range commitMessageParts {
params = append(params, mimm, m)
}

params = append(params, "-n")
stdout, stderr, err = new(exec.PipedExec).
_, stderr, err = new(exec.PipedExec).
Command(git, params...).
WorkingDir(wd).
RunToStrings()
if err != nil {
logger.Verbose(stderr)

if len(stderr) > 0 {
return errors.New(stderr)
if strings.Contains(stderr, MsgPreCommitError) {
var response string
fmt.Println("")
printLn(strings.TrimSpace(stderr))
fmt.Print("Do you want to commit anyway(y/n)?")
_, _ = fmt.Scanln(&response)

if response != "y" {
return nil
}

return fmt.Errorf("git commit failed: %w", err)
params = append(params, "-n")
stdout, stderr, err = new(exec.PipedExec).
Command(git, params...).
WorkingDir(wd).
RunToStrings()
if err != nil {
logger.Verbose(stderr)

if len(stderr) > 0 {
return errors.New(stderr)
}

return fmt.Errorf("git commit failed: %w", err)
}
}
}

// make pull before push
stdout, stderr, err = new(exec.PipedExec).
stdout, stderr, err := new(exec.PipedExec).
Command(git, pull).
WorkingDir(wd).
RunToStrings()
Expand Down
23 changes: 11 additions & 12 deletions internal/commands/u.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -39,20 +38,20 @@ func U(cmd *cobra.Command, cfgUpload vcs.CfgUpload, wd string) error {
}

files := gitcmds.GetFilesForCommit(wd)
if len(files) == 0 {
return errors.New("there is nothing to commit")
}

if err := setCommitMessage(cmd, cfgUpload, wd, isMain); err != nil {
return err
}
neetToCommit := len(files) > 0
// If there are files to commit, set commit message
if neetToCommit {
if err := setCommitMessage(cmd, cfgUpload, wd, isMain); err != nil {
return err
}

// Ensure large file hook content is up to date
if err := gitcmds.EnsureLargeFileHookUpToDate(wd); err != nil {
logger.Verbose("Error updating large file hook content:", err)
// Ensure large file hook content is up to date
if err := gitcmds.EnsureLargeFileHookUpToDate(wd); err != nil {
logger.Verbose("Error updating large file hook content:", err)
}
}

return gitcmds.Upload(cmd, wd)
return gitcmds.Upload(cmd, wd, neetToCommit)
}

func setCommitMessage(
Expand Down
2 changes: 1 addition & 1 deletion internal/systrun/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ func (st *SystemTest) processSyncState() error {
return st.setSyncState(
true,
true,
true,
false,
2,
false,
"",
Expand Down
26 changes: 26 additions & 0 deletions sys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,32 @@ func TestUpload(t *testing.T) {
require.NoError(err)
}

// TestUpload_NothingToCommit tests pushing when there are no uncommitted changes but unpushed commits exist
func TestUpload_NothingToCommit(t *testing.T) {
require := require.New(t)

testConfig := &systrun.TestConfig{
TestID: strings.ToLower(t.Name()),
GHConfig: getGithubConfig(t),
CommandConfig: &systrun.CommandConfig{
Command: "u",
Stdin: "y",
},
UpstreamState: systrun.RemoteStateOK,
ForkState: systrun.RemoteStateOK,
SyncState: systrun.SyncStateCloneIsAheadOfFork,
ClipboardContent: systrun.ClipboardContentGithubIssue,
NeedCollaboration: true,
Expectations: []systrun.ExpectationFunc{
systrun.ExpectationCloneIsSyncedWithFork,
},
}

sysTest := systrun.New(t, testConfig)
err := sysTest.Run()
require.NoError(err)
}

// TestDevD_DevBranch_NoRT_NoPR - develop branch exists, no remote tracking branch, no pull request
func TestDevD_DevBranch_NoRT_NoPR(t *testing.T) {
require := require.New(t)
Expand Down
Loading