| 149 | } |
| 150 | |
| 151 | func (r *Repo) Cleanup() { |
| 152 | // pop out if necessary |
| 153 | r.Popd() |
| 154 | |
| 155 | // Make sure cwd isn't inside a path we're going to delete |
| 156 | oldwd, err := os.Getwd() |
| 157 | if err == nil { |
| 158 | if strings.HasPrefix(oldwd, r.Path) || |
| 159 | strings.HasPrefix(oldwd, r.GitDir) { |
| 160 | os.Chdir(os.TempDir()) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | if r.GitDir != "" { |
| 165 | os.RemoveAll(r.GitDir) |
| 166 | r.GitDir = "" |
| 167 | } |
| 168 | if r.Path != "" { |
| 169 | os.RemoveAll(r.Path) |
| 170 | r.Path = "" |
| 171 | } |
| 172 | for _, remote := range r.Remotes { |
| 173 | remote.Cleanup() |
| 174 | } |
| 175 | r.Remotes = nil |
| 176 | } |
| 177 | |
| 178 | // NewRepo creates a new git repo in a new temp dir |
| 179 | func NewRepo(callback RepoCallback) *Repo { |