Skip to content

Display file mode changes #23159

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

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ issues.action_check_all = Check/Uncheck all items
issues.opened_by = opened %[1]s by <a href="%[2]s">%[3]s</a>
pulls.merged_by = by <a href="%[2]s">%[3]s</a> was merged %[1]s
pulls.merged_by_fake = by %[2]s was merged %[1]s
pulls.changed_file_mode = %[1]s → %[2]s
issues.closed_by = by <a href="%[2]s">%[3]s</a> was closed %[1]s
issues.opened_by_fake = opened %[1]s by %[2]s
issues.closed_by_fake = by %[2]s was closed %[1]s
Expand Down
12 changes: 12 additions & 0 deletions services/gitdiff/gitdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ type DiffFile struct {
IsViewed bool // User specific
HasChangedSinceLastReview bool // User specific
Language string
Mode string
OldMode string
}

// GetType returns type of diff file.
Expand Down Expand Up @@ -577,9 +579,19 @@ parsingLoop:
break curFileLoop
case strings.HasPrefix(line, "old mode ") ||
strings.HasPrefix(line, "new mode "):

if strings.HasPrefix(line, "old mode ") {
curFile.OldMode = strings.ReplaceAll(line, "old mode ", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it should be TrimPrefix and then TrimSpace, because there is a line below strings.HasSuffix(line, " 160000\n")

}
if strings.HasPrefix(line, "new mode ") {
curFile.Mode = strings.ReplaceAll(line, "new mode ", "")
}

if strings.HasSuffix(line, " 160000\n") {
curFile.IsSubmodule = true
}
case strings.HasPrefix(line, "new file mode "):
curFile.Mode = strings.ReplaceAll(line, "new file mode ", "")
case strings.HasPrefix(line, "rename from "):
curFile.IsRenamed = true
curFile.Type = DiffFileRename
Expand Down
3 changes: 3 additions & 0 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
{{if $file.IsVendored}}
<span class="ui label gt-ml-3">{{$.locale.Tr "repo.diff.vendored"}}</span>
{{end}}
{{if and $file.Mode $file.OldMode}}
<span class="ui gt-ml-5 gt-mono">{{$.locale.Tr "repo.pulls.changed_file_mode" $file.OldMode $file.Mode}}</span>
{{end}}
</div>
<div class="diff-file-header-actions gt-df gt-ac">
{{if $showFileViewToggle}}
Expand Down