I've hacked together an updater for my app, so that people with little to no coding skill can install, run, and update the app on their own machines.
Here is an example of an updater, written for Windows command prompt:
@echo off
for /f %%i in ('call git status --porcelain') do set stash=%%i
if not [%stash%] == [] (
echo Stashing local changes...
call git add .
call git stash -q
)
echo Updating App...
call git pull origin master
if not [%stash%] == [] (
echo Restoring local changes...
call git stash apply -q
)
echo Updating Dependencies...
call npm update
echo Done
pause
As you can see, I'm calling git status --porcelain to tell whether or not an app has local changes which need to be stashed before pulling the remote master branch.
This command will return nothing if the working directory is clean, but will always return something if there are local changes, tracked or otherwise.
I've read from other SO posts that it's bad to use porcelain commands to do plumbing work in git, but in this case, it is working well for me, and I don't see why the git status --porcelain command would ever return something when there is a clean working directory.
So my questions are: Is it wrong to use porcelain for this specific use-case? And if so, why?
Bonus: What would be a better way to go about this?