| 115 | } |
| 116 | |
| 117 | func getCommitAndDirty() (commit string, dirty bool, err error) { |
| 118 | info, ok := debug.ReadBuildInfo() |
| 119 | if !ok { |
| 120 | return "", false, fmt.Errorf("unable to read build info") |
| 121 | } |
| 122 | |
| 123 | var commitFound bool |
| 124 | |
| 125 | // get the commit and modified status |
| 126 | // (that is the flag for repository dirty or not) |
| 127 | for _, kv := range info.Settings { |
| 128 | switch kv.Key { |
| 129 | case "vcs.revision": |
| 130 | commit = kv.Value |
| 131 | commitFound = true |
| 132 | case "vcs.modified": |
| 133 | if kv.Value == "true" { |
| 134 | dirty = true |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if !commitFound { |
| 140 | return "", false, fmt.Errorf("no commit found") |
| 141 | } |
| 142 | |
| 143 | return commit, dirty, nil |
| 144 | } |