Commit 093dfca1 authored by Ivanq's avatar Ivanq

Git: Implement makeTreeDeltaPath()

parent e651ac3f
......@@ -832,6 +832,43 @@ class Git {
return promise.then(() => base);
}
makeTreeDeltaPath(base, changes) {
// changes:
// [
// path: "dir/subdir/subfile",
// type: "blob",
// content: "hhgfd"
// ]
let tree = {
name: "",
type: "tree",
content: []
};
changes.forEach(change => {
let currentTree = tree;
change.path.split("/").forEach(pathPart => {
let item = currentTree.content.find(item => item.name == pathPart);
if(!item) {
item = {
name: pathPart,
type: "tree",
content: []
};
currentTree.content.push(item);
}
currentTree = item;
});
currentTree.type = change.type;
currentTree.content = change.content;
currentTree.remove = change.remove;
});
return this.makeTreeDelta(base, tree.content);
}
toString() {
return "<Git " + this.root + ">";
......
......@@ -76,6 +76,25 @@ For example,
3. Replace tree `olddir` with blob `olddir`
4. Leave all not mentioned files (if there was `dir/somefile` or `readme.md` they would be added to resulting tree).
You can also use `makeTreeDeltaPath(base, changes)`. It works like `makeTreeDelta()` but accepts slash-separated `path` property instead of `name`:
[
{
path: "dir/subdir/subfile",
type: "blob",
content: "neworchangedfile"
},
{
path: "file",
remove: true
},
{
path: "olddir",
type: "blob",
content: "fds"
}
]
### And some actions between repositories?
Yes! Run `importObject(otherGit, sha)` to read `sha` from `otherGit` and save it to `this`. And `importObjectWithDependencies(otherGit, sha)` also imports commit parents and tree, tree subitems, etc.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment