| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9e50766 commit 496c335
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,30 +1,34 @@ | |||
| 1 | 1 | --- | |
| 2 | - layout: default | ||
| 2 | + layout: guides | ||
| 3 | 3 | menu_item: guides | |
| 4 | 4 | title: Guides | |
| 5 | 5 | description: Learning NodeGit | |
| 6 | 6 | --- | |
| 7 | 7 | ||
| 8 | - ## [Install](install/) | ||
| 8 | + ## Install | ||
| 9 | 9 | ||
| 10 | 10 | > How to install NodeGit | |
| 11 | 11 | ||
| 12 | - - [Basics](install/basics/) | ||
| 12 | + - [Basics](install/) | ||
| 13 | 13 | - [From source](install/from-source) | |
| 14 | 14 | - [Atom Shell](install/atom-shell/) | |
| 15 | 15 | - [NW.js](install/nw.js/) | |
| 16 | 16 | ||
| 17 | - ## [Repository](repositories/) | ||
| 17 | + *** | ||
| 18 | + | ||
| 19 | + ## Repository | ||
| 18 | 20 | ||
| 19 | 21 | > How to work with repositories | |
| 20 | 22 | ||
| 23 | + - [Opening](repositories/) | ||
| 21 | 24 | - [Initializing](repositories/initializing) | |
| 22 | - - [Opening](repositories/opening) | ||
| 23 | 25 | ||
| 24 | - ## [Cloning](cloning/) | ||
| 26 | + *** | ||
| 27 | + | ||
| 28 | + ## Cloning | ||
| 25 | 29 | ||
| 26 | 30 | > How to clone repositories | |
| 27 | 31 | ||
| 28 | - - [HTTP/HTTPS](cloning/http/) | ||
| 32 | + - [HTTP/HTTPS](cloning/) | ||
| 29 | 33 | - [SSH w/ Agent](cloning/ssh-with-agent/) | |
| 30 | 34 | - [GitHub Two Factor Auth](cloning/gh-two-factor/) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,29 +1,130 @@ | |||
| 1 | 1 | --- | |
| 2 | 2 | layout: full | |
| 3 | 3 | menu_item: guides | |
| 4 | - title: Cloning Guides | ||
| 5 | - description: How to clone repositories | ||
| 4 | + title: HTTP/HTTPS Guide | ||
| 5 | + description: How to clone with HTTP/HTTPS | ||
| 6 | 6 | --- | |
| 7 | 7 | ||
| 8 | - [Return to all guides](../) | ||
| 8 | + **In order to run examples, you will need to [Install NodeGit](../../install/basics) | ||
| 9 | + first.** | ||
| 10 | + | ||
| 11 | + [Return to cloning guides](../) | ||
| 9 | 12 | ||
| 10 | 13 | * * * | |
| 11 | 14 | ||
| 12 | - ### [HTTP/HTTPS](http/) | ||
| 15 | + HTTP/HTTPS | ||
| 16 | + ---------- | ||
| 17 | + | ||
| 18 | + This guide explains how to clone a repository, and in the case of failure, | ||
| 19 | + attempt to open the existing path. | ||
| 20 | + | ||
| 21 | + [View example source](index.js) | ||
| 22 | + | ||
| 23 | + ### Requiring NodeGit | ||
| 24 | + | ||
| 25 | + In the guides directory, we like to keep our NodeGit relative to the project | ||
| 26 | + root. | ||
| 27 | + | ||
| 28 | + ``` javascript | ||
| 29 | + var Git = require("../../../"); | ||
| 30 | + ``` | ||
| 31 | + | ||
| 32 | + However, in your project you will most likely be using the following command: | ||
| 33 | + | ||
| 34 | + ``` javascript | ||
| 35 | + var Git = require("nodegit"); | ||
| 36 | + ``` | ||
| 37 | + | ||
| 38 | + ### Clone URL | ||
| 39 | + | ||
| 40 | + The first argument to the `clone` method is a URL. | ||
| 41 | + | ||
| 42 | + In this example we're going to clone one of our test repositories from GitHub. | ||
| 43 | + You could easily substitute this with any valid http or https Git repository | ||
| 44 | + URL. | ||
| 45 | + | ||
| 46 | + ``` javascript | ||
| 47 | + var cloneURL = "https://github.com/nodegit/test"; | ||
| 48 | + ``` | ||
| 49 | + | ||
| 50 | + ### Clone path | ||
| 51 | + | ||
| 52 | + The second argument to the `clone` method is a path. | ||
| 53 | + | ||
| 54 | + Ideally your application will clone a repository into the same folder path | ||
| 55 | + regardless of how or where you execute it from. Paths are relative to the | ||
| 56 | + current working directory in NodeGit, so you will need to normalize it first. | ||
| 57 | + | ||
| 58 | + This is very simple in Node: | ||
| 59 | + | ||
| 60 | + ``` javascript | ||
| 61 | + var localPath = require("path").join(__dirname, "tmp"); | ||
| 62 | + ``` | ||
| 63 | + | ||
| 64 | + Now this `tmp` directory will be created along side your script, no matter how | ||
| 65 | + or where you execute it from. | ||
| 66 | + | ||
| 67 | + ### Clone options | ||
| 68 | + | ||
| 69 | + The third argument to the `clone` method is an optional simple object. | ||
| 70 | + | ||
| 71 | + ``` javascript | ||
| 72 | + var cloneOptions = {}; | ||
| 73 | + ``` | ||
| 74 | + | ||
| 75 | + **If you are using HTTP the OS X issue below does not affect you.** | ||
| 76 | + | ||
| 77 | + #### GitHub certificate issue in OS X | ||
| 78 | + | ||
| 79 | + Unfortunately in OS X there is a problem where libgit2 is unable to look up | ||
| 80 | + GitHub certificates correctly. In order to bypass this problem, we're going | ||
| 81 | + to passthrough the certificate check. | ||
| 82 | + | ||
| 83 | + *Note: this is not a problem with Windows or Linux* | ||
| 84 | + | ||
| 85 | + ``` javascript | ||
| 86 | + cloneOptions.remoteCallbacks = { | ||
| 87 | + certificateCheck: function() { return 1; } | ||
| 88 | + }; | ||
| 89 | + ``` | ||
| 90 | + | ||
| 91 | + ### Invoking the clone method | ||
| 92 | + | ||
| 93 | + You can easily invoke our top-level Clone as a function passing along the three | ||
| 94 | + aforementioned arguments. | ||
| 95 | + | ||
| 96 | + ``` javascript | ||
| 97 | + var cloneRepository = Git.Clone(cloneURL, localPath, cloneOptions); | ||
| 98 | + ``` | ||
| 13 | 99 | ||
| 14 | - > Emulates `git clone https://github.com/nodegit/test` | ||
| 100 | + Notice how we store the return value from `Git.Clone`. This is a | ||
| 101 | + [Promise](https://www.promisejs.org/) to represent the asynchronous operation. | ||
| 102 | + It offers finer control flow by allowing us to capture errors and fallback if | ||
| 103 | + there is a clone failure. | ||
| 15 | 104 | ||
| 16 | - For cloning HTTP or HTTPS repositories from servers like GitHub. | ||
| 105 | + ### Handling clone failure | ||
| 17 | 106 | ||
| 18 | - ### [SSH w/ Agent](ssh-with-agent/) | ||
| 107 | + A naive way to handle a clone failure is to try opening the same path. Clones | ||
| 108 | + will most commonly fail when the directory already exists. We can define | ||
| 109 | + a function to attempt opening in this case. | ||
| 19 | 110 | ||
| 20 | - > Emulates `git clone git@github.com:nodegit/test` | ||
| 111 | + ``` javascript | ||
| 112 | + var errorAndAttemptOpen = function() { | ||
| 113 | + return Git.Repository.open(local); | ||
| 114 | + }; | ||
| 115 | + ``` | ||
| 21 | 116 | ||
| 22 | - For cloning SSH repositories using an SSH agent. | ||
| 117 | + This will be called as part of the Promise resolution in the final step. | ||
| 23 | 118 | ||
| 24 | - ### [GitHub Two Factor Auth](gh-two-factor/) | ||
| 119 | + ### The Promise chain | ||
| 25 | 120 | ||
| 26 | - > Emulates `git clone https://gh-token:-oauth-basic@github.com/nodegit/test` | ||
| 121 | + Lastly in our clone operation, we'll assemble a Promise chain to handle errors | ||
| 122 | + and work with the `Git.Repository` instance result. | ||
| 27 | 123 | ||
| 28 | - For cloning repositories from GitHub when two-factor authorization is | ||
| 29 | - enabled. | ||
| 124 | + ``` javascript | ||
| 125 | + cloneRepository.catch(errorAndAttemptOpen) | ||
| 126 | + .then(function(repository) { | ||
| 127 | + // Access any repository methods here. | ||
| 128 | + console.log("Is the repository bare? %s", Boolean(repository.isBare())); | ||
| 129 | + }); | ||
| 130 | + ``` | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,26 +1,43 @@ | |||
| 1 | 1 | --- | |
| 2 | 2 | layout: full | |
| 3 | 3 | menu_item: guides | |
| 4 | - title: Install Guides | ||
| 4 | + title: Install Basics | ||
| 5 | 5 | description: How to install NodeGit | |
| 6 | 6 | --- | |
| 7 | 7 | ||
| 8 | - [Return to all guides](../) | ||
| 8 | + [Return to install guides](../) | ||
| 9 | 9 | ||
| 10 | 10 | * * * | |
| 11 | 11 | ||
| 12 | - ### [Basics](basics/) | ||
| 12 | + <a name="with-npm"></a>From NPM | ||
| 13 | + ------------------------------- | ||
| 13 | 14 | ||
| 14 | - Learn how to install NodeGit | ||
| 15 | + To install from the NPM repository you can issue the following command: | ||
| 15 | 16 | ||
| 16 | - ### [From source](from-source/) | ||
| 17 | + ``` bash | ||
| 18 | + npm install nodegit | ||
| 19 | + ``` | ||
| 17 | 20 | ||
| 18 | - Learn how to build NodeGit from source | ||
| 21 | + <a name="from-github"></a>From GitHub | ||
| 22 | + ------------------------------------- | ||
| 19 | 23 | ||
| 20 | - ### [Atom Shell](atom-shell/) | ||
| 24 | + This is required to contribute or run the examples. | ||
| 21 | 25 | ||
| 22 | - Learn how to use NodeGit with Atom Shell | ||
| 26 | + Start by cloning the repository, chances are you will only need the latest | ||
| 27 | + commit, so you can pass the `--depth` flag to make a shallow clone: | ||
| 23 | 28 | ||
| 24 | - ### [Nw.js](nw.js/) | ||
| 29 | + ``` bash | ||
| 30 | + git clone --depth=1 https://github.com/nodegit/nodegit | ||
| 31 | + ``` | ||
| 25 | 32 | ||
| 26 | - Learn how to use NodeGit with NW.js | ||
| 33 | + Change your directory into the newly created nodegit folder. | ||
| 34 | + | ||
| 35 | + ``` bash | ||
| 36 | + cd nodegit | ||
| 37 | + ``` | ||
| 38 | + | ||
| 39 | + Now you can issue the local installation command: | ||
| 40 | + | ||
| 41 | + ``` bash | ||
| 42 | + npm install | ||
| 43 | + ``` | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments