| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,35 +1,38 @@ | |||
| 1 | - var nodegit = require('../'); | ||
| 2 | - var path = require('path'); | ||
| 3 | - var Promise = require('nodegit-promise'); | ||
| 4 | - var promisify = require('promisify-node'); | ||
| 5 | - var fse = promisify(require('fs-extra')); | ||
| 6 | - var fileName = 'newfile.txt'; | ||
| 7 | - var fileContent = 'hello world'; | ||
| 8 | - var directoryName = 'salad/toast/strangerinastrangeland/theresnowaythisexists'; | ||
| 1 | + var nodegit = require("../"); | ||
| 2 | + var path = require("path"); | ||
| 3 | + var promisify = require("promisify-node"); | ||
| 4 | + var fse = promisify(require("fs-extra")); | ||
| 5 | + var fileName = "newfile.txt"; | ||
| 6 | + var fileContent = "hello world"; | ||
| 7 | + var directoryName = "salad/toast/strangerinastrangeland/theresnowaythisexists"; | ||
| 9 | 8 | // ensureDir is an alias to mkdirp, which has the callback with a weird name | |
| 10 | - // and in the 3rd position of 4 (the 4th being used for recursion). We have to force | ||
| 11 | - // promisify it, because promisify-node won't detect it on its own and assumes sync | ||
| 9 | + // and in the 3rd position of 4 (the 4th being used for recursion). We have to | ||
| 10 | + // force promisify it, because promisify-node won't detect it on its | ||
| 11 | + // own and assumes sync | ||
| 12 | 12 | fse.ensureDir = promisify(fse.ensureDir); | |
| 13 | 13 | ||
| 14 | 14 | /** | |
| 15 | - * This example creates a certain file `newfile.txt`, adds it to the git index and | ||
| 16 | - * commits it to head. Similar to a `git add newfile.txt` followed by a `git commit` | ||
| 15 | + * This example creates a certain file `newfile.txt`, adds it to the git | ||
| 16 | + * index and commits it to head. Similar to a `git add newfile.txt` | ||
| 17 | + * followed by a `git commit` | ||
| 17 | 18 | **/ | |
| 18 | 19 | ||
| 19 | 20 | var repo; | |
| 20 | 21 | var index; | |
| 21 | 22 | var oid; | |
| 22 | - var parent; | ||
| 23 | 23 | ||
| 24 | - nodegit.Repository.open(path.resolve(__dirname, '../.git')) | ||
| 24 | + nodegit.Repository.open(path.resolve(__dirname, "../.git")) | ||
| 25 | 25 | .then(function(repoResult) { | |
| 26 | 26 | repo = repoResult; | |
| 27 | 27 | return fse.ensureDir(path.join(repo.workdir(), directoryName)); | |
| 28 | 28 | }).then(function(){ | |
| 29 | 29 | return fse.writeFile(path.join(repo.workdir(), fileName), fileContent); | |
| 30 | 30 | }) | |
| 31 | 31 | .then(function() { | |
| 32 | - return fse.writeFile(path.join(repo.workdir(), directoryName, fileName), fileContent); | ||
| 32 | + return fse.writeFile( | ||
| 33 | + path.join(repo.workdir(), directoryName, fileName), | ||
| 34 | + fileContent | ||
| 35 | + ); | ||
| 33 | 36 | }) | |
| 34 | 37 | .then(function() { | |
| 35 | 38 | return repo.openIndex(); | |
@@ -52,17 +55,19 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) | |||
| 52 | 55 | }) | |
| 53 | 56 | .then(function(oidResult) { | |
| 54 | 57 | oid = oidResult; | |
| 55 | - return nodegit.Reference.nameToId(repo, 'HEAD'); | ||
| 58 | + return nodegit.Reference.nameToId(repo, "HEAD"); | ||
| 56 | 59 | }) | |
| 57 | 60 | .then(function(head) { | |
| 58 | 61 | return repo.getCommit(head); | |
| 59 | 62 | }) | |
| 60 | 63 | .then(function(parent) { | |
| 61 | - var author = nodegit.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60); | ||
| 62 | - var committer = nodegit.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90); | ||
| 64 | + var author = nodegit.Signature.create("Scott Chacon", | ||
| 65 | + "schacon@gmail.com", 123456789, 60); | ||
| 66 | + var committer = nodegit.Signature.create("Scott A Chacon", | ||
| 67 | + "scott@github.com", 987654321, 90); | ||
| 63 | 68 | ||
| 64 | - return repo.createCommit('HEAD', author, committer, 'message', oid, [parent]); | ||
| 69 | + return repo.createCommit("HEAD", author, committer, "message", oid, [parent]); | ||
| 65 | 70 | }) | |
| 66 | 71 | .done(function(commitId) { | |
| 67 | - console.log('New Commit: ', commitId); | ||
| 72 | + console.log("New Commit: ", commitId); | ||
| 68 | 73 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,24 +10,24 @@ | |||
| 10 | 10 | // | |
| 11 | 11 | // node git_profanity_check some/repo/.git | |
| 12 | 12 | // | |
| 13 | - var git = require('../../'); | ||
| 13 | + var git = require("../../"); | ||
| 14 | 14 | ||
| 15 | - var curses = ['put', 'curse', 'words', 'here']; | ||
| 16 | - var path = './.git'; | ||
| 17 | - var branch = 'master'; | ||
| 18 | - var reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi'); | ||
| 15 | + var curses = ["put", "curse", "words", "here"]; | ||
| 16 | + var path = "./.git"; | ||
| 17 | + var branch = "master"; | ||
| 18 | + var reCurse = new RegExp("\\b(?:" + curses.join("|") + ")\\b", "gi"); | ||
| 19 | 19 | ||
| 20 | 20 | // Default path is `.git`. | |
| 21 | 21 | if (process.argv.length < 3) { | |
| 22 | - console.log('No path passed as argument, defaulting to .git.'); | ||
| 22 | + console.log("No path passed as argument, defaulting to .git."); | ||
| 23 | 23 | } | |
| 24 | 24 | // Otherwise defaults. | |
| 25 | 25 | else { | |
| 26 | 26 | path = process.argv[2]; | |
| 27 | 27 | ||
| 28 | 28 | // Set repo branch | |
| 29 | 29 | if (process.argv.length < 4) { | |
| 30 | - console.log('No branch passed as argument, defaulting to master.'); | ||
| 30 | + console.log("No branch passed as argument, defaulting to master."); | ||
| 31 | 31 | } | |
| 32 | 32 | else { | |
| 33 | 33 | branch = process.argv[3]; | |
@@ -44,12 +44,12 @@ git.Repo.open(path) | |||
| 44 | 44 | var history = firstCommit.history(); | |
| 45 | 45 | ||
| 46 | 46 | // Iterate over every commit message and test for words. | |
| 47 | - history.on('commit', function(commit) { | ||
| 47 | + history.on("commit", function(commit) { | ||
| 48 | 48 | var message = commit.message(); | |
| 49 | 49 | ||
| 50 | 50 | if (reCurse.test(message)) { | |
| 51 | - console.log('Curse detected in commit', commit.sha()); | ||
| 52 | - console.log('=> ', message); | ||
| 51 | + console.log("Curse detected in commit", commit.sha()); | ||
| 52 | + console.log("=> ", message); | ||
| 53 | 53 | return; | |
| 54 | 54 | } | |
| 55 | 55 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - var nodegit = require('../'); | ||
| 1 | + var nodegit = require("../"); | ||
| 2 | 2 | var promisify = require("promisify-node"); | |
| 3 | 3 | var fse = promisify(require("fs-extra")); | |
| 4 | 4 | var path = "/tmp/nodegit-clone-demo"; | |
@@ -11,20 +11,20 @@ fse.remove(path).then(function() { | |||
| 11 | 11 | path, | |
| 12 | 12 | { ignoreCertErrors: 1}) | |
| 13 | 13 | .then(function(repo) { | |
| 14 | - return repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5'); | ||
| 14 | + return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5"); | ||
| 15 | 15 | }) | |
| 16 | 16 | .then(function(commit) { | |
| 17 | - return commit.getEntry('README.md') | ||
| 17 | + return commit.getEntry("README.md"); | ||
| 18 | 18 | }) | |
| 19 | 19 | .then(function(entryResult) { | |
| 20 | 20 | entry = entryResult; | |
| 21 | 21 | return entry.getBlob(); | |
| 22 | 22 | }) | |
| 23 | 23 | .done(function(blob) { | |
| 24 | - console.log(entry.filename(), entry.sha(), blob.rawsize() + 'b'); | ||
| 25 | - console.log('========================================================\n\n'); | ||
| 26 | - var firstTenLines = blob.toString().split('\n').slice(0, 10).join('\n'); | ||
| 24 | + console.log(entry.filename(), entry.sha(), blob.rawsize() + "b"); | ||
| 25 | + console.log("========================================================\n\n"); | ||
| 26 | + var firstTenLines = blob.toString().split("\n").slice(0, 10).join("\n"); | ||
| 27 | 27 | console.log(firstTenLines); | |
| 28 | - console.log('...'); | ||
| 28 | + console.log("..."); | ||
| 29 | 29 | }); | |
| 30 | 30 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,10 @@ | |||
| 1 | - var nodegit = require('../'); | ||
| 2 | - var path = require('path'); | ||
| 3 | - var Promise = require('nodegit-promise'); | ||
| 4 | - var promisify = require('promisify-node'); | ||
| 5 | - var fse = promisify(require('fs-extra')); | ||
| 6 | - var fileName = 'newfile.txt'; | ||
| 7 | - var fileContent = 'hello world'; | ||
| 8 | - var repoDir = '../../newRepo'; | ||
| 1 | + var nodegit = require("../"); | ||
| 2 | + var path = require("path"); | ||
| 3 | + var promisify = require("promisify-node"); | ||
| 4 | + var fse = promisify(require("fs-extra")); | ||
| 5 | + var fileName = "newfile.txt"; | ||
| 6 | + var fileContent = "hello world"; | ||
| 7 | + var repoDir = "../../newRepo"; | ||
| 9 | 8 | ||
| 10 | 9 | fse.ensureDir = promisify(fse.ensureDir); | |
| 11 | 10 | ||
@@ -37,13 +36,15 @@ fse.ensureDir(path.resolve(__dirname, repoDir)) | |||
| 37 | 36 | return index.writeTree(); | |
| 38 | 37 | }) | |
| 39 | 38 | .then(function(oid) { | |
| 40 | - var author = nodegit.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60); | ||
| 41 | - var committer = nodegit.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90); | ||
| 39 | + var author = nodegit.Signature.create("Scott Chacon", | ||
| 40 | + "schacon@gmail.com", 123456789, 60); | ||
| 41 | + var committer = nodegit.Signature.create("Scott A Chacon", | ||
| 42 | + "scott@github.com", 987654321, 90); | ||
| 42 | 43 | ||
| 43 | 44 | // Since we're creating an inital commit, it has no parents. Note that unlike | |
| 44 | 45 | // normal we don't get the head either, because there isn't one yet. | |
| 45 | - return repository.createCommit('HEAD', author, committer, 'message', oid, []); | ||
| 46 | + return repository.createCommit("HEAD", author, committer, "message", oid, []); | ||
| 46 | 47 | }) | |
| 47 | 48 | .done(function(commitId) { | |
| 48 | - console.log('New Commit: ', commitId); | ||
| 49 | + console.log("New Commit: ", commitId); | ||
| 49 | 50 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,28 +1,29 @@ | |||
| 1 | - var nodegit = require('../'); | ||
| 2 | - var path = require('path'); | ||
| 1 | + var nodegit = require("../"); | ||
| 2 | + var path = require("path"); | ||
| 3 | 3 | ||
| 4 | 4 | /** | |
| 5 | 5 | * This shows how to get details from a tree entry or a blob | |
| 6 | 6 | **/ | |
| 7 | 7 | ||
| 8 | - nodegit.Repository.open(path.resolve(__dirname, '../.git')) | ||
| 9 | - .then(function(repo) { | ||
| 10 | - return repo.getTree("e1b0c7ea57bfc5e30ec279402a98168a27838ac9") | ||
| 11 | - .then(function(tree) { | ||
| 12 | - var treeEntry = tree.entryByIndex(0); | ||
| 8 | + nodegit.Repository.open(path.resolve(__dirname, "../.git")) | ||
| 9 | + .then(function(repo) { | ||
| 10 | + return repo.getTree("e1b0c7ea57bfc5e30ec279402a98168a27838ac9") | ||
| 11 | + .then(function(tree) { | ||
| 12 | + var treeEntry = tree.entryByIndex(0); | ||
| 13 | 13 | ||
| 14 | - // Tree entry doesn't have any data associated with the actual entry | ||
| 15 | - // To get that we need to get the index entry that this points to | ||
| 16 | - return repo.openIndex().then(function(index) { | ||
| 17 | - var indexEntry = index.getByPath(treeEntry.path()); | ||
| 14 | + // Tree entry doesn't have any data associated with the actual entry | ||
| 15 | + // To get that we need to get the index entry that this points to | ||
| 16 | + return repo.openIndex().then(function(index) { | ||
| 17 | + var indexEntry = index.getByPath(treeEntry.path()); | ||
| 18 | 18 | ||
| 19 | - // With the index entry we can now view the details for the tree entry | ||
| 20 | - console.log("Entry path: " + indexEntry.path()); | ||
| 21 | - console.log("Entry time in seconds: " + indexEntry.mtime().seconds()); | ||
| 22 | - console.log("Entry oid: " + indexEntry.id().toString()); | ||
| 23 | - console.log("Entry size: " + indexEntry.fileSize()); | ||
| 19 | + // With the index entry we can now view the details for the tree entry | ||
| 20 | + console.log("Entry path: " + indexEntry.path()); | ||
| 21 | + console.log("Entry time in seconds: " + indexEntry.mtime().seconds()); | ||
| 22 | + console.log("Entry oid: " + indexEntry.id().toString()); | ||
| 23 | + console.log("Entry size: " + indexEntry.fileSize()); | ||
| 24 | + }); | ||
| 24 | 25 | }); | |
| 25 | 26 | }) | |
| 26 | - }).done(function() { | ||
| 27 | - console.log("Done!"); | ||
| 28 | - }); | ||
| 27 | + .done(function() { | ||
| 28 | + console.log("Done!"); | ||
| 29 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,20 @@ | |||
| 1 | - var nodegit = require('../'); | ||
| 2 | - var path = require('path'); | ||
| 1 | + var nodegit = require("../"); | ||
| 2 | + var path = require("path"); | ||
| 3 | 3 | ||
| 4 | 4 | // This code examines the diffs between a particular commit and all of its | |
| 5 | 5 | // parents. Since this commit is not a merge, it only has one parent. This is | |
| 6 | 6 | // similar to doing `git show`. | |
| 7 | 7 | ||
| 8 | - nodegit.Repository.open(path.resolve(__dirname, '../.git')) | ||
| 8 | + nodegit.Repository.open(path.resolve(__dirname, "../.git")) | ||
| 9 | 9 | .then(function(repo) { | |
| 10 | - return repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5'); | ||
| 10 | + return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5"); | ||
| 11 | 11 | }) | |
| 12 | 12 | .then(function(commit) { | |
| 13 | - console.log('commit ' + commit.sha()); | ||
| 14 | - console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>'); | ||
| 15 | - console.log('Date:', commit.date()); | ||
| 16 | - console.log('\n ' + commit.message()); | ||
| 13 | + console.log("commit " + commit.sha()); | ||
| 14 | + console.log("Author:", commit.author().name() + | ||
| 15 | + " <" + commit.author().email() + ">"); | ||
| 16 | + console.log("Date:", commit.date()); | ||
| 17 | + console.log("\n " + commit.message()); | ||
| 17 | 18 | ||
| 18 | 19 | return commit.getDiff(); | |
| 19 | 20 | }) | |
@@ -24,7 +25,8 @@ nodegit.Repository.open(path.resolve(__dirname, '../.git')) | |||
| 24 | 25 | patch.hunks().forEach(function(hunk) { | |
| 25 | 26 | console.log(hunk.header().trim()); | |
| 26 | 27 | hunk.lines().forEach(function(line) { | |
| 27 | - console.log(String.fromCharCode(line.origin()) + line.content().trim()); | ||
| 28 | + console.log(String.fromCharCode(line.origin()) + | ||
| 29 | + line.content().trim()); | ||
| 28 | 30 | }); | |
| 29 | 31 | }); | |
| 30 | 32 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,13 @@ | |||
| 1 | - var nodegit = require('../'); | ||
| 2 | - var path = require('path'); | ||
| 1 | + var nodegit = require("../"); | ||
| 2 | + var path = require("path"); | ||
| 3 | 3 | ||
| 4 | - nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) { | ||
| 5 | - return repo.fetch("origin", { | ||
| 6 | - credentials: function(url, userName) { | ||
| 7 | - return nodegit.Cred.sshKeyFromAgent(userName); | ||
| 8 | - } | ||
| 4 | + nodegit.Repository.open(path.resolve(__dirname, "../.git")) | ||
| 5 | + .then(function(repo) { | ||
| 6 | + return repo.fetch("origin", { | ||
| 7 | + credentials: function(url, userName) { | ||
| 8 | + return nodegit.Cred.sshKeyFromAgent(userName); | ||
| 9 | + } | ||
| 10 | + }); | ||
| 11 | + }).done(function() { | ||
| 12 | + console.log("It worked!"); | ||
| 9 | 13 | }); | |
| 10 | - }).done(function() { | ||
| 11 | - console.log("It worked!"); | ||
| 12 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments