From ce87b54d034958ec08bf02c43409167383210f17 Mon Sep 17 00:00:00 2001 From: Jens Lincke Date: Tue, 29 Sep 2015 18:34:32 +0200 Subject: [PATCH] Fix to allow both writing new files and overwriting old --- github.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/github.js b/github.js index 6f8dc215..c585648b 100644 --- a/github.js +++ b/github.js @@ -676,13 +676,14 @@ this.write = function(branch, path, content, message, cb) { that.getSha(branch, encodeURI(path), function(err, sha) { - if (err && err.error !== 404) return cb(err); - _request("PUT", repoPath + "/contents/" + encodeURI(path), { - message: message, - content: btoa(content), - branch: branch, - sha: sha - }, cb); + var options = { + message: message, + content: btoa(content), + branch: branch + }; + // if no error, we set the sha to overwrite an existing file + if (!(err && err.error !== 404)) options.sha = sha; + _request("PUT", repoPath + "/contents/" + encodeURI(path), options, cb); }); };