MCPcopy Index your code
hub / github.com/nodegit/nodegit / getPathHunks

Function getPathHunks

lib/repository.js:129–175  ·  view source on GitHub ↗
(repo, index, filePath, isStaged, additionalDiffOptions)

Source from the content-addressed store, hash-verified

127}
128
129function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) {
130 var diffOptions = additionalDiffOptions ? {
131 flags: additionalDiffOptions
132 } : undefined;
133
134 return Promise.resolve()
135 .then(function() {
136 if (isStaged) {
137 return repo.getHeadCommit()
138 .then(function getTreeFromCommit(commit) {
139 return commit.getTree();
140 })
141 .then(function getDiffFromTree(tree) {
142 return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);
143 });
144 }
145
146 return NodeGit.Diff.indexToWorkdir(repo, index, {
147 flags:
148 NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT |
149 NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS |
150 (additionalDiffOptions || 0)
151 });
152 })
153 .then(function(diff) {
154 return NodeGit.Status.file(repo, filePath)
155 .then(function(status) {
156 if (!(status & NodeGit.Status.STATUS.WT_MODIFIED) &&
157 !(status & NodeGit.Status.STATUS.INDEX_MODIFIED)) {
158 return Promise.reject
159 ("Selected staging is only available on modified files.");
160 }
161 return diff.patches();
162 });
163 })
164 .then(function(patches) {
165 var pathPatch = patches.filter(function(patch) {
166 return patch.newFile().path() === filePath;
167 });
168
169 if (pathPatch.length !== 1) {
170 return Promise.reject("No differences found for this file.");
171 }
172
173 return pathPatch[0].hunks();
174 });
175}
176
177function getReflogMessageForCommit(commit) {
178 var parentCount = commit.parentcount();

Callers 1

repository.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…