Skip to content

Commit

Permalink
Added fix for intellimerge
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed May 21, 2024
1 parent d30f0ee commit 0dc5a7a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def merge(
if use_cache:
cache_entry["sha"] = sha
cache_entry["merge status"] = merge_status.name
output = f"command: {' '.join(command)}\n stdout: {p.stdout}\n stderr: {p.stderr}"
output_file = (
self.sha_cache_directory
/ self.owner
Expand All @@ -553,7 +552,7 @@ def merge(
output_file.parent.mkdir(parents=True, exist_ok=True)
cache_entry["merge_logs"] = str(output_file)
with open(output_file, "w", encoding="utf-8") as f:
f.write(output)
f.write(explanation)
set_in_cache(
cache_entry_name,
cache_entry,
Expand Down
2 changes: 1 addition & 1 deletion src/python/utils/delete_intellimerge_keys_from_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def delete_import_keys(directory):

def main():
"""Main function."""
directory = "cache"
directory = "cache-small"
potential_deletions = count_import_keys(directory)
print(f"Potential deletions: {potential_deletions}")
confirm = input("Do you want to proceed with deleting these keys? (yes/no): ")
Expand Down
2 changes: 1 addition & 1 deletion src/python/variables.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RIGHT_BRANCH_NAME = BRANCH_BASE_NAME + "_RIGHT"

CACHE_BACKOFF_TIME = 2 * 60 # 2 minutes, in seconds
DELETE_WORKDIRS = True
DELETE_WORKDIRS = False
REPOS_PATH = Path("repos")
WORKDIR_DIRECTORY = Path(
".workdir"
Expand Down
64 changes: 45 additions & 19 deletions src/scripts/merge_tools/intellimerge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,68 @@ intellimerge_absolutepath="${ROOT_DIR}/${intellimerge_relativepath}"
clone_dir=$1
branch1=$2
branch2=$3
temp_dir="/tmp/intelli_temp_$$/"
mkdir $temp_dir
temp_out_dir="/tmp/intelli_temp_out_$$/"
temp_intellimerge_dir="/tmp/intelli_temp_$$/"
mkdir $temp_out_dir

echo "IntelliMerge: $intellimerge_absolutepath"
echo "Clone dir: $clone_dir"
echo "Branch 1: $branch1"
echo "Branch 2: $branch2"
echo "Temp dir: $temp_dir"
echo "Temp dir: $temp_out_dir"

clone_dir_absolutepath=$(realpath "$clone_dir")

# run intellimerge
java -jar "$intellimerge_absolutepath" -r "$clone_dir" -b "$branch1" "$branch2" -o $temp_dir
cd "$clone_dir" || exit 1

java -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -Djava.io.tmpdir="$temp_intellimerge_dir" -jar "$intellimerge_absolutepath" -r "$clone_dir_absolutepath" -b "$branch1" "$branch2" -o $temp_out_dir

# run git merge
cd "$clone_dir" || exit 1
git checkout "$branch1" --force

git merge --no-edit "$branch2"
cd - || exit 1

# move files
find $temp_dir -type f | while read -r f; do
# construct paths
suffix=${f#"$temp_dir"}
mv "$f" "$clone_dir/$suffix"
done
rm -rf $temp_dir

cd "$clone_dir" || exit 1
# Detect conflicts using Git commands
# List conflicitng files
conflict_files=$(git diff --name-only --diff-filter=U)

if [ -n "$conflict_files" ]; then
echo "Conflict detected in the following files:"
# Initialize a flag to track conflict resolution
conflicts_resolved=true

# Iterate through conflicting files
for file in $conflict_files; do
# Check if the conflicting file exists in the temp_out_dir
if [ ! -f "$temp_out_dir$file" ]; then
echo "Conflict not resolved for file: $file"
conflicts_resolved=false
fi
done

# If conflicts_resolved is false, there are unresolved conflicts
if [ "$conflicts_resolved" = false ]; then
echo "Conflict detected. Aborting the merge. Please resolve the conflicts."
echo "All conflicting files:"
echo "$conflict_files"
exit 1
fi

echo "No conflicts detected. $conflict_files"
# move files
find $temp_out_dir -type f | while read -r f; do
# construct paths
suffix=${f#"$temp_out_dir"}
# CHeck that $f exists
if [ ! -f "$f" ]; then
echo "File $f does not exist. Skipping."
continue
fi
echo "Moving $f to $clone_dir_absolutepath"
cp "$f" "$clone_dir_absolutepath/$suffix"
done
# rm -rf $temp_out_dir $temp_intellimerge_dir

git add .
git commit -m "IntelliMerge: Merge $branch2 into $branch1"

rm -rf ours_refactorings.csv theirs_refactorings.csv

exit 0

0 comments on commit 0dc5a7a

Please sign in to comment.