Skip to content

Commit 4bf42a7

Browse files
author
Jonathan Dahan
committed
Fix git conflict counting with multiple files, thanks @gluxon
@gluxon came up with a solution to "no such file or directory" errors, which exposed underlying issues with our git conflict counting. The solution was to use null characters and xargs instead of newlines. `git diff` has the `-z` flag to list names with \0 instead of \n, and zsh has an expansion modifier `0` which expands on \0 instead of \n. This also fixes the `20f` issue when only one file has conflicts, it was counting characters of the filename instead of the file list. Thank you @gluxon!
1 parent 7047a23 commit 4bf42a7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

changelog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
44
and this project adheres to [Semantic Versioning](http://semver.org/).
55

66
## Unreleased
7+
8+
### Fixed
79
- Fix git functions erroring out in non-git directories (thanks @duncanbeevers!)
10+
- Git conflict counting with multiple files (thanks @gluxon!)
811

912
## 2.2.0 - 2020-01-13
1013

@@ -21,7 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2124
- lazy load functions with autoload instead of sourcing (thanks @alxbl!)
2225

2326
### Added
24-
- geometry_newline for two-line prompts (thanks @ducklin5)
27+
- geometry_newline for two-line prompts (thanks @ducklin5!)
2528
- geometry::hostcolor to allow host-based colorization for all (thanks @crasx!)
2629

2730
### Fixed
@@ -105,8 +108,9 @@ Now uses GEOMETRY_SEPARATOR like everything else.
105108
- Dozens of other small fixes
106109

107110
## 1.0.0 - 2017-04-05
111+
108112
### Added
109113
- Change Log file
110114
- Initial release features
111115

112-
[Unreleased]: https://github.com/geometry-zsh/geometry/compare/v1.0.0...HEAD
116+
[Unreleased]: https://github.com/geometry-zsh/geometry/compare/v2.2.0...HEAD

functions/geometry_git

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,22 @@ geometry_git_remote() {
5757
echo "$unpushed $unpulled"
5858
}
5959

60+
geometry_git_symbol() { echo ${(j: :):-$(geometry_git_rebase) $(geometry_git_remote)}; }
61+
6062
geometry_git_conflicts() {
6163
_geometry_git_guard || return
6264
local _grep
6365
local conflicts conflict_list
64-
local file_count raw_file_count
66+
local file_count
6567
local total raw_total
66-
conflicts=$(git diff --name-only --diff-filter=U)
68+
conflicts=$(git diff --name-only --diff-filter=U -z)
6769

6870
[[ -z "$conflicts" ]] && return
6971

7072
_grep=${GEOMETRY_GIT_GREP:=${commands[rg]:=${commands[ag]:=${commands[grep]}}}}
71-
conflict_list=$($_grep -cH '^=======$' $conflicts)
73+
conflict_list=$($_grep -cH '^=======$' ${(0)conflicts})
7274

73-
raw_file_count="${#${(@f)conflict_list}}"
74-
file_count=${raw_file_count##*( )}
75+
file_count="${(w)#conflict_list}"
7576

7677
raw_total=$(echo $conflict_list | cut -d ':' -f2 | paste -sd+ - | bc)
7778
total=${raw_total##*( )}

0 commit comments

Comments
 (0)