Skip to content

Instantly share code, notes, and snippets.

@meatballs
Last active November 6, 2023 08:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save meatballs/f362b67712dc13d62ea0d288b03bb63a to your computer and use it in GitHub Desktop.
Save meatballs/f362b67712dc13d62ea0d288b03bb63a to your computer and use it in GitHub Desktop.
Anvil Workflow

Anvil Git Workflow

Introduction

This is the workflow I use for anvil apps where I want multiple copies of the app for development and testing purposes or where I want to collaborate with somebody else on its development.

For the purposes of this guide, I'll assume there is an existing app at anvil called 'my-app.' That's already live and it will become the 'production' copy.

Any other copies of the app are for development purposes. They can be created and destroyed as necessary. Their history is not important and can be overwritten.

Setup

  • Create a copy of my-app at anvil using its clone link. We'll call this new copy 'dev-app'
  • Create a local git repository using the url for my-app:
git clone <my-app-url> my-app
  • Add dev-app as a remote in that repository using its url:
git remote add dev-app <dev-app-url>
  • Force dev-app to have the same history as my-app:
git fetch -all
git checkout -b master my-app/master
git push -f dev-app master
  • At anvil, open dev-app, attempt to run it and fix any problems caused by the forced push of anvil.yaml (e.g. data tables).
  • Configure how to handle `anvil.yaml`:
git config --local merge.ignore.driver true
echo "anvil.yaml merge=ignore" > .git/config/info/attributes

TODO: Write up fuller explanation of what this is doing and why

TODO: Investigate windows alternative for true

  • The repository is now configured to leave anvil.yaml untouched for any conflicting changes when branches are merged. However, non-conflicting changes would still be merged and we need to stop that happening. The fix is to ensure there will always be a conflict:
git checkout master
echo "#  Config file for production app" >> anvil.yaml
git add anvil.yaml
git commit -m "Add comment to production copy of anvil.yaml"
git push
git checkout -b dev dev-app/master
echo "#  Config file for dev app" >> anvil.yaml
git add anvil.yaml
git commit -m "Add comment to development copy of anvil.yaml"
git push
  • Configure git to ignore any further local changes to anvil.yaml:
git update-index --skip-worktree anvil.yaml

TODO: Write a fuller explanation of what this does

Making Changes in Anvil IDE

Whenever dev-app is run at anvil, anvil.yaml is overwritten and the comment that we added will be removed. Although git will ignore local changes to anvil.yaml, it will still include that deletion in commits that are pulled from anvil to our local repository.

In order to work on dev-app and pull our changes into our local repository for merging to production, we'll need to ensure that those changes are removed.

Let's assume some work has been carried out and the master branch at dev-app is now ahead of our local repository. We wish to pull that work into our local dev branch, merge the changes into master and push them to production.

  • Pull the changes from dev-app and remove any changes to anvil.yaml:
git checkout dev
git fetch dev-app
git merge dev-app/master --no-commit --no-ff
git reset HEAD anvil.yaml
git commit -m "merge changes from anvil"
git checkout -- anvil.yaml
  • Force dev-app to have the same history as our local repository:
git push -f dev dev-app:master
  • Merge the changes into our master branch (I stage and commit the changes in two steps so I can check the contents of the index before committing - mainly to ensure there's no change to anvil.yaml):
git checkout master
git merge dev --no-commit --no-ff
git commit -m "Merge dev branch into master"
git push

Collaboration

TODO Write up how to add github and how a collaborator can set up their own development copy of my-app and their own local repository.

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