Fix: bare first branch name, truncated output hanging (#157)

This commit is contained in:
Thomas Miceli 2023-11-21 02:03:59 +09:00 committed by GitHub
parent d518a44d32
commit 09fb647f03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 11 deletions

View file

@ -2,6 +2,7 @@ package git
import (
"bytes"
"context"
"fmt"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
@ -12,6 +13,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
)
var (
@ -121,7 +123,12 @@ func GetFileContent(user string, gist string, revision string, filename string,
maxBytes = truncateLimit
}
cmd := exec.Command(
// Set up a context with a timeout
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
cmd := exec.CommandContext(
ctx,
"git",
"--no-pager",
"show",
@ -129,22 +136,17 @@ func GetFileContent(user string, gist string, revision string, filename string,
)
cmd.Dir = repositoryPath
stdout, _ := cmd.StdoutPipe()
err := cmd.Start()
output, err := cmd.Output()
if err != nil {
return "", false, err
}
output, truncated, err := truncateCommandOutput(stdout, maxBytes)
content, truncated, err := truncateCommandOutput(bytes.NewReader(output), maxBytes)
if err != nil {
return "", false, err
}
if err := cmd.Wait(); err != nil {
return "", false, err
}
return output, truncated, nil
return content, truncated, nil
}
func GetLog(user string, gist string, skip int) ([]*Commit, error) {
@ -459,6 +461,12 @@ fi
const postReceive = `#!/bin/sh
while read oldrev newrev refname; do
if ! git rev-parse --verify --quiet HEAD &>/dev/null; then
git symbolic-ref HEAD "$refname"
fi
done
echo ""
echo "Your new repository has been created here: %s"
echo ""

View file

@ -80,7 +80,7 @@ gist.revision.go-to-revision: Go to revision
gist.revision.file-created: file created
gist.revision.file-deleted: file deleted
gist.revision.file-renamed: renamed to
gist.revision.diff-truncated: Diff truncated because it's too large to be shown
gist.revision.diff-truncated: Diff is too large to be shown
gist.revision.file-renamed-no-changes: File renamed without changes
gist.revision.empty-file: Empty file
gist.revision.no-changes: No changes

View file

@ -80,7 +80,7 @@ gist.revision.go-to-revision: Aller à la révision
gist.revision.file-created: fichier créé
gist.revision.file-deleted: fichier supprimé
gist.revision.file-renamed: renommé en
gist.revision.diff-truncated: Révision tronquée car trop volumineuse pour être affichée
gist.revision.diff-truncated: Révision trop volumineuse pour être affichée
gist.revision.file-renamed-no-changes: Fichier renommé sans modifications
gist.revision.empty-file: Fichier vide
gist.revision.no-changes: Aucun changement