Skip to content

Instantly share code, notes, and snippets.

@chrish619
Created June 20, 2019 11:08
Show Gist options
  • Save chrish619/68a6725b7002e58e2dcfdf160e217fcf to your computer and use it in GitHub Desktop.
Save chrish619/68a6725b7002e58e2dcfdf160e217fcf to your computer and use it in GitHub Desktop.
[GIT Hook] Remove 'project.assets.json' from folder structure when switching branches
#! /bin/bash
# The intention behind this post-checkout hook, is to 'reset' the project state
# when switching branches in .Net Core projects / solutions
#
# Why?: A repository can be in a multiple states of migration - this resolves
# switching between branches, where some of those branches/projects are in a
# .Net.Sdk style, and others are yet to be migrated
RESET='\033[0m'
#colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
#emoji
EMOJI_WASTEBASKET='\xf0\x9f\x97\x91' #Single width emoji, which gets truncated in git bash!
EMOJI_EXPLOSION='\xF0\x9F\x92\xA5'
# From repo root
cd ./$(git rev-parse --show-cdup)
printf "${RED}${EMOJI_EXPLOSION} ${YELLOW}Deleting 'obj\\project.assets.json' manifests"
find . -wholename "*/obj/project.assets.json" -exec printf "." \; -exec rm -rf {} +
printf "${RESET}\n"
# if, simply removing the 'project.assets.json' does not work, you can erase the
# 'obj' folder instead
# printf "${RED}${EMOJI_EXPLOSION} ${YELLOW}Deleting 'obj' folders"
# find . -name "obj" -type d -exec printf "." \; -exec rm -rf {} +
# printf "${RESET}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment