Problem/Motivation
The composer-ready project templates (drupal/recommended-project) nearly shipped with a .gitignore that would have caused all the composer-managed files to be excluded from any git repository the owner of the new project might set up. Discussion late in #2982680: Add composer-ready project templates to Drupal core revealed that there are established and opposing schools of thought about whether vendored files should be a part of one's git repository. That .gitignore was deemed too opinionated for core, and it was just removed entirely with the creation of this follow-on issue to find a more helpful solution.
Excluding any .gitignore from the official composer-built drupal/recommended-project project template is very likely to create an immediate chore for users of it, to figure out what is an appropriate .gitignore for Drupal and get it added to their project.
When this issue originated (in 2019), the goal was to provide a .gitignore starting point in our project templates for these two personas:
a) People who deploy site updates using only git, and so require all code to exist in git.
b) People who do not want large quantities of vendored code in their git repository, and develop advanced CI/build artifact systems to deploy site updates.
As several years have passed, it doesn't seem necessary to provide a starting point for folks who want to have all code in Git (persona "a" above), as best practices have evolved.
Proposed resolution
Have one well-documented .gitignore per project template that meets persona b)'s needs.
Remaining tasks
Postponed on #2381091: Improve example.gitignore .
- Check locally with Composer if the scaffolding: 1. Creates a .gitignore, 2. Which is not overwritten/updated
- Determine the best way to include a .gitignore file when using the drupal/recommended-project Composer template that won't overwrite any existing .gitignore file when the drupal/core-composer-scaffold runs.
- Determine how to write a test for this.
Documenting how to test Composer templates locally under Tricks for using Composer in local development would be very helpful.
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|
Issue fork drupal-3082958
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mbayntonComment #3
aaronmchaleQuoting myself from #2982680-110: Add composer-ready project templates to Drupal core:
Diff and quote above are by @mbaynton in #2982680-104: Add composer-ready project templates to Drupal core.
Comment #4
mbayntonAdded another possible solution, to have one well-documented .gitignore with lots of commented-out things, per suggestion in 2982680.117
Comment #5
aaronmchaleMy preferences for which possible solution should be used:
I am very much in favour of this.
I am also in favour of doing this in addition to option 1, I think doing both is useful, because further down the road the setup might change so the gitignore might need to change, so providing the example files would be helpful.
I'm hesitant about this because we could end up with a spiders web of templates just for differences between a single file, and I think 1 and 2 are better solutions for the problem.
Doing this instead of option 2 might be better, reduces the number of overall files which need to exist.
Ultimately my opinion is: definitely do 1, along with either 2 or 4, and don't do 3.
Comment #6
mbayntonI'm also very much in favor of incorporating #1 into the solution. It's a bit of extra futzing/complexity to optimize a small amount of output, but nowadays when I try a new framework and it comes with an official command to start a project, I am used to pretty refined experiences. I think it'd help with first impressions. It's also just nice to have.
Even if the difference in the .gitignores was only in what was commented out. (#4)
Comment #7
greg.1.anderson commentedAny prompting must be disabled via
--no-interaction. Ideally, it should also be possible to provide default values, e.g. via environment variables.Overall, I am kind of -1 on prompting in Drupal Core's project templates. When using a full-featured CLI tool such as Drupal Console or Drush, there is an entire config system available for defaults, environment variable overrides are possible, and so on. Composer is a full-featured CLI, but it does not offer us a good mechanism to pass values through to our customization scripts when using
composer create-project.Furthermore, if you are targeting your site to a very specific / opinionated hosting platform, e.g. Acquia or Pantheon, then ideally your host will provide a template that has been pre-customized to suit the environment. An example of this is example-drops-8-composer.
It seems better to me to provide a reasonable default with comments and instructions on how to customize things. We can put interaction in third-party tools and allow hosting providers to document how to best use Composer for their particular system. If we try to cover all contingencies in core, there's a risk that the user won't understand how to answer the question, and we'll have a lot of extra code to maintain. We don't want to have to involve a core committer every time someone wants to fine-tune how a template project installs for some specific environment, do we?
Comment #8
johnwebdev commented+1 #7
Generally I’m in favor of adopting to convention over configuration, because of better practices and decisions I don’t need to take myself.
However Drupal is not built to be conventional (there are many ways to do one thing, and sometimes you need to figure out which path to take on your own)
However, comment #7 raises some really good points and if I’m not part of the defined personas I would be lost in what choice I need to make, but also additionally do my own configuration afterwards anyways, or as Greg puts it try to pursue a fine tuning on the template.
Big +1 on sensible defaults and instructions how to configure for my own use cases.
Comment #9
ressaThanks for a great write up @mbaynton and outlining the different scenario options.
I am generally in favour of streamlining as much as possible and consolidating on an agreed best practice to simplify things, and reduce the likelihood of errors as much as possible. So I am in favour of shipping with a default
.gitignorefile, based on the best practice of Drupal, as well as for the simplest solution, to lower the barrier of entry for people just starting with Drupal.This would mean as little interaction as possible during installation, with sane, best-practice defaults used.
I have read many places that having Composer installed on the server is bad practice. Yet, the current
.gitignorein the Composer template for Drupal projects excludes many directories.So, if Composer shouldn't be installed on the server, the default
.gitignoreshould include all necessary files for git-based deployment from repository to server. Example.gitignoresettings for other scenarios could be included at the bottom of the included.gitignorefile, commented out. Having an extra example file likeexample.thisorthat.gitignorewould only add clutter.In essence, as comment #7 and #8, I vote for option #4
Comment #10
greg.1.anderson commented#3084298: Make composer installer paths consistent between drupal/drupal and the project templates adds
modules/custom/${name}to the installer paths. To support this, we should use the following .gitignore pattern:Comment #11
mbayntonRe: #9
But people can and do put Composer between their git repos and the server in CI/CD pipelines. That's fancier, but I don't think many people would say it's bad practice. This issue exists because there are two accepted but different ways to do it.
That said, people starting up new Drupal projects who intend to deploy such pipelines will also not be too thrown by uncommenting some lines in a .gitignore. I just think of prompting as a way to provide the trappings of a refined framework while early impressions of Drupal may be forming.
Re: #7
That's fair. There's no way for create-project to know any custom things at the time that it determines and parses command line options.
I wonder what percent of invocations of create-project for the offical core template will be run non-interactively, though. I'm not thinking of the reason for lots of different entities to set up workflows like that where the default .gitignore is also important, so there won't be mass confusion over what environment variables are respected. Also, any non-interactive workflow will be well equipped to just immediately overwrite our default .gitignore with the one exactly fitting that workflow or host. Good chance they do that regardless.
So I still think it's okay to prompt when we're interactive, because I think it optimizes for the dominant use case.
Perhaps this fact is how fine-tuning for those uncommonly specific environments happens without involving core committers? Then if the official project also helps users of less specialized environments, that sounds like a win all around. Maybe we don't prompt from the scaffold plugin if the root project's name doesn't suggest an official one.
Yeah. Maybe a compromise could be just generating some helpful "next steps" output at the end of project creation, a-la Symfony's create-project. "Check your .gitignore" which is the "#4" heavily commented-out one.
Comment #12
johnwebdev commented#10 I am wondering if we really should have modules/custom be ignored. I believe it is more common to keep your custom modules directly in the project's repository rather than maintaining them in their own separate ones. https://github.com/drupal-composer/drupal-project does not ignore the custom module path for instance.
Comment #13
greg.1.anderson commentedI personally always commit my private modules directly to the repository; however, in my case, a "private" module is always a site-specific module. I do not have private modules shared between multiple sites. This use case is common in agencies.
If we were doing this from scratch, I'd put drupal.org Packagist modules in `contrib`, commit site-specific modules to `custom`, and put private Packagist modules in `private`. However, the type `drupal-custom-module` was invented and added to Drupal some time ago. I therefore think that folks are probably using it. Since the use-case is going to be primarily for private modules, it's difficult to do a survey.
It is possible for these two conventions to co-exist per #10. There typically are not very many site-specific modules in a site, so most sites won't have too many directories to un-ignore. Those sites that are outliers can always decide to change their .gitignore to match their use case. We are also suggesting that these ignore rules be commented out, so sites that don't want them can just leave them commented out.
In summary, I am not opposed to the idea in #12, but since the path referenced in #10 has a corresponding type that is (presumably) in use, that represents a certain amount of inertia, and I'm not sure it's worth making the change.
Comment #14
mbayntonHere's some new .gitignores, consistent with the "#4" option from the IS, so that we can have *something* as a starting point.
These are based on example.gitignore and the final .gitignores from #2982680: Add composer-ready project templates to Drupal core (patch #91).
Notables:
create-project, it appends rules for the files it's scaffolded, and so the .gitignore we present the user with is messy. I chatted briefly with @greg.1.anderson about this; his suggestion was perhaps we could disable this behavior automatically if there is a .gitignore and /vendor is not ignored./sites/*/services*.yml.The gitignores in #91 were a bit out of sync. I've added some entries that were missing from the LegacyProject, like /modules/README.txt.Comment #15
greg.1.anderson commentedI created an issue, #3085354: Better default behavior for scaffold-created .gitignore files to track the .gitignore behavior described in #14.
Comment #16
ressaThanks @baynton, that looks like a great starting point for a .gitignore file.
Like you write, there are not a lot of comments yet. Perhaps we could add a bit about something that puzzled me a bit, namely the line with the exclamation mark? Perhaps add this, taken from https://git-scm.com/docs/gitignore:
Also, I suppose the .gitignore file from
composer/Template/LegacyProject/.gitignorewill end up in the root of the installation after runningcomposer -n create-project drupal/recommended-project:^8.8 my-project, right? I tried running the command, but it returned withCould not find package drupal/recommended-project with version ^8.8....Comment #17
mmjvb commented@ressa Either use 8.8.x-dev or add -s dev or use ^8.8@dev to get the dev version of that project. Basic composer 101 !
Comment #18
ressaThanks for helping out @mmjvb, all three options you suggested worked just fine.
Comment #19
mbaynton@ressa yeah, testing this patch locally (and all work on the Composer templates) is inordinately difficult and needs to be better documented somewhere. I'm not sure if there's an existing likely place for it.
The tl;dr is that to get Composer to use your modified files as the basis for a `create-project`, and not publicly available version that is out there in packagist now for 8.8, you need to
Call this file something like packages_drupal_templates.json
composer create-project:composer create-project -s dev --repository /path/to/packages_drupal_templates.json drupal/recommended-project my_test_projectYes, I wanted to make entirely sure that this in fact worked as expected. Doing all the above, I confirmed that it does copy the .gitignore into the new project root, as with any other files in the template.
Comment #20
ressaThank you for sharing the method for setting up a local Composer repository @baynton. It does seem a bit convoluted, and a bit of a chicken-or-egg-firsts situation. I will probably not try to replicate it, but still it will undoubtedly be quite useful to have the method documented. It might even be referred to from the Using Composer with Drupal guide?
I am glad to hear that .gitignore will be placed in the root of the installation.
Comment #21
greg.1.anderson commentedUsing
composer create-projectfrom on-disk templates is something that is only needed for folks developing a template project. Perhaps a good place for this would be in TESTING.txt in thecomposer/Templatedirectory.Comment #22
mmjvb commentedBasic composer 101 again: No need to make it more difficult.
This assumes those packages only contain a composer.json. Obviously, you need the folder contents when they start to have more than just a composer.json.
Also, several existing distributions already use --no-install on the create-project command. That is for allowing to make the desired changes on the downloaded package. Folow up with composer install. That is the way to get rid of drupal/core-recommended and replace it with drupal/core.
Comment #23
greg.1.anderson commentedHere's an updated patch with comments added to just the legacy project. Once we have wordsmithed the one project to our satisfaction, we can duplicate equivalent text in the recommended project as well.
Setting to 'needs work' because a) it does, and b) there's no need to run the tests on this patch; I changed only a .gitignore file.
Comment #24
Mixologic@mmjvb If you're planning on participating on core development of composer initiative issues, please participate in a constructive manner that isn't insulting or demeaning. Running composer create-project on a directory with solely a composer.json is documented in a singular line of all of the composer documentation, and is neither "composer 101" nor "Basic". Its an obscure piece of trivia that you happen to know.
That obscure piece of trivia isn't relevant in this case, because, as you said yourself
This issue is about *adding* a file to those packages for .gitignore, and as such isn't suitable for testing the way you described.
Comment #25
mmjvb commented@mixologic It is these kind of responses from you that makes me stay away from that project as much as possible.
Comment #26
aaronmchaleI'm a little concerned that some of the discussion here, as valuable as it is, might be taking the issue a little off track. The discussion around how best to document and setup ones local environment for contributing to the Composer initiative development is of course valuable and important, but it should probably be addressed in a follow-up issue.
@mmjvb @Mixologic please consider reading the Drupal Code of Conduct before allowing this disagreement to escalate any further.
Going back to the primary topic, one thought that popped into my head is that in both the LegacyProject and RecommendedProject templates we would have gitignore files which are almost identical, the only difference being (as far as I can tell) the inclusion of "/web" for at the beginning of directories for one of the gitignore files. I wonder if instead of having these two static files having the scaffold plugin generate the gitignore file with the correct paths based on which template was used would be a good idea. One advantage of doing that would be that it reduces the risk of these files becoming out of sync in the future, and means updates to the gitignore only have to be made in one place, rather than two.
Anyway, think I'm going to lye down, my cold seems to be getting the better of me 🤒
Comment #27
ressaI agree that it is always worth aiming for avoiding extra and duplicating work, but if it will delay the patch too much for inclusion in the next release, perhaps the task can be postponed for later refactoring? Except, of course, if it's very simple to do.
I hope you feel better soon @AaronMcHale!
Comment #28
mmjvb commented@AaronMcHale Sorry to hear that you consider this topic going off track. My understanding is that this issue is about what to do related to a .gitignore in the to be introduced project templates. Looks like the OP considers this issue still open for debate. Clearly a .gitignore is related to how you manage your project. The point I made was there is no need for the mini repository. Copy your own template and use composer create-project or composer install in your new project. Consider the mini repository shooting with a canon at a fly.
Surely, the way you manage your projects influences your opinion about the alternatives provided.
Comment #29
greg.1.anderson commented@mmjvb #19 is really about testing this issue in a context where #3085354: Better default behavior for scaffold-created .gitignore files could be tested. That bug was discovered while working on this issue. The situation is that
composer create-projectwill create a git repository at the target location, but only if it creates the project from source rather than from a dist. When doing a dist install, Composer simply unpacks the archive, and no git repository is created. When there is a git repository, the scaffold plugin behaves differently. The details are outlined in the linked issue.@mbayton and I discussed testing that issue and this issue at BADCamp. The technique in #22 is not sufficient to test #3085354, because it does not create a git repository, which is a necessary precondition to expose that bug. I am not experienced enough with Composer to have known in advance that
composer create-projectcan even be used on a bare composer.json file. I am still unclear on how create-project differs from acomposer installin this instance; I think it would be necessary to read the Composer source code to discover the difference. In any event, though, a basiccomposer installis sufficient to do basic testing of the .gitignore in this issue. It is really good that @mbayton ran this code throughcomposer create-projectwith a packages.json file, so that the code would run in-situ as it will once this patch is committed. We would not have found #3085354 otherwise. However, it is not necessary to test like that every time. Simpler techniques will suffice for most runs through the iterative development process.The interrelationship between the different parts of this rather complex system are why I feel like the topics being raised here are not out of scope for this issue. The simple question of what we should put in our .gitignore touches on many different parts of the system, and shining light on some things that have not been considered yet. It's good to try to keep things on topic and focused in an issue, but sometimes it's better to expose important points in the main thread that everyone is following. By all means, we should put the fine details in follow-on issues such as happened with #3085354.
Finally, regarding #26, I think this is a fine idea, although it should be discussed more fully in a follow-on issue. My initial impression is that it won't happen before the alpha code freeze, and even after the freeze, it might be considered to be too much complexity to do template replacement on scaffold files. We are currently doing this for the autoload.php generation, but only there. I'm undecided on this point at the moment, though.
And Finally^2, I think I have already made the point that we're beyond basic Composer here, even for basic issues like what to put in the .gitignore. Everyone is working hard here, so let's all be nice, and be nice about being nice, k? Thanks everyone.
Comment #30
aaronmchaleThanks @ressa!
Re @NEW in #28
I supose it would, I provided my initial thoughts in comment #5, I'm assuming you're referring to the options explained in the issue summary?
Re @greg.1.anderson in #29: Ah I now see more clearly why more of the recent discussion may have been more on-topic than I had initially thought.
Comment #31
mmjvb commentedNo need to read the code, its documented:
Appreciate the elaboration on the circumstances. Wasn't aware of the consequences of using source. Not convinced its relevant here. Agree that the contents, number of and what provides them are relevant here. Sounds like a responsibility for the new scaffold plugin to me.
Comment #32
greg.1.anderson commentedThis does not describe in what way
composer create-projectis different thancomposer installwhen used in this way. I think for most purposes,composer installshould be sufficient for testing this issue. I don't think that further examination of composer create-project is necessary, unless someone wants to help out with #3085354. If you have any concerns about the test coverage of that issue, please comment there.Comment #33
mmjvb commentedThat is documented as second line of the documentation:
Comment #34
mbayntonI think we have here about as carefully groomed and documented a .gitignore as one could ever aspire to. I learned some things reading @greg.1.anderson's comments. They're definitely warranted and valuable.
I reverted one semi functionality-related thing that was done in 23, to make the
!example have one # again and not two. This is being very pedantic, but the only reason for it is I sort of envisioned our original "persona b" folks who want nothing Composer lays down in their repo might use this .gitignore bysed s/##//g-ing it. In that case they'd have an active but unused!/modules/custom/module_in_repo.Also fixed a typo.
There've been no other reviews of the documentation that we needed to add so far, so I feel like it's too soon to copy to RecommendedProject/.gitignore, but I foresee doing that tomorrow if there are no more changes.
Comment #35
mbayntonCopied the documentation to RecommendedProject
Comment #36
mile23OK, so we have two .gitignore files and they're essentially the same, just that the recommended project one uses a web/ path.
I can imagine a use case where someone wants to update their site to use composer, so they create-project a a legacy project and then just copy all the files into their existing Drupal repo.
Then they're angry because we messed up their .gitignore file. But wait, they're using git so they can revert, problem solved, we’re all happy again.
In the use case of a tarball site that has a preferred .gitignore configuration, our composerizer tool will likely create-project using the legacy template and then copy the existing files back over the scaffolded ones which is similar to the previous use case.
This leads us to some ambiguities about how to handle this situation, such as whether the composerizer tool should fix it, etc. Our idea of an MVP for the composerizer is that it should be able to detect the difference and warn the user about it with a suggested course of action.
Given that we’ll do this in the composerizer tool, we can go ahead with adding .gitignore files here, and add this scenario to the spec for the tool.
So RTBC yay.
Comment #37
mile23Comment #38
mbayntonFixed up IS a little bit.
Deleted suggestion to remove [web-root]/example.gitignore because many other files are also getting scaffoleded into the web root that aren't strictly necessary.
Comment #39
MixologicI think people do this with private composer repos', like private packagist and/or satis repos locally. Maybe this could be "register them in a package repository"
Either way though +1 on RTBC. There'd be no real way to efficiently document exactly how everything is done, so probably better to do this, iterate as necessary.
Comment #40
greg.1.anderson commented#39: Yeah, a custom module does not necessarily need to be private, so I thought I'd just stick with the simplest explanation. If someone comes here wondering about private modules, they can search for how to add private repos to Packagist, which will get them to Private Packagist and Satis and etc.
Comment #41
webchickMy initial 2 cents:
1) The documentation here is excellent. I understand what each* section of this is trying to do, and feel confident I could make adjustments within the examples for my site.
2) That said, keeping said documentation/examples in sync going forward between the two files sounds like a pretty tough maintenance burden. It'd be ideal if we handled this with _one_ file, e.g. "example.gitignore.txt" or something, like we do in e.g. sites/example.sites.php, that could serve as the basis for both. (I see there's a concrete reason for the discrepancy, which is that one's examples start with web/ and the other's doesn't, but I wonder if we could capture that in the docs and direct people to do the right thing, instead.)
3) I said each* ... the asterisk is that I don't understand what "add all of the scaffold file locations" means, and I'm not sure we should expect average site builders, especially those new to D8/Composer, to know what that means, either. It /seems/ to mean all of the "top-level" files/directories that are not /vendor. So it'd be nice if we said that (or some other similar instruction that's actually correct ;)).
4) Similarly, this also feels like a maintenance burden because I could see the list of top-level files changing and us forgetting to update these docs. I doubt it, but have to ask... is there any way to programmatically (e.g. automated test; an automatic-generated hook_help() page that we could point to?) ensure that the list here is always up to date with what's "live" in core?
Not bumping down to "needs work" since most of these are questions, though it would be nice to "English-ize" the scaffold piece a bit, unless you think this is a me problem vs. a general "site builders out of the loop on Composer stuff" problem. :)
Comment #42
greg.1.anderson commented2) It was suggested that we could scaffold these files into place. If we did that, though, we would have to add a templated scaffold files feature to the scaffold plugin. I was reluctant to add the complexity, but it is something we could consider.
3) The scaffold files are mostly at the top level, but there are some in sites and sites/default, for example. You are right that this list can change over time.
4) If the user .gitignores their vendor directory, and does not .gitignore all of the scaffold files, then the scaffold plugin will edit the user's .gitignore file and add ignores for any scaffold file that should be ignored. Maybe rather than trying to keep the scaffold file section up-to-date, we should instead just document this behavior and tell users what to do with the .gitignore changes added by the tool. (Commit them.)
Comment #43
mbayntonI agree that adding a template-based generation of the .gitignores is better for maintenance, but that's a problem that will only come up the first time they need maintenance. In the meantime, as you can see from all the stuff in these .gitignores, it can be a bit of a chore to come up with the correct one. Do we want to ask every user of 8.8.0 that starts a project with Composer to do that chore (well just about, who doesn't use git ;)), or can we ship the static files and create a follow-up?
Comment #44
greg.1.anderson commentedSetting to 'needs work' for #42.4.
Comment #45
greg.1.anderson commentedCreated #3086819: Allow template substitutions in scaffold files to serve as either a follow-on or blocker.
Comment #46
aaronmchaleIf the gitignore gets generated based on the template that the user starts out with, we wouldn't need to ask every user though, we would only need to start getting interactive if we decide to do approach #1 in the IS.
Comment #47
webchickFor #3086819: Allow template substitutions in scaffold files I would say that's a (REALLY) nice to have follow-up. I do think we still need to reduce this patch to only one "example" file that gets copy/pasted, even if it has stuff the site builder needs to reconcile like
[webroot]/path, though I'm happy for another committer to say I'm wrong about that.Comment #48
greg.1.anderson commented#3086819: Allow template substitutions in scaffold files is green, so it could use docs, community reviews, etc.
Comment #50
greg.1.anderson commentedHere's a patch addressing #47, assuming that #3086819: Allow template substitutions in scaffold files is committed.
I had an idea that would allow us to use
/[web-root]/core/instead of/[web-root]core/, but it would require another update to #3086819. Maybe that could be done as a bugfix follow-up. If these do not make it in for 8.8.0-alpha1, then I'll go ahead and make the improvement.Comment #51
greg.1.anderson commentedHere is a proposal to provide a scaffolded example.gitignore to replace the existing example.gitignore file. The theory is that this is documentation, and can be backported to the 8.8.x branch. On the 8.9.x branch, once #3086819: Allow template substitutions in scaffold files is committed, then the
/[web-root]/pattern in the file will be automatically renamed to/or/web/, as appropriate (or to some other value, as stipulated in the "locations" section of the drupal-scaffold metadata. This file is still scaffolded as "example.gitignore", as the user must examine it and decide what edits to make to match the strategy for their particular site.Note also that we are deliberately changing example.gitignore here. It is a goal to ensure that the tarballs produced by the scaffold operation have high fidelity with the tarballs produced with the historic automation tools; however, I feel that it is okay to decide on a case-by-case basis to change the contents of existing files if new contents is more appropriate in Drupal 8.8.x / 8.9.x.
Comment #52
mbaynton+1 to @greg.1.anderson's proposal.
Comment #53
aaronmchale@greg.1.anderson so just to clarify, what you're proposing in #51 means that when someone creates a new Drupal site, regardless of which template they use, a .gitignore file wouldn't automatically be created but instead an example.gitignore file which they can modify then move/copy to .gitignore?
Comment #54
greg.1.anderson commented@AaronMcHale That is correct.
Comment #55
MixologicWhat are the interactions between this issue and #3086819: Allow template substitutions in scaffold files ?
If the latter gets in, does this one need to change? If this goes in, and then #3086819: Allow template substitutions in scaffold files is committed, do we come back and reopen this to leverage the new features? Im not sure what might be postponed on what.
Comment #56
greg.1.anderson commentedIf #3086819: Allow template substitutions in scaffold files goes in, we just need to come back here and edit some of the comments. This file will be correctly processed by that patch.
Comment #57
MixologicI didnt mean to actually set this RTBC before, because of my questions in #55, but they're answered, so now it is. Groovy.
Comment #58
aaronmchaleRe #53 and #54: sounds good, thanks for clarifying :)
Comment #59
alexpottThis issue needs an issue summary update so the latest state of the patch - once that's done the issue can go back to rtbc.
Comment #60
geerlingguy commentedJust ran into this as I'm starting work on switching a number of projects to use and recommend the drupal/recommended-project template, but realized after running
git add -Athat it added all kinds of files that should not be in a git repo (regardless of the validity of committing all the vendored files).The git output included a large number of warnings out of the box:
Committing the vendor stuff, I'm not sure if there's a way around some of those warnings. But it's certainly not a pleasant experience.
I think Drupal core should be opinionated here, and I'd rather see all the vendored files excluded by default. They could be in a gitignore section that says "If you want to commit all your site's files to your git repository (warning: you should know what you're doing—this could introduce a security risk), you should comment out all the lines below."
The problem is, most (all?) devs I've worked with throw the kitchen sink at local development, meaning modules like devel, php, etc. are all enabled and present locally. If we have everything committed by default, we don't have the protection of those modules not being installed if someone installs only prod dependencies with Composer.
But either way, we definitely need to ship something (because it's even more important to gitignore the files dir, settings.php, etc., and right now they aren't!), so if that bikeshed is going to stir up another month's waiting on this, please disregard for now.
Comment #61
mile23Following your link, it looks like you're using this line:
If you remove the
@dev, you get the stable release of Drupal 8.8.0, and you also don't end up with embedded git repos. You can also add--prefer-distto make it more explicit that you don't want repos:Then
git add -Adoesn't report any embedded repos.Comment #62
ressaIf you just want the latest version, this also works:
composer create-project drupal/recommended-project my-project -nComment #63
geerlingguy commented@Mile23: Indeed, using prefer-dist and stable results in only one warning, which is much less intimidating:
@ressa: True, however, even in documentation I feel a lot safer at least specifying a major version (e.g.
^8) because a lot of little dependent things are not yet tested against Drupal 9.Comment #64
greg.1.anderson commented@geerlingguy: One thing that is not clear to a lot of folks is that the version you specify on the command line with
composer create-projectis not saved anywhere in your project. It is only used to select the initial version of Drupal to install.Composer will use the version you specify on the command line to select some version of
drupal/recommended-project. The version that it selects has its own composer.json file that includesdrupal/core-recommended: ^8.8. It seems logical to most folks that if they use ~8.8.0 to installdrupal/recommended-project, that future updates will continue to use that constraint, but that isn't the case; the ^8.8 from the template will be used, unless you change it yourself after the project is created.It's kind of weird, but that's how Composer works.
Also, related to all of the git warnings, Composer will add a .git directory to any vendored dependency that it installs from source. It has to install dev dependencies from source, and the behat/mink components you reference above have not had a stable release in over three years. Folks from the community have been asking for a stable tag periodically, but it has not been provided.
Comment #65
mile23Regarding #61... @geerlingguy was working off the change record, not the documentation. I updated the CR to reflect that there is more up-to-date documentation.
We still need to deal with what sort of .gitignore stuff we care about in this issue. :-)
Comment #66
nicxvan commentedI created a project over the weekend using this.
I was unaware that there was no .gitignore so I ended up adding not only the vendor files that are apparently contested but also site files, settings.php etc.
I think when it comes to something like .gitignore it's better to be more aggressive with the ignore if you look at the two failure modes when creating a project.
Failure mode 1 no .gitignore:
You end up with all the default/files, settings.php, and vendor.
Resolution for failure mode 1
Delete the files.
Adding those deletions to git
Adding the .gitignore
Failure mode 2 aggressive .gitignore:
You end up with no vendor files in git that you expected.
Resolution for failure mode 2
Modify .gitignore to stop ignoring vendor
Add those files
The only other comment is regarding modifying a scaffold file if you decide you want to keep the vendor files. However there are already conventions for having a modified scaffold file with composer.
Looking at these two options I think it's clear that having the more aggressive .gitignore makes sense as it's easier to add a missing folder than removing many files and directories you mistakenly added.
Another possible solution, but probably more work would be to have two composer create profiles, like we have with standard and minimal.
One has no gitignore, one has gitignore.
This is a long comment just to say that I used this over the weekend and it felt unfinished and not ready for use. I didn't realize there was a different school of thought on including vendor or not, but I think of the two options, needing to modify something to include something is less painful than removing something you inadvertently included.
Comment #67
greg.1.anderson commented#66 makes some good points.
Also, I'm not sure why .gitignore is a scaffold file. Why don't we just add two different .gitignore files, one to the recommended template and one to the legacy template? We could add a test to ensure they stay in sync. That would probably be better than keeping this blocked on the template substitutions issue. Also, making this a scaffold file isn't a good idea (even with template substitutions) because .gitignore is highly project-specific and usually modified. It wouldn't be desirable to to have a project's .gitignore be overwritten every time there is some minor update to the file contents in the assets file (or worse, prior to #3092563: Avoid overwriting .htaccess changes during scaffolding > security problem landing).
Comment #68
mbayntonSo that's #35, right? It's already been RTBCed once before we switched directions to making it scaffolded. Should we shoot to return this to RTBC via #35?
Comment #69
greg.1.anderson commentedYeah. We moved away from #35 after #41 in an attempt to use templating to keep the .gitignore's DRY, but the templating didn't go in.
So, I think we should in fact go back to #35. Let's compare and see if #50 made any substantive changes to what was ignored (I don't remember) and also update the issue summary and add a change record. Then we can review and move this back to RTBC.
Comment #70
mbayntonLight changes between #35 and #50, incorporated without scaffolding here.
Comment #71
mbayntonIssue summary
Comment #72
greg.1.anderson commentedWhoops, I think I spoke too soon in #69. There's another thing that is bothering me here.
Currently, if you download Drupal from drupal.org (e.g. version 8.8.1), then you will get (once you untar it) a Drupal site that has no .gitignore file, but that does have an example.gitignore file. If we committed #71, then there would be both an example.gitignore AND a .gitignore in the tarball downloads (because these are now generated from drupal/legacy-project). There has never been a .gitignore in the download files before. If we added one now, then folks who are still using
drush pm-updateto update their sites will find that each Drupal update will start overwriting their .gitignore file. Do we want this for Drupal 8.9.0? Do we want this for Drupal 9.0.0? Perhaps we should consider that the .gitignore should appear in the template projects, but should not appear in the downloads. At a minimum, we should decide what the aspirational behavior is.We also have not addressed #41.2. At a minimum, I think we should have a test that detects variations in the template project .gitignore files with the example.gitignore file at the root / in the scaffold assets directory. (Note that it would be easier to write this test if the non-comment, non-blank lines of example.gitignore always exist in the project template .gitignore files.)
We should also take some time to discuss the implications of #66. The example.gitignore file is set up by default to ignore /vendor/. In a way this is an odd choice for sites that are usually going to be maintained with
drush pm-update(perhaps the primary use-case for the download tarballs), and yet somehow this was the default recommendation. Back in 8.0.0, we had:In 8.1.x, this was changed to:
In 8.8.x, we have no .gitignore at all in the template projects, but we still have the example.gitignore file, and it recommends ignoring /vendor/. While I recognize that there are valid use cases for committing vendor, I'm not sure that it's best to reverse the recommendation from the example gitignore file, which has recommended ignoring vendor since 8.1.1. Perhaps we did this because it would be easier for a user to remove comments (to convert commented-out vendor into an ignored vendor) than to have documentation on where to add the comment characters for users who want to commit vendor et. al.
I updated the issue summary with things that we still need to consider before calling this issue RTBC.
Comment #73
aaronmchalePart of me agrees with an aggressive approach, because as it was pointed out, it's harder to remove something that you already committed in that even if you remove it by commit it still exists in past commits, but it's trivial to commit something that was never committed in the first place.
That said, core doesn't ship with a settings.php, only a default.settings.php, settings.php is created during install. All I'm saying with that statement is that it's a precedent.
That's it, that's all the thoughts I have right now.
Comment #74
ressaI was a little surprised to see that there was no "starter"
.gitignorefile included when I began using thedrupal/recommended-projectproject template. If it is the easiest solution to build, can't we just put anexample.gitignorein the root of both Composer installs as well as tarball downloads, which people can rename themselves to.gitignoreif they want to use it? @greg.1.anderson writes:I agree that probably only template projects needs a
.gitignore, so leaving it out from the tarball is an option. I would think that not many users whodrush pm-updatetheir sites use Git, but I could be mistaken.After reading the comment by @nicxvan in #66, I agree with having an aggressive, more exclusionary approach as default, yet also documenting the more inclusive way, like how to handle the
vendorfolder. Like geerlinggy writes in #60:Comment #75
tyeth commentedIt feels all that's been said is enough to have fleshed this out...
@ressa +1
I'd like to see example gitignore in the tarball plus recommended-project. What's the harm?
Can we ship this please.
Comment #76
Anonymous (not verified) commented@tyeth +1 - seems like there is no reason that a example.gitignore couldn't be merged in today, it will break nothing.
Deleting a .gitignore file is a very simple step that is easy to explain and takes no time at all, renaming example.gitignore is equally simple. Rebuilding a .gitignore file for a large project like Drupal with zero guidance is confusing as there are many opinions on it. I also just do not get the reasoning behind stating that "composer is the recommended approach to managing your Drupal project going forward" then NOT providing support for composer based builds by including a .gitignore in the recommended project template.
Comment #77
bserem commentedIn parallel to this issue there was also a PR in github about the same thing: https://github.com/drupal/recommended-project/pull/2#issuecomment-616630579 with several upvotes. Thanks to @drumm for pointing to this issue right here.
I am also in favor of an example file, like already discussed!
Comment #78
jcandan commentedWhat is the community's thoughts on this enhancement to these excellent patches?
Comment #79
lpalgarvio commentedHello,
Sorry for my extremely long absence (months). I decided to do some community work today as I've been having to work on Drupal 8 projects in the last few weeks.
#78
I don't think generic non-drupal stuff belongs in a project .gitignore.
that should be user centric on the user's global .gitignore_global file.
About the opposing schools of gitignore this largely depends on the project in my opinion.
For old unsupported Drupal 6-7 projects, or complex big projects, or projects that lack CI i might use the "commit all" approach" including vendor, or everything but vendor.
Then for everything else, including proper pipelined CI projects, small projects, projects without any obsolete or missing **disapeared from web** dependencies i will use the "commit only custom and composer.json" approach.
I think having proper wording in the .gitignore might help alleviate concerns.
I'm providing some input for consideration as i've just pushed for upstream changes at github/gitignore and gitignore.io:
- https://github.com/toptal/gitignore/pull/297
- https://github.com/github/gitignore/pull/3386
- https://github.com/toptal/gitignore/pull/296
- https://www.gitignore.io/
- https://www.gitignore.io/api/drupal
Feel free to comment if i should change any wording in those merge requests or paths in the proposed changes.
Perhaps if these are good enough or after fixing if needed they could be reused here?
Comment #81
ressaI just created a Drupal 9 instance with Composer, and see an
example.gitignorefile is included, which is great. But it is located in thewebfolder, and also seems very limited in its scope ...Comment #83
leksat commentedMy user experience:
Because there were no
.gitignorenorexample.gitignorefiles in projects created bycomposer create-project drupal/recommended-project, I was copying.gitignorefrom older projects. By doing that I was adding all the scaffolded files under VCS. Like in the good old times 😅And of course I completely misseddrupal/core-composer-scaffoldexistence and all of its cool features.I just want to say that
.gitignoreshould be definitely shipped withdrupal/recommended-project🙏Comment #84
benjifisherI added a note to Starting a Site Using Drupal Composer Project Templates mentioning the file
example.gitignorein theweb/directory. Anyone who reads the docs should have an easier time than @ressa (Comment #81).Comment #85
makkus183 commentedThanks @benjifisher for adding that note mentioned in #84 to the info page.
My user experience:
I want to have the
.gitignorein project root instead of the web root. So i was unsure if i just shouldcptheexample.gitignoreand keep it in the webroot directory (where the example file is located) or should move it to project root.(I simply moved it to project root, but i wasnt sure if thats the "recommended default way" ).
Comment #86
mchelenYeah #84 thank you for pointing this out, it's a little unclear if the
example.gitignoreis supposed to go inside the/webdirectory or in the repo root? The/vendorpath only works if.gitignoreis in the root level, in which case all the other paths need to be updated to include/web.#85 I ended up using the example
.gitignoreinside the/websubdirectory, and creating a second `.gitignore` at the repo root containing/vendor.Comment #88
zuhair_akI would also love to have this patch committed. Thanks to @benjifisher (#84) for adding the documentation
Comment #89
ressaI agree @zuhair_ak, it would be great, but a few Remaining Tasks were added in January 2020 (see @greg.1.anderson's comment) which we probably need to decide on, before this can move on.
I shared my point of view in #74, and those who want to improve the chances of moving this issue along and include an example
.gitignorefile in the root of a fresh Drupal installation should feel free to share their opinion on the Remaining Tasks.Comment #92
brad.bulger commentedI would like to see both project root and web root files, neither of which would be literal .gitignore files. Rename the existing example.gitignore file to something like example.webroot.gitignore and add example.project.gitignore, perhaps, to make it unambiguous. This is the model for eg settings.local.php.
I'd also suggest ignoring vendor by default, as well as files created from scaffolding assets. The suggestions along those lines in this article by @james.williams make sense to me.
Comment #95
ben coleman commentedI ran into this recently while noticing that the Drupal 9 example.gitignore file will only work if in the project root. Since I create Drupal sites via Ansible currently, I'm copying my own customized version of that into the project root. I still like the prospect of two example .gitignore files, one geared for web root, and one geared for project root. I'd probably have Ansible copy the project root one and have Ansible make any changes I'd want.
Comment #96
ressaIt's so sad that this issue has stalled.
I just started a new Drupal 10 project, and using the .gitignore file from the MR here worked beautifully.
I really appreciate all the hard work which went into getting it. Not only are the rules very precise, so that only relevant files are committed, the comments are also extremely helpful and enlightening. For example in helping to choose whether to include custom modules and themes as separate repositories, or simply commit them directly to the repository of the site where they are used.
This is the kind of information which is invaluable for a new Drupal user, helping them get started well, on their Drupal journey.
I hope this issue can be restarted, so new Drupal users can have a .gitignore file included in freshly created projects before too long. It will save them much time and trouble down the road.
Comment #98
crasx commentedBringing this back to life @ DC Pittsburgh. Learned way too much about the Drupal composer project templates. Some brilliant stuff for sure.
First, I wanted to share this nifty command I came across to make testing this easier (ie: create-project from a local directory)
composer create-project --prefer-dist drupal/recommended-project="@dev" 3082958-test-`date +%s` --repository '{"type": "path", "url": "drupal-3082958/composer/Template/RecommendedProject", "options": {"symlink": false}}'source
I tested MR1627 using the above method with both legacy and recommended project and they worked well. I also think the approach of a .gitignore file with commented lines makes the most sense.
My initial hesitation with this was in the multiple gitignore files. But looking back at #3082958 it makes sense that we would have different gitignore files for each project template. The rules for those are pretty tightly coupled to the template they come from.
We have the example.gitignore file that gets scaffolded in from drupal/core, but that only has rules for sites/default/… I played with the idea of putting everything in example.gitignore and scaffolding it to project-root instead of web-root, but I think that will make the file overwhelming as noted in 3082958.
Now that we have a few years of composer deployments under our belts I think we can make these changes with a little more confidence. I +1 the approach in MR 1627. Using this approach has the added benefit of being compatible with projects like acquia/drupal-recommended-project who also provide a gitignore file via composer template (and not via scaffold)
In terms of remaining tasks I think we might want to consider opening another ticket to deal with the non-composer gitignore files. If we keep this ticket scoped to the composer templates we can probably move this along
Comment #99
ressaThanks for the thorough review @crasx. I recently started a Drupal 10 project, and the example .gitignore worked really well (comments in #96).
Getting this committed will help users with limited Drupal and Git experience start out on the right foot, and be a step in the right direction of attracting more Drupal site builders and increase Drupal's potential user base, as proposed by Dries in his blog post Drupal is for ambitious site builders.
Another relevant ambitious site builder issue would be getting a README included in the Recommended project repository: #3144211: Add README.md to composer project templates. Maybe that issue can get some attention at Pittsburgh2023 as well? :)
Comment #100
smustgrave commentedCan the MR be updated for 11.x please.
Comment #102
ressaI tried re-basing via the Gitlab GUI (as someone else also recently did) which resulted in disaster, and I am getting
Failed to create branch '3082958-add-gitignores-11x': invalid reference name '11.x'from Gitlab when I try to create a new branch ...So I am attaching a good old patch, what is essentially #70 again.
Comment #103
smustgrave commentedThanks!
Comment #104
ressaFantastic, thanks @smustgrave and @crasx for moving this issue closer to completion!
Comment #105
brad.bulger commentedIs the project root .gitignore file meant to replace the webroot example.gitignore? The project root file looks to me like it does everything the webroot file does except ignore /vendor/, which doesn't initially exist in the webroot anyway.
Comment #106
crasx commented@brad.bulger it is not. The example.gitignore in Drupal root is used when a user downloads Drupal as a zip, the others are used during composer create-project. Do we maybe want to add a post composer create-project hook to remove example.gitignore?
Also linking #3294241 which removes the legacy project.
Comment #107
brad.bulger commentedI see. I'd think comments in the files saying something like what you just said would suffice.
Comment #108
crasx commentedUpdating status, planning on circling back to this soon
Comment #109
crasx commentedAdded some docs to the top of gitignores
Comment #110
crasx commentedComment #112
ressaThanks @crasx, it's more precise now.
It looks like core/assets/scaffold/files/example.gitignore also needs to be updated. I also see now that Composer is not capitalized a few places, and there was a +80 character line, so here is a re-roll.
Comment #113
smustgrave commentedTests are green and change looks good still.
Comment #114
quietone commentedI am doing triage on the core RTBC queue.
1) The Issue Summary has a proposed resolution but there are 4 remaining tasks. In reading the comments I see that in #89 @ressa, pointed out that they need to be decided on. From #89 onwards I don't see discussion of those 4 points. Have those items been resolved and I missed it? Was it done in a Slack discussion?
2) There is a change record here which has not been touched since Jan 2020. That should be reviewed for accuracy and to update the branch/version numbers. Adding tag and setting to NW for this.
3) I applied the patch and read the comments. I thought the new paragraph in the 2 example.gitignore files could be easy to read if it were in plain English. I have made a patch as a suggestion. I am not running tests, that can be done if there is agreement to keep the changes.
Comment #115
quietone commentedI just remembered that because this is changing a file managed by the site, it should have a release note snippet. Correct me if I am wrong.
I've added that heading to the issue summary.
Comment #116
ressaThanks @quietone.
About deciding the structure (the first three items) we probably need @mbaynton, @greg.1.anderson, @Mile23, and @Mixologic to chime in, and make a final decision.
About committing
/vendorand related files by default or not (the fourth item), since #60 by @geerlingguy December 2019, the consensus in the comments is to ignore/vendor, and these users have stated that they prefer to not include/vendor:Currently, the patch includes
/vendor, so as an example, I am attaching a patch which reverses this, and excludes/vendor, and also directories generated by Composer and scaffold files. What do you all think about that?Comment #117
ressaAmbitious Site Builders use Git, and it would be nice if they had a great
.gitignorefile in their new Drupal 10 projects.Comment #118
smustgrave commentedNot sure who could make the call about those remaining tasks. May be worth posting in #contribute on slack?
Comment #119
ressaI don't use Slack, but If you could nudge it along by mentioning it in that channel, that would be fantastic.
Comment #120
joachim commentedThat seems rather specialized to go in uncommented.
On all project I've worked on, web/modules/custom is committed to the repo.
If we have our own modules in a Composer Packagist, they might go in web/modules/COMPANY_NAME for example.
Comment #121
ressaThat makes sense @joachim, do you have a suggestion on how to reword it?
In the meantime, here is a re-roll, to match changes in file locations, and extension.
Comment #122
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #123
ressaI tried this and failed (see #112). Should we stick to an old school patch?
Comment #124
smustgrave commentedTagging for framework manager to hopefully get this moving.
Comment #126
nicxvan commentedI'm moving the patch to an MR
Comment #128
nicxvan commented@ressa I was able to convert your patch to an MR.
Comment #129
nicxvan commentedHiding outdated patches.
Comment #130
ressaPerfect, thanks @nicxvan :)
Comment #131
imclean commentedI'm a little unclear on this. Wouldn't
core/assets/vendoralways be ignored if/core/is ignored, as suggested in the previous section? Same with contrib directories.Comment #132
ressaIt was added in comment #50 by @greg.1.anderson, and taken from the
example.gitignorefile added in 2018, so perhaps it can be handled in a follow up issue?Maybe a framework manager can give it a look over? It would be great if this improvement got committed in 2024.
Comment #133
smustgrave commentedLearned something new.
So for the framework manager to take a look can the pros/cons on each remaining task be listed in the summary vs needing to read 130+
Comment #134
mile23+1 on #120. We should not be instructing people to make new packagist entries for their custom modules, and we should not ignore the custom modules directory.
Comment #135
mile23We also need to summarize decisions here in the IS, so a maintainer can review it easily.
Comment #136
ressaI agree, the default
.gitignorefile should be aimed at the broader audience, and managing modules via Packagist is rare.Comment #137
smustgrave commentedIssue summary is still needed though.
Comment #138
quietone commentedComment #139
ultimikeThe fact that there is no example.gitignore in the project root when using the drupal/recommended-project Composer template has always struck me as very odd, especially considering that one exists in the Drupal docroot.
I've been complaining about this for a few years now (mainly while muttering to myself) and unfortunately for me (heh), with a little help I was able to find this issue. Seeing how close it is to the finish line, I'd love to be a part of getting it done.
I just reviewed the existing issue summary and the last 70-ish comments. FWIW, my feelings are as follows:
1. I don't see any need for a project-level example.gitignore to be part of the Drupal core tarball. I really think it is important for one to be included as part of drupal/recommended-project. The fact that we've named it "recommended-project" makes it a bit opinionated, no? So, there's no reason why we shouldn't have an example.gitignore that recommends that Composer dependencies are ignored by Git.
2. I think a more aggressive approach (as @nickvan detailed in comment 66) is the way to go.
3. As I just alluded in my first thought above, I think it should be an example.gitignore and not a .gitignore file. I'm a bit confused though because the existing MR [!5622] has a title of "Add example gitignores", but it actually adding two .gitignore (not example.gitignore) files. Is this just a case where the title is old/incorrect? (related to the first "remaining task" listed in the issue summary)
Regarding the second "remaining task" (.gitignore in tarballs) in the issue summary, is this really something we still need to consider four years later? I think the whole point to this issue is to help folks newer to Drupal who are using drupal/recommended-project (or similar) to set up their code base properly. I think that if you're cloning Drupal core (or downloading the tarball - {{shudder}}), you probably don't need any help with setting up a .gitignore file.
Regarding the third remaining task (strategy to exclude .gitignore in downloads), I don't see any discussion about this in previous comments. Is this still an issue? If we decide to use example.gitignore instead of .gitignore, how does that impact this task?
Regarding the fourth remaining task (vendor committed by default), I think this is the easiest to decide - we should ignore the vendor directory. The fact that the current MR does this makes me think that this task is obsolete.
Finally, my only comment on the existing MR is that if we're including a rule to ignore PhpStorm files, then we should probably do the same for Visual Studio Code files, as the most recent Drupal Local Development Tools survey shows 55.4% of respondents using PhpStorm and 36.9% using Visual Studio Code - not an insignificant amount.
Let's figure out the next steps we need to complete in order to get this ready for review. It seems that updating the issue summary's remaining tasks is a priority, so any guidance that anyone can provide on that front seems like it would be most helpful.
thanks,
-mike
Comment #140
ressaThanks for nudging this issue along @ultimike, let's get it moving :) About your comments
I agree, and that's how it is now, after #116, where I summarized the general opinion (aggressively ignore) and created a patch accordingly.
The Issue Summary has this sentence, which I agree with:
I would prefer to not clutter the folder with an
example.gitignorefile, but prefer a hidden.gitignorefile, as it is in the current patch.About PHPStorm and VSCode, I agree -- let's add ignore rule for Visual Studio Code files as well.
About the two
example.gitignorefiles in the current patch, I have no opinion. Perhaps @mbaynton, @Mixologic, or @greg.1.anderson can weigh in, if they are necessary, or can be removed?My main goal is to get an aggressively ignoring
.gitignorein the project root ofdrupal/recommended-project, out of the box.Comment #141
aaronmchaleI decided to try out this gitignore for recommended-project in a recent project and am pleased to see it works well.
Something though I found odd, the .env line is commented out, I don’t think we should comment this out. I can’t think of a single case where you would ever want to commit the .env file, so if you have one you’re pretty much always going to be uncommenting that line. Or worse, forget to uncomment it and accidentally commit your .env file, which could be a real problem!
Let’s do ourselves a favour and have the .env always ignored by default. I think that’s in the spirit of this being a recommended setup.
Comment #142
james.williamstl;dr - I vote for an example.gitiginore file instead of .gitignore !
I reckon the ignore file would be customised on many (perhaps most?) projects, which would require tricks to get around the composer scaffolding, which can be tricky and frustrating if & when updates are made to the original version of the file in future. It would become an extra thing for core release managers to keep track of changes to, just as they currently have to explicitly state when files like .htaccess are changed. (I suspect putting more responsibility on them is unhelpful & makes the Drupal project less sustainable.)
I do not see the .gitignore file as a 'functional' file, it's much more of a development / project-management file - so more like settings.php, which we have an example.settings.php version for too.
But regardless of how any one of us sees this file, the very fact that there are opposing schools of thought - as evidenced by the original report in this issue's summary, and the issue this one came out of - makes me think that we really shouldn't be imposing an approach too much, but instead providing an easy place to start from. For me, that means an aggressive example.gitignore, rather than confusing users with a .gitignore file that will easily lead users to have partially-built codebases that would not be functional. An incomplete codebase would also encourage running composer on production, which I don't believe is a good idea either.
---
Meanwhile, let's be careful about getting confused about what drupal/recommended-project actually is. It is not supposed to be a opinionated recommendation of a default codebase. That's what distributions are/were. Instead, it is simply about setting up the codebase with the recommended directory structure, with a relocated document root, and with versions of dependencies that are 'recommended' in the sense that they have been tested with Drupal core. I suggest that we carefully restrict this issue's goals to the scope of the two personas in the issue summary rather than getting too excited about each of our own opinions ;) Even if ideas like excluding .env files etc might be good! I just mean let's ensure the motivations that drive decisions in this issue align with what the packages exist for.
Comment #143
ressaThanks @AaronMcHale, great suggestion adding
.envby default, I have updated the patch.@james.williams: I think I missed the argument before, that using
example.gitignoreeases the burden on the core release managers, or didn't understand it. But it's a strong argument, so I have renamed the two.gitignorefiles files toexample.gitignore.Comment #144
nicxvan commentedI still think that having an actual .gitignore is more important than an example.
If there is a .gitignore and you don't want one then the resolution is a lot simpler than if there is no .gitignore and you expected one.
I also think the use case where a .gitignore is expected is a lot higher in the Drupal community, but I may be wrong.
As a developer using composer I expect vendor, core, and contrib to be ignored. When starting a new project and those get committed it is something I have to resolve. If I am using a host with no build process and need to commit those files the resolution is a lot simpler, I just delete or comment out the default gitignore.
For my use case having an example.gitignore does not solve the problem that brought me to this issue in the first place.
Also @ressa I'm curious why this is back in a patch rather than the Merge request?
Comment #145
ressaSorry @nicxvan, I forgot that you managed to create an MR in Gitlab, which I have updated.
I agree,
.gitignorewould be easier out-of-the box, so I'll leave it at that again, and not convert toexample.gitignore. So this commit only adds ignore rule by default for PhpStorm and VSCode folders, and.envfileCore maintainers should be allowed to veto
.gitignore-files, if it makes maintenance very hard. But it would be great with some feedback from them, to clarify if this assumption is true or not.Comment #146
ressa@james.williams:
As I understand it, when
composer create-project drupal/recommended-projectis run, thecomposer/Template/RecommendedProject/.gitignorefile will be copied to the root of the project. After that, it's left to its own devices, and Composer will not update it again.Comment #147
ultimikeHeh - seems like we're playing ping-pong with example.gitignore vs. .gitignore...
I really appreciate everyone's speedy comments in the past few days - while that's a great sign of a healthy debate about a feature we all want to make happen, it also could lead us to the dark side (bikeshedding).
From @ressa's (thanks for keeping the MR updated, by the way) previous comment:
Actually, I think that if we go with .gitignore, and then it is customized, the next time drupal-core-scaffold runs, it will overwrite the changes - just like what happens if robots.txt or .htaccess is customized. This, IMHO, is a solid reason why I think using example.gitignore is the way to go.
If we name it .gitignore, why don't we just use sites/default/settings.local.php instead of sites/example.settings.local.php (amongst other examples - pun intended)?
Back to the 4 remaining tasks in the issues summary:
Am I missing anything?
-mike
Comment #148
ressaThanks for the fast reply @ultimike, I do think that the current debate is healthy, and we are making progress, and feel we are pretty close now. I much prefer discussion to silence :)
About "3. To .gitignore or example.gitignore - undecided.":
That does seem to be the case ... But it looks like
.gitignorecan be excluded from any further updates during scaffolding, by setting thefile-mappingvalue tofalse. See Drupal's Composer Scaffold > Excluding scaffold files.I have tried to add this to the MR.
To experiment with excluding a file from getting updated in a standard
drupal/recommended-projectinstallation with an existing scaffolded file, try adding the below snippet, edit the/web/.htaccessfile, and update with or without it being excluded. The file is overwritten with default set up, but excluded from updates whenfile-mappingis set tofalse.It would be great to be able to actually test the patch with Composer commands locally, and have it do the scaffolding. Tricks for using Composer in local development exists, but is only for contrib modules, so far.
Comment #149
nicxvan commentedI agree that not updating gitignore after the initial scaffold is ideal as well.
Comment #150
aaronmchaleI'm in favor of
.gitignoreinstead ofexample.gitignoreand excluding it from scaffold updates.Comment #151
ultimike@ressa - thanks for keeping the MR up-to-date.
It makes sense that with
The .gitignore file that is being added to the drupal/recommended-project template will not get overridden each time the drupal/core-composer-scaffold plugin runs. This will ensure that if/when the .gitignore is modified, those changes are not overwritten the next time drupal/core-composer-scaffold runs.
While going with example.gitignore is my preferred solution, it is not a hill I am willing to die on and can (quite comfortably) live with this MR providing a .gitignore file by default.
With this being said, I think we can remove all of the remaining tasks, no?
If so, we can do that and then update the issue summary with more up-to-date info regarding the contents of the MR. Am I missing anything?
-mike
Comment #152
ressaYou're welcome @ultimike, and I agree that the four remaining tasks have been resolved, so the Issue Summary can be updated.
Comment #153
joestewart commentedWould overwrite be a better option for the .gitignore file?
https://www.drupal.org/docs/develop/using-composer/using-drupals-compose...
Comment #154
ressaThat could work better, thanks for the suggestion @joestewart. Feel free to update the MR using that method instead.
I am not even sure the current solution works, since testing Composer scaffolding locally is not simple, so I haven't actually had opportunity to run it ... (see last paragraph in #148, "It would be great [...]")
Comment #155
ressaI updated the patch to this, perhaps it could work?
Comment #156
ultimikeI've updated the issue summary and have been talking to some folks in the Drupal Slack workspace about this issue in hopes of getting more voices in this thread.
I've also hidden previous patch files - let's stick with the existing MR for this issue.
Of particular note, I'm really curious to figure out if/how we need to write a test for this change.
From @crasx's comment 98 above, I'd love to manually test this using the method he described, but I can't decipher exactly what I need to do to make that happen. Can someone post step-by-step instructions?
thanks,
-mike
Comment #157
smustgrave commentedRemoving that tag
But MR appears to have a spell error.
And also would love to see this land (hopefully by D11)
Comment #158
ressaIt looks like #3401988: Spell-checking job fails with "Argument list too long" when too many files are changed.
Perhaps someone can do the Git steps in #11 or #37, if that's what it takes?
Comment #159
smustgrave commentedMay just need a rebase
Comment #160
nicxvan commentedI'll do it
Comment #161
nicxvan commentedThat seems to have worked!
Comment #162
smustgrave commentedlot of comments to digest but this does appear to be working when used. Maybe any additional additions can be follow ups
Comment #163
ultimikeThanks, @nicxvan and @smustgrave - do either of you feel that a test of some sort will be necessary for this to get merged?
-mike
Comment #164
ressaAlso, can someone test with Composer commands locally and have it do the scaffolding, to check if the
.gitignoreis overwritten, or not? Or perhaps that has already been confirmed? I added it in the Issue Summary as a remaining task.Comment #165
longwaveI don't understand what
composer/Template/LegacyProject/.gitignoreis for or where it would be used.Also, I don't see how the
pathsetting works in the recommended template, because thecomposerdirectory isn't present in scaffolded installs.Comment #166
ressaGreat questions @longwave, perhaps the
LegacyProjectfile can be removed from the patch?It's a blocker for this issue, that we can't test this Composer template patch locally, to check if the scaffolding works.
@mbaynton kindly shared a method in #19, but things have changed since 2019, so perhaps someone can share an updated method? I have added two tasks in the Issue Summary:
[...]
Comment #167
benjifisherI will see if I can come up with testing instructions. But before I forget ...
There is some discussion of whether to call the file
.gitignoreorexample.gitignore., and the current MR uses.gitignore. The problem with that is it can have unexpected effects because Git will respect what it says in any subdirectory ofcomposer/Template/LegacyProject/orcomposer/Template/RecommendedProject/.TL;DR: I think we should go with
example.gitignore.Comment #168
benjifisherI think my previous comment duplicates the start of the issue summary:
@longwave asked on the MR:
In fact, the current approach does not work.
It is reasonable to guess that the
drupal/recommended-projectmetapackage is generated fromcomposer/Template/RecommendedProject/by cloning that directory, since currently that means just the one filecomposer.json. If that were the case, then adding.gitignorein that directory would add it to the metapackage.In fact, the metapackage is generated using the code in
composer/Generator/. Looking at the code there, I think it creates a metapackage with just the one filecomposer.json, just as it says incomposer/Metapackage/README.txt:I think that what will work is
recommended-project.gitignore, tocore/assets/scaffold/files/.composer/Template/RecommendedProject/composer.json.Back to NW.
From Comment #162:
@smustgrave, can you describe your testing steps?
Comment #169
benjifisherOn second thought, referencing the gitignore file from
composer/Template/RecommendedProject/composer.jsondoes not work. The code incomposer/Generator/Builder/DrupalCoreRecommendedBuilder.phpbuildscomposer/Metapackage/CoreRecommended/composer.jsonfromcomposer.lock.What does work is adding the
extra/drupal-scaffoldsection to the array inDrupalCoreRecommendedBuilder::initialPackageMetadata().Testing instructions
For manual testing, execute
and confirm that
composer/Metapackage/CoreRecommended/composer.jsonis updated as intended.If someone can confirm this, then we should add these instructions to the issue summary.
Comment #170
nicxvan commentedWhat if we called it template.gitignore?
Is there a way to have the scaffold change the name from template.gitignore to .gitignore?
The objection to using example.gitignore is that it will not by default ignore the files that a CI approach would want ignored whereas having a gitignore you don't want is much easier to resolve.
Example implies suggestion where template implies that something is meant as a starter I think.
Comment #171
benjifisherBTW, the other
drupal-scaffoldconfiguration incomposer/Metapackage/CoreRecommended/composer.jsoncomes fromcore/composer.json.Comment #172
nicxvan commentedJust to clarify what I think the requirements have become.
After setting the initial .gitignore it should not be overwritten if the user updates the gitignore.
The template .gitignore should not add gitignore rules to where the template is stored i.e. it should not be called .gitignore
An actual gitignore file was settled on because it is less destructive to have a gitignore and not want one than to not have a gitignore and want one.
Comment #173
aaronmchaleI agree that the end result should be that a
.gitignorefile (of that name) is placed at the root of the project after running thecomposer create-projectcommand; And that existing project should, ideally, not be impacted.Whether we call it
template.gitignoreor something different in our source control, I don't feel strongly, assuming we have a mechanism to place it at the project root with a different name.Comment #174
ultimike@benjifisher - thank so much for your work on this issue. I know it has been a few weeks since we discussed this at MidCamp - I appreciate your patience with me finally having a moment to take a look at this.
@nicxvan, @AaronMcHale - appreciate your input in keeping this discussion going.
To summarize what I believe @benjifisher is suggesting:
recommended-project.gitignore(it can't beexample.gitignorebecause that file already exists forweb/example.gitignorefor drupal/recommended-project), to core/assets/scaffold/files/.extrassection toDrupalCoreRecommendedBuilder::initialPackageMetadata():If I understand all this correctly, we are no longer involving
LegacyProjectat all, nor do we need to, correct?Am I understanding this correctly?
thanks,
-mike
Comment #175
aaronmchaleThanks for summarizing that @ultimike, based on what you're saying there I think that all makes sense, and it looks like the end result will be a
.gitignorefile in the project root, so I am happy :)Comment #176
ressaTo prevent this issue from stalling, it would be amazing if someone with the right skills could check locally with Composer if the scaffolding in the patch:
.gitignoreComment #177
ressaDrupal 11 is planned to be released the week of July 29, 2024. It would be great to include this improvement.
Comment #178
ressaDrupal CMS may finally push this forward :)
Comment #179
ressaAdding database export files such as db.sql and db.sql.gz, for example created by Drush or DDEV.
Comment #181
quietone commentedBased on this comment I am postponing this on #2381091: Improve example.gitignore .
Comment #182
ressaI hope that solving the other issue may help complete this "active .gitignore by default"-issue eventually (fingers crossed) since it will result in an amazing and complete .gitignore file, active by default, preventing an accidental commit of for example /vendor folder.
It was created in 2019, has 80 subscribers, and seen many comments and commits. So in a sense, the community voted by activity that this is the .gitignore solution to pursue. I feel it just needs the final push, to get it over the finishing line, and then it will have an enduring and positive effect, helping new users.