Problem/Motivation
I am having a hard time understanding the "proper way" to install and manage my Drupal 8 project, especially with regards to building it and using source control. Where I'm coming from: I've been a Drupal developer since Drupal 4.7, so my typical workflow would be to download the tarball of Drupal (typically with drush) and use that as my starting point. I would commit the core Drupal download into version control as "initial commit" on master when starting, and I would branch from there, etc. With Drupal 8, we see the advent of Composer.
The other thing I'm used to is copying example files directly into their counterparts, and modifying from there. With Drupal 8, I'm seeing example.gitignore (rather than having Drupal ship with a .gitignore directly).
My "tarball" approach and my "use example.* as baseline" don't mix well. What I'm trying to understand here is if we have any sort of actual "bug" here at all with any component, so I'm initially filing this as a support request. Here's my issue:
- I start by downloading and extracting a tarball of Drupal 8 (the particular site I see this on started as 8.1.0 and went to 8.1.1 recently)
- I copy my example.gitignore to .gitignore - this ignores "vendor" folders by default.
- I commit, push, deploy to production (after some development).
- My co-worker comes along and clones the site, they get nothing in /vendor, NOR IN /core/assets
- Co-worker (logically?) runs `composer install` from root of Drupal project
- Co-worker sees site running kind of OK, except nothing's been installed in /core/assets - so there is no jquery, normalize, etc.
Proposed resolution
One of these:
- Change vendor to /vendor
- Exclude /core/assets/vendor
Remaining tasks
Decision on which method is preferable.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #72 | gitignore-rules-web.txt | 1.49 KB | ressa |
| #65 | interdiff-2737773-61-65.txt | 717 bytes | antongp |
| #65 | drupal-gitignore_example_ignore_root_vendor_only-2737773-65.patch | 636 bytes | antongp |
| #61 | interdiff-2737773-44-61.txt | 570 bytes | antongp |
| #61 | drupal-gitignore_example_ignore_root_vendor_only-2737773-61.patch | 636 bytes | antongp |
Comments
Comment #2
jhodgdonThis is an excellent question. I think it is a documentation bug and not a support request. Thanks for raising it!
However, I'm not sure how to fix it. I'm setting the component to "base system" instead of "documentation" for the time being, so that the base system maintainers will notice this issue and hopefully respond. If they don't respond in a timely manner, I would suggest pinging either the branch maintainers or the "base system" maintainers in IRC and bringing this to their attention, and/or discussing there and then adding a summary of the discussion to this issue.
Comment #3
bdanin commentedPerhaps this recent article helps http://blog.netgloo.com/2016/05/14/configuring-drupal-8-for-a-simple-git... ? Specifically the #deployment section.
Comment #4
chrisfromredfinIt doesn't seem to solve this initial issue which is that ignoring "vendor" ignores any folder matching "vendor" as a name, which includes core/vendor/assets, which does not get built with a 'composer install' from root.
Comment #5
luismagr commentedThis is really interesting. What I'm doing actually is to force git to add these files with -f option:
git add -f core/vendor/assetsbut i'm not very happy with this solution.Comment #6
chrisfromredfinI think where I've settled so far is to either have vendor commented out in the example.gitignore by default, and improve the commenting to say why you would uncomment it.
Mostly because most people with a composer workflow are likely(??) to do something like "drupal site:new" with Drupal Console and it handles your .gitignore file for you. Just my $0.02.
Comment #7
ericg8645 commentedWhat about:
!/core/assets/vendorin .gitignore ?
Comment #8
ahoms commentedI also think that #7 is best solution
Comment #10
antongp commented#7 looks good for me.
may be an option.
Comment #11
Tom Nelson commentedTalking with engineers here, they think changing vendor to /vendor in .gitignore would work too. But I got !/core/assets/vendor to work.
The engineers concern is that /vendor would work in other instances where vendor fails like it does in /core/assets/vendor.
Comment #12
fadehelix commented/vendorworks perfectly, thanks!.I had issue with backup_migrate module because git was ignoring vendor directory inside the module.
Comment #13
denns0r commentedwhat about
/vendorto only ignore the root vendor directory?!
Comment #14
antongp commentedOkay, let's try to accelerate it...
I'm not sure what should the comment for the line say to be more descriptive and to avoid misunderstanding, but I would not recommend to comment the /vendor line out by default.
Comment #15
josueValRob commentedLook this https://github.com/hechoendrupal/drupal-console-launcher/blob/master/.gi...
Comment #16
baronmunchowsen commentedWhen I add to gitignore:
!/core/assets/vendor - this works only at including the /core/assets/vendor directory
When I add to gitignode
/vendor - this works for all nested vendor directories:
core/assets/
modules/contrib/backup_migrate/vendor/
...
So I'm guessing that /vendor is preferable?
Comment #17
Ante890 commentedI recommended to install Drupal core and all modules via composer
https://github.com/drupal-composer/drupal-project
Comment #18
pcambraReplacing "vendor" by "/vendor" fixes the issue for me, it is very easy to overlook the core/assets/vendor folder when not working in an install profile environment, whether that's a best practice or not is another discussion.
Comment #19
cilefen commentedI am not sure what is to be committed here.
Comment #20
antongp commentedThere is only one patch attached in the issue (#14). example.gitignore file is often used as is on projects, just copied and renamed. So I believe example.gitignore file should be fixed, it's not just a documentation problem or so.
Thanks.
Comment #21
cilefen commentedThat would work only for sites using continuous integration.
Edited: this is a silly comment.
Comment #22
cilefen commentedOh I see, /vendor vs "vendor"...
Comment #23
cilefen commentedI am more into #7.
Comment #24
pcambraBack to RTBC, I think /vendor and !/core/assets/vendor are specific enough and a solution needs to be chosen.
Comment #25
pcambraAdding the alternative patch that uses !/core/assets/vendor instead
Comment #26
antongp commentedI think we should take into account the fact that some contrib projects, libraries, etc. may contain vendor directory as well and ignoring them by default may be a problem sometimes (I'm not saying here that this is a good practice:)). See #12 for example.
Comment #27
wturrell commented- Updated issue summary
- Updated the second patch with clearer description.
I don't feel qualified to judge which is the best solution.
Comment #29
webcultist commentedI would say as well, that "/vendor/" is much more secure.
There are many projects with vendor in it and it cause many problems.
the drupal composer template (https://github.com/drupal-composer/drupal-project/blob/8.x/.gitignore) uses "/vendor/" as well and worked very nice for every project I built on it.
I ran into the problem with ne normal .gitignore and missing jquery files through the project of another developer and it's really nasty.
Comment #30
pcambraComment #31
pcambraBack to RTBC, I think any of the 2 alternatives are valid and this would avoid confusion on non-install profile environments.
Comment #32
alexpottWell less is more so I think making the vendor line specific is preferable. In #23 @cilefen expresses a preference for #7 but doesn't explain why.
For me, the intent of
Is to ignore Composer's vendor directory. But it is also causes core/vendor/assets to be ignored. So it needs fixing. Otherwise some other module that adds a vendor directory that is not from composer but has something else with have the same problem.
Comment #33
alexpottWith manual testing,
/vendor/orvendor/*works. Given #29 points out that drupal-project uses /vendor/ let's go for that since it has lots of usages on real projects.Comment #34
wturrell commentedAs per @alexpott in #33, with an explanatory comment.
Comment #35
alexpottShould break at 80. I would point toward core/assets/vendor explicitly.
So something like:
Comment #36
wturrell commentedSorry...
Comment #37
el7cosmosIs there any reason behind
core/assets/vendornaming? I find it ambiguous with composer vendor directory, what if we change to other than vendor (egcore/assets)?Comment #38
manningpete commentedI think the approach of ignoring the root /vendor/ directory (and not explicitly not-ignoring the specific /core/assets/vendor/ directory) is correct and what I've seen used successfully on several projects. This way vendor directories that are needed for core (and specific modules and libraries that might include vendor directories #26 #33) will not be ignored by default. #37 is worth considering, but would be out of scope for this issue.
Comment #39
antongp commented+1 to #38. The only thing I'm not sure is
/vendor/vs/vendor.Comment #40
manningpete commentedRe: #39 . without the trailing slash, it will ignore both a directory matching "vendor" as well as a filename matching "vendor" as well as a symlink matching "vendor".
Because we are unlikely to ever have a file or symlink named vendor at the root, it wouldn't make much practical difference in this case. But it's a good practice if you know you want to ignore a directory and not also files and symlinks to include that trailing slash.
Comment #42
antongp commented@manningpete
Checked some discussions and sometimes people symlink vendor because of several reasons. This case is specific though, and I don't think we should care about it and think about, if we should ignore it by default or not. So +1 to
/vendor/No no no. Let's have it in 8.4.x, please! This change is not disruptive (it's just an example file) and unlikely will affect existing installations.
Comment #43
cilefen commentedI'd like to suggest "Core's PHP dependencies are managed with Composer." and that's all for the comment.
Comment #44
antongp commented@cilefen
So, basically we returned to original comment.
Comment #45
cilefen commentedUsing fewer words is clearer.
Comment #46
darvanenThe bits and pieces of education sprinkled throughout comments in the code helped me immensely when I was a beginner. Clarity is great but it's not the only worthy goal.
I respectfully disagree with the latest change.
Comment #47
Koen Verheyen commentedDoes anyone know of a way to regenerate these files once they are "gone"? The only way I can think of is to copy them from a fresh Drupal installation but I'd like to think there is a better way for this.
Comment #48
manningpete commentedI also disagree with the change in #44. This is an example file. The explanation is already clear, and helpful to newcomers, who are the target audience for the file.
Nevertheless, it is currently wrong and is causing people to lose their core files, so I would rather have it fixed with the less helpful instruction than for it to sit here in the bikeshed for another month so I'm RTBCing.
Comment #50
wturrell commentedIMHO it's a mistake to remove an entire sentence of supplementary information; the extra context about core/assets/vendor is useful (though perhaps the phrasing can be improved further). I suspect most people can't remember much .gitignore syntax; it's the kind of file most only edit occasionally.
I'd argue detailed inline/code comments/UI text reduce the need for documentation / tutorials / Q&As elsewhere, alternatives which can be inconsistent or don't age well. However, rightly or wrongly, I've struggled to make that case convincingly elsewhere in Drupal core.
Comment #51
rooby commentedI also don't see how "Core's dependencies are managed with Composer." is clearer than "Core's dependencies are managed with Composer. This directive is explicit to the root vendor directory so, for example, core/assets/vendor is not ignored."
I feel like someone with less experience with composer and/or git would appreciate the latter version.
Comment #52
wesleymusgrove commentedWhen adding a new Composer package to "docroot/composer.json" and running "composer install", the package files get downloaded and installed properly under "docroot/vendor/new-package-name". However they fail to get added to version control due to the "vendor" line in "docroot/.gitignore".
Can this line be safely commented out if I actually need new Composer packages to be added to Git, committed, and pushed up?
I feel like core's "docroot/core/assets/vendor" directory should be ignored because I'll never need to add anything to it or change it in any way. However "docroot/vendor" should not be ignored because of the exact scenario I'm experiencing above, i.e. needing to add a new Composer package to version control. Is that assumption correct?
I don't have a build process that would run "composer install" in prod, which is why I'm needing to add and commit the new package locally.
Comment #53
cilefen commentedYes.
You may want to remove any git directories in /vendor before committing. Something like this untested composer variation may work for you.
Comment #54
wesleymusgrove commentedThanks @cilefen, I'm not intentionally trying to hack this thread, but it seemed relevant to the discussion.
Even after:
find vendor -type d -name .git -exec rm -rf {} \\;to remove all ".git" folders from vendor sub-directoriesNew vendor files do not show up as untracked changes waiting to be added to git.
I'm not sure how to commit something that still thinks it needs to be ignored.
Making changes to existing vendor files did show changes in my working directory.
Making changes to new vendor files did not show changes in my working directory.
Comment #55
cilefen commented"I'm not sure how to commit something that still thinks it needs to be ignored."
git add -f
Comment #56
wesleymusgrove commentedI thought that too, but I get
fatal: Pathspec '/vendor/package-name' is in submodule 'package-name'I'll stop hijacking this post because this is trailing off as my personal Git issue, but it all was related to the .gitignore file ignoring vendor.
My journey leads me to these posts:
https://stackoverflow.com/questions/1084969/unable-to-track-files-within...
https://stackoverflow.com/questions/24472596/git-fatal-pathspec-is-in-su...
Thanks for your help @cilefen
Comment #57
akupaka commentedHi there! I'm new to Drupal, Composer and all this stuff, and as a newcomer I rely on instructions and guides a lot!
Last weekend I was trying to build my Drupal 8 landscape with Git using this, on the one hand, beautiful guide - https://www.drupal.org/node/803746 . On the other hand, I spent few hours trying to understand why my "copied" site has got some glitches. After some research I finally was able to find that core/assets folder was missing! Unfortunately the only way to fix that was to copy this folder from the "source" site.
Today I've found this thread and I see that there is no single way to resolve this issue. So maybe it would be a good idea to mention this issue in "Setting up the .gitignore file" part of the guide - https://www.drupal.org/node/803746 . So newcomers won't do mistake like I did?
Thx in advance!
Comment #59
gaurav.kapoor commentedAny resolution?
Comment #60
cilefen commentedComment #61
antongp commentedOne more patch. Hope rule comment is good enough to proceed. I also made the first line of the comment more consistent with comments for other rules.
@gaurav.kapoor any of #36, #44 and #61 is correct solution, and you don't have to wait until patch is applied to fix your .gitignore file. We just need to agree on comment so it's clear and descriptive.
Comment #62
gaurav.kapoor commentedLOL. I already fixed it way before.
That's what i wanted to know as well. Thanks @antongp
Comment #63
darvanen+++ b/example.gitignore
@@ -11,8 +11,11 @@
+# contain directories named "vendor" which should not be ingored by default.
spelling error "ingored".
Comment #64
darvanenI did find the message a little hard to parse, may I suggest the following comment?:
Ignore dependencies that are managed with Composer.
Generally you should only ignore the root vendor directory. It's important that core/assets/vendor and any vendor folders in contrib and custom modules are not ignored unless you specifically choose to do so.
Comment #65
antongp commented@Darvanen thanks for finding a typo.
Here is one more version... I've changed text a little.
More feedback would be great!
Comment #66
darvanenSuper nitpick, I don't know how much we care about grammar in comments?
The sentence makes more sense if you use "directories" and "are not ignored" because we're talking about multiple things.
Comment #67
joelpittetI agree with @Darvanen in #66, a possible fix on commit or @antongp feel free to update the comment and I'll re-RTBC this.
Comment #68
alexpottI've been thinking about this some more. I'm not sure that this file should by default ignore vendor. It's much like the entry for core
If you are using the tarball I'm not sure how relevant this file is for you. Mixing tarball and git feels weird and we also not recommending starting Drupal 8 projects from git anymore. That said this is a better default than the current one but I think we should review this file's content as part of the composer initiative. I think we need two versions of it - one for composer driver projects and one for people doing core contribution.
Anyhow, fixed the grammar on commit.
Committed and pushed 4a03584d2f to 8.6.x and 65ee0376cc to 8.5.x. Thanks!
Comment #72
ressaPerhaps the paths to the
sitessub-folders should be changed toweb/sites, since that is the structure you get Starting a Site Using Drupal Composer Project Templates? (See attached file)