Skip to content

Conversation

goran-w
Copy link
Contributor

@goran-w goran-w commented May 23, 2025

Improved IsConflicResolved check, to work correctly for submodule conflicts.

Added an extra (lock-free) call to git-status with --porcelain=v2 which makes it easy to check that:

  • The file is still "unmerged".
  • The file is a submodule (or not).

If the file is a submodule, we always return false (while it's unmerged) regard the conflict as unresolved (while Unstaged), since we can't use text-diff check on submodules and the conflict is not resolved until it's Staged.

@goran-w goran-w changed the base branch from master to develop May 23, 2025 12:18
@love-linger
Copy link
Collaborator

I'd like to change the modifications as follows

First, use different commands for text-files and submodules

public class IsConflictResolved : Command
{
    public IsConflictResolved(string repo, Models.Change change, bool isSubmodule)
    {
        _change = change;
        _isSubmodule = isSubmodule;

        WorkingDirectory = repo;
        Context = repo;
    }

    public bool Result()
    {
        if (!_isSubmodule)
        {
            var opt = new Models.DiffOption(_change, true);
            Args = $"diff -a --ignore-cr-at-eol --check {opt}";
            return ReadToEnd().IsSuccess;
        }
        
        Args = $"--no-optional-locks status --porcelain=v2 -- \"{_change.Path}\"";
        var rs = ReadToEnd();
        return rs.IsSuccess && rs.StdOut.StartsWith('u');
    }

    private readonly Models.Change _change = null;
    private readonly bool _isSubmodule = false;
}

The modify the constructor of SourceGit.ViewModels.Conflict

var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null;
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change, isSubmodule).Result();

@love-linger love-linger self-assigned this May 23, 2025
@love-linger love-linger added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels May 23, 2025
A submodule conflict is not resolved until it's Staged.
@goran-w goran-w force-pushed the fix_conflict_resolved_check_for_submodule branch from d928e69 to 6665a6b Compare May 23, 2025 14:34
@goran-w
Copy link
Contributor Author

goran-w commented May 23, 2025

@love-linger I rewrote my commit, the new solution is much simpler (if the file is a submodule entry we just bypass IsCommitResolved and regard the conflict as unresolved - it will be resolved when it's Staged).

@love-linger love-linger merged commit f3fe90b into sourcegit-scm:develop May 24, 2025
13 checks passed
@goran-w goran-w deleted the fix_conflict_resolved_check_for_submodule branch May 24, 2025 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants