aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/git_helper_for_declarative_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-10-12 01:13:27 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2019-10-12 08:13:27 +0800
commit5e759b60cca3cd8484a6235fcc9120d18e8cd455 (patch)
treeb9932067119f16197f69f12ec9b04aa74f68845a /integrations/git_helper_for_declarative_test.go
parentac3613b791884f29c386bda2ccaad5c7434d822c (diff)
downloadgitea-5e759b60cca3cd8484a6235fcc9120d18e8cd455.tar.gz
gitea-5e759b60cca3cd8484a6235fcc9120d18e8cd455.zip
Restore functionality for early gits (#7775)
* Change tests to make it possible to run TestGit with 1.7.2 * Make merge run on 1.7.2 * Fix tracking and staging branch name problem * Ensure that git 1.7.2 works on tests * ensure that there is no chance for conflicts * Fix-up missing merge issues * Final rm * Ensure LFS filters run on the tests * Do not sign commits from temp repo * Restore tracking fetch change * Apply suggestions from code review * Update modules/repofiles/temp_repo.go
Diffstat (limited to 'integrations/git_helper_for_declarative_test.go')
-rw-r--r--integrations/git_helper_for_declarative_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/integrations/git_helper_for_declarative_test.go b/integrations/git_helper_for_declarative_test.go
index 628611d2d7..294f0bc5fe 100644
--- a/integrations/git_helper_for_declarative_test.go
+++ b/integrations/git_helper_for_declarative_test.go
@@ -12,7 +12,9 @@ import (
"net/http"
"net/url"
"os"
+ "path"
"path/filepath"
+ "strings"
"testing"
"time"
@@ -37,7 +39,12 @@ func withKeyFile(t *testing.T, keyname string, callback func(string)) {
err = ssh.GenKeyPair(keyFile)
assert.NoError(t, err)
+ err = ioutil.WriteFile(path.Join(tmpDir, "ssh"), []byte("#!/bin/bash\n"+
+ "ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\" \"$@\""), 0700)
+ assert.NoError(t, err)
+
//Setup ssh wrapper
+ os.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
os.Setenv("GIT_SSH_COMMAND",
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
os.Setenv("GIT_SSH_VARIANT", "ssh")
@@ -54,6 +61,24 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
return &u2
}
+func allowLFSFilters() []string {
+ // Now here we should explicitly allow lfs filters to run
+ globalArgs := git.GlobalCommandArgs
+ filteredLFSGlobalArgs := make([]string, len(git.GlobalCommandArgs))
+ j := 0
+ for _, arg := range git.GlobalCommandArgs {
+ if strings.Contains(arg, "lfs") {
+ j--
+ } else {
+ filteredLFSGlobalArgs[j] = arg
+ j++
+ }
+ }
+ filteredLFSGlobalArgs = filteredLFSGlobalArgs[:j]
+ git.GlobalCommandArgs = filteredLFSGlobalArgs
+ return globalArgs
+}
+
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
prepareTestEnv(t, 1)
s := http.Server{
@@ -79,7 +104,9 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
+ oldGlobals := allowLFSFilters()
assert.NoError(t, git.Clone(u.String(), dstLocalPath, git.CloneRepoOptions{}))
+ git.GlobalCommandArgs = oldGlobals
assert.True(t, com.IsExist(filepath.Join(dstLocalPath, "README.md")))
}
}
@@ -140,7 +167,9 @@ func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
return func(t *testing.T) {
+ oldGlobals := allowLFSFilters()
_, err := git.NewCommand(append([]string{"checkout"}, args...)...).RunInDir(dstPath)
+ git.GlobalCommandArgs = oldGlobals
assert.NoError(t, err)
}
}
@@ -154,7 +183,9 @@ func doGitMerge(dstPath string, args ...string) func(*testing.T) {
func doGitPull(dstPath string, args ...string) func(*testing.T) {
return func(t *testing.T) {
+ oldGlobals := allowLFSFilters()
_, err := git.NewCommand(append([]string{"pull"}, args...)...).RunInDir(dstPath)
+ git.GlobalCommandArgs = oldGlobals
assert.NoError(t, err)
}
}