Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tfs unified diff file generation. header line mismatch with patch command

Tags:

diff

tfs

I am trying to generate diff file (patch file) and apply this patch to some already deployed folder. I am running the following command to generate diff file:

tf diff version.asp /format:unified > C:\patch.diff

It generates something like:

Comparing local to latest: C:\dev\folder\version.asp File: version.asp ===================================================================

--- version.asp (local) 2011-06-17 09:18 text, after file name, should not be here

+++ version.asp;958 (server) 2011-09-19 14:27 the same here

@@ -13,7 +13,7 @@
'============================================================
Dim APP_VERSION, APP_BUILD, APP_DATE  
APP_VERSION = 6
-APP_BUILD = 45
+APP_BUILD = 52
%>
\ No newline at end of file
============================================================

The problem appears on the line which is bold. The UNIX patch application does not recognize file names because these lines should contain only the file name without any additional info. If I remove text after file name on those lines, patch will run successfully. So my question is: is it possible to generate diff file from tf diff without such information in the header so that it is compatible with patch?

There is an alternative like applying regex and replacing such lines but it would be the last attempt to make it working.

Thank you

UPDATE

at the end i ended up with regex which removes those unnecessary info from the lines, run it with Unix sed utility, i got Windows version from MinGW.

sed "s/^\(+++\|---\)\(.*\)\(\.[A-Za-z0-9]\{1,4\}\)\(.*\)$/\1\2\3/" C:\patch.diff > C:\patch.new

patch.diff is malformed file generated from tfs and on the output patch.new is correct unified diff file and compatible with patch utility

UPDATE2

after hours of banging head against the wall, i found out that in diff files generated from tfs Unicode extended characters are simply escaped or replaced with its closest ASCII representation.

So for example, if code has ä letter, in the output diff file it will be replaced by a simple a letter.

This makes diff files, generated from tfs utility, useless.

This is a bug obviously.

FYI: I am using vs2010 and team foundation server 2010.

like image 477
Rustam Shakirov Avatar asked Nov 04 '22 19:11

Rustam Shakirov


2 Answers

For what it's worth, I couldn't figure this out either. TFS creates malformed files with /unified.

I worked around it using a local git install:

(shelve change set)
tfpt scorch
git init 
git add .
git commit -a -m "Original"
git checkout -b "New"
(checkout shelf in tfs)
git add . 
git commit -a -m "Change"
git format-patch master

:/

like image 60
Doug Avatar answered Nov 20 '22 11:11

Doug


If the output from tf diff /format:unified differs from diff -u and is incompatible with patch, then this is a bug you should report to Microsoft

As you say, the workaround is to tediously find and replace.

like image 43
Colonel Panic Avatar answered Nov 20 '22 10:11

Colonel Panic