Search code examples
gitcapistrano

How can I see modified files in a capistrano release?


I'd like to check if someone modified my files (coworker -> hotfix or hacker -> hack) before releasing a new release. Is it possible to see changed files via git status in a capistrano release?

$ ls -l
total 21692
lrwxrwxrwx 1 user www-data       55 Dec 14 14:31 current -> /path/to/my/releases/20161214132953
drwxr-xr-x 7 user www-data     4096 Dec 14 14:31 releases
drwxr-xr-x 7 user www-data     4096 Aug 18 14:05 repo
-rw-r--r-- 1 user www-data   121235 Dec 14 14:31 revisions.log
drwxr-xr-x 5 user www-data     4096 Dec  8  2014 shared
$ cd current
$ git status
fatal: Not a git repository (or any of the parent directories): .git
$ cd ../repo
$ git status
fatal: This operation must be run in a work tree

Solution

  • There is a way to do it, although it is not obvious.

    First, use tail revisions.log to find the Git commit SHA that was used for the release.

    $ tail -n1 revisions.log
    Branch master (at 66ba18ca4f689a7e9fdc9a45ba3c952785620157) deployed as release 20161214132953 by mbrictson
    

    Next, go to the repo directory and use the git archive command to create a pristine snapshot of the repository that existed at that commit.

    $ mkdir -p /tmp/pristine-release
    $ git archive 66ba18ca4 | tar -x -f - -C /tmp/pristine-release
    

    Now you can use diff to see the differences:

    $ diff -r /tmp/pristine-release /path/to/releases/20161214132953
    

    If you want to ignore files via .gitignore you can use the following command:

    rsync \
      -vanc\
      --no-links \
      --no-group \
      --no-owner \
      --no-perms \
      --no-times \
      --delete \
      --filter="dir-merge,- .gitignore" \
      /path/to/current/ \
      /tmp/pristine-release \
      | head -n -3 \
      | tail -n +2 \
      | grep -v 'skipping non-regular file'
    

    --filter="dir-merge,- .gitignore" reads and uses gitignore
    | head -n -3 removes rsync footer
    | tail -n +2 removes rsync header
    | grep -v 'skipping non-regular file' removes skipped files from list