From 0dc5a7a7b046c140a188aa71f42d7191f11401cd Mon Sep 17 00:00:00 2001 From: Benedikt Schesch Date: Tue, 21 May 2024 14:25:28 -0700 Subject: [PATCH] Added fix for intellimerge --- src/python/repo.py | 3 +- .../delete_intellimerge_keys_from_cache.py | 2 +- src/python/variables.py | 2 +- src/scripts/merge_tools/intellimerge.sh | 64 +++++++++++++------ 4 files changed, 48 insertions(+), 23 deletions(-) mode change 100755 => 100644 src/python/variables.py diff --git a/src/python/repo.py b/src/python/repo.py index d507b3579d..de65c00616 100755 --- a/src/python/repo.py +++ b/src/python/repo.py @@ -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 @@ -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, diff --git a/src/python/utils/delete_intellimerge_keys_from_cache.py b/src/python/utils/delete_intellimerge_keys_from_cache.py index 341f8558ba..dba10c3318 100644 --- a/src/python/utils/delete_intellimerge_keys_from_cache.py +++ b/src/python/utils/delete_intellimerge_keys_from_cache.py @@ -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): ") diff --git a/src/python/variables.py b/src/python/variables.py old mode 100755 new mode 100644 index 3fc00f30e8..dce0594596 --- a/src/python/variables.py +++ b/src/python/variables.py @@ -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" diff --git a/src/scripts/merge_tools/intellimerge.sh b/src/scripts/merge_tools/intellimerge.sh index 28cc112ecc..82a53b9bf1 100755 --- a/src/scripts/merge_tools/intellimerge.sh +++ b/src/scripts/merge_tools/intellimerge.sh @@ -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