Skip to content

Commit 60ecbcc

Browse files
committed
Cleaned up callbacks, descriptor, supplement, Stash implementation
Added features to nodegit that are now in libgit2: NodeGit.Stash.apply(repository, index, options) NodeGit.Stash.drop(repository, index) NodeGit.Stash.pop(repository, index, options) NodeGit.Stash.save(repository, index, options) As well as added in StashApplyOptions which contains: a CheckoutOptions field, and a stash progress callback. The stash progress takes 1 parameter: progress, which is of type NodeGit.Stash.APPLY_PROGRESS All the stash operations are tested.
1 parent 33e72a0 commit 60ecbcc

5 files changed

Lines changed: 343 additions & 60 deletions

File tree

generate/input/callbacks.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,24 @@
545545
"error": -1
546546
}
547547
},
548+
"git_stash_apply_progress_cb": {
549+
"args": [
550+
{
551+
"name": "progress",
552+
"cType": "git_stash_apply_progress_t"
553+
},
554+
{
555+
"name": "payload",
556+
"cType": "void *"
557+
}
558+
],
559+
"return": {
560+
"type": "int",
561+
"noResults":0,
562+
"success": 0,
563+
"error": -1
564+
}
565+
},
548566
"git_stash_cb": {
549567
"args": [
550568
{

generate/input/descriptor.json

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@
161161
}
162162
}
163163
},
164+
"git_branch_create_from_annotated": {
165+
"args": {
166+
"ref_out": {
167+
"isReturn": true
168+
},
169+
"repository": {},
170+
"branch_name": {},
171+
"commit": {},
172+
"force": {
173+
"isOptional": true
174+
}
175+
}
176+
},
164177
"git_branch_next": {
165178
"ignore": true
166179
},
@@ -1685,6 +1698,9 @@
16851698
"git_repository_hashfile": {
16861699
"ignore": true
16871700
},
1701+
"git_repository_ident": {
1702+
"ignore": true
1703+
},
16881704
"git_repository_mergehead_foreach": {
16891705
"ignore": true
16901706
},
@@ -1815,10 +1831,16 @@
18151831
"stash": {
18161832
"functions": {
18171833
"git_stash_apply": {
1818-
"ignore": true
1834+
"isAsync": true,
1835+
"return": {
1836+
"isErrorCode": true
1837+
}
18191838
},
1820-
"git_stash_apply_init_options": {
1821-
"ignore": true
1839+
"git_stash_drop": {
1840+
"isAsync": true,
1841+
"return": {
1842+
"isErrorCode": true
1843+
}
18221844
},
18231845
"git_stash_foreach": {
18241846
"isAsync": true,
@@ -1827,7 +1849,16 @@
18271849
}
18281850
},
18291851
"git_stash_pop": {
1830-
"ignore": true
1852+
"isAsync": true,
1853+
"return": {
1854+
"isErrorCode": true
1855+
}
1856+
},
1857+
"git_stash_save": {
1858+
"isAsync": true,
1859+
"return": {
1860+
"isErrorCode": true
1861+
}
18311862
}
18321863
}
18331864
},

generate/input/libgit2-supplement.json

