Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend xcdiff to become a git difftool for Xcode Projects #25

Open
kwridan opened this issue Nov 14, 2019 · 4 comments
Open

Extend xcdiff to become a git difftool for Xcode Projects #25

kwridan opened this issue Nov 14, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@kwridan
Copy link
Contributor

kwridan commented Nov 14, 2019

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.

@kwridan kwridan added the enhancement New feature or request label Nov 14, 2019
@hughescr
Copy link

hughescr commented Feb 6, 2023

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.

@hughescr
Copy link

hughescr commented Feb 6, 2023

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

@marciniwanicki
Copy link
Contributor

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

@hughescr
Copy link

hughescr commented Feb 8, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants