mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 19:09:45 +00:00
175 lines
3.9 KiB
Go
175 lines
3.9 KiB
Go
package pkg
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestStatus(t *testing.T) {
|
|
var tests = []struct {
|
|
makeTestRepo func(*testing.T) *Repo
|
|
want *RepoStatus
|
|
}{
|
|
{newRepoEmpty, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: StatusUnknown,
|
|
Branches: nil,
|
|
}},
|
|
{newRepoWithUntracked, &RepoStatus{
|
|
HasUntrackedFiles: true,
|
|
HasUncommittedChanges: false,
|
|
Current: StatusUnknown,
|
|
Branches: nil,
|
|
}},
|
|
{newRepoWithStaged, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: true,
|
|
Current: StatusUnknown,
|
|
Branches: nil,
|
|
}},
|
|
{newRepoWithCommit, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithModified, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: true,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithIgnored, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithLocalBranch, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "local",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
}, {
|
|
Name: "master",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithClonedBranch, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "local",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "local",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
}, {
|
|
Name: "master",
|
|
Upstream: "origin/master",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithDetachedHead, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: StatusDetached,
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "",
|
|
NeedsPull: false,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithBranchAhead, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "origin/master",
|
|
NeedsPull: false,
|
|
NeedsPush: true,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithBranchBehind, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "origin/master",
|
|
NeedsPull: true,
|
|
NeedsPush: false,
|
|
},
|
|
},
|
|
}},
|
|
{newRepoWithBranchAheadAndBehind, &RepoStatus{
|
|
HasUntrackedFiles: false,
|
|
HasUncommittedChanges: false,
|
|
Current: "master",
|
|
Branches: []*BranchStatus{
|
|
{
|
|
Name: "master",
|
|
Upstream: "origin/master",
|
|
NeedsPull: true,
|
|
NeedsPush: true,
|
|
},
|
|
},
|
|
}},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
repo := test.makeTestRepo(t)
|
|
|
|
err := repo.LoadStatus()
|
|
checkFatal(t, err)
|
|
|
|
if !reflect.DeepEqual(repo.Status, test.want) {
|
|
t.Errorf("Wrong repo status, got: %+v; want: %+v", repo.Status, test.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: test branch status when tracking a local branch
|
|
// TODO: newRepoWithGlobalGitignore
|
|
// TODO: newRepoWithGlobalGitignoreSymlink
|