Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
30734d4
git push initialized
06rajesh Jan 17, 2022
d3076bf
Merge branch 'main' into feature-bob-git-push
06rajesh Jan 18, 2022
6fde4e0
bob git push in progress
06rajesh Jan 18, 2022
1f47919
bob git push dry run added with combined output
06rajesh Jan 19, 2022
cfb6f50
Merge branch 'main' into feature-bob-git-push
06rajesh Jan 24, 2022
3c95c65
ask for confirmation added in case of not configured repo
06rajesh Jan 24, 2022
b571a31
formatted error with confirmation input for no remote
06rajesh Jan 25, 2022
25cf8b0
git push with formatted outputs implemented
06rajesh Jan 25, 2022
3961f59
git push continues to other repo in case of erros in one repo
06rajesh Jan 25, 2022
22c0e8a
Merge branch 'main' into feature-bob-git-push
06rajesh Feb 4, 2022
136c931
Merge branch 'main' into feature-bob-git-push
06rajesh Feb 21, 2022
2dab521
git push tests implemented using soft serve
06rajesh Mar 7, 2022
da1316b
push to ssh implemented using git ssh command
06rajesh Mar 7, 2022
90ffe9c
after go mod tidy run
06rajesh Mar 7, 2022
57c79f8
push tests output saved and tested using files from testdata
06rajesh Mar 8, 2022
8f334b7
more tests added for bob push
06rajesh Mar 8, 2022
05d9864
go mod updated
06rajesh Mar 8, 2022
cc62e6e
shutdown ssh server implemented using old soft serve version
06rajesh Mar 9, 2022
314acb0
public key added in git config ssh command
06rajesh Mar 9, 2022
cffa118
disabled removing recently created ssh host from known hosts in CI
06rajesh Mar 9, 2022
5b7831e
bob push testing codes formatted
06rajesh Mar 10, 2022
6c03d10
cleanups
06rajesh Mar 10, 2022
836c408
Merge branch 'main' into feature-bob-git-push
06rajesh Mar 14, 2022
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
101 changes: 54 additions & 47 deletions bobgit/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (

var addTestDataPath = "testdata/add"

// disable running tests for add,
// helpful while writing other tests
var runAddTests = true

func TestGitAdd(t *testing.T) {
type input struct {
// environment holds a function creating
Expand Down Expand Up @@ -335,65 +339,68 @@ func TestGitAdd(t *testing.T) {
},
}

for _, test := range tests {
dir, err := ioutil.TempDir("", test.name+"-*")
assert.Nil(t, err)

statusBeforeFile := test.name + "_before"
statusAfterFile := test.name + "_after"

// Don't cleanup in testdir mode
if !createTestDirs {
defer os.RemoveAll(dir)
}
if runAddTests {

if debug || createTestDirs {
println("Using test dir " + dir)
}
for _, test := range tests {
dir, err := ioutil.TempDir("", test.name+"-*")
assert.Nil(t, err)

test.input.environment(dir)
statusBeforeFile := test.name + "_before"
statusAfterFile := test.name + "_after"

if createTestDirs {
continue
}
// Don't cleanup in testdir mode
if !createTestDirs {
defer os.RemoveAll(dir)
}

execdir := filepath.Join(dir, test.execdir)
if debug || createTestDirs {
println("Using test dir " + dir)
}

statusBefore, err := getStatus(execdir)
assert.Nil(t, err)
test.input.environment(dir)

targets := strings.Split(test.target, " ")
err = executeAdd(execdir, targets...)
assert.Nil(t, err)
if createTestDirs {
continue
}

statusAfter, err := getStatus(execdir)
assert.Nil(t, err)
execdir := filepath.Join(dir, test.execdir)

if update {
err = os.RemoveAll(filepath.Join(addTestDataPath, statusBeforeFile))
assert.Nil(t, err)
err = os.RemoveAll(filepath.Join(addTestDataPath, statusAfterFile))
statusBefore, err := getStatus(execdir)
assert.Nil(t, err)
err = os.MkdirAll(addTestDataPath, 0775)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(addTestDataPath, statusBeforeFile), []byte(statusBefore.String()), 0664)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(addTestDataPath, statusAfterFile), []byte(statusAfter.String()), 0664)
assert.Nil(t, err)
continue
}

expectBefore, err := os.ReadFile(filepath.Join(addTestDataPath, statusBeforeFile))
assert.Nil(t, err, test.name)

diff := cmp.Diff(statusBefore.String(), string(expectBefore))
assert.Equal(t, "", diff, statusBeforeFile)
targets := strings.Split(test.target, " ")
err = executeAdd(execdir, targets...)
assert.Nil(t, err)

expectAfter, err := os.ReadFile(filepath.Join(addTestDataPath, statusAfterFile))
assert.Nil(t, err, test.name)
statusAfter, err := getStatus(execdir)
assert.Nil(t, err)

diff = cmp.Diff(statusAfter.String(), string(expectAfter))
assert.Equal(t, "", diff, statusAfterFile)
if update {
err = os.RemoveAll(filepath.Join(addTestDataPath, statusBeforeFile))
assert.Nil(t, err)
err = os.RemoveAll(filepath.Join(addTestDataPath, statusAfterFile))
assert.Nil(t, err)
err = os.MkdirAll(addTestDataPath, 0775)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(addTestDataPath, statusBeforeFile), []byte(statusBefore.String()), 0664)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(addTestDataPath, statusAfterFile), []byte(statusAfter.String()), 0664)
assert.Nil(t, err)
continue
}

expectBefore, err := os.ReadFile(filepath.Join(addTestDataPath, statusBeforeFile))
assert.Nil(t, err, test.name)

diff := cmp.Diff(statusBefore.String(), string(expectBefore))
assert.Equal(t, "", diff, statusBeforeFile)

expectAfter, err := os.ReadFile(filepath.Join(addTestDataPath, statusAfterFile))
assert.Nil(t, err, test.name)

diff = cmp.Diff(statusAfter.String(), string(expectAfter))
assert.Equal(t, "", diff, statusAfterFile)
}
}

