Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including new files in SVN diff

Tags:

diff

svn

patch

I have a script which builds my application, uploads it to a remote machine, runs a performance test there and captures some metrics that I care about. The script creates a patch file for the local modifications I make in my workspace and shows it along with the performance numbers. This helps me compare the effect of various tuning options. If I want to recreate my workspace at a later date, I can use the SVN revision number and the patch.

svn diff does not report a new files I add to the workspace unless I explicitly use svn add on them first. Is there some way to create a patch file which will include the new files also?

PS: A similar question was asked here but was not answered adequately, IMO.

like image 802
Binil Thomas Avatar asked Nov 22 '10 18:11

Binil Thomas


People also ask

Can multiple files be added in svn?

Edit These files exist in a directory tree so adding * for one directory will not work. @your edit: So then provide multiple paths to add like: svn add dir1/* dir2/* dir3/* or as many have mentioned grep the ouput of svn stat from the root and pipe it to cut or awk and then to add.

How do I compare changes in svn?

Just hold down the Shift key while you right click on the file. Then select TortoiseSVN → Diff with URL. In the following dialog, specify the URL in the repository with which you want to compare your local file to.

How do you find the difference between two svn revisions?

Display the differences between two paths. The ways you can use svn diff are: Use just svn diff'to display local modifications in a working copy. Display the changes made to TARGET s as they are seen in REV between two revisions.

What is svn diff command?

svn diff (di) — This displays the differences between two revisions or paths.


2 Answers

To make svn diff include all the unversioned files from your local working copy you have to add these files first. svn diff outputs the same changeset that svn commit would use.

If you know for sure that all unversioned files should be added here's what you could do.

Prepare a list of unversioned files by taking from the output of svn status all the lines that start with a question mark:

svn status | grep ^? | sed -r 's/^\? +//' > ../unversioned_files_list.txt

You can then pass that list of files to svn addusing xargs:

xargs -r -d '\n' svn add < ../unversioned_files_list.txt

And then produce the patch:

svn diff > ../my_patch.patch

If you don't want to keep those files added, use the list of files to unadd them:

xargs -r -d '\n' svn rm --keep-local < ../unversioned_files_list.txt
like image 124
Alex Jasmin Avatar answered Sep 27 '22 10:09

Alex Jasmin


Thanks Alexandre. At first, his approach didn't work in my case. I was sure all new files were maked A in svn status, however, the diff file was still empty. Finally, I found the difference in svn status outputs, the fourth columns in my case are all populated with +, like:

$ svn st
M      .
A  +    New.java

This means the item is scheduled for addition-with-history[1]. This typically happens when you svn move or svn copy a file or directory[2]. In my case, the New.java is svn merged from another branch, including previous commit history in that branch. Let's removed these history information.

First, find all addition-with-history items:

svn status | grep ^A | sed -r 's/^A[ +]+//' > /tmp/add_list

Optionally, remove directory paths in /tmp/add_list to avoid warnings in next step.

Next, remove their history commit information by svn remove:

xargs -r -d '\n' svn remove --keep-local --force < /tmp/add_list

Then, go back to Alexandre's solution to add them to subversion again and get the diff.

References:

[1]http://svnbook.red-bean.com/nightly/en/svn.ref.svn.c.status.html
[2]http://www.linuxtopia.org/online_books/programming_tool_guides/version_control_with_subversion/svn.ref.svn.c.status.html
like image 26
guiwuu Avatar answered Sep 26 '22 10:09

guiwuu