Skip to content

Commit 53420c9

Browse files
authored
Merge pull request #263 from hekki/fix-file-permission-loss
Preserve file modes
2 parents 49c02dc + 44c680c commit 53420c9

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

tagpr.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (tp *tagpr) Run(ctx context.Context) error {
355355
}
356356

357357
// Detect modified files and create a new tree object
358-
diffFiles, _, err := tp.c.Git("diff", "--name-status", "HEAD")
358+
diffFiles, _, err := tp.c.Git("diff", "--raw", "HEAD")
359359
if err != nil {
360360
return err
361361
}
@@ -364,12 +364,15 @@ func (tp *tagpr) Run(ctx context.Context) error {
364364
if strings.TrimSpace(line) == "" {
365365
continue
366366
}
367+
if !strings.HasPrefix(line, ":") {
368+
continue
369+
}
367370
parts := strings.Fields(line)
368-
if len(parts) < 2 {
371+
if len(parts) < 6 {
369372
continue
370373
}
371374

372-
status, filePath := parts[0], parts[1]
375+
newMode, status, filePath := parts[1], parts[4], parts[5]
373376
switch status {
374377
case "A", "M": // Created or modified files
375378
contentBytes, err := os.ReadFile(filePath)
@@ -380,7 +383,7 @@ func (tp *tagpr) Run(ctx context.Context) error {
380383
Path: github.Ptr(filePath),
381384
Type: github.Ptr("blob"),
382385
Content: github.Ptr(string(contentBytes)),
383-
Mode: github.Ptr("100644"),
386+
Mode: github.Ptr(newMode),
384387
})
385388
case "D": // Deleted files
386389
treeEntries = append(treeEntries, &github.TreeEntry{

0 commit comments

Comments
 (0)