From c6b00bf4ba952873bce2d109c7dce5b9e914850a Mon Sep 17 00:00:00 2001 From: Salendarsingh Gaud Date: Thu, 5 Jun 2025 14:42:54 +0530 Subject: [PATCH 1/4] ci-merge : Bypass in case of merge conflict Introducing a option -p, which will bypass a conflicting branch in case of non-interactive merge. Branch would be reset with git merge --abort and next branch would be merged, instead of exiting. Signed-off-by: Salendarsingh Gaud --- ci-merge | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/ci-merge b/ci-merge index 3261ddc..179d0eb 100755 --- a/ci-merge +++ b/ci-merge @@ -111,6 +111,8 @@ RERERE_CACHE="" RERERE_CACHE_DIR="" +BYPASS=0 + # Global variable to test if a change occured during the last merge # or not. If one branch is added, deleted or updated, this variable # will be different from zero and will lead to the merge operation @@ -142,6 +144,7 @@ Help() { echo " -f|--config : Config file listing branches to be merged [$CONFIG]" echo " -n|--interactive : Whether to run the tool interactively [$INTERACTIVE]" echo " -y|--force : Whether to force merging the branches [$FORCE]" + echo " -p|--pass : Whether to bypass conflicting branch [$BYPASS]" echo } @@ -152,8 +155,8 @@ Help() { # options_setup() { - SHORTOPT="hnl:r:b:i:t:c:f:y" - LONGOPT="help,interactive,local:,remote:,baseline:,integ:,track:,cache:,config:,force" + SHORTOPT="hnl:r:b:i:t:c:f:y:p" + LONGOPT="help,interactive,local:,remote:,baseline:,integ:,track:,cache:,config:,force:,pass" OPTS=$(getopt -o $SHORTOPT -l $LONGOPT -- "$@") @@ -218,6 +221,10 @@ options_setup() { --config|-f) CONFIG=$1 ;; + + --pass|-p) + BYPASS=1 + ;; --) break ;; @@ -618,7 +625,6 @@ echo "Create a new integration branch based on $TAG" git checkout -b $INTEG_BRANCH $TAG echo "Merging topic branches..." - MERGED=0 # Dup STDIN onto fd 3 @@ -626,6 +632,7 @@ exec 3<&0 while read LINE; do + is_conflict=0 echo $LINE | egrep -q '(^#|^\s*$|^\s*\t*#)' && continue REMOTE_NAME=$(echo $LINE | awk '{ print $1 }') REMOTE_URL=$(echo $LINE | awk '{print $2}') @@ -644,8 +651,8 @@ while read LINE; do echo "------------------------------------------" echo " ** Merging topic branch: $MERGER" - - git merge -q --no-ff --no-edit -m "Merge remote-tracking branch $REMOTE_NAME into $INTEG_BRANCH" $MERGER + branch_tip=$(git rev-parse $MERGER) + MERGE_OUTPUT=$(git merge --no-ff --no-edit -m "Merge remote-tracking branch $REMOTE_NAME into $INTEG_BRANCH" $MERGER) if [ $? -ne 0 ]; then if [ $INTERACTIVE -eq 0 ]; then # try to commit, may be resolved by rerere @@ -654,7 +661,11 @@ while read LINE; do if [ $commit_ec -ne 0 ]; then echo "Merge failed, $REMOTE_NAME $REMOTE_URL $REMOTE_BRANCH" git merge --abort - exit $commit_ec + if [ $BYPASS -eq 1 ]; then + is_conflict=1 + else + exit $commit_ec + fi fi else echo "Merge failed, manual merge" @@ -663,7 +674,15 @@ while read LINE; do fi fi - MERGED=$((MERGED+1)) + if echo "$MERGE_OUTPUT" | grep -q "Already up to date." ; then + echo "Nothing to merge: Already up to date." + elif [ $is_conflict != 1 ]; then + echo "Merge successful : $REMOTE_NAME : $branch_tip" + MERGED=$((MERGED+1)) + else + echo "Merge conflict : $REMOTE_NAME : $branch_tip" + CONFLICTED=$((CONFLICTED+1)) + fi done < $CONFIG From cd95869e6665a9034440e32bd48dba37e5a023d3 Mon Sep 17 00:00:00 2001 From: Salendarsingh Gaud Date: Tue, 10 Jun 2025 09:25:49 +0530 Subject: [PATCH 2/4] log-parser : Adding script to parse logs Script to parse the merge logs, this will search for "Merge sucessful: " string and capture branch name and SHA in a text file. Signed-off-by: Salendarsingh Gaud --- log-parser.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 log-parser.sh diff --git a/log-parser.sh b/log-parser.sh new file mode 100755 index 0000000..2796db1 --- /dev/null +++ b/log-parser.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Usage check +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Input and output file names +INPUT_FILE=$1 +MERGED_FILE="topic_SHA1" +CONFLICT_FILE="topic_conflict" + +# Create or clear the output file +> "$MERGED_FILE" +> "$CONFLICT_FILE" + +# Write header +printf "%-20s %*s\n" "Name" 20 "SHA" >> "$MERGED_FILE" +printf "%s\n" "--------------------------------------------------------" >> "$MERGED_FILE" +printf "%-20s %*s\n" "Name" 20 "SHA" >> "$CONFLICT_FILE" +printf "%s\n" "--------------------------------------------------------" >> "$CONFLICT_FILE" + +while read -r line; do + echo "$line" | grep -E "^Merge successful : .+ : [a-fA-F0-9]{7,40}$" + if [ $? -eq 0 ]; then + branch=$(echo "$line" | cut -d':' -f2 | xargs) + sha=$(echo "$line" | cut -d':' -f3 | xargs) + printf "%-20s %*s\n" "$branch" 45 "$sha" >> "$MERGED_FILE" + fi + + echo "$line" | grep -E "^Merge conflict : .+ : [a-fA-F0-9]{7,40}$" + if [ $? -eq 0 ]; then + branch=$(echo "$line" | cut -d':' -f2 | xargs) + sha=$(echo "$line" | cut -d':' -f3 | xargs) + printf "%-20s %*s\n" "$branch" 45 "$sha" >> "$CONFLICT_FILE" + fi + +done < "$INPUT_FILE" From 7f27af8cf38f16806432972fa4c69f7cb4e700ea Mon Sep 17 00:00:00 2001 From: Salendarsingh Gaud Date: Thu, 19 Jun 2025 12:19:14 +0530 Subject: [PATCH 3/4] ci-merge : Capture number of commits in merged branch Calculate and print number of commits present in each branch that is merged into baseline. Signed-off-by: Salendarsingh Gaud --- ci-merge | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci-merge b/ci-merge index 179d0eb..5eef9b4 100755 --- a/ci-merge +++ b/ci-merge @@ -677,7 +677,8 @@ while read LINE; do if echo "$MERGE_OUTPUT" | grep -q "Already up to date." ; then echo "Nothing to merge: Already up to date." elif [ $is_conflict != 1 ]; then - echo "Merge successful : $REMOTE_NAME : $branch_tip" + num_commits=$(git log --oneline --no-merges $TAG..$MERGER | wc -l) + echo "Merge successful : $REMOTE_NAME : $branch_tip : $num_commits" MERGED=$((MERGED+1)) else echo "Merge conflict : $REMOTE_NAME : $branch_tip" From 300ae26ada4419d8b6f3beb7e1979c6d8c844b21 Mon Sep 17 00:00:00 2001 From: Salendarsingh Gaud Date: Thu, 19 Jun 2025 13:08:46 +0530 Subject: [PATCH 4/4] log-parser : Capture number of commits in topic_SHA1 Parse number of commits from log file and add to topic_SHA1 file Signed-off-by: Salendarsingh Gaud --- log-parser.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/log-parser.sh b/log-parser.sh index 2796db1..27e8136 100755 --- a/log-parser.sh +++ b/log-parser.sh @@ -1,5 +1,4 @@ #!/bin/bash - # Usage check if [ "$#" -ne 1 ]; then echo "Usage: $0 " @@ -16,17 +15,18 @@ CONFLICT_FILE="topic_conflict" > "$CONFLICT_FILE" # Write header -printf "%-20s %*s\n" "Name" 20 "SHA" >> "$MERGED_FILE" -printf "%s\n" "--------------------------------------------------------" >> "$MERGED_FILE" +printf "%-20s %*s %*s\n" "Name" 20 "SHA" 40 "Commits">> "$MERGED_FILE" +printf "%s\n" "------------------------------------------------------------------------------------" >> "$MERGED_FILE" printf "%-20s %*s\n" "Name" 20 "SHA" >> "$CONFLICT_FILE" printf "%s\n" "--------------------------------------------------------" >> "$CONFLICT_FILE" while read -r line; do - echo "$line" | grep -E "^Merge successful : .+ : [a-fA-F0-9]{7,40}$" + echo "$line" | grep -E "^Merge successful : .+ : [a-fA-F0-9]{7,40} : [0-9]+$" if [ $? -eq 0 ]; then branch=$(echo "$line" | cut -d':' -f2 | xargs) sha=$(echo "$line" | cut -d':' -f3 | xargs) - printf "%-20s %*s\n" "$branch" 45 "$sha" >> "$MERGED_FILE" + commits=$(echo "$line" | cut -d':' -f4 | xargs) + printf "%-20s %*s %10s\n" "$branch" 45 "$sha" "$commits">> "$MERGED_FILE" fi echo "$line" | grep -E "^Merge conflict : .+ : [a-fA-F0-9]{7,40}$"