diff --git a/appl/lib/git/git.b b/appl/lib/git/git.b index 26f648f19..00facb9e0 100644 --- a/appl/lib/git/git.b +++ b/appl/lib/git/git.b @@ -1860,6 +1860,24 @@ findgitdir(dir: string): string return nil; } +# Read the push credentials for a repository. The file holds one +# "user:token" line, which sendpack encodes as HTTP Basic. Returns nil when +# it is absent or empty, which push reports as "no credentials found". +readcredentials(gitdir: string): string +{ + fd := sys->open(gitdir + "/credentials", Sys->OREAD); + if(fd == nil) + return nil; + buf := array [1024] of byte; + n := sys->read(fd, buf, len buf); + if(n <= 0) + return nil; + creds := strtrim(string buf[:n]); + if(len creds == 0) + return nil; + return creds; +} + getremoteurl(gitdir, remote: string): string { fd := sys->open(gitdir + "/config", Sys->OREAD); diff --git a/dis/lib/git/git.dis b/dis/lib/git/git.dis index 0e4fc6609..b582229fa 100644 Binary files a/dis/lib/git/git.dis and b/dis/lib/git/git.dis differ diff --git a/module/git.m b/module/git.m index f81426f5a..8d53363e5 100644 --- a/module/git.m +++ b/module/git.m @@ -137,6 +137,7 @@ splitfirst: fn(s: string, sep: int): (string, string); findgitdir: fn(dir: string): string; getremoteurl: fn(gitdir, remote: string): string; + readcredentials: fn(gitdir: string): string; writeref: fn(gitdir, name: string, h: Hash); writesymref: fn(gitdir, name, target: string); mkdirp: fn(filepath: string);