Hey 👋🏻

My name is Christian, an Agile Developer, living in Trento (IT)

I write good code at Wonderflow

You can follow me on and Github


More about me 🤖




pm2 deploy shallow git repository with –depth, also known as fetch: fast

I found it. It found me…

Whatever!

I came across the only documentation about cloning a git repo with the --depth option, to create a “shallow” copy with the specified number of commits truncated from HEAD.

            if test fetch != "fast"; then
              log "full fetch"
              run "git clone $repo $path/source"
            else
              log "fast fetch"
              run "git clone --depth=5 --branch $branch $repo $path/source"
            fi
          

Found in the source code of pm2-deploy.

Apart from the IRRATIONAL INVERTED IF STATEMENT ™ there, it seems to do it’s job. (Why wouldn’t you simply test for the truthy condition and invert both branches?)

Usage in pm2 ecosystem.config.js

I found that you can just specify "fetch": "fast" in your pm2 ecosystem configuration.

This means that it would fetch the last 5 commits from the HEAD (as you can see above).

Good enough for me.

            ...
            deploy : {
              production : {
                fetch: 'fast',
                user: 'node',
                host: '0.0.0.0',
                ref: 'origin/master',
                repo: '[email protected]:repo.git',
                path: '/app',
                'post-deploy': 'npm install && pm2 reload ecosystem.config.js --env production'
              }
            }
            ...
          

If you know any place where this is documented, please reach on Twitter [@christian_fei](https://twitter.com/christian_fei) and send me a link 📖

Maybe a PR would be nice in the future, let’s see.