diff --git a/forge.go b/forge.go index 8b5b012..643c804 100644 --- a/forge.go +++ b/forge.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "os" "path/filepath" @@ -714,7 +713,7 @@ func syncForgeToModuleDir(name string, m ForgeModule, moduleDir string) { Debugf("Nothing to do, existing Forge module: " + targetDir + " has the same version " + me.version + " as the to be synced version: " + m.version) return } - log.Println(funcName + "(): Need to sync, because existing Forge module: " + targetDir + " has version " + me.version + " and the to be synced version is: " + m.version) + Infof("Need to sync, because existing Forge module: " + targetDir + " has version " + me.version + " and the to be synced version is: " + m.version) createOrPurgeDir(targetDir, " targetDir for module "+me.name) } else { Debugf("Need to purge " + targetDir + ", because it exists without a metadata.json. This shouldn't happen!") diff --git a/g10k.go b/g10k.go index cbf3478..92c8018 100644 --- a/g10k.go +++ b/g10k.go @@ -176,7 +176,7 @@ func main() { version := *versionFlag if version { - fmt.Println("g10k version 0.4.3 Build time:", buildtime, "UTC") + fmt.Println("g10k version 0.4.5 Build time:", buildtime, "UTC") os.Exit(0) } diff --git a/g10k_test.go b/g10k_test.go index 59dd23b..110158b 100644 --- a/g10k_test.go +++ b/g10k_test.go @@ -818,7 +818,7 @@ func TestResolvePuppetfileFallback(t *testing.T) { t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s", string(out)) } - if !strings.Contains(string(out), "executeCommand(): Executing git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-apt.git rev-parse --verify 'foooooobbaar'") { + if !strings.Contains(string(out), "executeCommand(): Executing git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-apt.git rev-parse --verify 'foooooobbaar^{object}'") { t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s", string(out)) } @@ -871,7 +871,7 @@ func TestResolvePuppetfileDefaultBranch(t *testing.T) { t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s", string(out)) } - if !strings.Contains(string(out), "Executing git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-apache.git rev-parse --verify 'master' took") { + if !strings.Contains(string(out), "Executing git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-apache.git rev-parse --verify 'master^{object}' took") { t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s", string(out)) } @@ -924,7 +924,7 @@ func TestResolvePuppetfileControlBranch(t *testing.T) { t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s", string(out)) } - if !strings.Contains(string(out), "Executing git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-apache.git rev-parse --verify 'master' took") { + if !strings.Contains(string(out), "Executing git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-apache.git rev-parse --verify 'master^{object}' took") { t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s", string(out)) } @@ -1037,3 +1037,37 @@ func TestResolvePuppetfileLocalModules(t *testing.T) { debug = false } + +func TestResolvePuppetfileInvalidGitObject(t *testing.T) { + quiet = true + funcName := strings.Split(funcName(), ".")[len(strings.Split(funcName(), "."))-1] + config = readConfigfile("tests/TestConfigPrefix.yaml") + if os.Getenv("TEST_FOR_CRASH_"+funcName) == "1" { + debug = true + resolvePuppetEnvironment("invalid_git_object") + return + } + + cmd := exec.Command(os.Args[0], "-test.run="+funcName+"$") + cmd.Env = append(os.Environ(), "TEST_FOR_CRASH_"+funcName+"=1") + out, err := cmd.CombinedOutput() + + exitCode := 0 + if msg, ok := err.(*exec.ExitError); ok { // there is error code + exitCode = msg.Sys().(syscall.WaitStatus).ExitStatus() + } + + //fmt.Println(string(out)) + if 1 != exitCode { + t.Errorf("resolvePuppetEnvironment() terminated with %v, but we expected exit status %v Output: %s", exitCode, 1, string(out)) + } + + expectingString := "executeCommand(): git command failed: git --git-dir /tmp/g10k/modules/https-__github.com_puppetlabs_puppetlabs-firewall.git rev-parse --verify '0000000000000000000000000000000000000000^{object}' exit status 128" + if !strings.Contains(string(out), expectingString) { + t.Errorf("resolvePuppetEnvironment() terminated with the correct exit code, but the expected output was missing. out: %s\nExpecting string: %s", string(out), expectingString) + } + + moduleParam = "" + debug = false + +} diff --git a/git.go b/git.go index 9cfe789..b070bfc 100644 --- a/git.go +++ b/git.go @@ -133,7 +133,7 @@ func syncToModuleDir(srcDir string, targetDir string, tree string, allowFail boo Fatalf("Could not find cached git module " + srcDir) } } - logCmd := "git --git-dir " + srcDir + " rev-parse --verify '" + tree + "'" + logCmd := "git --git-dir " + srcDir + " rev-parse --verify '" + tree + "^{object}'" er := executeCommand(logCmd, config.Timeout, allowFail) hashFile := targetDir + "/.latest_commit" needToSync := true