Skip to content

Commit f4e91e6

Browse files
committed
Merge pull request #971 from nodegit/async-index
Make index methods async
2 parents f67de63 + a0fb5d4 commit f4e91e6

File tree

15 files changed

+489
-260
lines changed

15 files changed

+489
-260
lines changed

examples/merge-cleanly.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ fse.remove(path.resolve(__dirname, repoDir))
4646
return repository.refreshIndex();
4747
})
4848
.then(function(index) {
49-
index.addByPath(ourFileName);
50-
index.write();
51-
52-
return index.writeTree();
49+
return index.addByPath(ourFileName)
50+
.then(function() {
51+
return index.write();
52+
})
53+
.then(function() {
54+
return index.writeTree();
55+
});
5356
})
5457
.then(function(oid) {
5558
return repository.createCommit("HEAD", ourSignature,
@@ -81,10 +84,13 @@ fse.remove(path.resolve(__dirname, repoDir))
8184
return repository.refreshIndex();
8285
})
8386
.then(function(index) {
84-
index.addByPath(theirFileName);
85-
index.write();
86-
87-
return index.writeTree();
87+
return index.addByPath(theirFileName)
88+
.then(function() {
89+
return index.write();
90+
})
91+
.then(function() {
92+
return index.writeTree();
93+
});
8894
})
8995
.then(function(oid) {
9096
// You don"t have to change head to make a commit to a different branch.
@@ -110,8 +116,10 @@ fse.remove(path.resolve(__dirname, repoDir))
110116
// the repository instead of just writing it.
111117
.then(function(index) {
112118
if (!index.hasConflicts()) {
113-
index.write();
114-
return index.writeTreeTo(repository);
119+
return index.write()
120+
.then(function() {
121+
return index.writeTreeTo(repository);
122+
});
115123
}
116124
})
117125

examples/merge-with-conflicts.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ fse.remove(path.resolve(__dirname, repoDir))
5252
return repository.refreshIndex();
5353
})
5454
.then(function(index) {
55-
index.addByPath(fileName);
56-
index.write();
57-
58-
return index.writeTree();
55+
return index.addByPath(fileName)
56+
.then(function() {
57+
return index.write();
58+
})
59+
.then(function() {
60+
return index.writeTree();
61+
});
5962
})
6063
.then(function(oid) {
6164
return repository.createCommit("HEAD", baseSignature,
@@ -95,10 +98,13 @@ fse.remove(path.resolve(__dirname, repoDir))
9598
.then(function() {
9699
return repository.refreshIndex()
97100
.then(function(index) {
98-
index.addByPath(fileName);
99-
index.write();
100-
101-
return index.writeTree();
101+
return index.addByPath(fileName)
102+
.then(function() {
103+
return index.write();
104+
})
105+
.then(function() {
106+
return index.writeTree();
107+
});
102108
});
103109
})
104110
.then(function(oid) {
@@ -120,11 +126,15 @@ fse.remove(path.resolve(__dirname, repoDir))
120126
);
121127
})
122128
.then(function() {
123-
return repository.refreshIndex().then(function(index) {
124-
index.addByPath(fileName);
125-
index.write();
126-
127-
return index.writeTree();
129+
return repository.refreshIndex()
130+
.then(function(index) {
131+
return index.addByPath(fileName)
132+
.then(function() {
133+
return index.write();
134+
})
135+
.then(function() {
136+
return index.writeTree();
137+
});
128138
});
129139
})
130140
.then(function(oid) {
@@ -170,12 +180,15 @@ fse.remove(path.resolve(__dirname, repoDir))
170180
// we need to get a new index as the other one isnt backed to
171181
// the repository in the usual fashion, and just behaves weirdly
172182
.then(function() {
173-
return repository.refreshIndex().then(function(index) {
174-
175-
index.addByPath(fileName);
176-
index.write();
177-
178-
return index.writeTree();
183+
return repository.refreshIndex()
184+
.then(function(index) {
185+
return index.addByPath(fileName)
186+
.then(function() {
187+
return index.write();
188+
})
189+
.then(function() {
190+
return index.writeTree();
191+
});
179192
});
180193
})
181194
.then(function(oid) {

examples/push.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ fse.remove(path.resolve(__dirname, repoDir))
3333
return repository.refreshIndex();
3434
})
3535
.then(function(index) {
36-
index.addByPath(fileName);
37-
index.write();
38-
39-
return index.writeTree();
36+
return index.addByPath(fileName)
37+
.then(function() {
38+
return index.write();
39+
})
40+
.then(function() {
41+
return index.writeTree();
42+
});
4043
})
4144
.then(function(oid) {
4245
return repository.createCommit("HEAD", signature, signature,

examples/remove-and-commit.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
2424
})
2525
.then(function() {
2626
//remove the file from the index...
27-
_index.removeByPath(fileName);
27+
return _index.removeByPath(fileName);
28+
})
29+
.then(function() {
2830
return _index.write();
2931
})
3032
.then(function() {

generate/input/descriptor.json

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,12 @@
959959
},
960960
"index": {
961961
"functions": {
962+
"git_index_add": {
963+
"isAsync": true,
964+
"return": {
965+
"isErrorCode": true
966+
}
967+
},
962968
"git_index_add_all": {
963969
"args": {
964970
"pathspec": {
@@ -976,11 +982,34 @@
976982
"isErrorCode": true
977983
}
978984
},
985+
"git_index_add_bypath": {
986+
"isAsync": true,
987+
"return": {
988+
"isErrorCode": true
989+
}
990+
},
979991
"git_index_add_frombuffer": {
980992
"ignore": true
981993
},
982-
"git_index_conflict_get": {
994+
"git_index_clear": {
995+
"isAsync": true,
996+
"return": {
997+
"isErrorCode": true
998+
}
999+
},
1000+
"git_index_conflict_add": {
1001+
"isAsync": true,
1002+
"return": {
1003+
"isErrorCode": true
1004+
}
1005+
},
1006+
"git_index_conflict_cleanup": {
9831007
"isAsync": true,
1008+
"return": {
1009+
"isErrorCode": true
1010+
}
1011+
},
1012+
"git_index_conflict_get": {
9841013
"args": {
9851014
"ancestor_out": {
9861015
"isReturn": true
@@ -992,6 +1021,7 @@
9921021
"isReturn": true
9931022
}
9941023
},
1024+
"isAsync": true,
9951025
"return": {
9961026
"isErrorCode": true
9971027
}
@@ -1005,6 +1035,12 @@
10051035
"git_index_conflict_next": {
10061036
"ignore": true
10071037
},
1038+
"git_index_conflict_remove": {
1039+
"isAsync": true,
1040+
"return": {
1041+
"isErrorCode": true
1042+
}
1043+
},
10081044
"git_index_entrycount": {
10091045
"jsFunctionName": "entryCount"
10101046
},
@@ -1024,11 +1060,33 @@
10241060
"git_index_new": {
10251061
"ignore": true
10261062
},
1063+
"git_index_open": {
1064+
"isAsync": true,
1065+
"return": {
1066+
"isErrorCode": true
1067+
}
1068+
},
10271069
"git_index_read": {
10281070
"args": {
10291071
"force": {
10301072
"isOptional": true
10311073
}
1074+
},
1075+
"isAsync": true,
1076+
"return": {
1077+
"isErrorCode": true
1078+
}
1079+
},
1080+
"git_index_read_tree": {
1081+
"isAsync": true,
1082+
"return": {
1083+
"isErrorCode": true
1084+
}
1085+
},
1086+
"git_index_remove": {
1087+
"isAsync": true,
1088+
"return": {
1089+
"isErrorCode": true
10321090
}
10331091
},
10341092
"git_index_remove_all": {
@@ -1048,6 +1106,18 @@
10481106
"isErrorCode": true
10491107
}
10501108
},
1109+
"git_index_remove_bypath": {
1110+
"isAsync": true,
1111+
"return": {
1112+
"isErrorCode": true
1113+
}
1114+
},
1115+
"git_index_remove_directory": {
1116+
"isAsync": true,
1117+
"return": {
1118+
"isErrorCode": true
1119+
}
1120+
},
10511121
"git_index_update_all": {
10521122
"args": {
10531123
"pathspec": {
@@ -1070,7 +1140,23 @@
10701140
"force": {
10711141
"isOptional": true
10721142
}
1073-
}
1143+
},
1144+
"isAsync": true,
1145+
"return": {
1146+
"isErrorCode": true
1147+
}
1148+
},
1149+
"git_index_write_tree": {
1150+
"isAsync": true,
1151+
"return": {
1152+
"isErrorCode": true
1153+
}
1154+
},
1155+
"git_index_write_tree_to": {
1156+
"isAsync": true,
1157+
"return": {
1158+
"isErrorCode": true
1159+
}
10741160
}
10751161
},
10761162
"dependencies": [

0 commit comments

Comments
 (0)