|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# gitkeep.sh |
| 4 | +# |
| 5 | + |
| 6 | +description=\ |
| 7 | +'bash script for adding empty ".gitkeep" files at the branch ends of empty directory trees' |
| 8 | + |
| 9 | +use_case=\ |
| 10 | +"Use case: |
| 11 | +
|
| 12 | + Force git to track otherwise empty directories such as doc/dependency_tree/opencoarrays, |
| 13 | + which exists solely for purposes of displaying the OpenCoarrays dependency tree via the |
| 14 | + command 'tree opencoarrays'." |
| 15 | +# |
| 16 | +# OpenCoarrays is distributed under the OSI-approved BSD 3-clause License: |
| 17 | +# Copyright (c) 2015, Sourcery, Inc. |
| 18 | +# Copyright (c) 2015, Sourcery Institute |
| 19 | +# All rights reserved. |
| 20 | +# |
| 21 | +# Redistribution and use in source and binary forms, with or without modification, |
| 22 | +# are permitted provided that the following conditions are met: |
| 23 | +# |
| 24 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 25 | +# list of conditions and the following disclaimer. |
| 26 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this |
| 27 | +# list of conditions and the following disclaimer in the documentation and/or |
| 28 | +# other materials provided with the distribution. |
| 29 | +# 3. Neither the names of the copyright holders nor the names of their contributors |
| 30 | +# may be used to endorse or promote products derived from this software without |
| 31 | +# specific prior written permission. |
| 32 | +# |
| 33 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 34 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 35 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 36 | +# IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 37 | +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 38 | +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 39 | +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 40 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 41 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | +# POSSIBILITY OF SUCH DAMAGE. |
| 43 | +# |
| 44 | +this_script=`basename $0` |
| 45 | + |
| 46 | +usage() |
| 47 | +{ |
| 48 | + echo "" |
| 49 | + echo " $this_script - $description" |
| 50 | + echo "" |
| 51 | + echo " Usage: " |
| 52 | + echo " $this_script <path-to-modify>" |
| 53 | + echo "" |
| 54 | + echo " Examples:" |
| 55 | + echo "" |
| 56 | + echo " $this_script ." |
| 57 | + echo "" |
| 58 | + printf "$use_case" |
| 59 | + exit 1 |
| 60 | +} |
| 61 | + |
| 62 | +# If this script is invoked without arguements, print usage information |
| 63 | +# and terminate execution of the script. |
| 64 | +if [[ $# == 0 || "$1" == "-h" || "$1" == "--help" ]]; then |
| 65 | + usage | less |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | + |
| 69 | +# Interpret the first argument as the name of the directory tree to fill |
| 70 | +export path_to_modify=$1 |
| 71 | + |
| 72 | +# Create an empty ".gitkeep" file in all empty subdirectories |
| 73 | +find $path_to_modify -type d -empty -exec touch {}/.gitkeep \; |
0 commit comments