Skip to content

Issue path resolution #9

@3dyuval

Description

@3dyuval

Bug Report: git-resolve-conflict fails to detect conflicted files in certain cases

Summary

git-resolve-conflict incorrectly reports files as "not in conflicted state" even when they are clearly conflicted according to git status and contain standard conflict markers.

Environment

  • Tool version: 2.0.0
  • Git version: (user should add: git --version)
  • OS: Linux
  • Shell: bash
  • Installation method: npm install -g git-resolve-conflict

Problem Description

The tool fails with the message:

/path/to/file.ts is not in conflicted state; aborting.

Even when:

  1. git status --porcelain shows UU /path/to/file.ts (unmerged, both modified)
  2. git status shows the file under "Unmerged paths: both modified"
  3. The file contains standard conflict markers (<<<<<<<, =======, >>>>>>>)
  4. We are in an active merge state (git status shows "You have unmerged paths")

Root Cause Analysis

After investigating the source code in lib/git-resolve-conflict.sh, the issue is in this section:

FILE_PATH_FOR_GREP=${FILE_PATH#./}
if ! git diff --name-only --diff-filter=U | grep -Fxq "$FILE_PATH_FOR_GREP"; then
    echo "$FILE_PATH is not in conflicted state; aborting."
    return
fi

The problem: The tool only checks git diff --name-only --diff-filter=U but the file path provided by the user doesn't match exactly what this command outputs due to:

  1. Path normalization issues: User provides absolute paths, but git outputs relative paths from repo root
  2. Working directory differences: Tool may be called from different directories than git root
  3. Path format mismatches: Different handling of leading ./, trailing slashes, etc.

Reproduction Steps

  1. Be in an active merge with conflicts
  2. Verify file shows as UU in git status --porcelain <file>
  3. Run git-resolve-conflict --ours <absolute-path-to-file>
  4. Tool incorrectly reports file is not conflicted

Debug Evidence

When we added debug output, we found:

  • Git status: UU src/pages/secure-upload/files/files.component.ts ✅ (correctly shows conflict)
  • File in unmerged list: false ❌ (tool's check fails)
  • Unmerged files from git diff: (shows list, but path doesn't match)

Attempted Solutions

  1. Path stripping: Tried git reset HEAD -- <file> to unstage - didn't help
  2. Working directory: Ensured running from git root - didn't help
  3. Path formats: Tried relative vs absolute paths - still failed

Proposed Fix

The tool needs more robust path resolution. Instead of just stripping ./, it should:

  1. Normalize paths: Convert any input path to the correct relative path from git root
  2. Try multiple formats: Check against various path formats when matching
  3. Better debugging: Show what paths it's trying and what git diff returns

Suggested Implementation

# Get git root directory to normalize paths
GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)

# Convert file path to absolute, then to relative from git root
if [[ "$FILE_PATH" = /* ]]; then
    ABS_FILE_PATH="$FILE_PATH"
else
    ABS_FILE_PATH="$(cd "$(dirname "$FILE_PATH")" && pwd)/$(basename "$FILE_PATH")"
fi

REL_FILE_PATH="${ABS_FILE_PATH#$GIT_ROOT/}"

# Try multiple path formats when checking
if echo "$UNMERGED_FILES" | grep -Fxq "$REL_FILE_PATH" || \
   echo "$UNMERGED_FILES" | grep -Fxq "$FILE_PATH_FOR_GREP" || \
   echo "$UNMERGED_FILES" | grep -Fxq "$FILE_PATH"; then
    # File is conflicted, proceed
fi

Impact

This bug makes the tool unusable in common scenarios where:

  • Users provide absolute file paths
  • Tool is called from different working directories
  • Path formats don't exactly match git's internal representation

Expected Behavior

The tool should successfully resolve conflicts for any file that shows as unmerged in git status, regardless of how the path is specified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions