Skip to content

Merge conflict display fails if CWD is not git repo root #326

@turbocrime

Description

@turbocrime

geometry_git_conflicts() {
_geometry_git_guard || return
local _grep
local conflicts conflict_list
local file_count
local total raw_total
conflicts=$(git diff --name-only --diff-filter=U -z 2>/dev/null)
[[ -z "$conflicts" ]] && return
_grep=${GEOMETRY_GIT_GREP:=${commands[rg]:=${commands[ag]:=${commands[grep]}}}}
conflict_list=$($_grep -cH '^=======$' ${(0)conflicts})
file_count="${(w)#conflict_list}"
raw_total=$(echo $conflict_list | cut -d ':' -f2 | paste -sd+ - | bc)
total=${raw_total##*( )}
[[ -z "$total" ]] && ansi ${GEOMETRY_GIT_COLOR_CONFLICTS_SOLVED:-green} ${GEOMETRY_GIT_SYMBOL_CONFLICTS_SOLVED:-"◆"} && return
count="(${file_count}f|${total}c)"
ansi ${GEOMETRY_GIT_COLOR_CONFLICTS_UNSOLVED:-red} "${GEOMETRY_GIT_SYMBOL_CONFLICTS_UNSOLVED:-'◈'} $count"
}

when the list of conflicts is created with git diff, all paths are relative from the repo root. then, the grep call on line 73 searching for the conflict symbol will grep from the CWD, which is not necessarily the repo root. this will cause the search to fail, and possibly display an error for every file that couldn't be pathed.

a simple fix would be to prefix each item in the list with git rev-parse --show-toplevel which should return the git root.

more ideally, it might be preferable to use git diff --check, which contains a built-in tool for detecting merge conflicts.

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