8000 Warn users who deploy with out-of-date git branches · Issue #524 · preaction/Statocles · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
preaction opened this issue Dec 7, 2016 · 0 comments
Open

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

preaction opened this issue Dec 7, 2016 · 0 comments

Comments

@preaction
Copy link
Owner

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:

  • git rev-parse --abbrev-ref HEAD will get you the current branch
  • git config branch.<branchname>.remote will give you the default remote of the given <branchname>
  • git config branch.<branchname>.merge will give you the remote "ref" that is merged into the local ref
  • git ls-remote <remote> will list all the refs in the remote, and you want the one that corresponds to branch.<branchname>.merge
  • Finally, git rev-parse HEAD will get you the current commit hash 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.

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

No branches or pull requests

1 participant
0