Skip to content

Commit e007c7c

Browse files
committed
_content/ref/mod: add documentation for ignore and go-get subdirectories
Add documentation for the new ignore directive, and the option to provide subdirectories in meta-tags used to resolve modules. Update release notes to point to the documentation. Change-Id: Ia6ab22f052948b42b3b6b2386b93f8fab73c300d Reviewed-on: https://go-review.googlesource.com/c/website/+/680197 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 2026416 commit e007c7c

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

_content/doc/go1.25.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ included, but tools not invoked by build or test operations will be built
4040
and run by `go tool` as needed.
4141

4242
<!-- go.dev/issue/42965 -->
43-
The new `go.mod` `ignore` directive can be used to specify directories
44-
the `go` command should ignore. Files in these directories and their subdirectories
45-
will be ignored by the `go` command when matching package patterns,
46-
such as `all` or `./...`, but will still be included in module zip files.
43+
The new `go.mod` `ignore` [directive](/ref/mod#go-mod-file-ignore) can be used to
44+
specify directories the `go` command should ignore. Files in these directories
45+
and their subdirectories will be ignored by the `go` command when matching package
46+
patterns, such as `all` or `./...`, but will still be included in module zip files.
4747

4848
<!-- go.dev/issue/68106 -->
4949
The new `go doc` `-http` option will start a documentation server showing
@@ -57,7 +57,7 @@ The new `go version -m -json` option will print the JSON encodings of the
5757

5858
<!-- go.dev/issue/34055 -->
5959
The `go` command now supports using a subdirectory of a repository as the
60-
path for a module root, using the syntax
60+
path for a module root, when [resolving a module path](/ref/mod#vcs-find) using the syntax
6161
`<meta name="go-import" content="root-path vcs repo-url subdir">` to indicate
6262
that the `root-path` corresponds to the `subdir` of the `repo-url` with
6363
version control system `vcs`.

_content/ref/mod.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ GoMod = { Directive } .
476476
Directive = ModuleDirective |
477477
GoDirective |
478478
ToolDirective |
479+
IgnoreDirective |
479480
RequireDirective |
480481
ExcludeDirective |
481482
ReplaceDirective |
@@ -749,6 +750,36 @@ tool (
749750
)
750751
```
751752

753+
### `ignore` directive {#go-mod-file-ignore}
754+
755+
An `ignore` directive will cause the go command ignore the slash-separated
756+
directory paths, and any files or directories recursively contained in them,
757+
when matching package patterns.
758+
759+
If the path starts with `./`, the path is interpreted relative to the
760+
module root directory, and that directory and any directories or files
761+
recursively contained in it will be ignored when matching package patterns.
762+
763+
Otherwise, any directories with the path at any depth in the module, and
764+
any directories or files recursively contained in them will be ignored.
765+
766+
```
767+
IgnoreDirective = "ignore" ( IgnoreSpec | "(" newline { IgnoreSpec } ")" newline ) .
768+
IgnoreSpec = RelativeFilePath newline .
769+
RelativeFilePath = /* slash-separated relative file path */ .
770+
```
771+
772+
Example
773+
```
774+
ignore ./node_modules
775+
776+
ignore (
777+
static
778+
content/html
779+
./third_party/javascript
780+
)
781+
```
782+
752783
### `exclude` directive {#go-mod-file-exclude}
753784

754785
An `exclude` directive prevents a module version from being loaded by the `go`
@@ -1850,7 +1881,7 @@ arguments must satisfy the following constraints:
18501881

18511882
* Arguments must be package paths or package patterns (with "`...`" wildcards).
18521883
They must not be standard packages (like `fmt`), meta-patterns (`std`, `cmd`,
1853-
`all`), or relative or absolute file paths.
1884+
`all`, `work`, `tool`), or relative or absolute file paths.
18541885
* All arguments must have the same version suffix. Different queries are not
18551886
allowed, even if they refer to the same version.
18561887
* All arguments must refer to packages in the same module at the same version.
@@ -3167,13 +3198,15 @@ avoid confusing the `go` command's restricted parser. In particular, it should
31673198
appear before any raw JavaScript or CSS. The `<meta>` tag must have the form:
31683199

31693200
```
3170-
<meta name="go-import" content="root-path vcs repo-url">
3201+
<meta name="go-import" content="root-path vcs repo-url [subdirectory]">
31713202
```
31723203

31733204
`root-path` is the repository root path, the portion of the module path that
3174-
corresponds to the repository's root directory. It must be a prefix or an exact
3175-
match of the requested module path. If it's not an exact match, another request
3176-
is made for the prefix to verify the `<meta>` tags match.
3205+
corresponds to the repository's root directory, or to the `subdirectory`,
3206+
if present and using Go 1.25 or later (see the section on `subdirectory` below).
3207+
It must be a prefix or an exact match of the requested module path. If it's
3208+
not an exact match, another request is made for the prefix to verify the `<meta>`
3209+
tags match.
31773210

31783211
`vcs` is the version control system. It must be one of the tools listed in the
31793212
table below or the keyword `mod`, which instructs the `go` command to download
@@ -3188,6 +3221,13 @@ control system. For example, with Git, the `go` command will try `https://` then
31883221
`git+ssh://`. Insecure protocols (like `http://` and `git://`) may only be used
31893222
if the module path is matched by the `GOINSECURE` environment variable.
31903223

3224+
`subdirectory`, if present, is the slash-separated subdirectory of the repository
3225+
that the `root-path` corresponds to, overriding the default of the repository's
3226+
root directory. `go-import` meta tags providing a `subdirectory` are only recognized
3227+
by Go 1.25 and later. Attempts to fetch resolve modules on earlier versions of
3228+
Go will ignore the meta tag and result in a resolution failure if the module can
3229+
not be resolved elsewhere.
3230+
31913231
<table id="vcs-support" class="ModTable">
31923232
<thead>
31933233
<tr>

0 commit comments

Comments
 (0)