Search code examples
gitdeploymentgithooksautodeploy

GIT POST-MERGE Hook, Get updated files


I've a branch titled uat on git.

I want to get a clone of all the files which are updated in merge in the uat branch.
(Basically idea behind it is to create a build to upload on uat server).

I've tried doing this.

#!/bin/bash
branch=$(git symbolic-ref HEAD | sed -e "s/^refs\/heads\///");
if [ "uat" == "$branch" ]; then
    // to do
    // 1. get all updated files
    // 2. create a clone of these files
fi

Can someone please help me with setp 1 i.e. get all the file updated in current merge.


Solution

  • If the merge just took place (which should be the case in a post-merge hook), you could use ORIG_HEAD:

    git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD