Detect buildpacks for specific branch (fall back to deploy-branch to be consistent with deployment behavior)
This commit is contained in:
@@ -64,15 +64,25 @@ func validBuildpackURL(buildpack string) (string, error) {
|
||||
return buildpack, fmt.Errorf("Invalid buildpack specified: %v", buildpack)
|
||||
}
|
||||
|
||||
func checkoutBareGitRepo(sourceWorkDir string) (string, error) {
|
||||
func checkoutBareGitRepo(sourceWorkDir string, branch string) (string, error) {
|
||||
tmpdir, err := os.MkdirTemp("", "bare-git-checkout")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unable to create temporary directory: %s", err.Error())
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--git-dir=" + sourceWorkDir,
|
||||
"--work-tree=" + tmpdir,
|
||||
"checkout", "-f",
|
||||
}
|
||||
|
||||
if branch != "" {
|
||||
args = append(args, branch)
|
||||
}
|
||||
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "git",
|
||||
Args: []string{"--git-dir=" + sourceWorkDir, "--work-tree=" + tmpdir, "checkout", "-f"},
|
||||
Args: args,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -20,7 +20,7 @@ Additional commands:`
|
||||
helpContent = `
|
||||
buildpacks:add [--index 1] <app> <buildpack>, Add new app buildpack while inserting into list of buildpacks if necessary
|
||||
buildpacks:clear <app>, Clear all buildpacks set on the app
|
||||
buildpacks:detect <app>, Detect the buildpack for an app
|
||||
buildpacks:detect <app> [--branch <branch-name>], Detect the buildpack for an app (if not specified, the branch flag defaults to the deploy branch)
|
||||
buildpacks:list <app>, List all buildpacks for an app
|
||||
buildpacks:remove <app> <buildpack>, Remove a buildpack set on the app
|
||||
buildpacks:report [<app>] [<flag>], Displays a buildpack report for one or more apps
|
||||
|
||||
@@ -32,9 +32,13 @@ func main() {
|
||||
err = buildpacks.CommandClear(appName)
|
||||
case "detect":
|
||||
args := flag.NewFlagSet("buildpacks:detect", flag.ExitOnError)
|
||||
branch := args.String("branch", "", "--branch: the branch to detect against (defaults to the deploy branch)")
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
err = buildpacks.CommandDetect(appName)
|
||||
if *branch == "" {
|
||||
*branch = common.PropertyGet("git", appName, "deploy-branch")
|
||||
}
|
||||
err = buildpacks.CommandDetect(appName, *branch)
|
||||
case "list":
|
||||
args := flag.NewFlagSet("buildpacks:list", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
@@ -32,13 +32,13 @@ func CommandClear(appName string) error {
|
||||
}
|
||||
|
||||
// CommandDetect implements buildpacks:detect
|
||||
func CommandDetect(appName string) error {
|
||||
func CommandDetect(appName string, branch string) (err error) {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
workDir := common.AppRoot(appName)
|
||||
checkedOutDir, err := checkoutBareGitRepo(workDir)
|
||||
checkedOutDir, err := checkoutBareGitRepo(workDir, branch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user