-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: subcommand as git merge tool for go.mod merge conflicts #32485
Comments
CC @jayconrod |
I'd be interested in writing git specific merge driver for go.sum, if anyone else is thinking of the same thing. |
Thinking about this some more... if the area under the merge tokens contains a |
what about just deleting go.sum and running |
@rbUUbr, the point of the |
It seems to me like the algorithm should be: Also I think a nice interface would be something like "go mod git-merge" or something like that. It could return an error exit code when it wasn't able to safely auto-merge everything. I think this could be plugged into .git/config so that doing a huge rebase with hundreds of commits would be mostly automatic. |
Hasn't been much movement on this issue, but I thought I'd throw in my vote for this feature. For what it's worth, I think this would be useful even if it only handled In this case, the workflow would be: resolve conflicts in |
If its of any help, I've added some notes on setting up a |
I wrote a script to deal with this based on the above merge tool, the script includes running I call it #!/usr/bin/env bash
set -e
# changesMadeGlobal flag tracks if any changes were made
changesMadeGlobal=0
# repoRoot points to the repository root
repoRoot="$(git rev-parse --show-toplevel)"
# Search for go.mod files from the repository root
while IFS= read -r goModFile; do
# Initialize a flag to track if changes were made
changesMade=0
# Directory of the go.mod file
goModDir="$(dirname "${goModFile}")"
# Corresponding go.sum file
goSumFile="${goModDir}/go.sum"
# Function to check for conflict markers and remove them if found
removeConflictMarkers() {
local file="${1}"
# Check if file contains any conflict markers
if grep -q -E '<<<<<<<|=======|>>>>>>>' "${file}"; then
echo "Removing conflict markers from ${file}"
# Remove the conflict markers
sed -i '/<<<<<<<\|=======\|>>>>>>>/d' "${file}"
# Indicate that changes have been made
changesMade=1
changesMadeGlobal=1
fi
}
# Check and remove conflict markers from go.mod
removeConflictMarkers "${goModFile}"
# Check if go.sum exists and remove conflict markers from it
if [ -f "${goSumFile}" ]; then
removeConflictMarkers "${goSumFile}"
fi
# Run go mod tidy only if changes were made
if [ "${changesMade}" -eq 1 ]; then
echo "Running 'go mod tidy' in ${goModDir}"
(cd "${goModDir}" && go mod tidy)
fi
# Use process substitution to avoid creating a subshell
done < <(find "${repoRoot}" -type f -name 'go.mod')
if [ "${changesMadeGlobal}" -eq 0 ]; then
echo "No conflict markers found in go.mod or go.sum files. Exiting..."
fi |
I expect merge conflicts in
go.mod
andgo.sum
to be a relatively common occurrence.Quoting from @bcmills in the Go Slack:
https://gophers.slack.com/archives/C9BMAAFFB/p1559923453042900?thread_ts=1559922004.041700&cid=C9BMAAFFB
This doesn't appear terribly burdensome but it does introduce friction in the development process. I'm opening this as an exploratory issue to investigate whether there's anything the tooling can/should do to mitigate the conflict.
My off the cuff question was whether
go mod tidy
could be updated to understand conflicts and automatically resolve them ingo.mod
andgo.sum
. My summary of the resulting conversation is that it's likely possible but it's unclear whether it's desirable.Some of the reasons against that were brought up:
It's possible there's a less invasive approach to mitigating conflicts so I'm including the above suggestion only as one potential option to explore.
The text was updated successfully, but these errors were encountered: