Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mergiraf to the evaluated tools #380

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions src/python/latex_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def latex_def(name, value) -> str:
"gitmerge_ort_ignorespace",
"git_hires_merge",
"spork",
"mergiraf",
"intellimerge",
"adjacent",
"imports",
Expand Down
1 change: 1 addition & 0 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def clone_repo(repo_slug: str, repo_dir: Path) -> None:
"gitmerge_resolve",
"git_hires_merge",
"spork",
"mergiraf",
"intellimerge",
"adjacent",
"imports",
Expand Down
74 changes: 74 additions & 0 deletions src/scripts/merge_tools/mergiraf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

# usage: <scriptname> [--verbose] <clone_dir> <branch-1> <branch-2>
# <clone_dir> must contain a clone of a repository.
# Merges branch2 into branch1, in <clone_dir>.
# Return code is 0 for merge success, 1 for merge failure, 2 for script failure.
# For merge failure, also outputs "Conflict" and aborts the merge.

set -o nounset

verbose=
if [ "$1" = "--verbose" ] ; then
# shellcheck disable=SC2034 # unused
verbose="$1"
shift
fi

if [ "$#" -ne 3 ]; then
echo "Usage: $0 [--verbose] CLONE_DIR BRANCH1 BRANCH2" >&2
exit 2
fi

MERGIRAF_VERSION="0.3.0"

SCRIPT_PATH="$(dirname "$0")"; SCRIPT_PATH="$(eval "cd \"$SCRIPT_PATH\" && pwd")"
ROOT_PATH="$(realpath "${SCRIPT_PATH}/../../../")"
mergiraf_relativepath=bin/mergiraf
mergiraf_absolutepath="${ROOT_PATH}/${mergiraf_relativepath}"
mkdir -p ${ROOT_PATH}/bin

if [ ! -e $mergiraf_absolutepath ]; then
ARCH=$(uname -m)
if [[ "$ARCH" == x86_64* ]]; then
ARCH="x86_64"
elif [[ "$ARCH" == i*86 ]]; then
echo "No mergiraf binaries for architecture $ARCH"
exit 2
elif [[ "$ARCH" == arm* ]]; then
ARCH="aarch64"
fi
mernst marked this conversation as resolved.
Show resolved Hide resolved
if [[ $OSTYPE == 'darwin'* ]]; then
VENDOR="apple-darwin"
else
VENDOR="unknown-linux-gnu"
fi
FULL_ARCH="${ARCH}-${VENDOR}"

wget https://codeberg.org/mergiraf/mergiraf/releases/download/v${MERGIRAF_VERSION}/mergiraf_${FULL_ARCH}.tar.gz -O ${ROOT_PATH}/bin/mergiraf.tar.gz
tar -zxf ${ROOT_PATH}/bin/mergiraf.tar.gz -C ${ROOT_PATH}/bin/
rm ${ROOT_PATH}/bin/mergiraf.tar.gz
fi

clone_dir=$1
branch1=$2
branch2=$3

cd "$clone_dir" || { echo "$0: cannot cd to $clone_dir"; exit 2; }

# set up mergiraf driver
git config --global merge.mergiraf.name mergiraf
mernst marked this conversation as resolved.
Show resolved Hide resolved
git config --global merge.mergiraf.driver "${mergiraf_absolutepath} merge --git %O %A %B -s %S -x %X -y %Y -p %P"
$(mergiraf_absolutepath) languages --gitattributes >> .gitattributes

# perform merge
git checkout "$branch1" --force
git merge --no-edit "$branch2"
retVal=$?

# report conflicts
if [ $retVal -ne 0 ]; then
echo "mergiraf.sh: Conflict"
fi

exit $retVal
Loading