Skip to content

Commit 496c335

Browse files
orderedlistJohn Haley
authored andcommitted
Move guides around to remove subindexes
1 parent 9e50766 commit 496c335

File tree

9 files changed

+154
-228
lines changed

9 files changed

+154
-228
lines changed

guides/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
---
2-
layout: default
2+
layout: guides
33
menu_item: guides
44
title: Guides
55
description: Learning NodeGit
66
---
77

8-
## [Install](install/)
8+
## Install
99

1010
> How to install NodeGit
1111
12-
- [Basics](install/basics/)
12+
- [Basics](install/)
1313
- [From source](install/from-source)
1414
- [Atom Shell](install/atom-shell/)
1515
- [NW.js](install/nw.js/)
1616

17-
## [Repository](repositories/)
17+
***
18+
19+
## Repository
1820

1921
> How to work with repositories
2022
23+
- [Opening](repositories/)
2124
- [Initializing](repositories/initializing)
22-
- [Opening](repositories/opening)
2325

24-
## [Cloning](cloning/)
26+
***
27+
28+
## Cloning
2529

2630
> How to clone repositories
2731
28-
- [HTTP/HTTPS](cloning/http/)
32+
- [HTTP/HTTPS](cloning/)
2933
- [SSH w/ Agent](cloning/ssh-with-agent/)
3034
- [GitHub Two Factor Auth](cloning/gh-two-factor/)

guides/cloning/README.md

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,130 @@
11
---
22
layout: full
33
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
66
---
77

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](../)
912

1013
* * *
1114

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+
```
1399

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.
15104

16-
For cloning HTTP or HTTPS repositories from servers like GitHub.
105+
### Handling clone failure
17106

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.
19110

20-
> Emulates `git clone git@github.com:nodegit/test`
111+
``` javascript
112+
var errorAndAttemptOpen = function() {
113+
return Git.Repository.open(local);
114+
};
115+
```
21116

22-
For cloning SSH repositories using an SSH agent.
117+
This will be called as part of the Promise resolution in the final step.
23118

24-
### [GitHub Two Factor Auth](gh-two-factor/)
119+
### The Promise chain
25120

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.
27123

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+
```

guides/cloning/http/README.md

Lines changed: 0 additions & 130 deletions
This file was deleted.

guides/install/README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
---
22
layout: full
33
menu_item: guides
4-
title: Install Guides
4+
title: Install Basics
55
description: How to install NodeGit
66
---
77

8-
[Return to all guides](../)
8+
[Return to install guides](../)
99

1010
* * *
1111

12-
### [Basics](basics/)
12+
<a name="with-npm"></a>From NPM
13+
-------------------------------
1314

14-
Learn how to install NodeGit
15+
To install from the NPM repository you can issue the following command:
1516

16-
### [From source](from-source/)
17+
``` bash
18+
npm install nodegit
19+
```
1720

18-
Learn how to build NodeGit from source
21+
<a name="from-github"></a>From GitHub
22+
-------------------------------------
1923

20-
### [Atom Shell](atom-shell/)
24+
This is required to contribute or run the examples.
2125

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:
2328

24-
### [Nw.js](nw.js/)
29+
``` bash
30+
git clone --depth=1 https://github.com/nodegit/nodegit
31+
```
2532

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+
```

0 commit comments

Comments
 (0)