Skip to content

Commit

Permalink
Merge branch 'improve_git_rev-parse'
Browse files Browse the repository at this point in the history
  • Loading branch information
xorpaul committed Feb 12, 2018
2 parents fd917fb + a77971f commit 9d8ab0e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
3 changes: 1 addition & 2 deletions forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -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!")
Expand Down
2 changes: 1 addition & 1 deletion g10k.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
40 changes: 37 additions & 3 deletions g10k_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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

}
2 changes: 1 addition & 1 deletion git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d8ab0e

Please sign in to comment.