preaction / Statocles

Static website CMS
http://preaction.me/statocles
Other
84 stars 33 forks source link

Warn users who deploy with out-of-date git branches #524

Open preaction opened 7 years ago

preaction commented 7 years ago

If a user deploys their site, it captures the current state of the site source from their local machine. If they are using git to collaborate on a site and forget to pull from the remote source, they could end up deploying an out-of-date site. It would be courteous to warn the user when they are doing so, and prevent them from deploying.

We should check the status of the default remote of the current branch:

If the current commit hash of the current branch does not match the remote, either the remote has commits that aren't in the local, or the local has commits that aren't in the remote. To see if we have the commit, we can do git merge-base HEAD <remote commit id>. If the commit ID returned by that command is the same as <remote commit id>, then the remote commit is wholly contained in the current branch, which means we've got nothing to worry about. If nothing is returned and the exit code is non-zero, then the commit is not in our branch and we're likely out-of-date.

If we determine we are out-of-date when we run deploy (before the site is built), we should display an error and then exit. If the user then passes the -f or --force flag, we should still display an error, but then proceed with the build and deploy.