From b36134194cf8304ba553c2623447ea60586cd5e2 Mon Sep 17 00:00:00 2001
From: Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
Date: Wed, 3 Jun 2015 15:46:37 +0200
Subject: [PATCH 1/4] settings/password: no minimal required characters for
 OldPassword

If users are added to gogs due a reverse proxy automatically, their password is
set to their initial username. If their username is shorter than 6 characters,
they can never set a password. But since this password is required for some
operations (e.g. repository deletion), they could not use all features of gogs
until now.
---
 modules/auth/user_form.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go
index b616a460ffa9..d3d7306774fd 100644
--- a/modules/auth/user_form.go
+++ b/modules/auth/user_form.go
@@ -107,7 +107,7 @@ func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) bindi
 }
 
 type ChangePasswordForm struct {
-	OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(255)"`
+	OldPassword string `form:"old_password" binding:"Required;MinSize(1);MaxSize(255)"`
 	Password    string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
 	Retype      string `form:"retype"`
 }

From 6eecbf17cd8be6c2ee7f935e53a45c4f41f86d04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn?= <bo@kbct.de>
Date: Wed, 13 May 2015 14:15:05 +0200
Subject: [PATCH 2/4] fix debian init script

- use start-stop-daemon's chuid feature insted of su
  - using `su -c` breaks if the git user has no usable shell
  - this fixes #1025
- put --test before --exec, instead it gets passed to gogs
- set cwd via --chdir
---
 scripts/init/debian/gogs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/init/debian/gogs b/scripts/init/debian/gogs
index 13e8b8aa5b89..b0b52286fcf5 100644
--- a/scripts/init/debian/gogs
+++ b/scripts/init/debian/gogs
@@ -49,10 +49,12 @@ do_start()
 	#   1 if daemon was already running
 	#   2 if daemon could not be started
 	sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
-			--exec $DAEMON -- $DAEMON_ARGS --test > /dev/null \\
+			--test --chdir $WORKINGDIR --chuid $USER \\
+			--exec $DAEMON -- $DAEMON_ARGS > /dev/null \\
 			|| return 1"
 	sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
-			--background --exec /bin/su -- - $USER -c \"cd \\\"$WORKINGDIR\\\" && $DAEMON -- $DAEMON_ARGS\" \\
+			--background --chdir $WORKINGDIR --chuid $USER \\
+			--exec $DAEMON -- $DAEMON_ARGS \\
 			|| return 2"
 }
 

From 73698d292a2c60cbe947efc2f62c05d8ffd88277 Mon Sep 17 00:00:00 2001
From: stephen mcquay <stephen@mcquay.me>
Date: Mon, 8 Jun 2015 00:40:38 -0700
Subject: [PATCH 3/4] fix .keys route

This change fixes the output from /{{ username }}.keys so that it can work in
a ~/.ssh/authorized_keys file
---
 routers/user/home.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/routers/user/home.go b/routers/user/home.go
index 3484e78050f0..ef05be27a3c6 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -152,6 +152,7 @@ func ShowSSHKeys(ctx *middleware.Context, uid int64) {
 	var buf bytes.Buffer
 	for i := range keys {
 		buf.WriteString(keys[i].OmitEmail())
+		buf.WriteString("\n")
 	}
 	ctx.RenderData(200, buf.Bytes())
 }

From d82d9bc153580a6e09df784414f9b12d467d3e69 Mon Sep 17 00:00:00 2001
From: Matt Butcher <mattbutcher@google.com>
Date: Thu, 18 Jun 2015 05:01:05 -0600
Subject: [PATCH 4/4] Fix minor spelling issues.

---
 cmd/serve.go | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/cmd/serve.go b/cmd/serve.go
index 484060c4c326..63c3890a9b13 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -82,7 +82,7 @@ func runServ(c *cli.Context) {
 	}
 
 	if len(c.Args()) < 1 {
-		fail("Not enough arguments", "Not enough arugments")
+		fail("Not enough arguments", "Not enough arguments")
 	}
 
 	keys := strings.Split(c.Args()[0], "-")
@@ -97,7 +97,7 @@ func runServ(c *cli.Context) {
 
 	user, err := models.GetUserByKeyId(keyId)
 	if err != nil {
-		fail("internal error", "Fail to get user by key ID(%d): %v", keyId, err)
+		fail("internal error", "Failed to get user by key ID(%d): %v", keyId, err)
 	}
 
 	cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
@@ -113,7 +113,7 @@ func runServ(c *cli.Context) {
 	repoPath := strings.Trim(args, "'")
 	rr := strings.SplitN(repoPath, "/", 2)
 	if len(rr) != 2 {
-		fail("Invalid repository path", "Invalide repository path: %v", args)
+		fail("Invalid repository path", "Invalid repository path: %v", args)
 	}
 	repoUserName := rr[0]
 	repoName := strings.TrimSuffix(rr[1], ".git")
@@ -123,7 +123,7 @@ func runServ(c *cli.Context) {
 		if err == models.ErrUserNotExist {
 			fail("Repository owner does not exist", "Unregistered owner: %s", repoUserName)
 		}
-		fail("Internal error", "Fail to get repository owner(%s): %v", repoUserName, err)
+		fail("Internal error", "Failed to get repository owner(%s): %v", repoUserName, err)
 	}
 
 	repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
@@ -135,7 +135,7 @@ func runServ(c *cli.Context) {
 				fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", repoUser.Name, repoName)
 			}
 		}
-		fail("Internal error", "Fail to get repository: %v", err)
+		fail("Internal error", "Failed to get repository: %v", err)
 	}
 
 	requestedMode, has := COMMANDS[verb]
@@ -171,7 +171,7 @@ func runServ(c *cli.Context) {
 	gitcmd.Stdin = os.Stdin
 	gitcmd.Stderr = os.Stderr
 	if err = gitcmd.Run(); err != nil {
-		fail("Internal error", "Fail to execute git command: %v", err)
+		fail("Internal error", "Failed to execute git command: %v", err)
 	}
 
 	if requestedMode == models.ACCESS_MODE_WRITE {
@@ -184,7 +184,7 @@ func runServ(c *cli.Context) {
 			err = models.Update(task.RefName, task.OldCommitId, task.NewCommitId,
 				user.Name, repoUserName, repoName, user.Id)
 			if err != nil {
-				log.GitLogger.Error(2, "Fail to update: %v", err)
+				log.GitLogger.Error(2, "Failed to update: %v", err)
 			}
 		}