Skip to content

Instantly share code, notes, and snippets.

@caveda
Last active March 3, 2024 15:27
Show Gist options
  • Save caveda/013014ebbb4f11f36755a40971455c2e to your computer and use it in GitHub Desktop.
Save caveda/013014ebbb4f11f36755a40971455c2e to your computer and use it in GitHub Desktop.
Script Function to Detect the Modules Modified Between Two Branches
#!/bin/bash
source_branch=$1
target_branch=$2
detectchanges() {
changed_modules=""
git diff $source_branch..$target_branch --name-only | { while read line
do
module_name=${line%%/*}
if [[( -d "$module_name" ) && ( $changed_modules != *"$module_name,"* )]];
then
changed_modules="${changed_modules}${module_name},"
fi
done
echo $changed_modules
}
}
detectchanges
@emilewakim96
Copy link

are you sure the shell script is correct? I have a syntax error

@caveda
Copy link
Author

caveda commented Mar 3, 2024

You're right @emilewakim96!I've corrected a couple of misplaced curly braces. Additionally, I've filled in the arguments, so you can simply run it like this:

./detectChanges.sh branch1 branch2

Thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment