Skip to content

Commit

Permalink
Make the test more interactive and add minified version
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Oct 4, 2013
1 parent 7ae5980 commit 27b76ee
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 57 deletions.
70 changes: 42 additions & 28 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
<!doctype html>
<html>
<head>
<script src="jsgit.js"></script>
<script src="jsgit.min.js"></script>
</head>
<body>
<h1>JS-Git Browser Test Page</h1>
<p>You must serve this page using the included node server that proxies websocket connections out to real git servers.</p>
<script>

// Create a new in-memory database
var db = jsgit.db("test");
var repo, remote;
db.init(onInit);
var repo, remote;
var url = prompt("Enter the git url to a small repo",
"git://github.com/creationix/conquest.git");
// Create a wrapper to a remote repository
var remote = jsgit.remote(url);
console.log(remote);
var name = url.substr(url.lastIndexOf("/") + 1);
// Create a new in-memory database
var db = jsgit.db(name);
console.log(db);
// Wrap it in git logic
var repo = jsgit.repo(db);
console.log(repo);
var element;
// Initialize the database
db.init(onInit);

function onInit(err) {
if (err) throw err;
// Wrap it in git logic
repo = jsgit.repo(db);
console.log(repo);
// Create a wrapper to a remote repository
remote = jsgit.remote("git://github.com/creationix/conquest.git");
console.log(remote);
// Clone the remote repo to te local db.
var opts = {
onProgress: onProgress,
deline: true
};
repo.fetch(remote, opts, onDone);
}
function onInit(err) {
if (err) throw err;
// Clone the remote repo to te local db.
onProgress("Fetching updates for or cloning " + url + "\n");
repo.fetch(remote, {
onProgress: onProgress,
deline: true
}, onDone);
}

function onProgress(progress) {
console.log(progress);
function onProgress(progress) {
if (!element || progress[progress.length - 1] === "\n") {
element = document.createElement("p");
document.body.appendChild(element);
}
element.textContent = progress.trim();
}

function onDone(err) {
if (err) throw err;
console.log("Done");
function onDone(err) {
if (err) {
onProgress(err.stack + "\n");
throw err;
}
onProgress("Done!\n");
}

</script>
</head>
<body>
Look at the console for output.
</body>
</html>
2 changes: 2 additions & 0 deletions build/jsgit.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion make.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ T.serial(
T.copy("src/index.html", "build/index.html"),
T.copy("src/server.js", "build/server.js"),
T.build("src/core.js", "build/jsgit.js")
)
),
T.execFile("uglifyjs", ["build/jsgit.js", "--screw-ie8", "-c", "-m", "-o", "build/jsgit.min.js"], {})
)(function (err) {
if (err) throw err;
console.log("done.");
Expand Down
70 changes: 42 additions & 28 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
<!doctype html>
<html>
<head>
<script src="jsgit.js"></script>
<script src="jsgit.min.js"></script>
</head>
<body>
<h1>JS-Git Browser Test Page</h1>
<p>You must serve this page using the included node server that proxies websocket connections out to real git servers.</p>
<script>

// Create a new in-memory database
var db = jsgit.db("test");
var repo, remote;
db.init(onInit);
var repo, remote;
var url = prompt("Enter the git url to a small repo",
"git://github.com/creationix/conquest.git");
// Create a wrapper to a remote repository
var remote = jsgit.remote(url);
console.log(remote);
var name = url.substr(url.lastIndexOf("/") + 1);
// Create a new in-memory database
var db = jsgit.db(name);
console.log(db);
// Wrap it in git logic
var repo = jsgit.repo(db);
console.log(repo);
var element;
// Initialize the database
db.init(onInit);

function onInit(err) {
if (err) throw err;
// Wrap it in git logic
repo = jsgit.repo(db);
console.log(repo);
// Create a wrapper to a remote repository
remote = jsgit.remote("git://github.com/creationix/conquest.git");
console.log(remote);
// Clone the remote repo to te local db.
var opts = {
onProgress: onProgress,
deline: true
};
repo.fetch(remote, opts, onDone);
}
function onInit(err) {
if (err) throw err;
// Clone the remote repo to te local db.
onProgress("Fetching updates for or cloning " + url + "\n");
repo.fetch(remote, {
onProgress: onProgress,
deline: true
}, onDone);
}

function onProgress(progress) {
console.log(progress);
function onProgress(progress) {
if (!element || progress[progress.length - 1] === "\n") {
element = document.createElement("p");
document.body.appendChild(element);
}
element.textContent = progress.trim();
}

function onDone(err) {
if (err) throw err;
console.log("Done");
function onDone(err) {
if (err) {
onProgress(err.stack + "\n");
throw err;
}
onProgress("Done!\n");
}

</script>
</head>
<body>
Look at the console for output.
</body>
</html>

0 comments on commit 27b76ee

Please sign in to comment.