mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 23:14:43 +00:00
Add cobra commands and update project folder structure
This commit is contained in:
177
pkg/status_test.go
Normal file
177
pkg/status_test.go
Normal file
@@ -0,0 +1,177 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
git "github.com/libgit2/git2go/v30"
|
||||
)
|
||||
|
||||
func TestStatusWithEmptyRepo(t *testing.T) {
|
||||
repo := newTestRepo(t)
|
||||
|
||||
entries, err := statusEntries(repo)
|
||||
checkFatal(t, err)
|
||||
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("Empty repo should have no status entries")
|
||||
}
|
||||
|
||||
status, err := NewRepoStatus(repo.Workdir())
|
||||
checkFatal(t, err)
|
||||
|
||||
want := RepoStatus{
|
||||
HasUntrackedFiles: false,
|
||||
HasUncommittedChanges: false,
|
||||
BranchStatuses: status.BranchStatuses,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(status, want) {
|
||||
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusWithUntrackedFile(t *testing.T) {
|
||||
repo := newTestRepo(t)
|
||||
createFile(t, repo, "SomeFile")
|
||||
|
||||
entries, err := statusEntries(repo)
|
||||
checkFatal(t, err)
|
||||
|
||||
if len(entries) != 1 {
|
||||
t.Errorf("Repo with untracked file should have only one status entry")
|
||||
}
|
||||
|
||||
if entries[0].Status != git.StatusWtNew {
|
||||
t.Errorf("Invalid status, got %d; want %d", entries[0].Status, git.StatusWtNew)
|
||||
}
|
||||
|
||||
status, err := NewRepoStatus(repo.Workdir())
|
||||
checkFatal(t, err)
|
||||
|
||||
want := RepoStatus{
|
||||
HasUntrackedFiles: true,
|
||||
HasUncommittedChanges: false,
|
||||
BranchStatuses: status.BranchStatuses,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(status, want) {
|
||||
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusWithUnstagedFile(t *testing.T) {
|
||||
//todo
|
||||
}
|
||||
|
||||
func TestStatusWithUntrackedButIgnoredFile(t *testing.T) {
|
||||
//todo
|
||||
}
|
||||
|
||||
func TestStatusWithStagedFile(t *testing.T) {
|
||||
repo := newTestRepo(t)
|
||||
createFile(t, repo, "SomeFile")
|
||||
stageFile(t, repo, "SomeFile")
|
||||
|
||||
entries, err := statusEntries(repo)
|
||||
checkFatal(t, err)
|
||||
|
||||
if len(entries) != 1 {
|
||||
t.Errorf("Repo with staged file should have only one status entry")
|
||||
}
|
||||
|
||||
if entries[0].Status != git.StatusIndexNew {
|
||||
t.Errorf("Invalid status, got %d; want %d", entries[0].Status, git.StatusIndexNew)
|
||||
}
|
||||
|
||||
status, err := NewRepoStatus(repo.Workdir())
|
||||
checkFatal(t, err)
|
||||
|
||||
want := RepoStatus{
|
||||
HasUntrackedFiles: false,
|
||||
HasUncommittedChanges: true,
|
||||
BranchStatuses: status.BranchStatuses,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(status, want) {
|
||||
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusWithSingleCommit(t *testing.T) {
|
||||
repo := newTestRepo(t)
|
||||
createFile(t, repo, "SomeFile")
|
||||
stageFile(t, repo, "SomeFile")
|
||||
createCommit(t, repo, "Initial commit")
|
||||
|
||||
entries, err := statusEntries(repo)
|
||||
checkFatal(t, err)
|
||||
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("Repo with no uncommitted files should have no status entries")
|
||||
}
|
||||
|
||||
status, err := NewRepoStatus(repo.Workdir())
|
||||
checkFatal(t, err)
|
||||
|
||||
want := RepoStatus{
|
||||
HasUntrackedFiles: false,
|
||||
HasUncommittedChanges: false,
|
||||
BranchStatuses: status.BranchStatuses,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(status, want) {
|
||||
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusWithMultipleCommits(t *testing.T) {
|
||||
repo := newTestRepo(t)
|
||||
createFile(t, repo, "SomeFile")
|
||||
stageFile(t, repo, "SomeFile")
|
||||
createCommit(t, repo, "Initial commit")
|
||||
createFile(t, repo, "AnotherFile")
|
||||
stageFile(t, repo, "AnotherFile")
|
||||
createCommit(t, repo, "Second commit")
|
||||
|
||||
entries, err := statusEntries(repo)
|
||||
checkFatal(t, err)
|
||||
|
||||
if len(entries) != 0 {
|
||||
t.Errorf("Repo with no uncommitted files should have no status entries")
|
||||
}
|
||||
|
||||
status, err := NewRepoStatus(repo.Workdir())
|
||||
checkFatal(t, err)
|
||||
|
||||
want := RepoStatus{
|
||||
HasUntrackedFiles: false,
|
||||
HasUncommittedChanges: false,
|
||||
BranchStatuses: status.BranchStatuses,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(status, want) {
|
||||
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusCloned(t *testing.T) {
|
||||
origin := newTestRepo(t)
|
||||
dir := newTempDir(t)
|
||||
|
||||
repo, err := CloneRepo(origin.Path(), dir)
|
||||
checkFatal(t, err)
|
||||
|
||||
status, err := NewRepoStatus(repo.Workdir())
|
||||
checkFatal(t, err)
|
||||
|
||||
want := RepoStatus{
|
||||
HasUntrackedFiles: false,
|
||||
HasUncommittedChanges: false,
|
||||
BranchStatuses: status.BranchStatuses,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(status, want) {
|
||||
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user