0

I'm trying to make an updater for my Electron app, I only want to update the html code that will be fetched from git. But I only want to fetch code if the origin has new commits, that way I can reload the browser if the app was updated. How can I do that?

Here's my latest code:

var Git = require("nodegit");
var pathToRepo = require("path").resolve("data");
Git.Repository.open(pathToRepo).then(function (repo) {
  return Git.Remote.load(repo, "origin");
  }).then(function(remote) {
    remote.connect(0);
    return remote.download();
  })
  .done(function() {
    console.log("Updated app");
});
  • What is the problem with fetching if there is nothing new? – Tim Biegeleisen Jun 19 '17 at 03:15
  • There is no problem, I just need a way to know if there's anything new to refresh the page, because I can't auto-refresh it every half hour for no reason – Stefano Gerli Jun 19 '17 at 03:17
  • pull = fetch + merge. If you want to know if the merge merged something, check before and after: if the hash ID changed, something was merged. (You can check before the fetch step and after the merge step, which means you can continue using `git pull` if you prefer it.) Remember also to consider the case where the merge *fails* though! – torek Jun 19 '17 at 04:35
  • Yes, but how can I do that with nodegit? – Stefano Gerli Jun 19 '17 at 11:16

0 Answers0