From 95a594d75aa14898ff266850fb3e65636a9396a9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Bakhmutov Date: Mon, 25 Aug 2014 20:28:14 +0700 Subject: [PATCH 1/6] Migrate all branches and tags --- models/repo.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/repo.go b/models/repo.go index f5d1ca834e..08c9f8dc25 100644 --- a/models/repo.go +++ b/models/repo.go @@ -305,17 +305,17 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str return repo, errors.New("git clone: " + stderr) } - // Pull data from source. + // Add remote and fetch data. if _, stderr, err = process.ExecDir(3*time.Minute, tmpDir, fmt.Sprintf("MigrateRepository(git pull): %s", repoPath), - "git", "pull", url); err != nil { - return repo, errors.New("git pull: " + stderr) + "git", "remote", "add", "-f", "--tags", "upstream", url); err != nil { + return repo, errors.New("git remote: " + stderr) } // Push data to local repository. if _, stderr, err = process.ExecDir(3*time.Minute, tmpDir, fmt.Sprintf("MigrateRepository(git push): %s", repoPath), - "git", "push", "origin", "master"); err != nil { + "git", "push", "--tags", "origin", "refs/remotes/upstream/*:refs/heads/*"); err != nil { return repo, errors.New("git push: " + stderr) } From 12639c577f297687539283bf8877a5583ecb8447 Mon Sep 17 00:00:00 2001 From: Marios Andreopoulos Date: Mon, 25 Aug 2014 18:54:50 +0300 Subject: [PATCH 2/6] Remove newline characters from ssh key before processing it. Fixes issue #370: https://github.com/gogits/gogs/issues/370 --- routers/user/setting.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routers/user/setting.go b/routers/user/setting.go index e091bc4381..21ff6df7c9 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -171,7 +171,10 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { return } - if ok, err := models.CheckPublicKeyString(form.Content); !ok { + // Remove newline characters from form.KeyContent + cleanKeyContent := strings.Replace(form.KeyContent, "\n", "", -1), + + if ok, err := models.CheckPublicKeyString(cleanKeyContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) ctx.Redirect("/user/settings/ssh") return @@ -180,7 +183,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { k := &models.PublicKey{ OwnerId: ctx.User.Id, Name: form.SSHTitle, - Content: form.Content, + Content: cleanKeyContent, } if err := models.AddPublicKey(k); err != nil { if err == models.ErrKeyAlreadyExist { From b40922f4d47001dcd7eeff811fcb96462e4bda41 Mon Sep 17 00:00:00 2001 From: Marios Andreopoulos Date: Mon, 25 Aug 2014 20:07:47 +0300 Subject: [PATCH 3/6] remove extra comma --- routers/user/setting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/user/setting.go b/routers/user/setting.go index 21ff6df7c9..51a647e3a5 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -172,7 +172,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { } // Remove newline characters from form.KeyContent - cleanKeyContent := strings.Replace(form.KeyContent, "\n", "", -1), + cleanKeyContent := strings.Replace(form.KeyContent, "\n", "", -1) if ok, err := models.CheckPublicKeyString(cleanKeyContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) From 3d79f59671b7e74ea1c66cb7bcb09bc85575e787 Mon Sep 17 00:00:00 2001 From: Marios Andreopoulos Date: Mon, 25 Aug 2014 20:20:44 +0300 Subject: [PATCH 4/6] fix wrong variable name --- routers/user/setting.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/user/setting.go b/routers/user/setting.go index 51a647e3a5..028e75212d 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -172,9 +172,9 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { } // Remove newline characters from form.KeyContent - cleanKeyContent := strings.Replace(form.KeyContent, "\n", "", -1) + cleanContent := strings.Replace(form.Content, "\n", "", -1) - if ok, err := models.CheckPublicKeyString(cleanKeyContent); !ok { + if ok, err := models.CheckPublicKeyString(cleanContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) ctx.Redirect("/user/settings/ssh") return @@ -183,7 +183,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { k := &models.PublicKey{ OwnerId: ctx.User.Id, Name: form.SSHTitle, - Content: cleanKeyContent, + Content: cleanContent, } if err := models.AddPublicKey(k); err != nil { if err == models.ErrKeyAlreadyExist { From cd0ddcfa01ea06ff64e4a05032f718a4b3097c25 Mon Sep 17 00:00:00 2001 From: Marios Andreopoulos Date: Mon, 25 Aug 2014 20:35:23 +0300 Subject: [PATCH 5/6] fix typo --- routers/user/setting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/user/setting.go b/routers/user/setting.go index 028e75212d..37039041c4 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -172,7 +172,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { } // Remove newline characters from form.KeyContent - cleanContent := strings.Replace(form.Content, "\n", "", -1) + cleanContent := string.Replace(form.Content, "\n", "", -1) if ok, err := models.CheckPublicKeyString(cleanContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) From 510d5a5d74301ad0083b1ea10aef6caa17cde8d8 Mon Sep 17 00:00:00 2001 From: Marios Andreopoulos Date: Mon, 25 Aug 2014 21:07:08 +0300 Subject: [PATCH 6/6] import strings --- routers/user/setting.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/user/setting.go b/routers/user/setting.go index 37039041c4..d3b792134d 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -5,6 +5,8 @@ package user import ( + "strings" + "github.com/Unknwon/com" "github.com/gogits/gogs/models" @@ -172,7 +174,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { } // Remove newline characters from form.KeyContent - cleanContent := string.Replace(form.Content, "\n", "", -1) + cleanContent := strings.Replace(form.Content, "\n", "", -1) if ok, err := models.CheckPublicKeyString(cleanContent); !ok { ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error()))