Skip to content

checkout from IPNS #7

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 24 additions & 1 deletion fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -56,6 +58,26 @@ func TestClone_unpacked(t *testing.T) {
rmDir(t, cloneAndCheckout(t, "ipfs://ipfs/QmYFpZJs82hLTyEpwkzVpaXGUabVVwiT8yrd6TK81XnoGB/unpackedTest", expectedClone))
}

func TestClone_ipnsPublished(t *testing.T) {
bareHash := "Qmf4ZzbmnqyKEjuBH3hNpQWu1fMUZWdy91DwAsUXXc4Kw1" // == /ipfs/QmYFpZJs82hLTyEpwkzVpaXGUabVVwiT8yrd6TK81XnoGB/unpackedTest
id, err := ipfsShell.ID()
checkFatal(t, err)
//err = ipfsShell.Publish(id.ID, bareHash)
err = ipfsShell.Publish("", bareHash)
Copy link
Owner Author

Choose a reason for hiding this comment

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

@whyrusleeping I can't get this to work.

L65 blocks indefinitely and L66 gives me failed to find any peer in table.

Any Idea how I could test this without relying on a remote node?

Copy link
Owner Author

Choose a reason for hiding this comment

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

20:01 <@whyrusleeping> yeah... we need an 'ipfs name publish --local' or something
20:01 <@whyrusleeping> or maybe just make the dht put not fail on no peers?
20:01 <@whyrusleeping> idk
20:04 <+cryptix> for the latter, the re-publisher ticker would still run, no?
20:05 <+cryptix> i imagine you'd also want this for a case where you are alone on a network and peers appear latter
20:07 <@whyrusleeping> yeah, the republisher ticker still runs no matter what

Copy link

Choose a reason for hiding this comment

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

checkFatal(t, err)
tmpDir := cloneAndCheckout(t, "ipfs://ipns/"+id.ID, expectedClone)
// check origin url
cmd := exec.Command(gitPath, "config", "--get", "remote.origin.url")
cmd.Dir = tmpDir
out, err := cmd.CombinedOutput()
checkFatal(t, err)
origin := strings.TrimSpace(string(out))
if origin != "ipfs://ipfs/"+bareHash {
t.Fatalf("remote url wasn't set correctly. is:%q", origin)
}
rmDir(t, tmpDir)
}

// helpers

func cloneAndCheckout(t *testing.T, repo string, expected map[string]string) (tmpDir string) {
Expand All @@ -74,7 +96,8 @@ func cloneAndCheckout(t *testing.T, repo string, expected map[string]string) (tm

func checkFatal(t *testing.T, err error) {
if err != nil {
t.Fatal(err)
_, file, line, _ := runtime.Caller(1)
t.Fatalf("error from %s:%d.\n%s", file, line, err)
}
}

Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ func main() {
log.Debug("prefix cut:", u)
}
}
for _, pref := range []string{"ipfs://ipns/", "ipfs:///ipns/"} {
if strings.HasPrefix(u, pref) {
current, err := ipfsShell.ResolvePath("/ipns/" + u[len(pref):])
if err != nil {
log.Fatal("ipns resolve for current version failed:", err)
}
log.Warnln("can't push to ipns addresses - using current hash. resolved to:", current)
u = current
}
}

p, err := path.ParsePath(u)
if err != nil {
log.Fatalf("path.ParsePath() failed: %s", err)
Expand Down