Skip to content

Commit

Permalink
Merge pull request #3007 from ipfs/feature/refs-format-regression
Browse files Browse the repository at this point in the history
commands: fix refs 'edges' option work
  • Loading branch information
whyrusleeping authored Aug 1, 2016
2 parents 0bd8ced + 66686e6 commit 149819f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
17 changes: 11 additions & 6 deletions core/commands/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,26 @@ NOTE: List all references recursively by using the flag '-r'.
return
}

edges, _, err := req.Option("edges").Bool()
format, _, err := req.Option("format").String()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

format, _, err := req.Option("format").String()
edges, _, err := req.Option("edges").Bool()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if edges {
if format != "<dst>" {
res.SetError(errors.New("using format arguement with edges is not allowed"),
cmds.ErrClient)
return
}

format = "<src> -> <dst>"
}

objs, err := objectsForPaths(ctx, n, req.Arguments())
if err != nil {
Expand All @@ -103,7 +112,6 @@ NOTE: List all references recursively by using the flag '-r'.
DAG: n.DAG,
Ctx: ctx,
Unique: unique,
PrintEdge: edges,
PrintFmt: format,
Recursive: recursive,
}
Expand Down Expand Up @@ -210,7 +218,6 @@ type RefWriter struct {

Unique bool
Recursive bool
PrintEdge bool
PrintFmt string

seen map[key.Key]struct{}
Expand Down Expand Up @@ -315,8 +322,6 @@ func (rw *RefWriter) WriteEdge(from, to key.Key, linkname string) error {
s = strings.Replace(s, "<src>", from.B58String(), -1)
s = strings.Replace(s, "<dst>", to.B58String(), -1)
s = strings.Replace(s, "<linkname>", linkname, -1)
case rw.PrintEdge:
s = from.B58String() + " -> " + to.B58String()
default:
s += to.B58String()
}
Expand Down
21 changes: 19 additions & 2 deletions test/sharness/t0500-issues-and-regressions-offline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ test_description="Tests for various fixed issues and regressions."

. lib/test-lib.sh

test_init_ipfs

# Tests go here

test_expect_success "ipfs init with occupied input works - #2748" '
export IPFS_PATH="ipfs_path"
echo "" | time-out ipfs init &&
rm -rf ipfs_path
'
test_init_ipfs

test_expect_success "ipfs cat --help succeeds with no input" '
time-out ipfs cat --help
Expand All @@ -22,4 +21,22 @@ test_expect_success "ipfs pin ls --help succeeds with no input" '
time-out ipfs pin ls --help
'

test_expect_success "ipfs add on 1MB from stdin woks" '
random 1048576 42 | ipfs add -q > 1MB.hash
'

test_expect_success "'ipfs refs -r -e \$(cat 1MB.hash)' succeeds" '
ipfs refs -r -e $(cat 1MB.hash) > refs-e.out
'

test_expect_success "output of 'ipfs refs -e' links to separate blocks" '
grep "$(cat 1MB.hash) ->" refs-e.out
'

test_expect_success "output of 'ipfs refs -e' contains all first level links" '
grep "$(cat 1MB.hash) ->" refs-e.out | sed -e '\''s/.* -> //'\'' | sort > refs-s.out &&
ipfs refs "$(cat 1MB.hash)" | sort > refs-one.out &&
test_cmp refs-s.out refs-one.out
'

test_done

0 comments on commit 149819f

Please sign in to comment.