Created
April 4, 2023 05:16
-
-
Save ssv445/ac49917cb8c30b0482f9295a1856ea09 to your computer and use it in GitHub Desktop.
Only Format files which were changed by your branch/PR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
parent_branch="${1:-master}" | |
# Switch to the root directory of the Git repository | |
cd "$(git rev-parse --show-toplevel)" | |
# Check if there are any uncommitted changes | |
if [[ -n $(git status -s) ]]; then | |
echo "There are uncommitted changes in the branch. Please commit or stash them before running this script." | |
exit 1 | |
fi | |
# Get the list of files that have been modified in the current branch | |
changed_files=$(git diff --name-only "$parent_branch") | |
#echo $changed_files; exit; | |
# Stage the modified files | |
git add $changed_files | |
composer style | |
# Revert any modified files that are not in the changed_files list | |
unstaged_files=$(git ls-files -m | grep -v "$(printf '%s\n' $changed_files)") | |
if [ -n "$unstaged_files" ]; then | |
git checkout -- $unstaged_files | |
count=$(echo "$unstaged_files" | wc -l) | |
echo "The $count files have been reverted:" | |
else | |
echo "No files have been reverted." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment