Last active
April 27, 2016 11:30
-
-
Save jtyr/7250a08a6ac628123fb3 to your computer and use it in GitHub Desktop.
Bundle and unbundle local Git repos
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
### | |
# | |
# This Makefile helps to bundle and unbundle local Git repos. Directories | |
# containing bare repos should end with `.git` (e.g. `mybarerepo.git`). | |
# | |
### | |
DIRS = $(shell find . -type d -maxdepth 1) | |
BUNDLES = $(filter-out $(wildcard *.git.bundle), $(wildcard *.bundle)) | |
BUNDLES_BARE = $(wildcard *.git.bundle) | |
.PHONY: all export import | |
all: | |
@echo "Usage: make [export|import]" | |
bundle: export | |
export: | |
@$(foreach DIR, $(DIRS), \ | |
echo "### Bundling $(DIR):"; \ | |
git -C $(DIR) bundle create ../$(DIR).bundle --all; \ | |
echo; \ | |
) | |
unbundle: import | |
import: | |
@$(foreach B, $(BUNDLES), \ | |
echo "### Unbundling $(B):"; \ | |
test -e $(B:.bundle=) && \ | |
echo "Repo already exists" || \ | |
( \ | |
git clone $(B) && \ | |
cd $(B:.bundle=) && \ | |
for i in $$(git branch -r | egrep -v "(HEAD|master)"); do \ | |
git branch --track $${i#*/} $i; \ | |
done \ | |
); \ | |
echo; \ | |
) | |
@$(foreach B, $(BUNDLES_BARE), \ | |
echo "### Unbundling $(B):"; \ | |
test -e $(B:.bundle=) && \ | |
echo "Repo already exists" || \ | |
git clone --bare $(B) $(B:.bundle=); \ | |
echo; \ | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment