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:

  1. 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)
  2. I copy my example.gitignore to .gitignore - this ignores "vendor" folders by default.
  3. I commit, push, deploy to production (after some development).
  4. My co-worker comes along and clones the site, they get nothing in /vendor, NOR IN /core/assets
  5. Co-worker (logically?) runs `composer install` from root of Drupal project
  6. 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:

  1. Change vendor to /vendor
  2. Exclude /core/assets/vendor
  3. Remaining tasks

    Decision on which method is preferable.

    User interface changes

    None.

    API changes

    None.

    Data model changes

    None.

Comments

cwells created an issue. See original summary.

jhodgdon’s picture

Component: documentation » base system
Category: Support request » Bug report

This 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.

bdanin’s picture

Perhaps this recent article helps http://blog.netgloo.com/2016/05/14/configuring-drupal-8-for-a-simple-git... ? Specifically the #deployment section.

chrisfromredfin’s picture

It 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.

luismagr’s picture

This is really interesting. What I'm doing actually is to force git to add these files with -f option: git add -f core/vendor/assets but i'm not very happy with this solution.

chrisfromredfin’s picture

I 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.

ericg8645’s picture

What about:

!/core/assets/vendor

in .gitignore ?

ahoms’s picture

I also think that #7 is best solution

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

antongp’s picture

#7 looks good for me.

/vendor

may be an option.

Tom Nelson’s picture

Talking 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.

fadehelix’s picture

/vendor works perfectly, thanks!.
I had issue with backup_migrate module because git was ignoring vendor directory inside the module.

denns0r’s picture

what about

/vendor

to only ignore the root vendor directory?!

antongp’s picture

Status: Active » Needs review
StatusFileSize
new319 bytes

Okay, 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.

baronmunchowsen’s picture

When 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?

Ante890’s picture

I recommended to install Drupal core and all modules via composer
https://github.com/drupal-composer/drupal-project

pcambra’s picture

Status: Needs review » Reviewed & tested by the community

Replacing "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.

cilefen’s picture

Category: Bug report » Support request
Status: Reviewed & tested by the community » Fixed

I am not sure what is to be committed here.

antongp’s picture

Category: Support request » Bug report
Status: Fixed » Reviewed & tested by the community

There 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.

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

That would work only for sites using continuous integration.

Edited: this is a silly comment.

cilefen’s picture

Oh I see, /vendor vs "vendor"...

cilefen’s picture

I am more into #7.

pcambra’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC, I think /vendor and !/core/assets/vendor are specific enough and a solution needs to be chosen.

pcambra’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new373 bytes

Adding the alternative patch that uses !/core/assets/vendor instead

antongp’s picture

I 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.

wturrell’s picture

Issue summary: View changes
StatusFileSize
new411 bytes
new437 bytes

- Updated issue summary
- Updated the second patch with clearer description.

I don't feel qualified to judge which is the best solution.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

webcultist’s picture

I 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.

pcambra’s picture

Version: 8.3.x-dev » 8.4.x-dev
pcambra’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC, I think any of the 2 alternatives are valid and this would avoid confusion on non-install profile environments.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Well 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

# Core's dependencies are managed with Composer.
vendor

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.

alexpott’s picture

With manual testing, /vendor/ or vendor/* works. Given #29 points out that drupal-project uses /vendor/ let's go for that since it has lots of usages on real projects.

wturrell’s picture

Status: Needs work » Needs review
StatusFileSize
new623 bytes
new519 bytes

As per @alexpott in #33, with an explanatory comment.

alexpott’s picture

Status: Needs review » Needs work
+++ b/example.gitignore
@@ -11,8 +11,9 @@
+# Core's dependencies are managed with Composer. Slashes used because we want to
+# ignore Composer's vendor directory, but not similar directories added by modules.
+/vendor/

Should break at 80. I would point toward core/assets/vendor explicitly.

So something like:

# 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.
/vendor/
wturrell’s picture

Status: Needs work » Needs review
StatusFileSize
new513 bytes
new599 bytes

Sorry...

el7cosmos’s picture

Is there any reason behind core/assets/vendor naming? I find it ambiguous with composer vendor directory, what if we change to other than vendor (eg core/assets)?

manningpete’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

antongp’s picture

+1 to #38. The only thing I'm not sure is /vendor/ vs /vendor.

manningpete’s picture

Re: #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.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

antongp’s picture

Version: 8.5.x-dev » 8.4.x-dev

@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/

Version: 8.4.x-dev » 8.5.x-dev

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.

cilefen’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/example.gitignore
@@ -11,8 +11,9 @@
-# Core's dependencies are managed with Composer.
-vendor
+# 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.
+/vendor/

I'd like to suggest "Core's PHP dependencies are managed with Composer." and that's all for the comment.

antongp’s picture

Status: Needs work » Needs review
StatusFileSize
new406 bytes
new447 bytes

@cilefen
So, basically we returned to original comment.

cilefen’s picture

Using fewer words is clearer.

darvanen’s picture

The 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.

Koen Verheyen’s picture

Does 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.

manningpete’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

Status: Reviewed & tested by the community » Needs work
wturrell’s picture

IMHO 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.

rooby’s picture

I 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.

wesleymusgrove’s picture

When 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.

cilefen’s picture

Can this line be safely commented out if I actually need new Composer packages to be added to Git, committed, and pushed up?

Yes.

You may want to remove any git directories in /vendor before committing. Something like this untested composer variation may work for you.

wesleymusgrove’s picture

Thanks @cilefen, I'm not intentionally trying to hack this thread, but it seemed relevant to the discussion.

Even after:

  1. commenting out "vendor" in .gitignore and
  2. running find vendor -type d -name .git -exec rm -rf {} \\; to remove all ".git" folders from vendor sub-directories

New 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.

cilefen’s picture

"I'm not sure how to commit something that still thinks it needs to be ignored."

git add -f

wesleymusgrove’s picture

I 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

akupaka’s picture

Hi 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!

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gaurav.kapoor’s picture

Any resolution?

cilefen’s picture

antongp’s picture

Status: Needs work » Needs review
StatusFileSize
new636 bytes
new570 bytes

One 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.

gaurav.kapoor’s picture

LOL. I already fixed it way before.

We just need to agree on comment so it's clear and descriptive.

That's what i wanted to know as well. Thanks @antongp

darvanen’s picture

Status: Needs review » Needs work

+++ b/example.gitignore
@@ -11,8 +11,11 @@
+# contain directories named "vendor" which should not be ingored by default.

spelling error "ingored".

darvanen’s picture

I 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.

antongp’s picture

Status: Needs work » Needs review
StatusFileSize
new636 bytes
new717 bytes

@Darvanen thanks for finding a typo.
Here is one more version... I've changed text a little.
More feedback would be great!

darvanen’s picture

+++ b/example.gitignore
@@ -11,8 +11,11 @@
+# that core/assets/vendor and any other vendor directory within contrib or
+# custom module, theme, etc., is not ignored unless you purposely do so.

Super 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.

joelpittet’s picture

Version: 8.5.x-dev » 8.6.x-dev
Status: Needs review » Reviewed & tested by the community

I agree with @Darvanen in #66, a possible fix on commit or @antongp feel free to update the comment and I'll re-RTBC this.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

I'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

# Ignore core when managing all of a project's dependencies with Composer
# including Drupal core.
# 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!

  • alexpott committed 4a03584 on 8.6.x
    Issue #2737773 by antongp, wturrell, pcambra, cilefen, Darvanen, cwells...

  • alexpott committed 65ee037 on 8.5.x
    Issue #2737773 by antongp, wturrell, pcambra, cilefen, Darvanen, cwells...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ressa’s picture

StatusFileSize
new1.49 KB

Perhaps the paths to the sites sub-folders should be changed to web/sites, since that is the structure you get Starting a Site Using Drupal Composer Project Templates? (See attached file)