Skip to content

Instantly share code, notes, and snippets.

@mig82
Last active April 26, 2021 16:01
Show Gist options
  • Save mig82/a21b5cc7b6d31d4291497690fa8c844b to your computer and use it in GitHub Desktop.
Save mig82/a21b5cc7b6d31d4291497690fa8c844b to your computer and use it in GitHub Desktop.
A makefile that applies Git sparse checkout on a Visualizer project.
# Pass in the path to the file that contains the path patterns for the app
# groups you want to check out —e.g.
#
# make checkout patterns=path/to/fooModule
#
# Where fooModule is a flat file with glob patterns like the ones defined
# at: https://www.git-scm.com/docs/git-sparse-checkout#_full_pattern_set
#
# You should ideally keep one of these pattern files per app group, and model
# your app groups after stand-alone modules, with matching names for forms
# and require modules —e.g. the patterns for a module called "fooModule" would
# be:
#
# /*
# !/forms/*
# forms/**/fooModule/*
#
# !/controllers/*
# controllers/**/fooModule/*
#
# !modules/require/*
# modules/require/utils/*
# modules/require/fooModule/*
#
# !themes/*
# themes/defaultTheme/*
#
# Invoke this to enable sparse checkout and check out a specific module —e.g. make module="fooModule"
checkout: clean set_module rm_empty list
# Invoke this to disable sparse checkout and check out the entire project —e.g. make disable
disable: clean set_all list
# Set the git sparse-checkout patterns to match a module.
set_module:
# Initialise sparse checkout.
git sparse-checkout init
# Check out the patterns for the module we want to work on.
cat $(patterns) | git sparse-checkout set --stdin
set_all:
# Disable sparse checkout.
git sparse-checkout disable
clean:
# Delete all the ignored files, so we can have a clean build.
git clean -fXd
# Delete the workspace webapps folder, so we can have a clean preview.
rm -rf ../.webapps/*
rm_empty:
# Delete the empty of modules we're not working on.
find ./forms -type d -empty -delete
find ./controllers -type d -empty -delete
find ./userwidgets -type d -empty -delete
find ./themes -type d -empty -delete
# Uncomment only one of the following two lines to use the ls command or the
# tree command to explore the file structure.
#list: list_ls
list: list_tree
#list: list_git
list_ls:
ls -lA .
ls -lAR forms
ls -lAR controllers
ls -lA modules
ls -lA modules/require
ls -lA themes
ls -lA userwidgets
list_tree:
# Show final directory tree.
tree -L 1 .
tree -L 3 forms/
tree -L 4 controllers/
tree -L 3 modules/
tree -L 1 themes/
tree -L 1 userwidgets/
list_git:
git ls-files forms
git ls-files controllers
git ls-files modules
git ls-files themes
git ls-files userwidgets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment