Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git difftool: how to measure progress, that is number of files diff'ed and to diff?

I know I can use git difftool with the --dir-diff option in order to compare all the files in one go.

But using difftool with prompt has its use (for a reasonably small number of files to diff), especially since git 1.7.8, where you can skip a file.

However, that prompt doesn't show how many files are in the diff queue or how many has already been diff'ed.
How would you display that information in the difftool prompt?

like image 593
VonC Avatar asked Dec 29 '13 08:12

VonC


People also ask

What is DiffTool in Git?

git difftool is a Git command that allows you to compare and edit files between revisions using common diff tools. git difftool is a frontend to git diff and accepts the same options and arguments. See git-diff [1].

What are the valid diff tool settings in Git?

Valid values include emerge, kompare, meld, and vimdiff. Run git difftool --tool-help for the list of valid <tool> settings. If a diff tool is not specified, git difftool will use the configuration variable diff.tool. If the configuration variable diff.tool is not set, git difftool will pick a suitable default.

What is diffing in Git?

This tutorial will discuss, with examples, the basics of diffing with Git and how to use the git diff command. By the end of reading this tutorial, you’ll be an expert at using the git diff command. The git diff command displays the differences between files in two commits or between a commit and your current repository.

How do I see differences between two files in Git?

By executing the git diff command, we can see the differences between these two files. By default, the git diff command produces a diff for all files between the latest commit and the current state of the repository. When we run the command, the following response is returned:


1 Answers

With git alone, you can't (git 1.8.x).
But that feature is coming (in Git 1.9/2.0 Q1 2014)

See commit 6904f9a from Zoltan Klinger's patch.

When --prompt option is set, git-difftool displays a prompt for each modified file to be viewed in an external diff program. At that point it could be useful to display a counter and the total number of files in the diff queue.

Below is the current difftool prompt for the first of 5 modified files:

Viewing: 'diff.c'
Launch 'vimdiff' [Y/n]:

Consider the modified prompt:

Viewing (1/5): 'diff.c'
Launch 'vimdiff' [Y/n]:

The current GIT_EXTERNAL_DIFF mechanism does not tell the number of paths in the diff queue nor the current counter.
To make this "counter/total" info available for GIT_EXTERNAL_DIFF programs without breaking existing ones:

  1. Modify run_external_diff() function in diff.c to set one environment variable for a counter and one for the total number of files in the diff queue.
    The size of the diff queue is already available in the diff_queue_struct.
    For the counter define a new variable in the diff_options struct and reset it to zero in diff_setup_done() function.
    Pre-increment the counter inside the run_external_diff() function.
  2. Modify git-difftool--helper.sh script to display the counter and the diff queue count values in the difftool prompt.

That results in:

git-difftool--helper.sh @@ launch_merge_tool () {

 # the user with the real $MERGED name before launching $merge_tool.
 if should_prompt
 then
   printf "\nViewing (%s/%s): '%s'\n" "$GIT_DIFF_PATH_COUNTER" \
     "$GIT_DIFF_PATH_TOTAL" "$MERGED"
 if use_ext_cmd
 then
   printf "Launch '%s' [Y/n]: " \
like image 198
VonC Avatar answered Sep 30 '22 03:09

VonC