From: Tim Henigan Date: Tue, 20 Mar 2012 17:43:52 GMT Subject: Re: [PATCH 7/9] difftool: teach difftool to handle directory diffs Message-ID: In-Reply-To: <1331949574-15192-1-git-send-email-tim.henigan@gmail.com> I have run into a problem with the way that the tmp directories are populated using 'git update-index' and 'git checkout-index'. I would appreciate any feedback that may help me understand what I am doing wrong. This is in regard to the following section of code: On Fri, Mar 16, 2012 at 9:59 PM, Tim Henigan wrote: > > +sub setup_dir_diff > +{ > +       # Run the diff; exit immediately if no diff found > +       my $repo = Git->repository(); > +       my $diffrtn = $repo->command_oneline(['diff', '--raw', '--no-abbrev', '-z', @ARGV]); > +       exit(0) if (length($diffrtn) == 0); > +       my @rawdiff = split('\0', $diffrtn); > + > +       for (my $i=0; $i<@rawdiff; $i+=2) { > +               my ($lmode, $rmode, $lsha1, $rsha1, $status) = split(' ', substr($rawdiff[$i], 1)); > +               my $path = $rawdiff[$i + 1]; > + > +               if (($lmode eq $submodule_mode) or ($rmode eq $submodule_mode)) { > +                       $submodule{$path}{left} = $lsha1; > +                       $submodule{$path}{right} = $rsha1; > +                       next; > +               } > + > +               if ($lmode ne $null_mode) { > +                       $lindex .= "$lmode $lsha1\t$path\0"; > +               } > + > +               if ($rmode ne $null_mode) { > +                       if ($rsha1 ne $null_sha1) { > +                               $rindex .= "$rmode $rsha1\t$path\0"; > +                       } else { > +                               push(@working_tree, $path); > +                       } > +               } > +       } > + > +       # Populate the left and right directories based on each index file > +       my ($inpipe, $ctx); > +       $ENV{GIT_INDEX_FILE} = "$tmpdir/lindex"; > +       ($inpipe, $ctx) = $repo->command_input_pipe(qw/update-index -z --index-info/); > +       print($inpipe $lindex); > +       $repo->command_close_pipe($inpipe, $ctx); > +       $repo->command_oneline(["checkout-index", "-a", "--prefix=$ldir/"]); When run from the root directory of a Git repository, the 'difftool --dir-diff' command operates as expected: - Temporary index files for each side of the diff are created using 'git update-index'. - 'git checkout-index --all --prefix=$tmp' is used to populate the tmp directory based on the index file. However, when 'difftool --dir-diff' is run from a subdirectory of the Git repository, there are problems. - The temporary index file generated by 'git update-index' appears to be correct. - 'git checkout-index --all --prefix=$tmp' command does not work (output tmp dir is empty). I have tried some combinations of setting $ENV{GIT_DIR} and $ENV{GIT_WORK_TREE}, but it has not fixed the problem. Is there anything obvious that I missed?