WIP: Refactor entire project #16
2 changed files with 19 additions and 18 deletions
|
@ -1,10 +1,8 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/go-crypto/openpgp"
|
||||
|
@ -95,22 +93,6 @@ func (c *Commit) Create(msg string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Commit) Exists(uid string, id uint) bool {
|
||||
commitIter, err := c.project.repository.Log(&git.LogOptions{})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
err = commitIter.ForEach(func(commit *object.Commit) error {
|
||||
if strings.Contains(commit.Message, fmt.Sprintf("Update %s", uid)) &&
|
||||
strings.Contains(commit.Message, fmt.Sprintf("version %d", id)) {
|
||||
return errors.New("version already committed")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err != nil
|
||||
}
|
||||
|
||||
func (c *Commit) addContent() error {
|
||||
file, err := c.project.worktree.Filesystem.Create(c.Filename)
|
||||
if err != nil {
|
||||
|
|
|
@ -3,12 +3,15 @@ package git
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/go-git/go-billy/v5"
|
||||
"github.com/go-git/go-billy/v5/memfs"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/storage/memory"
|
||||
|
@ -133,6 +136,22 @@ func (p *Project) Clone(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Project) CommitExists(uid string, id uint) bool {
|
||||
commitIter, err := p.repository.Log(&git.LogOptions{})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
err = commitIter.ForEach(func(commit *object.Commit) error {
|
||||
if strings.Contains(commit.Message, fmt.Sprintf("Update %s", uid)) &&
|
||||
strings.Contains(commit.Message, fmt.Sprintf("version %d", id)) {
|
||||
return errors.New("version already committed")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err != nil
|
||||
}
|
||||
|
||||
func (p *Project) HasChanges() bool {
|
||||
remoteBranchRef := plumbing.NewRemoteReferenceName("origin", p.Branch)
|
||||
remoteBranch, err := p.repository.Reference(remoteBranchRef, true)
|
||||
|
|
Loading…
Reference in a new issue