version: '3' tasks: git: desc: "Pushes a directory to a git remote" summary: | Given a directory, pushes it to a git remote whilst maintaining a linear history with the remote. usage: task deploy:git directory="/tmp/release" branch=main remote="git@github.com:Lullabot/drainpipe.git" message="Initial commit" push=true" directory= A directory containing the files to be pushed branch= Name of the branch to push to e.g. "main" remote= Git remote to push to message= Commit message push=true (optional) Push to the remote repository cmds: - if [ ! -d {{ shellQuote (.directory | default "") }} ]; then echo "Please provide a path to a directory to deploy" && exit 1; fi - if [ "" == {{ shellQuote (.branch | default "") }} ]; then echo "Please provide a branch to deploy to" && exit 1; fi - if [ "" == {{ shellQuote (.remote | default "") }} ]; then echo "Please provide a remote git repository to push to" && exit 1; fi - if [ "" == {{ shellQuote (.message | default "") }} ]; then echo "Please provide a commit message" && exit 1; fi - | TMP_DIR=$(mktemp -d) (git clone --depth 1 --branch {{.branch}} {{.remote}} $TMP_DIR && cd $TMP_DIR) || true if [[ ! -d "$TMP_DIR/.git" ]]; then git clone --depth 1 {{.remote}} $TMP_DIR cd $TMP_DIR git checkout -b {{.branch}} fi mv $TMP_DIR/.git {{.directory}} cd {{.directory}} git checkout -B {{.branch}} git add -A git commit --quiet --message {{shellQuote .message}} --allow-empty if [ {{shellQuote (.push | default "true") }} == "true" ]; then git push origin {{.branch}} fi