2

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.

Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59

2 Answers2

3

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
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

For a complete solution. Here is how to create a build with git post-merge hook.

#!/bin/bash

# get current branch    
branch=$(git symbolic-ref HEAD | sed -e "s/^refs\/heads\///");

# check if branch name is `uat` (or whatever you prefer)
if [ "uat" == "$branch" ]; then

    # create a folder outside the git repo
    # you can skip this step, if you want a static location
    mkdir -p $(pwd)/../uat/$(basename $(git root));

    # getting updated files, and
    # copy (and overwrite forcefully) in exact directory structure as in git repo
    yes | cp --parents -rf $(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD) $(pwd)/../uat/$(basename $(git root))/;
fi
Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59