mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 19:23:34 +01:00
Integrate `go-git` into the application, and use it to `git clone` cheatsheets when the installer runs. Previously, the installer required that `git` be installed on the system `PATH`, so this change has to big advantages: 1. It removes that system dependency on `git` 2. It paves the way for implementing the `--update` command Additionally, `cheat` now performs a `--depth=1` clone when installing cheatsheets, which should at least somewhat improve installation times (especially on slow network connections).
21 lines
453 B
Go
21 lines
453 B
Go
package git
|
|
|
|
import "strings"
|
|
|
|
// countLines returns the number of lines in a string à la git, this is
|
|
// The newline character is assumed to be '\n'. The empty string
|
|
// contains 0 lines. If the last line of the string doesn't end with a
|
|
// newline, it will still be considered a line.
|
|
func countLines(s string) int {
|
|
if s == "" {
|
|
return 0
|
|
}
|
|
|
|
nEOL := strings.Count(s, "\n")
|
|
if strings.HasSuffix(s, "\n") {
|
|
return nEOL
|
|
}
|
|
|
|
return nEOL + 1
|
|
}
|