Skip to content

Instantly share code, notes, and snippets.

@drugan
Last active August 30, 2019 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drugan/fd81d791d52c815f898e3bdd3af7dbef to your computer and use it in GitHub Desktop.
Save drugan/fd81d791d52c815f898e3bdd3af7dbef to your computer and use it in GitHub Desktop.
Commit the entire Drupal Commerce 2.x project including nested git repositories

First, as an alternative install this version of the Drupal Commerce:

composer create-project --repository=https://raw.githubusercontent.com/drugan/project-base/8.x/packages.json drugan/project-base some-dir --stability dev

If desired, you might not install it as a Drupal site, instead use it as a repository for all other of your projects (local or remote) to pull from. After composer installing open .gitignore file in the root of a repo and replace its content with the following:

hidden.git
PATCHES.txt
web/sites/*/files
web/sites/*/services.yml
web/sites/*/settings.php
web/sites/sites.php
web/sites/settings.local.php

Then in the repo root run this:

touch togglegit.sh && chmod u+x togglegit.sh

Fill the togglegit.sh file with the content as it shown below.

Now, run this:

./togglegit.sh hide

After that as usual:

git add .
git commit -m 'My initial commit'

When you want to update this centralized repo just run this:

./togglegit.sh show
composer update

And after the update:

./togglegit.sh hide
git add .
git commit -m 'Updated and commited'

That way you have all the code of the repo commited as one huge git repository from which you can pull. Or, if you like, just use it as the repository for a particular Drupal Commerce 2.x site.

#!/bin/bash
# @see: https://gist.github.com/drugan/fd81d791d52c815f898e3bdd3af7dbef
# Prepend to or remove 'hidden' prefix from .git repositories
# Also, replace string "old" in file names:
# find -L ./ -name "old" -type f | rename -v "s/old/new/g"
# Also, replace stirng "old" in files:
# grep -rl old . | xargs sed -i 's/old/new/g'
if [ "$1" = "hide" ]
then
find -L ./ -name ".git" -type d | rename -v "s/.git/hidden.git/g"
find -L ./ -wholename "./hidden.git" -type d | rename -v "s/hidden.git/.git/g"
echo
echo "HIDDEN!!!"
echo "All nested .git are turned into hidden.git."
echo "Now you can commit your changes on the repository and allow clones to pull ..."
exit 0
elif [ "$1" = "show" ]
then
find -L ./ -name "hidden.git" -type d | rename -v "s/hidden.git/.git/g"
echo
echo "SHOWN!!!"
echo "All nested hidden.git are turned into .git."
echo "Now you can use composer to update the project and all the dependencies ..."
exit 0
else
echo "Enter \"hide\" or \"show\" as the first argument ..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment