Это не сработает.
Прежде всего блок buildscript
оценивается в самом начале, перед любой другой частью скрипта groovy. Следовательно, свойства, определенные в блоке ext
, просто не существуют в то время.
Во-вторых, я не уверен в возможности обмена свойствами между buildscript
и другой частью скрипта.
Ответ Ярина сработал для меня, вот моя версия (мне не нужен подкаталог /wordpress
):
*
!.gitignore
!/wp-content/
!/wp-content/themes/
!/wp-content/themes/*
!/wp-content/themes/*/*
!/wp-content/themes/*/*/*
!/wp-content/themes/*/*/*/*
!/wp-content/themes/*/*/*/*/*
# I don't want to track this one, so it's included here, after the negated patterns.
wp-content/themes/index.php
Если вы префикс шаблона с восклицательным знаком (!
), он отменяет любой предыдущий шаблон, который исключил его. Таким образом, по-видимому, вы можете игнорировать все, а затем разрешить только то, что вы хотите, используя этот шаблон.
Я попробовал вышеупомянутое, и они не работали так хорошо. Гораздо лучший подход заключается в следующем: https://gist.github.com/444295
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
# content. Or see git's documentation for more info on .gitignore files:
# http://kernel.org/pub/software/scm/git/docs/gitignore.html
# Ignore everything in the root except the "wp-content" directory.
/*
!.gitignore
!wp-content/
# Ignore everything in the "wp-content" directory, except the "plugins"
# and "themes" directories.
wp-content/*
!wp-content/plugins/
!wp-content/themes/
# Ignore everything in the "plugins" directory, except the plugins you
# specify (see the commented-out examples for hints on how to do this.)
wp-content/plugins/*
# !wp-content/plugins/my-single-file-plugin.php
# !wp-content/plugins/my-directory-plugin/
# Ignore everything in the "themes" directory, except the themes you
# specify (see the commented-out example for a hint on how to do this.)
wp-content/themes/*
# !wp-content/themes/my-theme/
Еще одно простое решение:
Вы хотите игнорировать все файлы Wordpress, но не свою тему (например).
.gitignore , содержимое:
# All wordpress + content of revert ignored directories
wordpress/*
wordpress/wp-content/*
wordpress/wp-content/themes/*
# Revert ignoring directories
!wordpress/
!wordpress/wp-content/
!wordpress/wp-content/themes/
!wordpress/wp-content/themes/my_theme
В этом примере вы можете удалить wordpress , если .gitignore находится в корневой каталог WordPress
Вы можете делать то же самое с любыми папками и содержимым, которые хотите «исключительно» хранить в отредактированных папках / файлах
1116]
Обязательно игнорируйте все каталоги пути, который вы хотите игнорировать
НО
Обязательно игнорируйте все содержимое неопознанных каталогов, которые вы хотите игнорировать
Вот мое решение, которое предполагает проверку wp-content
# Ignore everything except directories
*
!*/
# except everything in the child theme and its required plugin
!/themes/mytheme-child/**
!/plugins/my-plugin/**
# and this file
!.gitignore
и тестирование:
git version 2.20.1 (Apple Git-117)
$ git check-ignore -v .foo foo foo/ themes/foo themes/foo/bar themes/mytheme-child \
themes/mytheme-child/foo plugins/foo plugins/my-plugin plugins/my-plugin/foo .gitignore
.gitignore:2:* .foo
.gitignore:2:* foo
.gitignore:2:* foo/
.gitignore:2:* themes/foo
.gitignore:2:* themes/foo/bar
.gitignore:2:* themes/mytheme-child
.gitignore:6:!/themes/mytheme-child/** themes/mytheme-child/foo
.gitignore:2:* plugins/foo
.gitignore:2:* plugins/my-plugin
.gitignore:7:!/plugins/my-plugin/** plugins/my-plugin/foo
.gitignore:10:!.gitignore .gitignore
, поэтому оно корректно игнорирует все, что я не хочу, и ничего, что я хочу сохранить.
Gitlab настроен с зеркалами репозитория для защищенных веток, в соответствии с https://docs.gitlab.com/ee/workflow/repository_mirroring.html
Когда код передается в защищенную ветвь, он будет зеркально отражен на промежуточных промежуточных и производственных серверах в голом репо /opt/checkout/repo.git/
. Следующий хук post-receive
(в /opt/checkout/repo.git/hooks/post-receive
) затем извлечет код в рабочий каталог.
#!/bin/bash
BRANCH=staging
GIT_DIR=/opt/checkout/repo.git
GIT_WORK_TREE=/opt/bitnami/apps/wordpress/htdocs/wp-content
# on push, checkout the code to the working tree
git checkout -f "${BRANCH}"
# ensure permissions are correct
sudo chown -R bitnami:daemon "${GIT_WORK_TREE}"
sudo chmod -R go-w "${GIT_WORK_TREE}"
Для получения дополнительной информации см. https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps
После нескольких попыток я наконец нашел решение [1]:
/*/
/*.*
!.git*
!/wordpress
Объяснение построчно:
.gitignore
(и, возможно, .gitattributes
). [1] Ограничения (о которых я знаю):
/*
нарушит всю схему). wordpress
), не может иметь .
в имени (например, wordpress.1
не будет работать). Если у него есть .
, удалите строку 2 и найдите другой способ исключить все файлы в корне. git version 2.17.1.windows.2
Для тех, кто ищет решение для очистки , попробуйте следующее.
Как уже упоминалось в комментариях к этого ответа, вы должны использовать этот метод рекурсивно.
В этом примере у вас есть настройка веб-сайта в ./
, где находится ваша папка .git
и файл .gitignore
, и установка установки WordPress в ./wordpress
. Чтобы правильно игнорировать все в каталоге ./wordpress
, кроме самого каталога темы (wordpress/wp-content/themes/my-theme
), вам придется рекурсивно игнорировать и разрешать каждый каталог вплоть до каталога, который вы хотите разрешить:
wordpress/*
wordpress/wp-content/*
wordpress/wp-content/themes/*
!wordpress/wp-content
!wordpress/wp-content/themes
!wordpress/wp-content/themes/my-theme
Причина игнорирования подстановочным знаком и разрешения (или игнорирования «отдельно от») самого каталога позволяет Git сначала заглянуть внутрь каталога, прежде чем игнорировать все внутри. Затем мы говорим Git игнорировать все, кроме указанного нами каталога. Вот тот же синтаксис, но в порядке того, как Git смотрит на него:
wordpress/* # Ignore everything inside here
!wordpress/wp-content # Apart from this directory
wordpress/wp-content/* # Ignore everything inside here
!wordpress/wp-content/themes # Apart from this directory
wordpress/wp-content/themes/* # Ignore everything inside here
!wordpress/wp-content/themes/my-theme # Apart from this directory
Надеюсь, это поможет кому-то лучше понять необходимость рекурсивного метода.