TempWorkdir creates a temporary directory and configures the Repository to use it as a work dir. HEAD is checked out to the temporary working directory. The path of the working directory is returned as a string.
()
| 10 | // TempWorkdir creates a temporary directory and configures the Repository to use it as a work dir. |
| 11 | // HEAD is checked out to the temporary working directory. The path of the working directory is returned as a string. |
| 12 | func (p *Project) TempWorkdir() (string, error) { |
| 13 | name, err := ioutil.TempDir("", "spread-workdir") |
| 14 | if err != nil { |
| 15 | return "", err |
| 16 | } |
| 17 | |
| 18 | opts := &git.CheckoutOpts{ |
| 19 | TargetDirectory: name, |
| 20 | } |
| 21 | |
| 22 | if err = p.repo.CheckoutHead(opts); err != nil { |
| 23 | os.RemoveAll(name) |
| 24 | return "", err |
| 25 | } |
| 26 | |
| 27 | return name, p.repo.SetWorkdir(name, false) |
| 28 | } |
| 29 | |
| 30 | // CleanupWorkdir removes the given directory and sets the repositories Workdir to an empty string. |
| 31 | func (p *Project) CleanupWorkdir(dir string) error { |