Skip to content

Instantly share code, notes, and snippets.

@slattery
Last active November 7, 2023 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slattery/51d064741262cae189d1facb7b06b995 to your computer and use it in GitHub Desktop.
Save slattery/51d064741262cae189d1facb7b06b995 to your computer and use it in GitHub Desktop.
compare two lando template dirs

Diff lando template dirs

Sometimes you want to know how two files in two sites differ.

Setup

Place the diffwith.sh file somewhere you can get at it, and either

  • chmod 755 path/to/diffwith.sh to make it executable
  • just know you'll type bash path/to/diffwith.sh name-of-comparedir each time, which is legit too.

Run it

  • Open a terminal at the root of a lando project, ex: /User/tishimself/lando/mysite-pantheon
  • run this script with the name of the other lando project you wish to compare

../scripts/local/diffwith.sh myothersite-pantheon

The script then runs a recursive find and execs diff -q on each pairing a few times to break out group of differences. We group the files that live either on one site or the other, then we list out the filenames that exist in both but differ. We don't list files that are identical!

Output

To break it up for easy digestion, for each dir comparison:

PROCESSING mysite-pantheon HOME ./web/themes/yse/templates/atoms AWAY myothersite-pantheon/web/themes/yse/templates/atoms SUBDIRS ... ONLY HOME ... ONLY AWAY ... DIFFERENCES ...

Massive oversight

Since this uses the dir you are in as the 'home', be aware that the 'away' site might have dirs that don't show up because they aren't part of the original dive.

#!/bin/bash
find ./web/themes/yse/templates -mindepth 1 -type d | while read dir; do
NL=$'\n'
base=${PWD/*\//}
home=$dir
away=${dir/\.\//${1}/}
echo "${NL}PROCESSING ${base}${NL}HOME ${home} AWAY ${away}"
echo "SUBDIRS" && diff -q ${home} ../${away} | grep "subdir" && echo ""
echo "ONLY HOME" && diff -q ${home} ../${away} | grep "Only in ./web" && echo ""
echo "ONLY AWAY" && diff -q ${home} ../${away} | grep "Only in ../" && echo ""
echo "DIFFERENCES" && diff -q ${home} ../${away} | grep "differ" | awk '{print $2}' && echo ""
echo ""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment