Last active
December 15, 2015 19:58
-
-
Save jakeboxer/5314712 to your computer and use it in GitHub Desktop.
Clean superfluous files out of a Git repo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| #/ Usage: script/clean-git-test-fixture <path.git> | |
| set -e | |
| path="${1%/}" | |
| # bail out if path not specified | |
| if [ -z "$path" ] | |
| then | |
| echo "$(basename $0): path not specified" 1>&2 | |
| exit 1 | |
| fi | |
| # check path ends in .git | |
| if ! echo "$path" | grep -q '.git$' | |
| then | |
| echo "$(basename $0): $path is not a bare repository path" 1>&2 | |
| exit 1 | |
| fi | |
| # make sure the repo we're cleaning already exists. | |
| if ! [ -d "$path" ] | |
| then | |
| echo "$(basename $0): $path does not exist" | |
| exit 1 | |
| fi | |
| # all the superfluous git file names | |
| # note: in most cases, it would be fine to just delete the hooks folder, but | |
| # some tests rely on real hooks, so just delete the sample hooks. | |
| superfluous_git_files=" | |
| COMMIT_EDITMSG | |
| hooks/applypatch-msg.sample | |
| hooks/commit-msg.sample | |
| hooks/post-update.sample | |
| hooks/pre-applypatch.sample | |
| hooks/pre-commit.sample | |
| hooks/pre-rebase.sample | |
| hooks/prepare-commit-msg.sample | |
| hooks/update.sample | |
| index | |
| info/exclude | |
| " | |
| for filename in $superfluous_git_files | |
| do | |
| filepath="$path/$filename" | |
| if [ -e "$filepath" ] | |
| then | |
| if [ -d "$filepath" ] | |
| then | |
| # If the thing at $filepath is a directory, delete it recursively. | |
| rm -r "$filepath" | |
| echo "Deleted dir at $filepath" | |
| else | |
| # If the thing at $filepath is a file, delete it the normal way. | |
| rm "$filepath" | |
| echo "Deleted file at $filepath" | |
| fi | |
| else | |
| # If there's nothing at $filepath, still echo something. | |
| echo "Skipped nonexistent file at $filepath" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment