Skip to content

Define this task better #4

Description

@EmilIvanichkovv

Some potential here

#!/bin/bash

# Function to get commits from a branch in topological order
get_commits() {
  local branch="$1"
  git rev-list --topo-order "$branch"
}

# Function to diff two commits and return if there is any difference
diff_commits() {
  local commit1="$1"
  local commit2="$2"

  # Perform a diff between the two commits
  git diff "$commit1" "$commit2" --quiet
  return $?  # Returns 0 if no difference, 1 if there is a difference
}

# Main function to compare two branches commit by commit
compare_branches() {
  local branch1="$1"
  local branch2="$2"

  # Get commit lists for both branches
  commits1=($(get_commits "$branch1"))
  commits2=($(get_commits "$branch2"))

  # Check if the number of commits is the same
  if [ "${#commits1[@]}" -ne "${#commits2[@]}" ]; then
    echo "The branches $branch1 and $branch2 have different numbers of commits."
    # print the number of commits in each branch
    echo "Branch $branch1 has ${#commits1[@]} commits."
    echo "Branch $branch2 has ${#commits2[@]} commits."
    return 1
  fi

  # Iterate over each commit pair and compare them
  for i in "${!commits1[@]}"; do
    commit1="${commits1[i]}"
    commit2="${commits2[i]}"

    # Diff the corresponding commits
    diff_commits "$commit1" "$commit2"
    if [ $? -ne 0 ]; then
      echo "Difference found between commits $commit1 and $commit2."
      return 1
    fi
  done

  echo "The branches $branch1 and $branch2 are exactly the same."
  return 0
}

# Replace with your branch names
branch_v1="backupOld"
branch_v2="backup"

# Compare the branches
compare_branches "$branch_v1" "$branch_v2"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions