Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands: fix refs 'edges' option work #3007

Merged
merged 1 commit into from
Aug 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't format be an empty string (rather than "<dst>") if it isn't provided?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because: .Default("<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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this default case? It would only trigger if --format is explicitly set to the empty string, which seems like a corner case better handled by either an error, or actually printing an empty string for each edge, rather than overriding the explicit intention of the user.

}
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