mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-23 04:52:40 +00:00
Fix: bare first branch name, truncated output hanging (#157)
This commit is contained in:
parent
d518a44d32
commit
09fb647f03
3 changed files with 19 additions and 11 deletions
|
@ -2,6 +2,7 @@ package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -121,7 +123,12 @@ func GetFileContent(user string, gist string, revision string, filename string,
|
||||||
maxBytes = truncateLimit
|
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",
|
"git",
|
||||||
"--no-pager",
|
"--no-pager",
|
||||||
"show",
|
"show",
|
||||||
|
@ -129,22 +136,17 @@ func GetFileContent(user string, gist string, revision string, filename string,
|
||||||
)
|
)
|
||||||
cmd.Dir = repositoryPath
|
cmd.Dir = repositoryPath
|
||||||
|
|
||||||
stdout, _ := cmd.StdoutPipe()
|
output, err := cmd.Output()
|
||||||
err := cmd.Start()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
output, truncated, err := truncateCommandOutput(stdout, maxBytes)
|
content, truncated, err := truncateCommandOutput(bytes.NewReader(output), maxBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
return content, truncated, nil
|
||||||
return "", false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return output, truncated, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLog(user string, gist string, skip int) ([]*Commit, error) {
|
func GetLog(user string, gist string, skip int) ([]*Commit, error) {
|
||||||
|
@ -459,6 +461,12 @@ fi
|
||||||
|
|
||||||
const postReceive = `#!/bin/sh
|
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 ""
|
||||||
echo "Your new repository has been created here: %s"
|
echo "Your new repository has been created here: %s"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
@ -80,7 +80,7 @@ gist.revision.go-to-revision: Go to revision
|
||||||
gist.revision.file-created: file created
|
gist.revision.file-created: file created
|
||||||
gist.revision.file-deleted: file deleted
|
gist.revision.file-deleted: file deleted
|
||||||
gist.revision.file-renamed: renamed to
|
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.file-renamed-no-changes: File renamed without changes
|
||||||
gist.revision.empty-file: Empty file
|
gist.revision.empty-file: Empty file
|
||||||
gist.revision.no-changes: No changes
|
gist.revision.no-changes: No changes
|
||||||
|
|
|
@ -80,7 +80,7 @@ gist.revision.go-to-revision: Aller à la révision
|
||||||
gist.revision.file-created: fichier créé
|
gist.revision.file-created: fichier créé
|
||||||
gist.revision.file-deleted: fichier supprimé
|
gist.revision.file-deleted: fichier supprimé
|
||||||
gist.revision.file-renamed: renommé en
|
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.file-renamed-no-changes: Fichier renommé sans modifications
|
||||||
gist.revision.empty-file: Fichier vide
|
gist.revision.empty-file: Fichier vide
|
||||||
gist.revision.no-changes: Aucun changement
|
gist.revision.no-changes: Aucun changement
|
||||||
|
|
Loading…
Reference in a new issue