bloomberg / xcdiff

A tool which helps you diff xcodeproj files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend xcdiff to become a git difftool for Xcode Projects

kwridan opened this issue · comments

commented

Is your feature request related to a problem? Please describe.

xcdiff can diff two standalone Xcode Projects. An interesting use case that can be extended from this is using xcdiff as a git difftool to allow comparing an Xcode project against itself within source control.

Describe the solution you'd like

There a few bits needed to make this work:

  • Support diffing .pbxproj files directly (not just .xcodeproj)

    • Difftools are passed two files to diff, in for Xcode project files this will be the underlying .pbxproj files
  • Add a new renderer that uses terms like "Removed" / "Added" rather than "Only in first" / "Only in second"

    • Optionally this renderer could use terminal colors, green text for added items, red for removed, yellow for modified
  • Update documentation with instructions on how to add xcdiff as a diff tool

e.g.

git config --local difftool.xcdiff.cmd 'xcdiff -p1 $(dirname "$LOCAL") -p2 $(dirname "$REMOTE") -d -v
git diff --tool xcdiff

There might be a way to make git automatically select a diff tool for certain file extensions which we could leverage as well (needs more research).

Describe alternatives you've considered

Instead of extending xcdiff itself, we can leverage a bash script to marshal the .pbxproj files to the desired format that enables xcdiff to read it.

e.g.

#!/bin/bash
tmp_dir_1="$(mktemp -d -t xcdif)"
cp "$1" $tmp_dir_1/project.pbxproj

tmp_dir_2="$(mktemp -d -t xcdiff)"
cp "$2" $tmp_dir_2/project.pbxproj

xcdiff -p1 "$tmp_dir_1" -p2 "$tmp_dir_2" -d -v

Another alternative could be to add an additional executable target xcgitdiff that manages some of this under the hood and uses a special renderer that is more suitable for this use case.

Additional context

I have a prototype of a custom renderer that replaces terms:

  • "Only in first" > "Removed"
  • "Only in second" > "Added"
  • "Value mismatch" > "Modified" or "Changed"

xcdiff --format git

Not sure how useful this feature is, but posting here to collect ideas and see if there's interest to pursue this further.

I use this:

xcdiff.sh:

#!/bin/sh

# Called by git as
# cmd path old-file old-hex old-mode new-file new-hex new-mode

THE_PATH=$1

OLD_FILE=$2
OLD_HEX=$3
OLD_MODE=$4

NEW_FILE=$5
NEW_HEX=$6
NEW_MODE=$7

xcdiff -p1 "$(dirname "$OLD_FILE")" -p2 "$(dirname "$NEW_FILE")" -v || true

In ~/.gitconfig:

[core]
    attributesFile = ~/.gitattributes
[diff "xcdiff"]
    command = /path/to/xcdiff.sh
    binary = true

In ~/.gitattributes:

*.pbxproj binary merge=mergepbx diff=xcdiff

Then git diff will use xcdiff (verbose) for changes to pbxproj files.

the || true is because it looks like xcdiff returns exit codes when the project has diffs? Anyway it causes git diff to abort and not show changes to other files unless xcdiff.sh returns exit code 0

Perhaps it's worth landing the script and extending the doc to cover this use-case?

Might be good by default to adjust the script to use -d as well to minimize the spew when doing a git diff - removes a thousand "nothing changed" green checkboxes that way...