0

Is there a way to diff two xaml files that differ in non functional white space i.e. new lines after attributes or the order of attributes?

I would like the following two xaml snippets to be recognized as the same

Snippet 1

<Button Name="myButton1" Click="myButton1_Clicked"/>

Snippet 2

<Button
    Click="myButton1_Clicked"
    Name="myButton1" />

But differences in element order should not be treated as being the same i.e.

<StackPanel>
    <Button />
    <TextBox />
</StackPanel>

should differ from

<StackPanel>
    <TextBox />
    <Button />
</StackPanel>

I looked into canonicalization for xml files with xmllint, but I could not get that to work with xaml files. Xmllint only returns an error when I call it on my xaml files with

xmllint -c14n myfile.xaml > myfile-canocicalized.xaml

In the ideal case I would like to be able to tell git about this, so that it generates meaningful diffs. I know that this can be achieved through setting diff.textconv in the .gitattribute file to a program that canonicalizes xaml files.

FlyingFoX
  • 3,379
  • 3
  • 32
  • 49

1 Answers1

1

Probably these options will give you the desired result: git diff -b or git diff --ignore-space-change

As they are going to ignore white spaces / tabs

J_P
  • 761
  • 8
  • 17
  • That is a good first step, but unfortunately not enough. This will still highlight changes in attribute order, that I would like to treat as the same. See my first example for that. – FlyingFoX Feb 03 '18 at 21:27