Skip to content

git-annex: views for annex files #22

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

Merged
merged 1 commit into from
Nov 27, 2022
Merged
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
7 changes: 7 additions & 0 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import (
"unicode"
"unicode/utf8"

"code.gitea.io/gitea/modules/annex"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -261,6 +262,12 @@ func IsLetter(ch rune) bool {
func EntryIcon(entry *git.TreeEntry) string {
switch {
case entry.IsLink():
isAnnexed, _ := annex.IsAnnexed(entry)
if isAnnexed {
// git-annex files are sometimes stored as symlinks;
// short-circuit that so like LFS they are displayed as regular files
return "file"
}
te, err := entry.FollowLink()
if err != nil {
log.Debug(err.Error())
1 change: 1 addition & 0 deletions options/locale/locale_cs-CZ.ini
Original file line number Diff line number Diff line change
@@ -1067,6 +1067,7 @@ view_git_blame=Zobrazit Git Blame
video_not_supported_in_browser=Váš prohlížeč nepodporuje značku pro HTML5 video.
audio_not_supported_in_browser=Váš prohlížeč nepodporuje značku pro HTML5 audio.
stored_lfs=Uloženo pomocí Git LFS
stored_annex=Uloženo pomocí Git Annex
symbolic_link=Symbolický odkaz
commit_graph=Graf commitů
commit_graph.select=Vybrat větve
1 change: 1 addition & 0 deletions options/locale/locale_de-DE.ini
Original file line number Diff line number Diff line change
@@ -1043,6 +1043,7 @@ view_git_blame=Git Blame ansehen
video_not_supported_in_browser=Dein Browser unterstützt das HTML5 'video'-Tag nicht.
audio_not_supported_in_browser=Dein Browser unterstützt den HTML5 'audio'-Tag nicht.
stored_lfs=Gespeichert mit Git LFS
stored_annex=Gespeichert mit Git Annex
symbolic_link=Softlink
commit_graph=Commit graph
commit_graph.select=Branches auswählen
1 change: 1 addition & 0 deletions options/locale/locale_el-GR.ini
Original file line number Diff line number Diff line change
@@ -1064,6 +1064,7 @@ view_git_blame=Προβολή Git Blame
video_not_supported_in_browser=Το πρόγραμμα περιήγησής σας δεν υποστηρίζει την ετικέτα HTML5 'video'.
audio_not_supported_in_browser=Το πρόγραμμα περιήγησής σας δεν υποστηρίζει την ετικέτα HTML5 'audio'.
stored_lfs=Αποθηκεύτηκε με το Git LFS
stored_annex=Αποθηκεύτηκε με το Git Annex
symbolic_link=Symbolic link
commit_graph=Γράφημα Υποβολών
commit_graph.select=Επιλογή κλάδων
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
@@ -1075,6 +1075,7 @@ view_git_blame = View Git Blame
video_not_supported_in_browser = Your browser does not support the HTML5 'video' tag.
audio_not_supported_in_browser = Your browser does not support the HTML5 'audio' tag.
stored_lfs = Stored with Git LFS
stored_annex = Stored with Git Annex
symbolic_link = Symbolic link
commit_graph = Commit Graph
commit_graph.select = Select branches
1 change: 1 addition & 0 deletions options/locale/locale_es-ES.ini
Original file line number Diff line number Diff line change
@@ -1064,6 +1064,7 @@ view_git_blame=Ver la culpa de Git
video_not_supported_in_browser=Su navegador no soporta el tag video de HTML5.
audio_not_supported_in_browser=Su navegador no soporta el tag audio de HTML5.
stored_lfs=Almacenados con Git LFS
stored_annex=Almacenados con Git Annex
symbolic_link=Enlace simbólico
commit_graph=Gráfico de commits
commit_graph.select=Seleccionar ramas
1 change: 1 addition & 0 deletions options/locale/locale_fa-IR.ini
Original file line number Diff line number Diff line change
@@ -964,6 +964,7 @@ file_copy_permalink=پرمالینک را کپی کنید
video_not_supported_in_browser=مرورگر شما از تگ video که در HTML5 تعریف شده است، پشتیبانی نمی کند.
audio_not_supported_in_browser=مرورگر شما از تگ audio که در HTML5 تعریف شده است، پشتیبانی نمی کند.
stored_lfs=ذخیره شده با GIT LFS
stored_annex=ذخیره شده با GIT Annex
symbolic_link=پیوند نمادین
commit_graph=نمودار کامیت
commit_graph.select=انتخاب برنچها
1 change: 1 addition & 0 deletions options/locale/locale_fr-FR.ini
Original file line number Diff line number Diff line change
@@ -1055,6 +1055,7 @@ file_copy_permalink=Copier le lien permanent
video_not_supported_in_browser=Votre navigateur ne supporte pas le tag HTML5 "video".
audio_not_supported_in_browser=Votre navigateur ne supporte pas la balise « audio » HTML5.
stored_lfs=Stocké avec Git LFS
stored_annex=Stocké avec Git Annex
symbolic_link=Lien symbolique
commit_graph=Graphique des révisions
commit_graph.select=Sélectionner les branches
1 change: 1 addition & 0 deletions options/locale/locale_hu-HU.ini
Original file line number Diff line number Diff line change
@@ -703,6 +703,7 @@ file_too_large=Ez a fájl túl nagy ahhoz, hogy megjelenítsük.
video_not_supported_in_browser=A böngésző nem támogatja a HTML5 video tag-et.
audio_not_supported_in_browser=A böngésző nem támogatja a HTML5 audio tag-et.
stored_lfs=Git LFS-el eltárolva
stored_annex=Git Annex-el eltárolva
symbolic_link=Szimbolikus hivatkozás
commit_graph=Commit gráf
commit_graph.hide_pr_refs=Pull request-ek elrejtése
1 change: 1 addition & 0 deletions options/locale/locale_id-ID.ini
Original file line number Diff line number Diff line change
@@ -675,6 +675,7 @@ file_permalink=Permalink
file_too_large=Berkas terlalu besar untuk ditampilkan.

stored_lfs=Tersimpan dengan GIT LFS
stored_annex=Tersimpan dengan GIT Annex
commit_graph=Grafik Komit
blame=Salahkan
normal_view=Pandangan Normal
1 change: 1 addition & 0 deletions options/locale/locale_is-IS.ini
Original file line number Diff line number Diff line change
@@ -697,6 +697,7 @@ file_view_rendered=Skoða Unnið

file_copy_permalink=Afrita Varanlega Slóð
stored_lfs=Geymt með Git LFS
stored_annex=Geymt með Git Annex
commit_graph.hide_pr_refs=Fela Sameiningarbeiðnir
commit_graph.monochrome=Einlitað
commit_graph.color=Litað
1 change: 1 addition & 0 deletions options/locale/locale_it-IT.ini
Original file line number Diff line number Diff line change
@@ -1051,6 +1051,7 @@ view_git_blame=Visualizza Git Blame
video_not_supported_in_browser=Il tuo browser non supporta i tag "video" di HTML5.
audio_not_supported_in_browser=Il tuo browser non supporta il tag "video" di HTML5.
stored_lfs=Memorizzati con Git LFS
stored_annex=Memorizzati con Git Annex
symbolic_link=Link Simbolico
commit_graph=Grafico dei commit
commit_graph.select=Seleziona rami
1 change: 1 addition & 0 deletions options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
@@ -1065,6 +1065,7 @@ view_git_blame=Git Blameを表示
video_not_supported_in_browser=このブラウザはHTML5のvideoタグをサポートしていません。
audio_not_supported_in_browser=このブラウザーはHTML5のaudioタグをサポートしていません。
stored_lfs=Git LFSで保管されています
stored_annex=Git Annexで保管されています
symbolic_link=シンボリック リンク
commit_graph=コミットグラフ
commit_graph.select=ブランチを選択
1 change: 1 addition & 0 deletions options/locale/locale_ko-KR.ini
Original file line number Diff line number Diff line change
@@ -634,6 +634,7 @@ file_too_large=보여주기에는 파일이 너무 큽니다.
video_not_supported_in_browser=당신의 브라우저가 HTML5 'video' 태그를 지원하지 않습니다.
audio_not_supported_in_browser=당신의 브라우저가 HTML5 'audio' 태그를 지원하지 않습니다.
stored_lfs=Git LFS에 저장되어 있습니다
stored_annex=Git Annex에 저장되어 있습니다
commit_graph=커밋 그래프

editor.new_file=새 파일
1 change: 1 addition & 0 deletions options/locale/locale_lv-LV.ini
Original file line number Diff line number Diff line change
@@ -1044,6 +1044,7 @@ view_git_blame=Aplūkot Git vainīgos
video_not_supported_in_browser=Jūsu pārlūks neatbalsta HTML5 video.
audio_not_supported_in_browser=Jūsu pārlūks neatbalsta HTML5 audio.
stored_lfs=Saglabāts Git LFS
stored_annex=Saglabāts Git Annex
symbolic_link=Simboliska saite
commit_graph=Revīziju grafs
commit_graph.select=Izvēlieties atzarus
1 change: 1 addition & 0 deletions options/locale/locale_ml-IN.ini
Original file line number Diff line number Diff line change
@@ -652,6 +652,7 @@ file_too_large=ഈ ഫയൽ കാണിക്കാൻ കഴിയാത്
video_not_supported_in_browser=നിങ്ങളുടെ ബ്രൌസർ HTML5 'വീഡിയോ' ടാഗിനെ പിന്തുണയ്ക്കുന്നില്ല.
audio_not_supported_in_browser=നിങ്ങളുടെ ബ്ര browser സർ HTML5 'ഓഡിയോ' ടാഗിനെ പിന്തുണയ്ക്കുന്നില്ല.
stored_lfs=ഗിറ്റു് LFS ഉപയോഗിച്ച് സംഭരിച്ചു
stored_annex=ഗിറ്റു് Annex ഉപയോഗിച്ച് സംഭരിച്ചു
commit_graph=കമ്മിറ്റ് ഗ്രാഫ്
blame=ചുമതല
normal_view=സാധാരണ കാഴ്ച
1 change: 1 addition & 0 deletions options/locale/locale_nl-NL.ini
Original file line number Diff line number Diff line change
@@ -1051,6 +1051,7 @@ view_git_blame=Bekijk Git Blame
video_not_supported_in_browser=Je browser ondersteunt de HTML5 'video'-tag niet.
audio_not_supported_in_browser=Je browser ondersteunt de HTML5 'audio'-tag niet.
stored_lfs=Opgeslagen met Git LFS
stored_annex=Opgeslagen met Git Annex
symbolic_link=Symbolic link
commit_graph=Commit grafiek
commit_graph.select=Selecteer branches
1 change: 1 addition & 0 deletions options/locale/locale_pl-PL.ini
Original file line number Diff line number Diff line change
@@ -972,6 +972,7 @@ file_copy_permalink=Kopiuj bezpośredni odnośnik
video_not_supported_in_browser=Twoja przeglądarka nie obsługuje znacznika HTML5 "video".
audio_not_supported_in_browser=Twoja przeglądarka nie obsługuje znacznika HTML5 "audio".
stored_lfs=Przechowane za pomocą Git LFS
stored_annex=Przechowane za pomocą Git Annex
symbolic_link=Dowiązanie symboliczne
commit_graph=Wykres commitów
commit_graph.select=Wybierz gałęzie
1 change: 1 addition & 0 deletions options/locale/locale_pt-BR.ini
Original file line number Diff line number Diff line change
@@ -1053,6 +1053,7 @@ view_git_blame=Ver Git Blame
video_not_supported_in_browser=Seu navegador não suporta a tag 'video' do HTML5.
audio_not_supported_in_browser=Seu navegador não suporta a tag 'audio' do HTML5.
stored_lfs=Armazenado com Git LFS
stored_annex=Armazenado com Git Annex
symbolic_link=Link simbólico
commit_graph=Gráfico de commits
commit_graph.select=Selecionar branches
1 change: 1 addition & 0 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
@@ -1067,6 +1067,7 @@ view_git_blame=Ver Git Blame
video_not_supported_in_browser=O seu navegador não suporta a etiqueta 'video' do HTML5.
audio_not_supported_in_browser=O seu navegador não suporta a etiqueta 'audio' do HTML5.
stored_lfs=Armazenado com Git LFS
stored_annex=Armazenado com Git Annex
symbolic_link=Ligação simbólica
commit_graph=Gráfico de cometimentos
commit_graph.select=Escolher ramos
1 change: 1 addition & 0 deletions options/locale/locale_ru-RU.ini
Original file line number Diff line number Diff line change
@@ -1020,6 +1020,7 @@ file_copy_permalink=Копировать постоянную ссылку
video_not_supported_in_browser=Ваш браузер не поддерживает HTML5 'video' тэг.
audio_not_supported_in_browser=Ваш браузер не поддерживает HTML5 'audio' тэг.
stored_lfs=Хранится Git LFS
stored_annex=Хранится Git Annex
symbolic_link=Символическая ссылка
commit_graph=Граф коммитов
commit_graph.select=Выбрать ветку
1 change: 1 addition & 0 deletions options/locale/locale_si-LK.ini
Original file line number Diff line number Diff line change
@@ -919,6 +919,7 @@ file_copy_permalink=පිටපත් මාමලින්ක්
video_not_supported_in_browser=ඔබගේ බ්රව්සරය HTML5 'වීඩියෝ' ටැගය සඳහා සහය නොදක්වයි.
audio_not_supported_in_browser=ඔබගේ බ්රව්සරය HTML5 'ශ්රව්ය' ටැගය සඳහා සහය නොදක්වයි.
stored_lfs=Git LFS සමඟ ගබඩා
stored_annex=Git Annex සමඟ ගබඩා
symbolic_link=සංකේතාත්මක සබැඳිය
commit_graph=ප්රස්තාරය කැප
commit_graph.select=ශාඛා තෝරන්න
1 change: 1 addition & 0 deletions options/locale/locale_sk-SK.ini
Original file line number Diff line number Diff line change
@@ -959,6 +959,7 @@ view_git_blame=Zobraziť Git Blame
video_not_supported_in_browser=Váš prehliadač nepodporuje HTML5 tag 'video'.
audio_not_supported_in_browser=Váš prehliadač nepodporuje HTML5 tag 'audio'.
stored_lfs=Uložené pomocou Git LFS
stored_annex=Uložené pomocou Git Annex
symbolic_link=Symbolický odkaz
commit_graph=Graf commitov

1 change: 1 addition & 0 deletions options/locale/locale_sv-SE.ini
Original file line number Diff line number Diff line change
@@ -775,6 +775,7 @@ file_too_large=Filen är för stor för att visas.
video_not_supported_in_browser=Din webbläsare stödjer ej HTML5-taggen 'video'.
audio_not_supported_in_browser=Din webbläsare stöder inte taggen 'audio' i HTML5.
stored_lfs=Sparad med Git LFS
stored_annex=Sparad med Git Annex
symbolic_link=Symbolisk länk
commit_graph=Commit-Graf
commit_graph.monochrome=Mono
1 change: 1 addition & 0 deletions options/locale/locale_tr-TR.ini
Original file line number Diff line number Diff line change
@@ -1065,6 +1065,7 @@ view_git_blame=Git Suç Görüntüle
video_not_supported_in_browser=Tarayıcınız HTML5 'video' etiketini desteklemiyor.
audio_not_supported_in_browser=Tarayıcınız HTML5 'audio' etiketini desteklemiyor.
stored_lfs=Git LFS ile depolandı
stored_annex=Git Annex ile depolandı
symbolic_link=Sembolik Bağlantı
commit_graph=İşleme Grafiği
commit_graph.select=Dalları seç
1 change: 1 addition & 0 deletions options/locale/locale_uk-UA.ini
Original file line number Diff line number Diff line change
@@ -971,6 +971,7 @@ file_copy_permalink=Копіювати постійне посилання
video_not_supported_in_browser=Ваш браузер не підтримує тег 'video' HTML5.
audio_not_supported_in_browser=Ваш браузер не підтримує тег HTML5 'audio'.
stored_lfs=Збережено з Git LFS
stored_annex=Збережено з Git Annex
symbolic_link=Символічне посилання
commit_graph=Графік комітів
commit_graph.select=Виберіть гілки
1 change: 1 addition & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
@@ -1067,6 +1067,7 @@ view_git_blame=查看 Git Blame
video_not_supported_in_browser=您的浏览器不支持使用 HTML5 'video' 标签。
audio_not_supported_in_browser=您的浏览器不支持使用 HTML5 'video' 标签。
stored_lfs=存储到Git LFS
stored_annex=存储到Git Annex
symbolic_link=符号链接
commit_graph=提交图
commit_graph.select=选择分支
1 change: 1 addition & 0 deletions options/locale/locale_zh-HK.ini
Original file line number Diff line number Diff line change
@@ -313,6 +313,7 @@ file_view_raw=查看原始文件
file_permalink=永久連結

stored_lfs=儲存到到 Git LFS
stored_annex=儲存到到 Git Annex

editor.preview_changes=預覽更改
editor.or=或
1 change: 1 addition & 0 deletions options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
@@ -1055,6 +1055,7 @@ view_git_blame=檢視 Git Blame
video_not_supported_in_browser=您的瀏覽器不支援使用 HTML5 播放影片。
audio_not_supported_in_browser=您的瀏覽器不支援 HTML5 的「audio」標籤
stored_lfs=已使用 Git LFS 儲存
stored_annex=已使用 Git Annex 儲存
symbolic_link=符號連結
commit_graph=提交線圖
commit_graph.select=選擇分支
49 changes: 49 additions & 0 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/annex"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/container"
@@ -390,6 +391,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
isTextFile := st.IsText()

isLFSFile := false
isAnnexFile := false
isDisplayingSource := ctx.FormString("display") == "source"
isDisplayingRendered := !isDisplayingSource

@@ -431,13 +433,60 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
}

isAnnexed, err := annex.IsAnnexed(entry)
if err != nil {
ctx.ServerError("annex.IsAnnexed()", err)
return
}
if isAnnexed {
// TODO: this code could be merged with the LFS case, especially the redundant type sniffer,
// but it is *currently* written this way to make merging with the non-annex upstream easier:
// this way, the git-annex patch is (mostly) pure additions.

isAnnexFile = true
annexContent, err := annex.Content(entry)
if err != nil {
// in the case where annex content is missing, what should happen?
// do we render the page with an error message?
// actually that's not a bad idea, there's some sort of error message situation
// TODO: display an error to the user explaining that their data is missing
ctx.NotFound("annex.Content", err)
return
}
defer annexContent.Close()

dataRc = annexContent // NB: annexContent is a File, dataRc is a io.ReadCloser; we need both

stat, err := annexContent.Stat()
if err != nil {
ctx.ServerError("annex.Content().Stat()", err)
return
}
fileSize = stat.Size()

buf = make([]byte, 1024)
n, _ = util.ReadAtMost(dataRc, buf)
buf = buf[:n]

st = typesniffer.DetectContentType(buf)
isTextFile = st.IsText()

// pre-git-annex v7, all annexed files were represented in-repo as symlinks;
// but we pretend they aren't, since that's a distracting quirk of git-annex
// and not a meaningful choice on the user's part
ctx.Data["FileIsSymlink"] = false

ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/media/" + ctx.Repo.BranchNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
}

isRepresentableAsText := st.IsRepresentableAsText()
if !isRepresentableAsText {
// If we can't show plain text, always try to render.
isDisplayingSource = false
isDisplayingRendered = true
}
ctx.Data["IsLFSFile"] = isLFSFile
ctx.Data["IsAnnexFile"] = isAnnexFile
ctx.Data["FileSize"] = fileSize
ctx.Data["IsTextFile"] = isTextFile
ctx.Data["IsRepresentableAsText"] = isRepresentableAsText
1 change: 1 addition & 0 deletions templates/repo/file_info.tmpl
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
{{if .FileSize}}
<div class="file-info-entry">
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.locale.Tr "repo.stored_lfs"}}){{end}}
{{if .IsAnnexFile}} ({{.locale.Tr "repo.stored_annex"}}){{end}}
</div>
{{end}}
{{if .LFSLock}}
132 changes: 132 additions & 0 deletions tests/integration/git_annex_test.go
Original file line number Diff line number Diff line change
@@ -107,6 +107,110 @@ func doAnnexMediaTest(t *testing.T, ctx APITestContext, file string) {
require.True(t, match, "Annexed files should be the same")
}

func TestGitAnnexViews(t *testing.T) {
if !setting.Annex.Enabled {
t.Skip("Skipping since annex support is disabled.")
}

onGiteaRun(t, func(t *testing.T, u *url.URL) {
// create a public repo
ctx := NewAPITestContext(t, "user2", "annex-template-render-test")
require.NoError(t, doCreateRemoteAnnexRepository(t, u, ctx, false))

session := loginUser(t, ctx.Username)

t.Run("Index", func(t *testing.T) {
// test that annex symlinks renders with the _file icon_ on the main list
defer tests.PrintCurrentTest(t)()

repoLink := path.Join("/", ctx.Username, ctx.Reponame)
req := NewRequest(t, "GET", repoLink)
resp := session.MakeRequest(t, req, http.StatusOK)

htmlDoc := NewHTMLParser(t, resp.Body)
isFileIcon := htmlDoc.Find("tr[data-entryname='annexed.tiff'] > td.name svg").HasClass("octicon-file")
require.True(t, isFileIcon, "annexed files should render a plain file icon, even when stored via annex symlink")
})

t.Run("View", func(t *testing.T) {
// test how routers/web/repo/view.go + templates/repo/view_file.tmpl handle annexed files
defer tests.PrintCurrentTest(t)()

doViewTest := func(file string) (htmlDoc *HTMLDoc, viewLink, mediaLink string) {
viewLink = path.Join("/", ctx.Username, ctx.Reponame, "/src/branch/master", file)
// rawLink := strings.Replace(viewLink, "/src/", "/raw/", 1) // TODO: do something with this?
mediaLink = strings.Replace(viewLink, "/src/", "/media/", 1)

req := NewRequest(t, "GET", viewLink)
resp := session.MakeRequest(t, req, http.StatusOK)

htmlDoc = NewHTMLParser(t, resp.Body)
// the first button on the toolbar on the view template is the "Raw" button
// this CSS selector is the most precise I can think to use
buttonLink, exists := htmlDoc.Find(".file-header").Find("a[download]").Attr("href")
require.True(t, exists, "Download button should exist on the file header")
require.EqualValues(t, mediaLink, buttonLink, "Download link should use /media URL for annex files")

return
}

t.Run("Binary", func(t *testing.T) {
// test that annexing a file renders the /media link in /src and NOT the /raw link
defer tests.PrintCurrentTest(t)()

doBinaryViewTest := func(file string) {
htmlDoc, _, mediaLink := doViewTest(file)

rawLink, exists := htmlDoc.Find("div.file-view > div.view-raw > a").Attr("href")
require.True(t, exists, "Download link should render instead of content because this is a binary file")
require.EqualValues(t, mediaLink, rawLink)
}

t.Run("AnnexSymlink", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
doBinaryViewTest("annexed.tiff")
})
t.Run("AnnexPointer", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
doBinaryViewTest("annexed.bin")
})
})

t.Run("Text", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()

doTextViewTest := func(file string) {
htmlDoc, _, _ := doViewTest(file)
require.True(t, htmlDoc.Find("div.file-view").Is(".code-view"), "should render as code")
}

t.Run("AnnexSymlink", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
doTextViewTest("annexed.txt")

t.Run("Markdown", func(t *testing.T) {
// special case: check that markdown can be pulled out of the annex and rendered, too
defer tests.PrintCurrentTest(t)()
htmlDoc, _, _ := doViewTest("annexed.md")
require.True(t, htmlDoc.Find("div.file-view").Is(".markdown"), "should render as markdown")
})
})
t.Run("AnnexPointer", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
doTextViewTest("annexed.rst")

t.Run("Markdown", func(t *testing.T) {
// special case: check that markdown can be pulled out of the annex and rendered, too
defer tests.PrintCurrentTest(t)()
htmlDoc, _, _ := doViewTest("annexed.markdown")
require.True(t, htmlDoc.Find("div.file-view").Is(".markdown"), "should render as markdown")
})
})
})
})
})
}

