Skip to content

Commit 7da4f5e

Browse files
committed
Add repository name as parent directory for archives
Addresses gogs/gogs#518
1 parent 1dad976 commit 7da4f5e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

commit_archive.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
package git
66

7-
import "fmt"
7+
import (
8+
"fmt"
9+
"path"
10+
"strings"
11+
)
812

913
type ArchiveType int
1014

@@ -13,7 +17,7 @@ const (
1317
TARGZ
1418
)
1519

16-
func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error {
20+
func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error {
1721
var format string
1822
switch archiveType {
1923
case ZIP:
@@ -24,6 +28,6 @@ func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error {
2428
return fmt.Errorf("unknown format: %v", archiveType)
2529
}
2630

27-
_, err := NewCommand("archive", "--format="+format, "-o", path, c.ID.String()).RunInDir(c.repo.Path)
31+
_, err := NewCommand("archive", "--prefix="+path.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/", "--format="+format, "-o", target, c.ID.String()).RunInDir(c.repo.Path)
2832
return err
2933
}

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.3.0"
13+
const _VERSION = "0.3.1"
1414

1515
func Version() string {
1616
return _VERSION

0 commit comments

Comments
 (0)