Skip to content

Instantly share code, notes, and snippets.

@berkus
Created January 21, 2022 08:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berkus/b4c6097bb95ea51069a449013c86b5a0 to your computer and use it in GitHub Desktop.
Save berkus/b4c6097bb95ea51069a449013c86b5a0 to your computer and use it in GitHub Desktop.
Pijularize a Git repository with all branches
#!/bin/sh
set -e
set -x
reponame=`basename $(pwd)`
echo "#######################################################################################"
echo "# Script to import all local branches from current repository (${reponame}) into pijul"
echo "# Will create a bunch of temp repos for import, so have sufficient disk space"
echo "#######################################################################################"
all_branches=(`git branch -a | grep -v remotes/ | tr '*' ' ' | awk '{print $1}' | tr '\n' ' '`)
echo "*** Importing ${#all_branches[@]} local branches to pijul"
mkdir -p ../${reponame}-temp
rm -rf ../${reponame}-pijul
pijul init ../${reponame}-pijul
for channel in "${all_branches[@]}"
do
echo "####################################################################################"
echo "*** Importing ${channel}"
echo "####################################################################################"
rm -rf ../${reponame}-temp/${channel}
mkdir -p ../${reponame}-temp/${channel}
cp -r . ../${reponame}-temp/${channel}
(cd ../${reponame}-temp/${channel}; \
git reset --hard ${channel}; \
git clean -fdx; \
pijul git; \
pijul fork ${channel})
(cd ../${reponame}-pijul; \
pijul channel new ${channel}; \
env EDITOR=true pijul pull --from-channel ${channel} --to-channel ${channel} ../${reponame}-temp/${channel})
rm -rf ../${reponame}-temp/${channel}
done
rm -rf ../${reponame}-temp
@berkus
Copy link
Author

berkus commented Jan 21, 2022

Run from inside a git repo.

Copies only local branches, checkout remote branches locally if you need to migrate them.

Temporary hack until pijul is taught to import branches by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment