prePushRefs parses commit information that the pre-push git hook receives: Each line describes a proposed update of the remote ref at the remote sha to the local sha. Multiple updates can be received on multiple lines (such as from 'git push --a
(r io.Reader)
| 72 | // the local sha. Multiple updates can be received on multiple lines (such as |
| 73 | // from 'git push --all'). These updates are typically received over STDIN. |
| 74 | func prePushRefs(r io.Reader) []*git.RefUpdate { |
| 75 | scanner := bufio.NewScanner(r) |
| 76 | refs := make([]*git.RefUpdate, 0, 1) |
| 77 | |
| 78 | // We can be passed multiple lines of refs |
| 79 | for scanner.Scan() { |
| 80 | line := strings.TrimSpace(scanner.Text()) |
| 81 | if len(line) == 0 { |
| 82 | continue |
| 83 | } |
| 84 | |
| 85 | tracerx.Printf("pre-push: %s", line) |
| 86 | |
| 87 | localRef, remoteRef := decodeRefs(line) |
| 88 | if git.IsZeroObjectID(localRef.Sha) { |
| 89 | continue |
| 90 | } |
| 91 | |
| 92 | refs = append(refs, git.NewRefUpdate(cfg.Git, cfg.PushRemote(), localRef, remoteRef)) |
| 93 | } |
| 94 | |
| 95 | return refs |
| 96 | } |
| 97 | |
| 98 | // decodeRefs pulls the sha1s out of the line read from the pre-push |
| 99 | // hook's stdin. |
no test coverage detected