gitdiffdir: Take diff options.
This commit is contained in:
parent
f0dd01f79a
commit
10420e0f99
|
@ -10,17 +10,20 @@ gitdiffdir - git diff, but between two dirs in different repositories
|
|||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
gitdiffdir dir1 dir2
|
||||
B<gitdiffdir> [I<diff options>] I<dir1> I<dir2>
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<git diff> only looks at tracked files. B<git diff dir1 dir2>
|
||||
B<git diff> only looks at tracked files. B<git diff> I<dir1 dir2>
|
||||
includes all untracked files.
|
||||
|
||||
B<gitdiffdir> tries to simulate B<git diff> but on two dirs in
|
||||
different repositories.
|
||||
B<gitdiffdir> tries to simulate B<git diff> by only looking at tracked
|
||||
files but on two dirs in different repositories.
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
B<gitdiffdir> passes options to B<diff>. Default: B<-Naur>
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
|
@ -32,6 +35,10 @@ Diff dirs with the different names:
|
|||
|
||||
gitdiffdir myproject/mydir1 myoldproject/mydir2
|
||||
|
||||
Ignore new files:
|
||||
|
||||
gitdiffdir -aur myproject/mydir1 myoldproject/mydir2
|
||||
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
|
@ -69,10 +76,34 @@ B<git>
|
|||
|
||||
=cut
|
||||
|
||||
dirA="$1"
|
||||
dirB="$2"
|
||||
diff_options=()
|
||||
others=()
|
||||
|
||||
stdout() {
|
||||
# Loop through all arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-*) diff_options+=("$1") ;; # Add to options array if it starts with -
|
||||
*) others+=("$1") ;; # Add to others array if it doesn't start with -
|
||||
esac
|
||||
shift # Shift to the next argument
|
||||
done
|
||||
if [ ${#diff_options[@]} -eq 0 ]; then
|
||||
# Default: diff -Naur
|
||||
diff_options+=("-Naur")
|
||||
fi
|
||||
|
||||
dirA="${others[0]}"
|
||||
dirB="${others[1]}"
|
||||
|
||||
# Remove all trailing slashes
|
||||
while [[ "$dirA" == */ ]]; do
|
||||
dirA="${dirA%/}"
|
||||
done
|
||||
while [[ "$dirB" == */ ]]; do
|
||||
dirB="${dirB%/}"
|
||||
done
|
||||
|
||||
less_or_cat() {
|
||||
if [ -t 1 ] ; then
|
||||
# STDOUT = terminal
|
||||
# use less
|
||||
|
@ -82,6 +113,5 @@ stdout() {
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
parallel -0 'cd {} && git ls-files' ::: "$dirA" "$dirB" | sort -u |
|
||||
parallel -q diff -Naur "$dirA"/{} "$dirB"/{} | stdout
|
||||
parallel -q diff "${diff_options[@]}" "$dirA"/{} "$dirB"/{} | less_or_cat
|
||||
|
|
Loading…
Reference in a new issue