A library with command line interface to sort Xcode's .xcodeproj
file. It sorts following sessions:
PBXGroup
andPBXVariantGroup
PBXResourcesBuildPhase
PBXSourcesBuildPhase
- Targets
- Remote Swift packages
You can find the command-line tool project under CLI
directory and build it by yourself. Or, you can download it from releases page.
xcodeproj-sorter [--case-insensitive] [--numeric] <path-to-xcodeproj-file>
Use xcodeproj-sorter -h
for more information.
You can use it to sort Xcode project file before committing it to git version control. Sorting project file can reduce merging conflict possibility.
Create a Tools
directory in project root directory, and put xcodeproj-sorter
into Tools
directory.
Put following codes into .git/hooks/pre-commit
.
#!/bin/sh
#
# Following script is to sort Xcode project files, and add them back to version control.
# The reason to sort project file is that it can reduce project.pbxproj file merging conflict possibility.
#
echo 'Sorting Xcode project files'
GIT_ROOT=$(git rev-parse --show-toplevel)
sorter="$GIT_ROOT/Tools/xcodeproj-sorter"
modifiedProjectFiles=( $(git diff --name-only --cached | grep "project.pbxproj") )
for filePath in ${modifiedProjectFiles[@]}; do
fullFilePath="$GIT_ROOT/$filePath"
$sorter -n $fullFilePath
git add $fullFilePath
done
echo 'Done sorting Xcode project files'
exit 0
Put following line into .gitattributes
then commit it.
*.pbxproj merge=union
MIT license.