-
Notifications
You must be signed in to change notification settings - Fork 11
Description
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:
git status --porcelainshowsUU /path/to/file.ts(unmerged, both modified)git statusshows the file under "Unmerged paths: both modified"- The file contains standard conflict markers (
<<<<<<<,=======,>>>>>>>) - We are in an active merge state (
git statusshows "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
fiThe 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:
- Path normalization issues: User provides absolute paths, but git outputs relative paths from repo root
- Working directory differences: Tool may be called from different directories than git root
- Path format mismatches: Different handling of leading
./, trailing slashes, etc.
Reproduction Steps
- Be in an active merge with conflicts
- Verify file shows as
UUingit status --porcelain <file> - Run
git-resolve-conflict --ours <absolute-path-to-file> - 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
- Path stripping: Tried
git reset HEAD -- <file>to unstage - didn't help - Working directory: Ensured running from git root - didn't help
- Path formats: Tried relative vs absolute paths - still failed
Proposed Fix
The tool needs more robust path resolution. Instead of just stripping ./, it should:
- Normalize paths: Convert any input path to the correct relative path from git root
- Try multiple formats: Check against various path formats when matching
- Better debugging: Show what paths it's trying and what
git diffreturns
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
fiImpact
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.