aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-03-01 23:17:57 +0100
committerGitHub <noreply@github.com>2019-03-01 23:17:57 +0100
commit7260ca05bc3588c0572887a7d8f1b897c7fc13da (patch)
tree66854358df3cb9de651f7688556ec5a4b8ab1868 /repository
parent0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff)
parentb6bed784e5664819250aac20b2b9690879ee6ab1 (diff)
downloadgit-bug-7260ca05bc3588c0572887a7d8f1b897c7fc13da.tar.gz
Merge pull request #89 from MichaelMure/identity
WIP identity in git
Diffstat (limited to 'repository')
-rw-r--r--repository/git.go16
-rw-r--r--repository/mock_repo.go10
-rw-r--r--repository/repo.go9
-rw-r--r--repository/tree_entry_test.go3
4 files changed, 34 insertions, 4 deletions
diff --git a/repository/git.go b/repository/git.go
index c2f0da0a..c982f820 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -20,6 +20,8 @@ const editClockFile = "/.git/git-bug/edit-clock"
// ErrNotARepo is the error returned when the git repo root wan't be found
var ErrNotARepo = errors.New("not a git repository")
+var _ ClockedRepo = &GitRepo{}
+
// GitRepo represents an instance of a (local) git repository.
type GitRepo struct {
Path string
@@ -29,7 +31,7 @@ type GitRepo struct {
// Run the given git command with the given I/O reader/writers, returning an error if it fails.
func (repo *GitRepo) runGitCommandWithIO(stdin io.Reader, stdout, stderr io.Writer, args ...string) error {
- //fmt.Println("Running git", strings.Join(args, " "))
+ // fmt.Printf("[%s] Running git %s\n", repo.Path, strings.Join(args, " "))
cmd := exec.Command("git", args...)
cmd.Dir = repo.Path
@@ -202,7 +204,7 @@ func (repo *GitRepo) ReadConfigs(keyPrefix string) (map[string]string, error) {
// RmConfigs remove all key/value pair matching the key prefix
func (repo *GitRepo) RmConfigs(keyPrefix string) error {
- _, err := repo.runGitCommand("config", "--remove-section", keyPrefix)
+ _, err := repo.runGitCommand("config", "--unset-all", keyPrefix)
return err
}
@@ -440,11 +442,21 @@ func (repo *GitRepo) WriteClocks() error {
return nil
}
+// CreateTime return the current value of the creation clock
+func (repo *GitRepo) CreateTime() lamport.Time {
+ return repo.createClock.Time()
+}
+
// CreateTimeIncrement increment the creation clock and return the new value.
func (repo *GitRepo) CreateTimeIncrement() (lamport.Time, error) {
return repo.createClock.Increment()
}
+// EditTime return the current value of the edit clock
+func (repo *GitRepo) EditTime() lamport.Time {
+ return repo.editClock.Time()
+}
+
// EditTimeIncrement increment the edit clock and return the new value.
func (repo *GitRepo) EditTimeIncrement() (lamport.Time, error) {
return repo.editClock.Increment()
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 74de8f57..97a4504f 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -9,6 +9,8 @@ import (
"github.com/MichaelMure/git-bug/util/lamport"
)
+var _ ClockedRepo = &mockRepoForTest{}
+
// mockRepoForTest defines an instance of Repo that can be used for testing.
type mockRepoForTest struct {
config map[string]string
@@ -227,10 +229,18 @@ func (r *mockRepoForTest) WriteClocks() error {
return nil
}
+func (r *mockRepoForTest) CreateTime() lamport.Time {
+ return r.createClock.Time()
+}
+
func (r *mockRepoForTest) CreateTimeIncrement() (lamport.Time, error) {
return r.createClock.Increment(), nil
}
+func (r *mockRepoForTest) EditTime() lamport.Time {
+ return r.editClock.Time()
+}
+
func (r *mockRepoForTest) EditTimeIncrement() (lamport.Time, error) {
return r.editClock.Increment(), nil
}
diff --git a/repository/repo.go b/repository/repo.go
index 3ae09057..8a66c320 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -83,6 +83,7 @@ type Repo interface {
GetTreeHash(commit git.Hash) (git.Hash, error)
}
+// ClockedRepo is a Repo that also has Lamport clocks
type ClockedRepo interface {
Repo
@@ -92,9 +93,15 @@ type ClockedRepo interface {
// WriteClocks write the clocks values into the repo
WriteClocks() error
+ // CreateTime return the current value of the creation clock
+ CreateTime() lamport.Time
+
// CreateTimeIncrement increment the creation clock and return the new value.
CreateTimeIncrement() (lamport.Time, error)
+ // EditTime return the current value of the edit clock
+ EditTime() lamport.Time
+
// EditTimeIncrement increment the edit clock and return the new value.
EditTimeIncrement() (lamport.Time, error)
@@ -122,7 +129,7 @@ func prepareTreeEntries(entries []TreeEntry) bytes.Buffer {
}
func readTreeEntries(s string) ([]TreeEntry, error) {
- split := strings.Split(s, "\n")
+ split := strings.Split(strings.TrimSpace(s), "\n")
casted := make([]TreeEntry, len(split))
for i, line := range split {
diff --git a/repository/tree_entry_test.go b/repository/tree_entry_test.go
index b5f774d3..58da075c 100644
--- a/repository/tree_entry_test.go
+++ b/repository/tree_entry_test.go
@@ -1,8 +1,9 @@
package repository
import (
- "github.com/MichaelMure/git-bug/util/git"
"testing"
+
+ "github.com/MichaelMure/git-bug/util/git"
)
func TestTreeEntryFormat(t *testing.T) {