if createTestDirs || update {
Expand Down
25 changes: 25 additions & 0 deletions bobgit/bobgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/Benchkram/errz"
"github.com/cli/cli/git"
)

var (
Expand Down Expand Up @@ -72,6 +73,30 @@ func findRepos(root string) ([]string, error) {
return repoNames, nil
}

// getRepoConfig detects repository current branch and
// returns the Branch Config with remote name, url and merge ref
func getRepoConfig(root string, repo string) (_ *git.BranchConfig, err error) {
repoPath := filepath.Join(root, repo)

err = os.Chdir(repoPath)
if err != nil {
return nil, err
}

defer func() {
err = os.Chdir(root)
errz.Fatal(err)
}()

branch, err := git.CurrentBranch()
if err != nil {
return nil, err
}

config := git.ReadBranchConfig(branch)
return &config, nil
}

// formatRepoNameForOutput returns formatted reponame for output.
//
// Example: "." => "/", "second-level" => "second-level/"
Expand Down
119 changes: 63 additions & 56 deletions bobgit/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (

var commitTestDataPath = "testdata/commit"

// disable running tests for commit,
// helpful while writing other tests
var runCommitTests = true

func TestCommit(t *testing.T) {

type input struct {
Expand Down Expand Up @@ -304,80 +308,83 @@ func TestCommit(t *testing.T) {
},
}

for _, test := range tests {
dir, err := ioutil.TempDir("", test.name+"-*")
assert.Nil(t, err)

// Don't cleanup in testdir mode
if !createTestDirs {
defer os.RemoveAll(dir)
}
if runCommitTests {

if debug || createTestDirs {
println("Using test dir " + dir)
}

test.input.environment(dir)
for _, test := range tests {
dir, err := ioutil.TempDir("", test.name+"-*")
assert.Nil(t, err)

if createTestDirs {
continue
}
// Don't cleanup in testdir mode
if !createTestDirs {
defer os.RemoveAll(dir)
}

execdir := filepath.Join(dir, test.execdir)
statusBeforeFile := test.name + "_before"
statusAfterFile := test.name + "_after"
if debug || createTestDirs {
println("Using test dir " + dir)
}

statusBefore, err := getStatus(execdir)
assert.Nil(t, err)
test.input.environment(dir)

s, err := executeCommit(execdir, test.message)
if test.expectedErr != nil {
if errors.Is(err, test.expectedErr) {
if createTestDirs {
continue
}
assert.Fail(t, fmt.Sprintf("expected error [%s] got [%s]", test.expectedErr.Error(), err.Error()))
}

// ignore the error caused by test.message nill
if err != nil && !errors.Is(err, ErrEmptyCommitMessage) {
assert.Nil(t, err)
}

assert.Equal(t, s, test.output, test.name)
execdir := filepath.Join(dir, test.execdir)
statusBeforeFile := test.name + "_before"
statusAfterFile := test.name + "_after"

statusAfter, err := getStatus(execdir)
assert.Nil(t, err)
statusBefore, err := getStatus(execdir)
assert.Nil(t, err)

if update {
// tests expecting a error don't need to compare their before and after putputs
s, err := executeCommit(execdir, test.message)
if test.expectedErr != nil {
continue
if errors.Is(err, test.expectedErr) {
continue
}
assert.Fail(t, fmt.Sprintf("expected error [%s] got [%s]", test.expectedErr.Error(), err.Error()))
}

err = os.RemoveAll(filepath.Join(commitTestDataPath, statusBeforeFile))
assert.Nil(t, err)
err = os.RemoveAll(filepath.Join(commitTestDataPath, statusAfterFile))
assert.Nil(t, err)
err = os.MkdirAll(commitTestDataPath, 0775)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(commitTestDataPath, statusBeforeFile), []byte(statusBefore.String()), 0664)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(commitTestDataPath, statusAfterFile), []byte(statusAfter.String()), 0664)
// ignore the error caused by test.message nill
if err != nil && !errors.Is(err, ErrEmptyCommitMessage) {
assert.Nil(t, err)
}

assert.Equal(t, s, test.output, test.name)

statusAfter, err := getStatus(execdir)
assert.Nil(t, err)
continue
}

expectBefore, err := os.ReadFile(filepath.Join(commitTestDataPath, statusBeforeFile))
assert.Nil(t, err, test.name)
if update {
// tests expecting a error don't need to compare their before and after putputs
if test.expectedErr != nil {
continue
}

err = os.RemoveAll(filepath.Join(commitTestDataPath, statusBeforeFile))
assert.Nil(t, err)
err = os.RemoveAll(filepath.Join(commitTestDataPath, statusAfterFile))
assert.Nil(t, err)
err = os.MkdirAll(commitTestDataPath, 0775)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(commitTestDataPath, statusBeforeFile), []byte(statusBefore.String()), 0664)
assert.Nil(t, err)
err = os.WriteFile(filepath.Join(commitTestDataPath, statusAfterFile), []byte(statusAfter.String()), 0664)
assert.Nil(t, err)
continue
}

expectBefore, err := os.ReadFile(filepath.Join(commitTestDataPath, statusBeforeFile))
assert.Nil(t, err, test.name)

diff := cmp.Diff(statusBefore.String(), string(expectBefore))
assert.Equal(t, "", diff, statusBeforeFile)
diff := cmp.Diff(statusBefore.String(), string(expectBefore))
assert.Equal(t, "", diff, statusBeforeFile)

expectAfter, err := os.ReadFile(filepath.Join(commitTestDataPath, statusAfterFile))
assert.Nil(t, err, test.name)
expectAfter, err := os.ReadFile(filepath.Join(commitTestDataPath, statusAfterFile))
assert.Nil(t, err, test.name)

diff = cmp.Diff(statusAfter.String(), string(expectAfter))
assert.Equal(t, "", diff, statusAfterFile)
diff = cmp.Diff(statusAfter.String(), string(expectAfter))
assert.Equal(t, "", diff, statusAfterFile)
}
}

if createTestDirs || update {
Expand Down
Loading