commands: fix refs 'edges' option work
also change it to use format instead of separate variable License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jul 28, 2016 at 20:25 UTC
66686e66be5c910fef0d3563160557ac72978a62
2 files changed
+30
-8
core/commands/refs.go
+11
-6
@@ -74,17 +74,26 @@ NOTE: List all references recursively by using the flag '-r'.
74
return
75
}
76
77
- edges, _, err := req.Option("edges").Bool()
77
+ format, _, err := req.Option("format").String()
78
if err != nil {
79
res.SetError(err, cmds.ErrNormal)
80
return
81
}
82
83
- format, _, err := req.Option("format").String()
83
+ edges, _, err := req.Option("edges").Bool()
84
if err != nil {
85
res.SetError(err, cmds.ErrNormal)
86
return
87
}
88
+ if edges {
89
+ if format != "<dst>" {
90
+ res.SetError(errors.New("using format arguement with edges is not allowed"),
91
+ cmds.ErrClient)
92
+ return
93
+ }
94
+
95
+ format = "<src> -> <dst>"
96
+ }
97
98
objs, err := objectsForPaths(ctx, n, req.Arguments())
99
if err != nil {
@@ -103,7 +112,6 @@ NOTE: List all references recursively by using the flag '-r'.
112
DAG: n.DAG,
113
Ctx: ctx,
114
Unique: unique,
106
- PrintEdge: edges,
115
PrintFmt: format,
116
Recursive: recursive,
117
}
@@ -210,7 +218,6 @@ type RefWriter struct {
218
219
Unique bool
220
Recursive bool
213
- PrintEdge bool
221
PrintFmt string
222
223
seen map[key.Key]struct{}
@@ -315,8 +322,6 @@ func (rw *RefWriter) WriteEdge(from, to key.Key, linkname string) error {
322
s = strings.Replace(s, "<src>", from.B58String(), -1)
323
s = strings.Replace(s, "<dst>", to.B58String(), -1)
324
s = strings.Replace(s, "<linkname>", linkname, -1)
318
- case rw.PrintEdge:
319
- s = from.B58String() + " -> " + to.B58String()
325
default:
326
s += to.B58String()
327
}
test/sharness/t0500-issues-and-regressions-offline.sh
+19
-2
@@ -4,8 +4,6 @@ test_description="Tests for various fixed issues and regressions."
4
5
. lib/test-lib.sh
6
7
-test_init_ipfs
8
-
7
# Tests go here
8
9
test_expect_success "ipfs init with occupied input works - #2748" '
@@ -13,6 +11,7 @@ test_expect_success "ipfs init with occupied input works - #2748" '
11
echo "" | time-out ipfs init &&
12
rm -rf ipfs_path
13
'
14
+test_init_ipfs
15
16
test_expect_success "ipfs cat --help succeeds with no input" '
17
time-out ipfs cat --help
@@ -22,4 +21,22 @@ test_expect_success "ipfs pin ls --help succeeds with no input" '
21
time-out ipfs pin ls --help
22
'
23
24
+test_expect_success "ipfs add on 1MB from stdin woks" '
25
+ random 1048576 42 | ipfs add -q > 1MB.hash
26
+'
27
+
28
+test_expect_success "'ipfs refs -r -e \$(cat 1MB.hash)' succeeds" '
29
+ ipfs refs -r -e $(cat 1MB.hash) > refs-e.out
30
+'
31
+
32
+test_expect_success "output of 'ipfs refs -e' links to separate blocks" '
33
+ grep "$(cat 1MB.hash) ->" refs-e.out
34
+'
35
+
36
+test_expect_success "output of 'ipfs refs -e' contains all first level links" '
37
+ grep "$(cat 1MB.hash) ->" refs-e.out | sed -e '\''s/.* -> //'\'' | sort > refs-s.out &&
38
+ ipfs refs "$(cat 1MB.hash)" | sort > refs-one.out &&
39
+ test_cmp refs-s.out refs-one.out
40
+'
41
+
42
test_done