@@ -1951,6 +1951,85 @@ func TestBuildInvokeBinaryHelper(t *testing.T) {
1951
1951
})
1952
1952
}
1953
1953
1954
+ func TestGitCloneOrFetch (t * testing.T ) {
1955
+ if ! test .CommandVersionIsAtLeast (t , "2.49.0" , "git" , "version" ) {
1956
+ t .Skip ("git version is not 2.49.0" )
1957
+ }
1958
+
1959
+ tests := map [string ]struct {
1960
+ revision string
1961
+ sha string
1962
+ depth int
1963
+ assertError bool
1964
+ }{
1965
+ "main branch matching sha" : {
1966
+ revision : "main" ,
1967
+ sha : "1ea27a9695f80d7816d9e8ce025d9b2df83d0dd7" ,
1968
+ },
1969
+ "main refs matching sha" : {
1970
+ revision : "refs/heads/main" ,
1971
+ sha : "1ea27a9695f80d7816d9e8ce025d9b2df83d0dd7" ,
1972
+ },
1973
+ "main refs matching sha with depth 1" : {
1974
+ revision : "refs/heads/main" ,
1975
+ sha : "1ea27a9695f80d7816d9e8ce025d9b2df83d0dd7" ,
1976
+ depth : 1 ,
1977
+ },
1978
+ "main refs previous sha with depth 1" : {
1979
+ revision : "refs/heads/main" ,
1980
+ sha : "035c3a26fadbc7bd2f4101c84812a8b6e722f562" ,
1981
+ depth : 1 ,
1982
+ assertError : true ,
1983
+ },
1984
+ "main refs wrong sha" : {
1985
+ revision : "refs/heads/main" ,
1986
+ sha : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ,
1987
+ assertError : true ,
1988
+ },
1989
+ }
1990
+
1991
+ for tn , tt := range tests {
1992
+ t .Run (tn , func (t * testing.T ) {
1993
+ t .Parallel ()
1994
+ shellstest .OnEachShell (t , func (t * testing.T , shell string ) {
1995
+ t .Parallel ()
1996
+ buildtest .WithEachFeatureFlag (t , func (t * testing.T , setup buildtest.BuildSetupFn ) {
1997
+ t .Parallel ()
1998
+
1999
+ jobResponse , err := common .GetRemoteBuildResponse (`echo "Hello World"` )
2000
+
2001
+ assert .NoError (t , err )
2002
+ build := newBuild (t , jobResponse , shell )
2003
+
2004
+ setup (t , build )
2005
+
2006
+ build .GitInfo .Ref = tt .revision
2007
+ build .GitInfo .Sha = tt .sha
2008
+ if tt .depth > 0 {
2009
+ build .GitInfo .Depth = tt .depth
2010
+ }
2011
+
2012
+ out , err := buildtest .RunBuildReturningOutput (t , build )
2013
+ if tt .assertError {
2014
+ assert .Error (t , err )
2015
+ return
2016
+ }
2017
+
2018
+ assert .NoError (t , err )
2019
+
2020
+ if build .IsFeatureFlagOn (featureflags .UseGitNativeClone ) {
2021
+ assert .Contains (t , out , "Cloning into" )
2022
+ } else {
2023
+ assert .Contains (t , out , "Fetching changes" )
2024
+ }
2025
+ checkingOutHEAD := fmt .Sprintf ("Checking out %s as detached HEAD" , tt .sha [:8 ])
2026
+ assert .Contains (t , out , checkingOutHEAD )
2027
+ }, featureflags .UseGitNativeClone )
2028
+ })
2029
+ })
2030
+ }
2031
+ }
2032
+
1954
2033
func TestBuildPwshHandlesSyntaxErrors (t * testing.T ) {
1955
2034
helpers .SkipIntegrationTests (t , shells .SNPwsh )
1956
2035
0 commit comments