Visitar URL original
Moving a file yields 422, must supply tree.sha or tree.content · Issue #78 · philschatz/octokit.js · GitHub
Skip to content

Moving a file yields 422, must supply tree.sha or tree.content #78

Open

Description

@lwassermann

The problem occurs when using branch.move. A workaround which worked for us is removing all the tree nodes, instead of only removing their sha-values. The move function would then look like:
var blobs = _.reject(tree, function (ref) { return ref.type === 'tree'; });
_.each(blobs, function(ref) {
if (ref.path === path) {
ref.path = newPath;
}
});
return _git.postTree(blobs).then(...
The side effects are that it would remove empty folders from the repo, and you can't move folders with that api endpoint.

Activity

  1. lwassermann commented on Mar 16, 2015

    @lwassermann
    Author

    A modified version of that fix works also for renaming folders (although it still would loose empty folders). Instead of replacing the path if it is equal, replace the old by the new part:
    if (ref.path.indexOf(path) === 0) {
    ref.path = ref.path.replace(path, newPath);
    }
    For the general application you should probably guard against partly renaming files etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions