Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imported repositories branch name issue #157

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions internal/git/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package git

import (
"bytes"
"context"
"fmt"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
Expand All @@ -12,6 +13,7 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -121,30 +123,30 @@ 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",
revision+":"+filename,
)
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) {
Expand Down Expand Up @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion internal/i18n/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/i18n/locales/fr-FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down