|
4 | 4 | "errors"
|
5 | 5 | "fmt"
|
6 | 6 | "io"
|
| 7 | + "os" |
| 8 | + "os/exec" |
7 | 9 | "strconv"
|
8 | 10 | "strings"
|
9 | 11 |
|
@@ -777,6 +779,36 @@ func printDeployMessages(out io.Writer, f fn.Function) {
|
777 | 779 | if !f.Local.Remote && (f.Build.Git.URL != "" || f.Build.Git.Revision != "" || f.Build.Git.ContextDir != "") {
|
778 | 780 | fmt.Fprintf(out, "Warning: git settings are only applicable when running with --remote. Local source code will be used.")
|
779 | 781 | }
|
| 782 | + |
| 783 | + // Git Branch Mismatch |
| 784 | + // ------------------- |
| 785 | + // When doing a remote build with --git-branch, warn if the local branch |
| 786 | + // doesn't match, as this can lead to confusion about which func.yaml is used. |
| 787 | + if f.Local.Remote && f.Build.Git.URL != "" && f.Build.Git.Revision != "" { |
| 788 | + // Doing a remote build, specified a git repository to pull from, and |
| 789 | + // specified a reference within that remote. |
| 790 | + currentBranch, err := getCurrentGitBranch() |
| 791 | + if err != nil { |
| 792 | + fmt.Fprintf(out, "Warning: unable to verify local and remote references match. %v\n", err) |
| 793 | + } else if currentBranch != f.Build.Git.Revision { |
| 794 | + fmt.Fprintf(out, "Warning: Local git branch '%s' does not match --git-branch '%s'. The local func.yaml will be used for function metadata (name, runtime, etc). Ensure your local branch matches the remote branch to avoid deployment issues.\n", currentBranch, f.Build.Git.Revision) |
| 795 | + } |
| 796 | + } |
| 797 | +} |
| 798 | + |
| 799 | +// getCurrentGitBranch returns the current git branch name |
| 800 | +func getCurrentGitBranch() (string, error) { |
| 801 | + gitCmd := os.Getenv("FUNC_GIT") |
| 802 | + if gitCmd == "" { |
| 803 | + gitCmd = "git" |
| 804 | + } |
| 805 | + |
| 806 | + cmd := exec.Command(gitCmd, "rev-parse", "--abbrev-ref", "HEAD") |
| 807 | + output, err := cmd.Output() |
| 808 | + if err != nil { |
| 809 | + return "", err |
| 810 | + } |
| 811 | + return strings.TrimSpace(string(output)), nil |
780 | 812 | }
|
781 | 813 |
|
782 | 814 | // isDigested checks that the given image reference has a digest. Invalid
|
|
0 commit comments