{"thread":{"id":"29970","subject":"[PATCH 8/9] difftool: teach dir-diff to copy modified files back to working tree","startedAt":"2012-03-17T01:59:54Z","lastAt":"2012-03-17T01:59:54Z","messageCount":1,"participants":["Tim Henigan"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"187124","messageId":"1331949594-15238-1-git-send-email-tim.henigan@gmail.com","threadId":"29970","inReplyTo":null,"subject":"[PATCH 8/9] difftool: teach dir-diff to copy modified files back to working tree","fromName":"Tim Henigan","fromEmail":"tim.henigan@gmail.com","sentAt":"2012-03-17T01:59:54Z","receivedAt":"2012-03-17T01:59:54Z","isPatch":true,"sender":{"key":"tim.henigan@gmail.com","avatar":"https://avatars.githubusercontent.com/u/42022?v=4"},"body":"If the user runs a diff when there are modified files in the working copy,\nthey expect to be able to be edit the files in the diff viewer and save\nthe changes. When using difftool in file mode (i.e. diffing one file at\na time), this works as expected.  However, when using difftool in directory\ndiff mode, the changes are not saved.\n\nThis commit teaches the directory diff mode to copy changes from the diff\nviewer back to the working copy.\n\nSigned-off-by: Tim Henigan <tim.henigan@gmail.com>\n---\n git-difftool.perl |   12 ++++++++++--\n 1 file changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex 0262c7a..ebffd1e 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -22,6 +22,8 @@ use File::Temp qw(tempdir);\n use Getopt::Long qw(:config pass_through);\n use Git;\n \n+my @working_tree;\n+\n sub usage\n {\n \tmy $exitcode = shift;\n@@ -54,7 +56,6 @@ sub setup_dir_diff\n \tmy $null_sha1 = 0 x 40;\n \tmy $lindex = \"\";\n \tmy $rindex = \"\";\n-\tmy @working_tree;\n \tmy %submodule;\n \tmy @rawdiff = split('\\0', $diffrtn);\n \n@@ -176,9 +177,16 @@ if (defined($dirdiff)) {\n \t\t$ENV{GIT_DIFFTOOL_DIRDIFF} = 'true';\n \t\tsystem(\"git difftool--helper $a $b\");\n \t}\n-\t# TODO: if the diff including working copy files and those\n+\n+\t# If the diff including working copy files and those\n \t# files were modified during the diff, then the changes\n \t# should be copied back to the working tree\n+\tmy $repo = Git->repository();\n+\tmy $workdir = $repo->wc_path();\n+\tfor (@working_tree) {\n+\t\tcopy(\"$b/$_\", \"$workdir/$_\") or die $!;\n+\t\tchmod(stat(\"$b/$_\")->mode, \"$workdir/$_\") or die $!;\n+\t}\n } else {\n \tif (defined($prompt)) {\n \t\t$ENV{GIT_DIFFTOOL_PROMPT} = 'true';\n-- \n1.7.9.1.290.gbd444\n"}]}