Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit 3cff96f

Browse files
author
Emmanuel Odeke
committed
feature: relative local path implemented
Adds the ability for one to go like this: mkdir ~/drive cd drive drive init ... drive pull Photos cd Photos drive push
1 parent 3ef6932 commit 3cff96f

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

pull.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io"
2020
"os"
2121
"path/filepath"
22+
"strings"
2223
"sync"
2324
)
2425

@@ -30,19 +31,29 @@ const (
3031
// directory, it recursively pulls from the remote if there are remote changes.
3132
// It doesn't check if there are remote changes if isForce is set.
3233
func (g *Commands) Pull() (err error) {
34+
absPath := g.context.AbsPathOf(g.opts.Path)
35+
var cwd string
36+
if cwd, err = os.Getwd(); err != nil {
37+
return
38+
}
39+
var relPath string
40+
if relPath, err = filepath.Rel(absPath, cwd); err != nil {
41+
return
42+
}
43+
44+
relPath = strings.Join([]string{"", relPath}, "/")
3345
var r, l *File
34-
if r, err = g.rem.FindByPath(g.opts.Path); err != nil {
46+
if r, err = g.rem.FindByPath(relPath); err != nil {
3547
return
3648
}
37-
absPath := g.context.AbsPathOf(g.opts.Path)
3849
localinfo, _ := os.Stat(absPath)
3950
if localinfo != nil {
40-
l = NewLocalFile(absPath, localinfo)
51+
l = NewLocalFile(cwd, localinfo)
4152
}
4253

4354
var cl []*Change
4455
fmt.Println("Resolving...")
45-
if cl, err = g.resolveChangeListRecv(false, g.opts.Path, r, l); err != nil {
56+
if cl, err = g.resolveChangeListRecv(false, relPath, r, l); err != nil {
4657
return
4758
}
4859

push.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"io/ioutil"
2020
"os"
21+
"path/filepath"
2122
gopath "path"
2223
"strings"
2324

@@ -29,20 +30,28 @@ import (
2930
// It doesn't check if there are local changes if isForce is set.
3031
func (g *Commands) Push() (err error) {
3132
absPath := g.context.AbsPathOf(g.opts.Path)
32-
r, err := g.rem.FindByPath(g.opts.Path)
33-
if err != nil && err != ErrPathNotExists {
34-
return err
33+
var cwd string
34+
if cwd, err = os.Getwd(); err != nil {
35+
return
36+
}
37+
var relPath string
38+
if relPath, err = filepath.Rel(absPath, cwd); err != nil {
39+
return
40+
}
41+
42+
relPath = strings.Join([]string{"", relPath}, "/")
43+
var r, l *File
44+
if r, err = g.rem.FindByPath(relPath); err != nil {
45+
return
3546
}
36-
37-
var l *File
3847
localinfo, _ := os.Stat(absPath)
3948
if localinfo != nil {
40-
l = NewLocalFile(absPath, localinfo)
49+
l = NewLocalFile(cwd, localinfo)
4150
}
4251

4352
fmt.Println("Resolving...")
4453
var cl []*Change
45-
if cl, err = g.resolveChangeListRecv(true, g.opts.Path, r, l); err != nil {
54+
if cl, err = g.resolveChangeListRecv(true, relPath, r, l); err != nil {
4655
return err
4756
}
4857

0 commit comments

Comments
 (0)