std/private/gitutils

Source   Edit  

internal API for now, API subject to change

Consts

commitHead = "HEAD"
Source   Edit  

Procs

proc diffFiles(path1, path2: string): tuple[output: string, same: bool] {.
    ...raises: [OSError, IOError, ValueError],
    tags: [ExecIOEffect, ReadIOEffect, RootEffect], forbids: [].}
Returns a human readable diff of files path1, path2, the exact form of which is implementation defined. Source   Edit  
proc diffStrings(a, b: string): tuple[output: string, same: bool] {.
    ...raises: [IOError, OSError, ValueError], tags: [ReadEnvEffect, ReadIOEffect,
    WriteIOEffect, WriteDirEffect, ExecIOEffect, RootEffect], forbids: [].}
Returns a human readable diff of a, b, the exact form of which is implementation defined. See also experimental.diff.

Example:

let a = "ok1\nok2\nok3\n"
let b = "ok1\nok2 alt\nok3\nok4\n"
let (c, same) = diffStrings(a, b)
doAssert not same
let (c2, same2) = diffStrings(a, a)
doAssert same2

Example: cmd: -r:off

let a = "ok1\nok2\nok3\n"
let b = "ok1\nok2 alt\nok3\nok4\n"
echo diffStrings(a, b).output
Source   Edit  
proc isGitRepo(dir: string): bool {....raises: [OSError, IOError], tags: [
    ExecIOEffect, ReadIOEffect, RootEffect], forbids: [].}
This command is used to get the relative path to the root of the repository. Using this, we can verify whether a folder is a git repository by checking whether the command success and if the output is empty. Source   Edit  

Templates

template retryCall(maxRetry = 3; backoffDuration = 1.0; call: untyped): bool
Retry call up to maxRetry times with exponential backoff and initial duraton of backoffDuration seconds. This is in particular useful for network commands that can fail.

Example:

doAssert not retryCall(maxRetry = 2, backoffDuration = 0.1, false)
var i = 0
doAssert: retryCall(maxRetry = 3, backoffDuration = 0.1, (i.inc; i >= 3))
doAssert retryCall(call = true)
Source   Edit