Lines changed: 84 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
"git_annotated_commit_free",
191191
"git_annotated_commit_from_fetchhead",
192192
"git_annotated_commit_from_ref",
193+
"git_annotated_commit_from_revspec",
193194
"git_annotated_commit_id",
194195
"git_annotated_commit_lookup"
195196
]
@@ -217,46 +218,73 @@
217218
],
218219
"types": [
219220
[
220-
"git_config_entry",
221+
"git_stash_apply_progress_t",
221222
{
223+
"type": "enum",
222224
"fields": [
223225
{
224-
"type": "const char *",
225-
"name": "name"
226+
"type": "int",
227+
"name": "GIT_STASH_APPLY_PROGRESS_NONE",
228+
"value": 0
226229
},
227230
{
228-
"type": "const char *",
229-
"name": "value"
231+
"type": "int",
232+
"name": "GIT_STASH_APPLY_PROGRESS_LOADING_STASH",
233+
"value": 1
230234
},
231235
{
232-
"type": "git_config_level_t",
233-
"name": "level"
236+
"type": "int",
237+
"name": "GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX",
238+
"value": 2
234239
},
235240
{
236-
"type": "void (*)(struct git_config_entry *)",
237-
"name": "free",
238-
"ignore": true
241+
"type": "int",
242+
"name": "GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED",
243+
"value": 3
244+
},
245+
{
246+
"type": "int",
247+
"name": "GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED",
248+
"value": 4
249+
},
250+
{
251+
"type": "int",
252+
"name": "GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED",
253+
"value": 5
254+
},
255+
{
256+
"type": "int",
257+
"name": "GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED",
258+
"value": 6
259+
},
260+
{
261+
"type": "int",
262+
"name": "GIT_STASH_APPLY_PROGRESS_DONE",
263+
"value": 7
239264
}
240265
]
241266
}
242267
],
243268
[
244-
"git_direction",
269+
"git_config_entry",
245270
{
246-
"type": "enum",
247-
"description": "Enum to indicate the direction that a remote connection is going to go",
248271
"fields": [
249272
{
250-
"type": "int",
251-
"name": "GIT_DIRECTION_FETCH",
252-
"comments": "Fetching from the remote repository",
253-
"value": 0
273+
"type": "const char *",
274+
"name": "name"
254275
},
255276
{
256-
"type": "int",
257-
"name": "GIT_DIRECTION_PUSH",
258-
"comments": "Pushing to a remote repository",
259-
"value": 1
277+
"type": "const char *",
278+
"name": "value"
279+
},
280+
{
281+
"type": "git_config_level_t",
282+
"name": "level"
283+
},
284+
{
285+
"type": "void (*)(struct git_config_entry *)",
286+
"name": "free",
287+
"ignore": true
260288
}
261289
]
262290
}
@@ -529,40 +557,6 @@
529557
}
530558
}
531559
],
532-
[
533-
"git_sort_t",
534-
{
535-
"type": "enum",
536-
"description": "Flags to specify the sorting which a revwalk should perform.",
537-
"fields": [
538-
{
539-
"type": "int",
540-
"name": "GIT_SORT_NONE",
541-
"comments": "Sort the repository contents in no particular ordering; this sorting is arbitrary, implementation-specific and subject to change at any time. This is the default sorting for new walkers.",
542-
"value": 0
543-
},
544-
{
545-
"type": "int",
546-
"name": "GIT_SORT_TOPOLOGICAL",
547-
"comments": "Sort the repository contents in topological order (parents before children); this sorting mode can be combined with time sorting.",
548-
"value": 1
549-
},
550-
{
551-
"type": "int",
552-
"name": "GIT_SORT_TIME",
553-
"comments": "Sort the repository contents by commit time; this sorting mode can be combined with topological sorting.",
554-
"value": 2
555-
},
556-
{
557-
"type": "int",
558-
"name": "GIT_SORT_REVERSE",
559-
"comments": "Iterate through the repository contents in reverse order; this sorting mode can be combined with any of the above.",
560-
"value": 4
561-
}
562-
],
563-
"comments": ""
564-
}
565-
],
566560
[
567561
"git_time_t",
568562
{
@@ -669,6 +663,40 @@
669663
]
670664
}
671665
}
666+
],
667+
[
668+
"git_stash_apply_options",
669+
{
670+
"type": "struct",
671+
"fields": [
672+
{
673+
"type": "unsigned int",
674+
"name": "version"
675+
},
676+
{
677+
"type": "git_stash_apply_flags",
678+
"name": "flags"
679+
},
680+
{
681+
"type": "git_checkout_options",
682+
"name": "checkout_options"
683+
},
684+
{
685+
"type": "git_stash_apply_progress_cb",
686+
"name": "progress_cb"
687+
},
688+
{
689+
"type": "void *",
690+
"name": "progress_payload"
691+
}
692+
],
693+
"used": {
694+
"needs": [
695+
"git_stash_apply_init_options",
696+
"git_checkout_init_options"
697+
]
698+
}
699+
}
672700
]
673701
]
674702
},
@@ -678,6 +706,7 @@
678706
"git_annotated_commit_free",
679707
"git_annotated_commit_from_fetchhead",
680708
"git_annotated_commit_from_ref",
709+
"git_annotated_commit_from_revspec",
681710
"git_annotated_commit_id",
682711
"git_annotated_commit_lookup"
683712
]

lib/stash.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var NodeGit = require("../");
2-
2+
var normalizeOptions = NodeGit.Utils.normalizeOptions;
3+
var shallowClone = require("./utils/shallow_clone");
34
var Stash = NodeGit.Stash;
45

56
// Override Stash.foreach to eliminate the need to pass null payload
@@ -14,3 +15,47 @@ Stash.foreach = function(repo, callback) {
1415

1516
return foreach(repo, wrappedCallback, null);
1617
};
18+
19+
var sApply = Stash.apply;
20+
Stash.apply = function(repo, index, options) {
21+
var checkoutOptions;
22+
23+
if (options) {
24+
options = shallowClone(options);
25+
checkoutOptions = options.checkoutOptions;
26+
delete options.checkoutOptions;
27+
} else {
28+
options = {};
29+
}
30+
31+
options = normalizeOptions(options, NodeGit.StashApplyOptions);
32+
33+
if (checkoutOptions) {
34+
options.checkoutOptions =
35+
normalizeOptions(checkoutOptions, NodeGit.checkoutOptions);
36+
}
37+
38+
return sApply(repo, index, options);
39+
};
40+
41+
var pop = Stash.pop;
42+
Stash.pop = function(repo, index, options) {
43+
var checkoutOptions;
44+
45+
if (options) {
46+
options = shallowClone(options);
47+
checkoutOptions = options.checkoutOptions;
48+
delete options.checkoutOptions;
49+
} else {
50+
options = {};
51+
}
52+
53+
options = normalizeOptions(options, NodeGit.StashApplyOptions);
54+
55+
if (checkoutOptions) {
56+
options.checkoutOptions =
57+
normalizeOptions(checkoutOptions, NodeGit.CheckoutOptions);
58+
}
59+
60+
return pop(repo, index, options);
61+
};

0 commit comments

Comments
 (0)