In our company we prefer to work development on the actual server where the code will eventually be live, and as such we FTP files up on save, test them on the server, then once they're complete, we commit and push them, which deploys the repo and changes to the same server where the FTP occurs.
Previously we've always worked with Beanstalk and an FTP deployment scheme, and because of this, no conflicts ever occurred since the local changes on the server will simply overwritten by FTP.
We've recently moved to GitLab which doesn't offer an FTP solution, only webhooks which pull the repo through GIT itself.
Consequently, we're getting errors for untracked files and local files since we're FTP'ing those up.
I've done quite a bit of research and it looks like the answer would be something like this:
https://stackoverflow.com/a/13242127/1136979
But, we need this to be converted to PHP to use within the web hooks.
Doing the fetch is simple enough, but is it possible to convert this section:
for file in `git diff HEAD..origin/master --name-status | awk '/^A/ {print $2}'`
do
rm -f -- "$file"
done
# Checkout all files which were locally modified
for file in `git diff --name-status | awk '/^[CDMRTUX]/ {print $2}'`
do
git checkout -- "$file"
done
to PHP?
Anyone that can share how to go about converting this awk command to something in php?
I'm assuming I can access the files like so:
$files = exec('git diff HEAD origin/master --name-status');
Then simply loop through them, but I'm not certain what the awk piece does.
All help greatly appreciated.