/*
Test that permissions are enforced on git-annex-shell commands.
@@ -1017,6 +1121,14 @@ func doInitAnnexRepository(repoPath string) error {
if err != nil {
return err
}
_, err = f.WriteString("*.rst filter=annex\n")
if err != nil {
return err
}
_, err = f.WriteString("*.markdown filter=annex\n")
if err != nil {
return err
}
f.Close()

err = git.AddChanges(repoPath, false, ".")
@@ -1041,6 +1153,18 @@ func doInitAnnexRepository(repoPath string) error {
return err
}

// // a text file
err = os.WriteFile(path.Join(repoPath, "annexed.md"), []byte("Overview\n=====\n\n1. Profit\n2. ???\n3. Review Life Activations\n"), 0777)
if err != nil {
return err
}

// // a markdown file
err = os.WriteFile(path.Join(repoPath, "annexed.txt"), []byte("We're going to see the wizard\nThe wonderful\nMonkey of\nBoz\n"), 0777)
if err != nil {
return err
}

err = git.NewCommandNoGlobals("annex", "add", ".").Run(&git.RunOpts{Dir: repoPath})
if err != nil {
return err
@@ -1053,6 +1177,14 @@ func doInitAnnexRepository(repoPath string) error {
return err
}

// // a text file
err = os.WriteFile(path.Join(repoPath, "annexed.rst"), []byte("Title\n=====\n\n- this is to test annexing a text file\n- lists are fun\n"), 0777)
if err != nil {
return err
}

// // a markdown file
err = os.WriteFile(path.Join(repoPath, "annexed.markdown"), []byte("Overview\n=====\n\n1. Profit\n2. ???\n3. Review Life Activations\n"), 0777)
if err != nil {
return err
}