{"id":17925949,"url":"https://github.com/shoenig/go-modtool","last_synced_at":"2026-02-02T02:32:30.395Z","repository":{"id":188254754,"uuid":"678073467","full_name":"shoenig/go-modtool","owner":"shoenig","description":"An opinionated tool for formatting and merging Go's go.mod and go.sum files.","archived":false,"fork":false,"pushed_at":"2024-05-01T20:33:02.000Z","size":45,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-14T05:31:07.249Z","etag":null,"topics":["go","gofmt","golang","gomod","gomodule","merge"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shoenig.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-13T15:45:57.000Z","updated_at":"2023-08-14T12:30:25.000Z","dependencies_parsed_at":"2024-05-01T22:02:11.443Z","dependency_job_id":"96e055a3-3dee-49d1-a5d2-dceeeafdadc2","html_url":"https://github.com/shoenig/go-modtool","commit_stats":null,"previous_names":["shoenig/go-modtool"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoenig%2Fgo-modtool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoenig%2Fgo-modtool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoenig%2Fgo-modtool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoenig%2Fgo-modtool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shoenig","download_url":"https://codeload.github.com/shoenig/go-modtool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247805850,"owners_count":20999230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","gofmt","golang","gomod","gomodule","merge"],"created_at":"2024-10-28T20:58:31.005Z","updated_at":"2026-02-02T02:32:30.356Z","avatar_url":"https://github.com/shoenig.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-modtool\n\nAn opinionated tool to format and merge `go.mod` (and soon `go.sum`) files.\n\n## Overview\n\nAlthough the `go mod tidy` command provided by the Go compiler will format `go.mod` files,\nthe way it does so is not strongly opinionated. Often, you'll end up with multiple `replace`\nstanzas where only one was intended. This `go-modtool` tool provides a way to format `go.mod`\nfiles in a way that is consistent no matter the input.\n\nProjects which need to merge `go.mod` files will also experience pain in how git often\nfails to resolve conflicts for `go.mod` and `go.sum` files. This `go-modtool` tool can be\nused to merge `go.mod` and `go.sum` with better context files so that merge conflicts are \nautomatically resolved, every time.\n\n### Strict go.mod Format\n\nThe strongly opinionated format of a `go.mod` file is described below.\n\n- The `module` stanza appears on the first line of the file.\n\n- The `go` version stanza appears after the `module` stanza.\n\n- A `replace` stanza appears next (if necessary) for third party modules.\n\n- A `replace` stanza appears next (if necessary) for local submodules.\n\n- A `require` stanza appears next (if necessary) for direct dependencies.\n\n- A `require` stanza appears next (if necessary) for indirect dependencies.\n\nComments are disallowed, with exceptions being enabled by specifying them through\narguments to the `go-modtool fmt` command.\n\n## Getting Started\n\n`go-modtool` is a command line tool written in Go. It can be built from source, installed\nvia `go install`, or downloaded from [Releases](https://github.com/shoenig/go-modtool/releases).\n\n#### Install\n\nInstall using `go install`\n\n```shell\ngo install github.com/shoenig/go-modtool@latest\n```\n\n## Subcommands\n\nThe `go-modtool` command line tool provides two subcommands, for formatting and merging\n`go.mod` files.\n\n#### fmt\n\nThe `fmt` subcommand is used to format a `go.mod` file.\n\n```shell\ngo-modtool fmt go.mod\n```\n\nBy default the output is printed to standard out. Use the `-w` flag to overwrite the\ninput `go.mod` file in place.\n\n```shell\ngo-modtool -w fmt go.mod\n```\n\nThe following flags enable specifying comments in the resulting `go.mod` file.\n\n- `--replace-comment` - Insert a comment before the `replace` stanza for third party modules.\n\n- `--subs-comment` - Insert a comment before the `replace` stanza for submodules.\n\n#### merge\n\nThe `merge` subcommand is used to merge two `go.mod` files.\n\nThe motivating use case for this is in merging the `go.mod` file of an OSS version\nof a repository with a private ENT version of the same reposotiry, where the ENT\nversion is a superset of OSS. Conflicts happen because git is not smart enough to\nresolve differences caused by module changes in nearby lines.\n\n```shell\ngo-modtool merge /ent/go.mod /oss/go.mod\n```\n\nThe same CLI arguments from the `fmt` command apply to the `merge` command.\n\n- `-w` - Write the output to the first `go.mod` file in the input.\n\n- `--replace-comment` - Insert a comment before the `replace` stanza for third party modules.\n\n- `--subs-comment` - Insert a comment before the `replace` stanza for submodules.\n\nNote that it is imperative to run `go mod tidy` after doing a merge to ensure only\nthe necessary modules remain in the resulting `go.mod` and `go.sum` files.\n\n## Config File\n\nTo make CI easier the subcommands above can be described in a TOML config file.\n\n```toml\nReplaceComment    = \"An example replace comment.\"\nSubmodulesComment = \"An example submodules comment.\"\nWriteFile         = true\n```\n\nUse the `--config` flag to specify a path to the config file.\n\n```shell-session\ngo-modtool -config=modtool.toml fmt go.mod\n```\n\n## Contributing\n\nThe `github.com/shoenig/go-modtool` module / cli tool is always improving with new features\nand bug fixes. For contributing such bug fixes and new features please file an issue.\n\n## License\n\nThe `github.com/shoenig/go-modtool` module is open source under the [MPL-2.0](LICENSE) license.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoenig%2Fgo-modtool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshoenig%2Fgo-modtool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoenig%2Fgo-modtool/lists"}