镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Conflict reason does not match the result of the "git merge" command. #850

Description

@laujinkai

I am trying to use git2go to write an utility to do automatic merge, in the process of development I encountered a strange phenomenon and do not know how to solve it.

One of my projects will get different conflict reasons than "git merge --no-ff ..." if I merge it with git2go.

The output of "git status" after running "git merge --no-ff ..." shows some unmerged files are "both added", but those same files
are shown as "modified" and merged if I run "git status" after merging branch using git2go.

Below is the code snippet I used to do the merge:

func Merge(projectPath, target, message  string) (MergeStatus, error) {
	repo, err := git.OpenRepository(projectPath)
	if err != nil {
		panic(err)
	}
	defer repo.Free()

	commit, err := resolveRefish(repo, target)
	if err != nil {
		panic(err)
	}
	defer commit.Free()

	analysis, _, err := repo.MergeAnalysis([]*git.AnnotatedCommit{commit})
	if err != nil {
		panic(err)
	}

	switch analysis {
	case git.MergeAnalysisNormal, git.MergeAnalysisFastForward:
		break // can merge

	case git.MergeAnalysisUpToDate:
		return AlreadyUpToDate, nil

	case git.MergeAnalysisNone:
		return NothingToMerge, nil

	default:
		panic(fmt.Sprintf("unhandled analysis: %v", analysis))
	}

	mergeOpts := git.MergeOptions{
		TreeFlags: git.MergeTreeFindRenames,
	}
	checkoutOpts := git.CheckoutOptions{
		Strategy: git.CheckoutForce,
	}
	err = repo.Merge([]*git.AnnotatedCommit{commit}, &mergeOpts, &checkoutOpts)
	if err != nil {
		panic(err)
	}

	index, err := repo.Index()
	if err != nil {
		panic(err)
	}
	defer index.Free()

	if index.HasConflicts() {
		return Conflicted, nil
	}

	createMergeCommit(repo, target, message)

	return Merged, nil
}

Is there something wrong with my code that causes this phenomenon?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions