2019-09-07 04:47:18 -04:00
|
|
|
package repo
|
2017-01-03 22:27:20 -08:00
|
|
|
|
|
|
|
|
import (
|
2024-02-13 01:09:24 -05:00
|
|
|
"fmt"
|
|
|
|
|
|
2017-10-02 16:50:05 -07:00
|
|
|
"github.com/dokku/dokku/plugins/common"
|
2017-01-03 22:27:20 -08:00
|
|
|
)
|
|
|
|
|
|
2019-09-07 04:47:18 -04:00
|
|
|
// CommandGc runs 'git gc --aggressive' against the application's repo
|
|
|
|
|
func CommandGc(appName string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
2019-09-07 04:47:18 -04:00
|
|
|
return err
|
2017-01-03 22:27:20 -08:00
|
|
|
}
|
|
|
|
|
|
2020-03-10 14:12:05 -04:00
|
|
|
appRoot := common.AppRoot(appName)
|
2017-01-03 22:27:20 -08:00
|
|
|
cmdEnv := map[string]string{
|
|
|
|
|
"GIT_DIR": appRoot,
|
|
|
|
|
}
|
2024-02-13 01:09:24 -05:00
|
|
|
|
|
|
|
|
result, err := common.CallExecCommand(common.ExecCommandInput{
|
|
|
|
|
Command: "git",
|
|
|
|
|
Args: []string{"gc", "--aggressive"},
|
|
|
|
|
Env: cmdEnv,
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Unable to run git gc: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if result.ExitCode != 0 {
|
|
|
|
|
return fmt.Errorf("Unable to run git gc: %s", result.StderrContents())
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-07 04:47:18 -04:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandPurgeCache deletes the contents of the build cache stored in the repository
|
|
|
|
|
func CommandPurgeCache(appName string) error {
|
2020-12-25 00:00:26 -05:00
|
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
|
|
|
return err
|
2019-09-07 04:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return PurgeCache(appName)
|
2017-01-03 22:27:20 -08:00
|
|
|
}
|