Reputation: 489
I have a script that applies patches and sometimes it fails for whatever reason (file permissions in my case). I want to run the script again after fixing the problem, but then there could be leftover files from the previous git apply attempt.
I do not want to run git clean
, which would throw away other files that I would like to keep. I only want to replace those untracked files that are affected by the patch.
My script:
for SITE in $SITES
do
echo "Updating $SITE ..."
cd /home/klausi/web/$SITE
chmod u+w sites/default
git fetch
git reset --hard origin/master
git apply --index /home/klausi/web/7.33.patch
git commit -m "Updated Drupal core to 7.33."
git push
done
When I run this again I get:
error: misc/throbber-active.gif: already exists in working directory
error: misc/throbber-inactive.png: already exists in working directory
error: modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php: already exists in working directory
So something like git apply --force
would be nice.
Upvotes: 5
Views: 6547
Reputation: 40001
There are a couple of options you could try.
git apply --check
to instead of applying the patch see if it can be applied, if not abort it. If check returns fine then go ahead and run git apply
as normalgit apply --cached
to apply directly to the index but leave the working copy intact. If this fails just clear out the index. If it works go ahead and commit it.Upvotes: 2