diff --git a/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh b/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh new file mode 100755 index 00000000..5e05df7a --- /dev/null +++ b/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# This script identifies the commit where a specified function was modified, +# starting from a given commit, and handles cases where the function or file +# might have been renamed or moved. + +# Usage: +# ./find_moved_or_renamed_commit.sh + +# Parameters: +FUNCTION_NAME="$1" +FILENAME="$2" # Relative Path +START_COMMIT="$3" + +if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Ensure we're in the root directory of the repository +cd "$(git rev-parse --show-toplevel)" + +METHOD_REGEX="(public|protected|private|static|\s)+\s+.*\s+$FUNCTION_NAME\s*\(.*\)" + +echo "Checking for function renames or file renames/moves..." + +# Track file renames: See commits where the file was renamed. +# Track function changes: See commits where the function was modified, or removed. +git log "$START_COMMIT"..HEAD \ + --follow \ + --find-renames \ + -G"$METHOD_REGEX" \ + -p \ + --name-status \ + --reverse \ + --color \ + --decorate \ + -- "$FILENAME" > outputfile.log \ No newline at end of file diff --git a/auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh b/auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh new file mode 100644 index 00000000..759a4012 --- /dev/null +++ b/auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# This script takes a batch of (FUNCTION_NAME, FILENAME, START_COMMIT) sets from a file +# and identifies the commit where each function was modified. + +# Usage: +# ./find_moved_or_renamed_commit_batch.sh +# +# The batch file should have one set of parameters per line, in the following format: +# FUNCTION_NAME FILENAME START_COMMIT + +BATCH_FILE="$1" + +if [ -z "$BATCH_FILE" ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ ! -f "$BATCH_FILE" ]; then + echo "Error: File '$BATCH_FILE' not found!" + exit 1 +fi + +# Ensure we're in the root directory of the repository +cd "$(git rev-parse --show-toplevel)" || exit 1 + +OUTPUT_FILE="batch_output.log" +> "$OUTPUT_FILE" # Clear the file at the start of each run + +echo "Processing batch input from $BATCH_FILE ..." | tee -a "$OUTPUT_FILE" +echo | tee -a "$OUTPUT_FILE" + +while IFS= read -r line; do + # Skip empty lines or lines starting with '#' + if [[ -z "$line" || "$line" =~ ^# ]]; then + continue + fi + + # Extract parameters from the line + FUNCTION_NAME=$(echo "$line" | awk '{print $1}') + FILENAME=$(echo "$line" | awk '{print $2}') + START_COMMIT=$(echo "$line" | awk '{print $3}') + + if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then + echo "Skipping malformed line: $line" | tee -a "$OUTPUT_FILE" + continue + fi + + echo "----------------------------------------" | tee -a "$OUTPUT_FILE" + echo "Checking for function renames or file renames/moves for:" | tee -a "$OUTPUT_FILE" + echo "FUNCTION_NAME: $FUNCTION_NAME" | tee -a "$OUTPUT_FILE" + echo "FILENAME: $FILENAME" | tee -a "$OUTPUT_FILE" + echo "START_COMMIT: $START_COMMIT" | tee -a "$OUTPUT_FILE" + echo "----------------------------------------" | tee -a "$OUTPUT_FILE" + + METHOD_REGEX="(public|protected|private|static|\\s)+\\s+.*\\s+$FUNCTION_NAME\\s*\\(.*\\)" + + git log "$START_COMMIT"..HEAD \ + --follow \ + --find-renames \ + -G"$METHOD_REGEX" \ + -p \ + --name-status \ + --reverse \ + --color \ + --decorate \ + -- "$FILENAME" >> "$OUTPUT_FILE" + + echo | tee -a "$OUTPUT_FILE" +done < "$BATCH_FILE" + +echo "All results have been logged to $OUTPUT_FILE." \ No newline at end of file diff --git a/auto-find-moved-or-renamed/readme.md b/auto-find-moved-or-renamed/readme.md new file mode 100644 index 00000000..c8070fc5 --- /dev/null +++ b/auto-find-moved-or-renamed/readme.md @@ -0,0 +1,41 @@ +# Overview +This automation script is designed to identify the specific commit that moved or renamed a test function or test file from the ones recorded in the IDOFT repository. + +# Instructions +1. Copy and paste `find_moved_or_renamed_commit.sh` to the Repo you are working on. +2. `git checkout xxx` (replace xxx with the commit hash that the flake test was detected in IDOFT) +3. Find and copy the **Relative Path** of the given testing file, it should contain the given FUNCTION_NAME. (Paste it somewhere, this is the FILENAME that will be used later) +4. `git checkout master` (or whichever branch you want that has the latest commit) +5. Execute the script by running: + +``` bash +chmod +x find_moved_or_renamed_commit.sh` +./find_moved_or_renamed_commit.sh +``` + +## Examples + +### A Row in IDOFT +``` +https://github.com/apache/ignite-3,a1aa7fd4e2398c72827777ec5417d67915ff4da3,modules/configuration,org.apache.ignite.internal.configuration.asm.ConfigurationAsmGeneratorTest.testConstructInternalConfig,ID,MovedOrRenamed,,https://github.com/apache/ignite-3/commit/b48ddcba7cd2bd3b9a053ae131c25b44a0400e27 +``` + +### Execute +``` +./find_moved_or_renamed_commit.sh testConstructInternalConfig modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java a1aa7fd4e2398c72827777ec5417d67915ff4da3 +``` + +### Output +``` +commit b48ddcba7cd2bd3b9a053ae131c25b44a0400e27 +Author: Aleksandr Pakhomov +Date: Wed Apr 26 20:02:34 2023 +0400 + + IGNITE-19152 Use schema information in LocalFileConfigurationStorage (#1988) + + --------- + + Co-authored-by: Ivan Bessonov + +D modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java +``` \ No newline at end of file