You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo.go 72 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
9 years ago
10 years ago
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
9 years ago
9 years ago
9 years ago
11 years ago
9 years ago
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
9 years ago
11 years ago
11 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
11 years ago
11 years ago
11 years ago
9 years ago
9 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
9 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
9 years ago
11 years ago
9 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
11 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
8 years ago
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
8 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "html/template"
  10. "io/ioutil"
  11. "os"
  12. "os/exec"
  13. "path"
  14. "path/filepath"
  15. "regexp"
  16. "sort"
  17. "strings"
  18. "time"
  19. "code.gitea.io/git"
  20. "code.gitea.io/gitea/modules/log"
  21. "code.gitea.io/gitea/modules/markdown"
  22. "code.gitea.io/gitea/modules/options"
  23. "code.gitea.io/gitea/modules/process"
  24. "code.gitea.io/gitea/modules/setting"
  25. "code.gitea.io/gitea/modules/sync"
  26. api "code.gitea.io/sdk/gitea"
  27. "github.com/Unknwon/cae/zip"
  28. "github.com/Unknwon/com"
  29. "github.com/go-xorm/builder"
  30. "github.com/go-xorm/xorm"
  31. version "github.com/mcuadros/go-version"
  32. ini "gopkg.in/ini.v1"
  33. )
  34. const (
  35. tplUpdateHook = "#!/usr/bin/env %s\n%s update $1 $2 $3 --config='%s'\n"
  36. )
  37. var repoWorkingPool = sync.NewExclusivePool()
  38. var (
  39. // ErrRepoFileNotExist repository file does not exist error
  40. ErrRepoFileNotExist = errors.New("Repository file does not exist")
  41. // ErrRepoFileNotLoaded repository file not loaded error
  42. ErrRepoFileNotLoaded = errors.New("Repository file not loaded")
  43. // ErrMirrorNotExist mirror does not exist error
  44. ErrMirrorNotExist = errors.New("Mirror does not exist")
  45. // ErrInvalidReference invalid reference specified error
  46. ErrInvalidReference = errors.New("Invalid reference specified")
  47. // ErrNameEmpty name is empty error
  48. ErrNameEmpty = errors.New("Name is empty")
  49. )
  50. var (
  51. // Gitignores contains the gitiginore files
  52. Gitignores []string
  53. // Licenses contains the license files
  54. Licenses []string
  55. // Readmes contains the readme files
  56. Readmes []string
  57. // LabelTemplates contains the label template files
  58. LabelTemplates []string
  59. // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
  60. ItemsPerPage = 40
  61. )
  62. // LoadRepoConfig loads the repository config
  63. func LoadRepoConfig() {
  64. // Load .gitignore and license files and readme templates.
  65. types := []string{"gitignore", "license", "readme", "label"}
  66. typeFiles := make([][]string, 4)
  67. for i, t := range types {
  68. files, err := options.Dir(t)
  69. if err != nil {
  70. log.Fatal(4, "Failed to get %s files: %v", t, err)
  71. }
  72. customPath := path.Join(setting.CustomPath, "options", t)
  73. if com.IsDir(customPath) {
  74. customFiles, err := com.StatDir(customPath)
  75. if err != nil {
  76. log.Fatal(4, "Failed to get custom %s files: %v", t, err)
  77. }
  78. for _, f := range customFiles {
  79. if !com.IsSliceContainsStr(files, f) {
  80. files = append(files, f)
  81. }
  82. }
  83. }
  84. typeFiles[i] = files
  85. }
  86. Gitignores = typeFiles[0]
  87. Licenses = typeFiles[1]
  88. Readmes = typeFiles[2]
  89. LabelTemplates = typeFiles[3]
  90. sort.Strings(Gitignores)
  91. sort.Strings(Licenses)
  92. sort.Strings(Readmes)
  93. sort.Strings(LabelTemplates)
  94. // Filter out invalid names and promote preferred licenses.
  95. sortedLicenses := make([]string, 0, len(Licenses))
  96. for _, name := range setting.Repository.PreferredLicenses {
  97. if com.IsSliceContainsStr(Licenses, name) {
  98. sortedLicenses = append(sortedLicenses, name)
  99. }
  100. }
  101. for _, name := range Licenses {
  102. if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
  103. sortedLicenses = append(sortedLicenses, name)
  104. }
  105. }
  106. Licenses = sortedLicenses
  107. }
  108. // NewRepoContext creates a new repository context
  109. func NewRepoContext() {
  110. zip.Verbose = false
  111. // Check Git installation.
  112. if _, err := exec.LookPath("git"); err != nil {
  113. log.Fatal(4, "Failed to test 'git' command: %v (forgotten install?)", err)
  114. }
  115. // Check Git version.
  116. var err error
  117. setting.Git.Version, err = git.BinVersion()
  118. if err != nil {
  119. log.Fatal(4, "Failed to get Git version: %v", err)
  120. }
  121. log.Info("Git Version: %s", setting.Git.Version)
  122. if version.Compare("1.7.1", setting.Git.Version, ">") {
  123. log.Fatal(4, "Gitea requires Git version greater or equal to 1.7.1")
  124. }
  125. // Git requires setting user.name and user.email in order to commit changes.
  126. for configKey, defaultValue := range map[string]string{"user.name": "Gitea", "user.email": "gitea@fake.local"} {
  127. if stdout, stderr, err := process.GetManager().Exec("NewRepoContext(get setting)", "git", "config", "--get", configKey); err != nil || strings.TrimSpace(stdout) == "" {
  128. // ExitError indicates this config is not set
  129. if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
  130. if _, stderr, gerr := process.GetManager().Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
  131. log.Fatal(4, "Failed to set git %s(%s): %s", configKey, gerr, stderr)
  132. }
  133. log.Info("Git config %s set to %s", configKey, defaultValue)
  134. } else {
  135. log.Fatal(4, "Failed to get git %s(%s): %s", configKey, err, stderr)
  136. }
  137. }
  138. }
  139. // Set git some configurations.
  140. if _, stderr, err := process.GetManager().Exec("NewRepoContext(git config --global core.quotepath false)",
  141. "git", "config", "--global", "core.quotepath", "false"); err != nil {
  142. log.Fatal(4, "Failed to execute 'git config --global core.quotepath false': %s", stderr)
  143. }
  144. RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
  145. }
  146. // Repository represents a git repository.
  147. type Repository struct {
  148. ID int64 `xorm:"pk autoincr"`
  149. OwnerID int64 `xorm:"UNIQUE(s)"`
  150. Owner *User `xorm:"-"`
  151. LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
  152. Name string `xorm:"INDEX NOT NULL"`
  153. Description string
  154. Website string
  155. DefaultBranch string
  156. NumWatches int
  157. NumStars int
  158. NumForks int
  159. NumIssues int
  160. NumClosedIssues int
  161. NumOpenIssues int `xorm:"-"`
  162. NumPulls int
  163. NumClosedPulls int
  164. NumOpenPulls int `xorm:"-"`
  165. NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
  166. NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
  167. NumOpenMilestones int `xorm:"-"`
  168. NumTags int `xorm:"-"`
  169. IsPrivate bool `xorm:"INDEX"`
  170. IsBare bool `xorm:"INDEX"`
  171. IsMirror bool `xorm:"INDEX"`
  172. *Mirror `xorm:"-"`
  173. ExternalMetas map[string]string `xorm:"-"`
  174. Units []*RepoUnit `xorm:"-"`
  175. IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
  176. ForkID int64 `xorm:"INDEX"`
  177. BaseRepo *Repository `xorm:"-"`
  178. Created time.Time `xorm:"-"`
  179. CreatedUnix int64 `xorm:"INDEX"`
  180. Updated time.Time `xorm:"-"`
  181. UpdatedUnix int64 `xorm:"INDEX"`
  182. }
  183. // BeforeInsert is invoked from XORM before inserting an object of this type.
  184. func (repo *Repository) BeforeInsert() {
  185. repo.CreatedUnix = time.Now().Unix()
  186. repo.UpdatedUnix = repo.CreatedUnix
  187. }
  188. // BeforeUpdate is invoked from XORM before updating this object.
  189. func (repo *Repository) BeforeUpdate() {
  190. repo.UpdatedUnix = time.Now().Unix()
  191. }
  192. // AfterSet is invoked from XORM after setting the value of a field of this object.
  193. func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
  194. switch colName {
  195. case "default_branch":
  196. // FIXME: use models migration to solve all at once.
  197. if len(repo.DefaultBranch) == 0 {
  198. repo.DefaultBranch = "master"
  199. }
  200. case "num_closed_issues":
  201. repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
  202. case "num_closed_pulls":
  203. repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
  204. case "num_closed_milestones":
  205. repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
  206. case "created_unix":
  207. repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
  208. case "updated_unix":
  209. repo.Updated = time.Unix(repo.UpdatedUnix, 0)
  210. }
  211. }
  212. // MustOwner always returns a valid *User object to avoid
  213. // conceptually impossible error handling.
  214. // It creates a fake object that contains error details
  215. // when error occurs.
  216. func (repo *Repository) MustOwner() *User {
  217. return repo.mustOwner(x)
  218. }
  219. // FullName returns the repository full name
  220. func (repo *Repository) FullName() string {
  221. return repo.MustOwner().Name + "/" + repo.Name
  222. }
  223. // HTMLURL returns the repository HTML URL
  224. func (repo *Repository) HTMLURL() string {
  225. return setting.AppURL + repo.FullName()
  226. }
  227. // APIFormat converts a Repository to api.Repository
  228. func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
  229. cloneLink := repo.CloneLink()
  230. permission := &api.Permission{
  231. Admin: mode >= AccessModeAdmin,
  232. Push: mode >= AccessModeWrite,
  233. Pull: mode >= AccessModeRead,
  234. }
  235. return &api.Repository{
  236. ID: repo.ID,
  237. Owner: repo.Owner.APIFormat(),
  238. Name: repo.Name,
  239. FullName: repo.FullName(),
  240. Description: repo.Description,
  241. Private: repo.IsPrivate,
  242. Fork: repo.IsFork,
  243. Mirror: repo.IsMirror,
  244. HTMLURL: repo.HTMLURL(),
  245. SSHURL: cloneLink.SSH,
  246. CloneURL: cloneLink.HTTPS,
  247. Website: repo.Website,
  248. Stars: repo.NumStars,
  249. Forks: repo.NumForks,
  250. Watchers: repo.NumWatches,
  251. OpenIssues: repo.NumOpenIssues,
  252. DefaultBranch: repo.DefaultBranch,
  253. Created: repo.Created,
  254. Updated: repo.Updated,
  255. Permissions: permission,
  256. }
  257. }
  258. func (repo *Repository) getUnits(e Engine) (err error) {
  259. if repo.Units != nil {
  260. return nil
  261. }
  262. repo.Units, err = getUnitsByRepoID(e, repo.ID)
  263. return err
  264. }
  265. func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) {
  266. return units, e.Where("repo_id = ?", repoID).Find(&units)
  267. }
  268. // EnableUnit if this repository enabled some unit
  269. func (repo *Repository) EnableUnit(tp UnitType) bool {
  270. repo.getUnits(x)
  271. for _, unit := range repo.Units {
  272. if unit.Type == tp {
  273. return true
  274. }
  275. }
  276. return false
  277. }
  278. var (
  279. // ErrUnitNotExist organization does not exist
  280. ErrUnitNotExist = errors.New("Unit does not exist")
  281. )
  282. // MustGetUnit always returns a RepoUnit object
  283. func (repo *Repository) MustGetUnit(tp UnitType) *RepoUnit {
  284. ru, err := repo.GetUnit(tp)
  285. if err == nil {
  286. return ru
  287. }
  288. if tp == UnitTypeExternalWiki {
  289. return &RepoUnit{
  290. Type: tp,
  291. Config: new(ExternalWikiConfig),
  292. }
  293. } else if tp == UnitTypeExternalTracker {
  294. return &RepoUnit{
  295. Type: tp,
  296. Config: new(ExternalTrackerConfig),
  297. }
  298. }
  299. return &RepoUnit{
  300. Type: tp,
  301. Config: new(UnitConfig),
  302. }
  303. }
  304. // GetUnit returns a RepoUnit object
  305. func (repo *Repository) GetUnit(tp UnitType) (*RepoUnit, error) {
  306. if err := repo.getUnits(x); err != nil {
  307. return nil, err
  308. }
  309. for _, unit := range repo.Units {
  310. if unit.Type == tp {
  311. return unit, nil
  312. }
  313. }
  314. return nil, ErrUnitNotExist
  315. }
  316. func (repo *Repository) getOwner(e Engine) (err error) {
  317. if repo.Owner != nil {
  318. return nil
  319. }
  320. repo.Owner, err = getUserByID(e, repo.OwnerID)
  321. return err
  322. }
  323. // GetOwner returns the repository owner
  324. func (repo *Repository) GetOwner() error {
  325. return repo.getOwner(x)
  326. }
  327. func (repo *Repository) mustOwner(e Engine) *User {
  328. if err := repo.getOwner(e); err != nil {
  329. return &User{
  330. Name: "error",
  331. FullName: err.Error(),
  332. }
  333. }
  334. return repo.Owner
  335. }
  336. // ComposeMetas composes a map of metas for rendering external issue tracker URL.
  337. func (repo *Repository) ComposeMetas() map[string]string {
  338. unit, err := repo.GetUnit(UnitTypeExternalTracker)
  339. if err != nil {
  340. return nil
  341. }
  342. if repo.ExternalMetas == nil {
  343. repo.ExternalMetas = map[string]string{
  344. "format": unit.ExternalTrackerConfig().ExternalTrackerFormat,
  345. "user": repo.MustOwner().Name,
  346. "repo": repo.Name,
  347. }
  348. switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
  349. case markdown.IssueNameStyleAlphanumeric:
  350. repo.ExternalMetas["style"] = markdown.IssueNameStyleAlphanumeric
  351. default:
  352. repo.ExternalMetas["style"] = markdown.IssueNameStyleNumeric
  353. }
  354. }
  355. return repo.ExternalMetas
  356. }
  357. // DeleteWiki removes the actual and local copy of repository wiki.
  358. func (repo *Repository) DeleteWiki() error {
  359. return repo.deleteWiki(x)
  360. }
  361. func (repo *Repository) deleteWiki(e Engine) error {
  362. wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
  363. for _, wikiPath := range wikiPaths {
  364. removeAllWithNotice(e, "Delete repository wiki", wikiPath)
  365. }
  366. _, err := e.Where("repo_id = ?", repo.ID).And("type = ?", UnitTypeWiki).Delete(new(RepoUnit))
  367. return err
  368. }
  369. func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
  370. if err = repo.getOwner(e); err != nil {
  371. return nil, err
  372. }
  373. accesses := make([]*Access, 0, 10)
  374. if err = e.
  375. Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite).
  376. Find(&accesses); err != nil {
  377. return nil, err
  378. }
  379. // Leave a seat for owner itself to append later, but if owner is an organization
  380. // and just waste 1 unit is cheaper than re-allocate memory once.
  381. users := make([]*User, 0, len(accesses)+1)
  382. if len(accesses) > 0 {
  383. userIDs := make([]int64, len(accesses))
  384. for i := 0; i < len(accesses); i++ {
  385. userIDs[i] = accesses[i].UserID
  386. }
  387. if err = e.In("id", userIDs).Find(&users); err != nil {
  388. return nil, err
  389. }
  390. }
  391. if !repo.Owner.IsOrganization() {
  392. users = append(users, repo.Owner)
  393. }
  394. return users, nil
  395. }
  396. // GetAssignees returns all users that have write access and can be assigned to issues
  397. // of the repository,
  398. func (repo *Repository) GetAssignees() (_ []*User, err error) {
  399. return repo.getAssignees(x)
  400. }
  401. // GetAssigneeByID returns the user that has write access of repository by given ID.
  402. func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) {
  403. return GetAssigneeByID(repo, userID)
  404. }
  405. // GetMilestoneByID returns the milestone belongs to repository by given ID.
  406. func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
  407. return GetMilestoneByRepoID(repo.ID, milestoneID)
  408. }
  409. // IssueStats returns number of open and closed repository issues by given filter mode.
  410. func (repo *Repository) IssueStats(uid int64, filterMode int, isPull bool) (int64, int64) {
  411. return GetRepoIssueStats(repo.ID, uid, filterMode, isPull)
  412. }
  413. // GetMirror sets the repository mirror, returns an error upon failure
  414. func (repo *Repository) GetMirror() (err error) {
  415. repo.Mirror, err = GetMirrorByRepoID(repo.ID)
  416. return err
  417. }
  418. // GetBaseRepo returns the base repository
  419. func (repo *Repository) GetBaseRepo() (err error) {
  420. if !repo.IsFork {
  421. return nil
  422. }
  423. repo.BaseRepo, err = GetRepositoryByID(repo.ForkID)
  424. return err
  425. }
  426. func (repo *Repository) repoPath(e Engine) string {
  427. return RepoPath(repo.mustOwner(e).Name, repo.Name)
  428. }
  429. // RepoPath returns the repository path
  430. func (repo *Repository) RepoPath() string {
  431. return repo.repoPath(x)
  432. }
  433. // GitConfigPath returns the repository git config path
  434. func (repo *Repository) GitConfigPath() string {
  435. return filepath.Join(repo.RepoPath(), "config")
  436. }
  437. // RelLink returns the repository relative link
  438. func (repo *Repository) RelLink() string {
  439. return "/" + repo.FullName()
  440. }
  441. // Link returns the repository link
  442. func (repo *Repository) Link() string {
  443. return setting.AppSubURL + "/" + repo.FullName()
  444. }
  445. // ComposeCompareURL returns the repository comparison URL
  446. func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string {
  447. return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
  448. }
  449. // HasAccess returns true when user has access to this repository
  450. func (repo *Repository) HasAccess(u *User) bool {
  451. has, _ := HasAccess(u, repo, AccessModeRead)
  452. return has
  453. }
  454. // UpdateDefaultBranch updates the default branch
  455. func (repo *Repository) UpdateDefaultBranch() error {
  456. _, err := x.ID(repo.ID).Cols("default_branch").Update(repo)
  457. return err
  458. }
  459. // IsOwnedBy returns true when user owns this repository
  460. func (repo *Repository) IsOwnedBy(userID int64) bool {
  461. return repo.OwnerID == userID
  462. }
  463. // CanBeForked returns true if repository meets the requirements of being forked.
  464. func (repo *Repository) CanBeForked() bool {
  465. return !repo.IsBare
  466. }
  467. // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
  468. func (repo *Repository) CanEnablePulls() bool {
  469. return !repo.IsMirror
  470. }
  471. // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
  472. func (repo *Repository) AllowsPulls() bool {
  473. return repo.CanEnablePulls() && repo.EnableUnit(UnitTypePullRequests)
  474. }
  475. // CanEnableEditor returns true if repository meets the requirements of web editor.
  476. func (repo *Repository) CanEnableEditor() bool {
  477. return !repo.IsMirror
  478. }
  479. // NextIssueIndex returns the next issue index
  480. // FIXME: should have a mutex to prevent producing same index for two issues that are created
  481. // closely enough.
  482. func (repo *Repository) NextIssueIndex() int64 {
  483. return int64(repo.NumIssues+repo.NumPulls) + 1
  484. }
  485. var (
  486. descPattern = regexp.MustCompile(`https?://\S+`)
  487. )
  488. // DescriptionHTML does special handles to description and return HTML string.
  489. func (repo *Repository) DescriptionHTML() template.HTML {
  490. sanitize := func(s string) string {
  491. return fmt.Sprintf(`<a href="%[1]s" target="_blank" rel="noopener">%[1]s</a>`, s)
  492. }
  493. return template.HTML(descPattern.ReplaceAllStringFunc(markdown.Sanitizer.Sanitize(repo.Description), sanitize))
  494. }
  495. // LocalCopyPath returns the local repository copy path
  496. func (repo *Repository) LocalCopyPath() string {
  497. return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
  498. }
  499. // UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
  500. // It creates a new clone if local copy does not exist.
  501. // This function checks out target branch by default, it is safe to assume subsequent
  502. // operations are operating against target branch when caller has confidence for no race condition.
  503. func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
  504. if !com.IsExist(localPath) {
  505. if err := git.Clone(repoPath, localPath, git.CloneRepoOptions{
  506. Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
  507. Branch: branch,
  508. }); err != nil {
  509. return fmt.Errorf("git clone %s: %v", branch, err)
  510. }
  511. } else {
  512. if err := git.Checkout(localPath, git.CheckoutOptions{
  513. Branch: branch,
  514. }); err != nil {
  515. return fmt.Errorf("git checkout %s: %v", branch, err)
  516. }
  517. if err := git.Pull(localPath, git.PullRemoteOptions{
  518. Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
  519. Remote: "origin",
  520. Branch: branch,
  521. }); err != nil {
  522. return fmt.Errorf("git pull origin %s: %v", branch, err)
  523. }
  524. }
  525. return nil
  526. }
  527. // UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
  528. func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
  529. return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
  530. }
  531. // PatchPath returns corresponding patch file path of repository by given issue ID.
  532. func (repo *Repository) PatchPath(index int64) (string, error) {
  533. if err := repo.GetOwner(); err != nil {
  534. return "", err
  535. }
  536. return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil
  537. }
  538. // SavePatch saves patch data to corresponding location by given issue ID.
  539. func (repo *Repository) SavePatch(index int64, patch []byte) error {
  540. patchPath, err := repo.PatchPath(index)
  541. if err != nil {
  542. return fmt.Errorf("PatchPath: %v", err)
  543. }
  544. dir := filepath.Dir(patchPath)
  545. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  546. return fmt.Errorf("Failed to create dir %s: %v", dir, err)
  547. }
  548. if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil {
  549. return fmt.Errorf("WriteFile: %v", err)
  550. }
  551. return nil
  552. }
  553. func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
  554. has, err := e.Get(&Repository{
  555. OwnerID: u.ID,
  556. LowerName: strings.ToLower(repoName),
  557. })
  558. return has && com.IsDir(RepoPath(u.Name, repoName)), err
  559. }
  560. // IsRepositoryExist returns true if the repository with given name under user has already existed.
  561. func IsRepositoryExist(u *User, repoName string) (bool, error) {
  562. return isRepositoryExist(x, u, repoName)
  563. }
  564. // CloneLink represents different types of clone URLs of repository.
  565. type CloneLink struct {
  566. SSH string
  567. HTTPS string
  568. Git string
  569. }
  570. // ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
  571. func ComposeHTTPSCloneURL(owner, repo string) string {
  572. return fmt.Sprintf("%s%s/%s.git", setting.AppURL, owner, repo)
  573. }
  574. func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
  575. repoName := repo.Name
  576. if isWiki {
  577. repoName += ".wiki"
  578. }
  579. repo.Owner = repo.MustOwner()
  580. cl := new(CloneLink)
  581. if setting.SSH.Port != 22 {
  582. cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
  583. } else {
  584. cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  585. }
  586. cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repoName)
  587. return cl
  588. }
  589. // CloneLink returns clone URLs of repository.
  590. func (repo *Repository) CloneLink() (cl *CloneLink) {
  591. return repo.cloneLink(false)
  592. }
  593. // MigrateRepoOptions contains the repository migrate options
  594. type MigrateRepoOptions struct {
  595. Name string
  596. Description string
  597. IsPrivate bool
  598. IsMirror bool
  599. RemoteAddr string
  600. }
  601. /*
  602. GitHub, GitLab, Gogs: *.wiki.git
  603. BitBucket: *.git/wiki
  604. */
  605. var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
  606. // wikiRemoteURL returns accessible repository URL for wiki if exists.
  607. // Otherwise, it returns an empty string.
  608. func wikiRemoteURL(remote string) string {
  609. remote = strings.TrimSuffix(remote, ".git")
  610. for _, suffix := range commonWikiURLSuffixes {
  611. wikiURL := remote + suffix
  612. if git.IsRepoURLAccessible(wikiURL) {
  613. return wikiURL
  614. }
  615. }
  616. return ""
  617. }
  618. // MigrateRepository migrates a existing repository from other project hosting.
  619. func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
  620. repo, err := CreateRepository(u, CreateRepoOptions{
  621. Name: opts.Name,
  622. Description: opts.Description,
  623. IsPrivate: opts.IsPrivate,
  624. IsMirror: opts.IsMirror,
  625. })
  626. if err != nil {
  627. return nil, err
  628. }
  629. repoPath := RepoPath(u.Name, opts.Name)
  630. wikiPath := WikiPath(u.Name, opts.Name)
  631. if u.IsOrganization() {
  632. t, err := u.GetOwnerTeam()
  633. if err != nil {
  634. return nil, err
  635. }
  636. repo.NumWatches = t.NumMembers
  637. } else {
  638. repo.NumWatches = 1
  639. }
  640. migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
  641. if err := os.RemoveAll(repoPath); err != nil {
  642. return repo, fmt.Errorf("Failed to remove %s: %v", repoPath, err)
  643. }
  644. if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
  645. Mirror: true,
  646. Quiet: true,
  647. Timeout: migrateTimeout,
  648. }); err != nil {
  649. return repo, fmt.Errorf("Clone: %v", err)
  650. }
  651. wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
  652. if len(wikiRemotePath) > 0 {
  653. if err := os.RemoveAll(wikiPath); err != nil {
  654. return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
  655. }
  656. if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
  657. Mirror: true,
  658. Quiet: true,
  659. Timeout: migrateTimeout,
  660. Branch: "master",
  661. }); err != nil {
  662. log.Warn("Clone wiki: %v", err)
  663. if err := os.RemoveAll(wikiPath); err != nil {
  664. return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
  665. }
  666. }
  667. }
  668. // Check if repository is empty.
  669. _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
  670. if err != nil {
  671. if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
  672. repo.IsBare = true
  673. } else {
  674. return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
  675. }
  676. }
  677. if !repo.IsBare {
  678. // Try to get HEAD branch and set it as default branch.
  679. gitRepo, err := git.OpenRepository(repoPath)
  680. if err != nil {
  681. return repo, fmt.Errorf("OpenRepository: %v", err)
  682. }
  683. headBranch, err := gitRepo.GetHEADBranch()
  684. if err != nil {
  685. return repo, fmt.Errorf("GetHEADBranch: %v", err)
  686. }
  687. if headBranch != nil {
  688. repo.DefaultBranch = headBranch.Name
  689. }
  690. }
  691. if opts.IsMirror {
  692. if _, err = x.InsertOne(&Mirror{
  693. RepoID: repo.ID,
  694. Interval: setting.Mirror.DefaultInterval,
  695. EnablePrune: true,
  696. NextUpdate: time.Now().Add(time.Duration(setting.Mirror.DefaultInterval) * time.Hour),
  697. }); err != nil {
  698. return repo, fmt.Errorf("InsertOne: %v", err)
  699. }
  700. repo.IsMirror = true
  701. return repo, UpdateRepository(repo, false)
  702. }
  703. return CleanUpMigrateInfo(repo)
  704. }
  705. // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
  706. // This also removes possible user credentials.
  707. func cleanUpMigrateGitConfig(configPath string) error {
  708. cfg, err := ini.Load(configPath)
  709. if err != nil {
  710. return fmt.Errorf("open config file: %v", err)
  711. }
  712. cfg.DeleteSection("remote \"origin\"")
  713. if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
  714. return fmt.Errorf("save config file: %v", err)
  715. }
  716. return nil
  717. }
  718. // createDelegateHooks creates all the hooks scripts for the repo
  719. func createDelegateHooks(repoPath string) (err error) {
  720. var (
  721. hookNames = []string{"pre-receive", "update", "post-receive"}
  722. hookTpls = []string{
  723. fmt.Sprintf("#!/usr/bin/env %s\nORI_DIR=`pwd`\nSHELL_FOLDER=$(cd \"$(dirname \"$0\")\";pwd)\ncd \"$ORI_DIR\"\nfor i in `ls \"$SHELL_FOLDER/pre-receive.d\"`; do\n sh \"$SHELL_FOLDER/pre-receive.d/$i\"\ndone", setting.ScriptType),
  724. fmt.Sprintf("#!/usr/bin/env %s\nORI_DIR=`pwd`\nSHELL_FOLDER=$(cd \"$(dirname \"$0\")\";pwd)\ncd \"$ORI_DIR\"\nfor i in `ls \"$SHELL_FOLDER/update.d\"`; do\n sh \"$SHELL_FOLDER/update.d/$i\" $1 $2 $3\ndone", setting.ScriptType),
  725. fmt.Sprintf("#!/usr/bin/env %s\nORI_DIR=`pwd`\nSHELL_FOLDER=$(cd \"$(dirname \"$0\")\";pwd)\ncd \"$ORI_DIR\"\nfor i in `ls \"$SHELL_FOLDER/post-receive.d\"`; do\n sh \"$SHELL_FOLDER/post-receive.d/$i\"\ndone", setting.ScriptType),
  726. }
  727. giteaHookTpls = []string{
  728. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' pre-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  729. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' update $1 $2 $3\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  730. fmt.Sprintf("#!/usr/bin/env %s\n\"%s\" hook --config='%s' post-receive\n", setting.ScriptType, setting.AppPath, setting.CustomConf),
  731. }
  732. )
  733. hookDir := filepath.Join(repoPath, "hooks")
  734. for i, hookName := range hookNames {
  735. oldHookPath := filepath.Join(hookDir, hookName)
  736. newHookPath := filepath.Join(hookDir, hookName+".d", "gitea")
  737. if err := os.MkdirAll(filepath.Join(hookDir, hookName+".d"), os.ModePerm); err != nil {
  738. return fmt.Errorf("create hooks dir '%s': %v", filepath.Join(hookDir, hookName+".d"), err)
  739. }
  740. // WARNING: This will override all old server-side hooks
  741. if err = ioutil.WriteFile(oldHookPath, []byte(hookTpls[i]), 0777); err != nil {
  742. return fmt.Errorf("write old hook file '%s': %v", oldHookPath, err)
  743. }
  744. if err = ioutil.WriteFile(newHookPath, []byte(giteaHookTpls[i]), 0777); err != nil {
  745. return fmt.Errorf("write new hook file '%s': %v", newHookPath, err)
  746. }
  747. }
  748. return nil
  749. }
  750. // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
  751. func CleanUpMigrateInfo(repo *Repository) (*Repository, error) {
  752. repoPath := repo.RepoPath()
  753. if err := createDelegateHooks(repoPath); err != nil {
  754. return repo, fmt.Errorf("createDelegateHooks: %v", err)
  755. }
  756. if repo.HasWiki() {
  757. if err := createDelegateHooks(repo.WikiPath()); err != nil {
  758. return repo, fmt.Errorf("createDelegateHooks.(wiki): %v", err)
  759. }
  760. }
  761. if err := cleanUpMigrateGitConfig(repo.GitConfigPath()); err != nil {
  762. return repo, fmt.Errorf("cleanUpMigrateGitConfig: %v", err)
  763. }
  764. if repo.HasWiki() {
  765. if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
  766. return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
  767. }
  768. }
  769. return repo, UpdateRepository(repo, false)
  770. }
  771. // initRepoCommit temporarily changes with work directory.
  772. func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
  773. var stderr string
  774. if _, stderr, err = process.GetManager().ExecDir(-1,
  775. tmpPath, fmt.Sprintf("initRepoCommit (git add): %s", tmpPath),
  776. "git", "add", "--all"); err != nil {
  777. return fmt.Errorf("git add: %s", stderr)
  778. }
  779. if _, stderr, err = process.GetManager().ExecDir(-1,
  780. tmpPath, fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath),
  781. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  782. "-m", "Initial commit"); err != nil {
  783. return fmt.Errorf("git commit: %s", stderr)
  784. }
  785. if _, stderr, err = process.GetManager().ExecDir(-1,
  786. tmpPath, fmt.Sprintf("initRepoCommit (git push): %s", tmpPath),
  787. "git", "push", "origin", "master"); err != nil {
  788. return fmt.Errorf("git push: %s", stderr)
  789. }
  790. return nil
  791. }
  792. // CreateRepoOptions contains the create repository options
  793. type CreateRepoOptions struct {
  794. Name string
  795. Description string
  796. Gitignores string
  797. License string
  798. Readme string
  799. IsPrivate bool
  800. IsMirror bool
  801. AutoInit bool
  802. }
  803. func getRepoInitFile(tp, name string) ([]byte, error) {
  804. cleanedName := strings.TrimLeft(name, "./")
  805. relPath := path.Join("options", tp, cleanedName)
  806. // Use custom file when available.
  807. customPath := path.Join(setting.CustomPath, relPath)
  808. if com.IsFile(customPath) {
  809. return ioutil.ReadFile(customPath)
  810. }
  811. switch tp {
  812. case "readme":
  813. return options.Readme(cleanedName)
  814. case "gitignore":
  815. return options.Gitignore(cleanedName)
  816. case "license":
  817. return options.License(cleanedName)
  818. case "label":
  819. return options.Labels(cleanedName)
  820. default:
  821. return []byte{}, fmt.Errorf("Invalid init file type")
  822. }
  823. }
  824. func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
  825. // Clone to temporary path and do the init commit.
  826. _, stderr, err := process.GetManager().Exec(
  827. fmt.Sprintf("initRepository(git clone): %s", repoPath),
  828. "git", "clone", repoPath, tmpDir,
  829. )
  830. if err != nil {
  831. return fmt.Errorf("git clone: %v - %s", err, stderr)
  832. }
  833. // README
  834. data, err := getRepoInitFile("readme", opts.Readme)
  835. if err != nil {
  836. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
  837. }
  838. cloneLink := repo.CloneLink()
  839. match := map[string]string{
  840. "Name": repo.Name,
  841. "Description": repo.Description,
  842. "CloneURL.SSH": cloneLink.SSH,
  843. "CloneURL.HTTPS": cloneLink.HTTPS,
  844. }
  845. if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
  846. []byte(com.Expand(string(data), match)), 0644); err != nil {
  847. return fmt.Errorf("write README.md: %v", err)
  848. }
  849. // .gitignore
  850. if len(opts.Gitignores) > 0 {
  851. var buf bytes.Buffer
  852. names := strings.Split(opts.Gitignores, ",")
  853. for _, name := range names {
  854. data, err = getRepoInitFile("gitignore", name)
  855. if err != nil {
  856. return fmt.Errorf("getRepoInitFile[%s]: %v", name, err)
  857. }
  858. buf.WriteString("# ---> " + name + "\n")
  859. buf.Write(data)
  860. buf.WriteString("\n")
  861. }
  862. if buf.Len() > 0 {
  863. if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
  864. return fmt.Errorf("write .gitignore: %v", err)
  865. }
  866. }
  867. }
  868. // LICENSE
  869. if len(opts.License) > 0 {
  870. data, err = getRepoInitFile("license", opts.License)
  871. if err != nil {
  872. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
  873. }
  874. if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
  875. return fmt.Errorf("write LICENSE: %v", err)
  876. }
  877. }
  878. return nil
  879. }
  880. // InitRepository initializes README and .gitignore if needed.
  881. func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts CreateRepoOptions) (err error) {
  882. // Somehow the directory could exist.
  883. if com.IsExist(repoPath) {
  884. return fmt.Errorf("initRepository: path already exists: %s", repoPath)
  885. }
  886. // Init bare new repository.
  887. if err = git.InitRepository(repoPath, true); err != nil {
  888. return fmt.Errorf("InitRepository: %v", err)
  889. } else if err = createDelegateHooks(repoPath); err != nil {
  890. return fmt.Errorf("createDelegateHooks: %v", err)
  891. }
  892. tmpDir := filepath.Join(os.TempDir(), "gitea-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  893. // Initialize repository according to user's choice.
  894. if opts.AutoInit {
  895. if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
  896. return fmt.Errorf("Failed to create dir %s: %v", tmpDir, err)
  897. }
  898. defer os.RemoveAll(tmpDir)
  899. if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
  900. return fmt.Errorf("prepareRepoCommit: %v", err)
  901. }
  902. // Apply changes and commit.
  903. if err = initRepoCommit(tmpDir, u.NewGitSig()); err != nil {
  904. return fmt.Errorf("initRepoCommit: %v", err)
  905. }
  906. }
  907. // Re-fetch the repository from database before updating it (else it would
  908. // override changes that were done earlier with sql)
  909. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  910. return fmt.Errorf("getRepositoryByID: %v", err)
  911. }
  912. if !opts.AutoInit {
  913. repo.IsBare = true
  914. }
  915. repo.DefaultBranch = "master"
  916. if err = updateRepository(e, repo, false); err != nil {
  917. return fmt.Errorf("updateRepository: %v", err)
  918. }
  919. return nil
  920. }
  921. var (
  922. reservedRepoNames = []string{".", ".."}
  923. reservedRepoPatterns = []string{"*.git", "*.wiki"}
  924. )
  925. // IsUsableRepoName returns true when repository is usable
  926. func IsUsableRepoName(name string) error {
  927. return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
  928. }
  929. func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
  930. if err = IsUsableRepoName(repo.Name); err != nil {
  931. return err
  932. }
  933. has, err := isRepositoryExist(e, u, repo.Name)
  934. if err != nil {
  935. return fmt.Errorf("IsRepositoryExist: %v", err)
  936. } else if has {
  937. return ErrRepoAlreadyExist{u.Name, repo.Name}
  938. }
  939. if _, err = e.Insert(repo); err != nil {
  940. return err
  941. }
  942. if err = deleteRepoRedirect(e, u.ID, repo.Name); err != nil {
  943. return err
  944. }
  945. // insert units for repo
  946. var units = make([]RepoUnit, 0, len(defaultRepoUnits))
  947. for i, tp := range defaultRepoUnits {
  948. units = append(units, RepoUnit{
  949. RepoID: repo.ID,
  950. Type: tp,
  951. Index: i,
  952. })
  953. }
  954. if _, err = e.Insert(&units); err != nil {
  955. return err
  956. }
  957. u.NumRepos++
  958. // Remember visibility preference.
  959. u.LastRepoVisibility = repo.IsPrivate
  960. if err = updateUser(e, u); err != nil {
  961. return fmt.Errorf("updateUser: %v", err)
  962. }
  963. // Give access to all members in owner team.
  964. if u.IsOrganization() {
  965. t, err := u.getOwnerTeam(e)
  966. if err != nil {
  967. return fmt.Errorf("getOwnerTeam: %v", err)
  968. } else if err = t.addRepository(e, repo); err != nil {
  969. return fmt.Errorf("addRepository: %v", err)
  970. }
  971. } else {
  972. // Organization automatically called this in addRepository method.
  973. if err = repo.recalculateAccesses(e); err != nil {
  974. return fmt.Errorf("recalculateAccesses: %v", err)
  975. }
  976. }
  977. if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
  978. return fmt.Errorf("watchRepo: %v", err)
  979. } else if err = newRepoAction(e, u, repo); err != nil {
  980. return fmt.Errorf("newRepoAction: %v", err)
  981. }
  982. return nil
  983. }
  984. // CreateRepository creates a repository for given user or organization.
  985. func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error) {
  986. if !u.CanCreateRepo() {
  987. return nil, ErrReachLimitOfRepo{u.MaxRepoCreation}
  988. }
  989. repo := &Repository{
  990. OwnerID: u.ID,
  991. Owner: u,
  992. Name: opts.Name,
  993. LowerName: strings.ToLower(opts.Name),
  994. Description: opts.Description,
  995. IsPrivate: opts.IsPrivate,
  996. }
  997. sess := x.NewSession()
  998. defer sessionRelease(sess)
  999. if err = sess.Begin(); err != nil {
  1000. return nil, err
  1001. }
  1002. if err = createRepository(sess, u, repo); err != nil {
  1003. return nil, err
  1004. }
  1005. // No need for init mirror.
  1006. if !opts.IsMirror {
  1007. repoPath := RepoPath(u.Name, repo.Name)
  1008. if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
  1009. if err2 := os.RemoveAll(repoPath); err2 != nil {
  1010. log.Error(4, "initRepository: %v", err)
  1011. return nil, fmt.Errorf(
  1012. "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
  1013. }
  1014. return nil, fmt.Errorf("initRepository: %v", err)
  1015. }
  1016. _, stderr, err := process.GetManager().ExecDir(-1,
  1017. repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath),
  1018. "git", "update-server-info")
  1019. if err != nil {
  1020. return nil, errors.New("CreateRepository(git update-server-info): " + stderr)
  1021. }
  1022. }
  1023. return repo, sess.Commit()
  1024. }
  1025. func countRepositories(userID int64, private bool) int64 {
  1026. sess := x.Where("id > 0")
  1027. if userID > 0 {
  1028. sess.And("owner_id = ?", userID)
  1029. }
  1030. if !private {
  1031. sess.And("is_private=?", false)
  1032. }
  1033. count, err := sess.Count(new(Repository))
  1034. if err != nil {
  1035. log.Error(4, "countRepositories: %v", err)
  1036. }
  1037. return count
  1038. }
  1039. // CountRepositories returns number of repositories.
  1040. // Argument private only takes effect when it is false,
  1041. // set it true to count all repositories.
  1042. func CountRepositories(private bool) int64 {
  1043. return countRepositories(-1, private)
  1044. }
  1045. // CountUserRepositories returns number of repositories user owns.
  1046. // Argument private only takes effect when it is false,
  1047. // set it true to count all repositories.
  1048. func CountUserRepositories(userID int64, private bool) int64 {
  1049. return countRepositories(userID, private)
  1050. }
  1051. // Repositories returns all repositories
  1052. func Repositories(opts *SearchRepoOptions) (_ RepositoryList, count int64, err error) {
  1053. if len(opts.OrderBy) == 0 {
  1054. opts.OrderBy = "id ASC"
  1055. }
  1056. repos := make(RepositoryList, 0, opts.PageSize)
  1057. if err = x.
  1058. Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
  1059. OrderBy(opts.OrderBy).
  1060. Find(&repos); err != nil {
  1061. return nil, 0, fmt.Errorf("Repo: %v", err)
  1062. }
  1063. if err = repos.loadAttributes(x); err != nil {
  1064. return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
  1065. }
  1066. count = countRepositories(-1, opts.Private)
  1067. return repos, count, nil
  1068. }
  1069. // RepoPath returns repository path by given user and repository name.
  1070. func RepoPath(userName, repoName string) string {
  1071. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  1072. }
  1073. // TransferOwnership transfers all corresponding setting from old user to new one.
  1074. func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error {
  1075. newOwner, err := GetUserByName(newOwnerName)
  1076. if err != nil {
  1077. return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
  1078. }
  1079. // Check if new owner has repository with same name.
  1080. has, err := IsRepositoryExist(newOwner, repo.Name)
  1081. if err != nil {
  1082. return fmt.Errorf("IsRepositoryExist: %v", err)
  1083. } else if has {
  1084. return ErrRepoAlreadyExist{newOwnerName, repo.Name}
  1085. }
  1086. sess := x.NewSession()
  1087. defer sessionRelease(sess)
  1088. if err = sess.Begin(); err != nil {
  1089. return fmt.Errorf("sess.Begin: %v", err)
  1090. }
  1091. owner := repo.Owner
  1092. // Note: we have to set value here to make sure recalculate accesses is based on
  1093. // new owner.
  1094. repo.OwnerID = newOwner.ID
  1095. repo.Owner = newOwner
  1096. // Update repository.
  1097. if _, err := sess.Id(repo.ID).Update(repo); err != nil {
  1098. return fmt.Errorf("update owner: %v", err)
  1099. }
  1100. // Remove redundant collaborators.
  1101. collaborators, err := repo.getCollaborators(sess)
  1102. if err != nil {
  1103. return fmt.Errorf("getCollaborators: %v", err)
  1104. }
  1105. // Dummy object.
  1106. collaboration := &Collaboration{RepoID: repo.ID}
  1107. for _, c := range collaborators {
  1108. collaboration.UserID = c.ID
  1109. if c.ID == newOwner.ID || newOwner.IsOrgMember(c.ID) {
  1110. if _, err = sess.Delete(collaboration); err != nil {
  1111. return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
  1112. }
  1113. }
  1114. }
  1115. // Remove old team-repository relations.
  1116. if owner.IsOrganization() {
  1117. if err = owner.getTeams(sess); err != nil {
  1118. return fmt.Errorf("getTeams: %v", err)
  1119. }
  1120. for _, t := range owner.Teams {
  1121. if !t.hasRepository(sess, repo.ID) {
  1122. continue
  1123. }
  1124. t.NumRepos--
  1125. if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil {
  1126. return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
  1127. }
  1128. }
  1129. if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
  1130. return fmt.Errorf("removeOrgRepo: %v", err)
  1131. }
  1132. }
  1133. if newOwner.IsOrganization() {
  1134. t, err := newOwner.getOwnerTeam(sess)
  1135. if err != nil {
  1136. return fmt.Errorf("getOwnerTeam: %v", err)
  1137. } else if err = t.addRepository(sess, repo); err != nil {
  1138. return fmt.Errorf("add to owner team: %v", err)
  1139. }
  1140. } else {
  1141. // Organization called this in addRepository method.
  1142. if err = repo.recalculateAccesses(sess); err != nil {
  1143. return fmt.Errorf("recalculateAccesses: %v", err)
  1144. }
  1145. }
  1146. // Update repository count.
  1147. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
  1148. return fmt.Errorf("increase new owner repository count: %v", err)
  1149. } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
  1150. return fmt.Errorf("decrease old owner repository count: %v", err)
  1151. }
  1152. if err = watchRepo(sess, newOwner.ID, repo.ID, true); err != nil {
  1153. return fmt.Errorf("watchRepo: %v", err)
  1154. } else if err = transferRepoAction(sess, doer, owner, repo); err != nil {
  1155. return fmt.Errorf("transferRepoAction: %v", err)
  1156. }
  1157. // Rename remote repository to new path and delete local copy.
  1158. dir := UserPath(newOwner.Name)
  1159. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  1160. return fmt.Errorf("Failed to create dir %s: %v", dir, err)
  1161. }
  1162. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
  1163. return fmt.Errorf("rename repository directory: %v", err)
  1164. }
  1165. RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath())
  1166. // Rename remote wiki repository to new path and delete local copy.
  1167. wikiPath := WikiPath(owner.Name, repo.Name)
  1168. if com.IsExist(wikiPath) {
  1169. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1170. if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
  1171. return fmt.Errorf("rename repository wiki: %v", err)
  1172. }
  1173. }
  1174. return sess.Commit()
  1175. }
  1176. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  1177. func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) {
  1178. oldRepoName = strings.ToLower(oldRepoName)
  1179. newRepoName = strings.ToLower(newRepoName)
  1180. if err = IsUsableRepoName(newRepoName); err != nil {
  1181. return err
  1182. }
  1183. has, err := IsRepositoryExist(u, newRepoName)
  1184. if err != nil {
  1185. return fmt.Errorf("IsRepositoryExist: %v", err)
  1186. } else if has {
  1187. return ErrRepoAlreadyExist{u.Name, newRepoName}
  1188. }
  1189. repo, err := GetRepositoryByName(u.ID, oldRepoName)
  1190. if err != nil {
  1191. return fmt.Errorf("GetRepositoryByName: %v", err)
  1192. }
  1193. // Change repository directory name.
  1194. if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
  1195. return fmt.Errorf("rename repository directory: %v", err)
  1196. }
  1197. wikiPath := repo.WikiPath()
  1198. if com.IsExist(wikiPath) {
  1199. if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
  1200. return fmt.Errorf("rename repository wiki: %v", err)
  1201. }
  1202. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1203. }
  1204. return nil
  1205. }
  1206. func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {
  1207. repos := make([]*Repository, 0, 10)
  1208. return repos, e.
  1209. Where("fork_id=?", forkID).
  1210. Find(&repos)
  1211. }
  1212. // GetRepositoriesByForkID returns all repositories with given fork ID.
  1213. func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
  1214. return getRepositoriesByForkID(x, forkID)
  1215. }
  1216. func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
  1217. repo.LowerName = strings.ToLower(repo.Name)
  1218. if len(repo.Description) > 255 {
  1219. repo.Description = repo.Description[:255]
  1220. }
  1221. if len(repo.Website) > 255 {
  1222. repo.Website = repo.Website[:255]
  1223. }
  1224. if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
  1225. return fmt.Errorf("update: %v", err)
  1226. }
  1227. if visibilityChanged {
  1228. if err = repo.getOwner(e); err != nil {
  1229. return fmt.Errorf("getOwner: %v", err)
  1230. }
  1231. if repo.Owner.IsOrganization() {
  1232. // Organization repository need to recalculate access table when visibility is changed.
  1233. if err = repo.recalculateTeamAccesses(e, 0); err != nil {
  1234. return fmt.Errorf("recalculateTeamAccesses: %v", err)
  1235. }
  1236. }
  1237. // If repo has become private, we need to set its actions to private.
  1238. if repo.IsPrivate {
  1239. _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{
  1240. IsPrivate: true,
  1241. })
  1242. if err != nil {
  1243. return err
  1244. }
  1245. }
  1246. // Create/Remove git-daemon-export-ok for git-daemon...
  1247. daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
  1248. if repo.IsPrivate && com.IsExist(daemonExportFile) {
  1249. if err = os.Remove(daemonExportFile); err != nil {
  1250. log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
  1251. }
  1252. } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
  1253. if f, err := os.Create(daemonExportFile); err != nil {
  1254. log.Error(4, "Failed to create %s: %v", daemonExportFile, err)
  1255. } else {
  1256. f.Close()
  1257. }
  1258. }
  1259. forkRepos, err := getRepositoriesByForkID(e, repo.ID)
  1260. if err != nil {
  1261. return fmt.Errorf("getRepositoriesByForkID: %v", err)
  1262. }
  1263. for i := range forkRepos {
  1264. forkRepos[i].IsPrivate = repo.IsPrivate
  1265. if err = updateRepository(e, forkRepos[i], true); err != nil {
  1266. return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
  1267. }
  1268. }
  1269. }
  1270. return nil
  1271. }
  1272. // UpdateRepository updates a repository
  1273. func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
  1274. sess := x.NewSession()
  1275. defer sessionRelease(sess)
  1276. if err = sess.Begin(); err != nil {
  1277. return err
  1278. }
  1279. if err = updateRepository(sess, repo, visibilityChanged); err != nil {
  1280. return fmt.Errorf("updateRepository: %v", err)
  1281. }
  1282. return sess.Commit()
  1283. }
  1284. // UpdateRepositoryUnits updates a repository's units
  1285. func UpdateRepositoryUnits(repo *Repository, units []RepoUnit) (err error) {
  1286. sess := x.NewSession()
  1287. defer sess.Close()
  1288. if err = sess.Begin(); err != nil {
  1289. return err
  1290. }
  1291. if _, err = sess.Where("repo_id = ?", repo.ID).Delete(new(RepoUnit)); err != nil {
  1292. return err
  1293. }
  1294. if _, err = sess.Insert(units); err != nil {
  1295. return err
  1296. }
  1297. return sess.Commit()
  1298. }
  1299. // DeleteRepository deletes a repository for a user or organization.
  1300. func DeleteRepository(uid, repoID int64) error {
  1301. repo := &Repository{ID: repoID, OwnerID: uid}
  1302. has, err := x.Get(repo)
  1303. if err != nil {
  1304. return err
  1305. } else if !has {
  1306. return ErrRepoNotExist{repoID, uid, ""}
  1307. }
  1308. // In case is a organization.
  1309. org, err := GetUserByID(uid)
  1310. if err != nil {
  1311. return err
  1312. }
  1313. if org.IsOrganization() {
  1314. if err = org.GetTeams(); err != nil {
  1315. return err
  1316. }
  1317. }
  1318. sess := x.NewSession()
  1319. defer sessionRelease(sess)
  1320. if err = sess.Begin(); err != nil {
  1321. return err
  1322. }
  1323. if org.IsOrganization() {
  1324. for _, t := range org.Teams {
  1325. if !t.hasRepository(sess, repoID) {
  1326. continue
  1327. } else if err = t.removeRepository(sess, repo, false); err != nil {
  1328. return err
  1329. }
  1330. }
  1331. }
  1332. if err = deleteBeans(sess,
  1333. &Repository{ID: repoID},
  1334. &Access{RepoID: repo.ID},
  1335. &Action{RepoID: repo.ID},
  1336. &Watch{RepoID: repoID},
  1337. &Star{RepoID: repoID},
  1338. &Mirror{RepoID: repoID},
  1339. &Milestone{RepoID: repoID},
  1340. &Release{RepoID: repoID},
  1341. &Collaboration{RepoID: repoID},
  1342. &PullRequest{BaseRepoID: repoID},
  1343. ); err != nil {
  1344. return fmt.Errorf("deleteBeans: %v", err)
  1345. }
  1346. // Delete comments and attachments.
  1347. issues := make([]*Issue, 0, 25)
  1348. attachmentPaths := make([]string, 0, len(issues))
  1349. if err = sess.
  1350. Where("repo_id=?", repoID).
  1351. Find(&issues); err != nil {
  1352. return err
  1353. }
  1354. for i := range issues {
  1355. if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil {
  1356. return err
  1357. }
  1358. if _, err = sess.Delete(&IssueUser{IssueID: issues[i].ID}); err != nil {
  1359. return err
  1360. }
  1361. attachments := make([]*Attachment, 0, 5)
  1362. if err = sess.
  1363. Where("issue_id=?", issues[i].ID).
  1364. Find(&attachments); err != nil {
  1365. return err
  1366. }
  1367. for j := range attachments {
  1368. attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
  1369. }
  1370. if _, err = sess.Delete(&Attachment{IssueID: issues[i].ID}); err != nil {
  1371. return err
  1372. }
  1373. }
  1374. if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
  1375. return err
  1376. }
  1377. if _, err = sess.Where("repo_id = ?", repoID).Delete(new(RepoUnit)); err != nil {
  1378. return err
  1379. }
  1380. if repo.IsFork {
  1381. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
  1382. return fmt.Errorf("decrease fork count: %v", err)
  1383. }
  1384. }
  1385. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
  1386. return err
  1387. }
  1388. // FIXME: Remove repository files should be executed after transaction succeed.
  1389. repoPath := repo.repoPath(sess)
  1390. removeAllWithNotice(sess, "Delete repository files", repoPath)
  1391. repo.deleteWiki(sess)
  1392. // Remove attachment files.
  1393. for i := range attachmentPaths {
  1394. removeAllWithNotice(sess, "Delete attachment", attachmentPaths[i])
  1395. }
  1396. // Remove LFS objects
  1397. var lfsObjects []*LFSMetaObject
  1398. if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil {
  1399. return err
  1400. }
  1401. for _, v := range lfsObjects {
  1402. count, err := sess.Count(&LFSMetaObject{Oid: v.Oid})
  1403. if err != nil {
  1404. return err
  1405. }
  1406. if count > 1 {
  1407. continue
  1408. }
  1409. oidPath := filepath.Join(v.Oid[0:2], v.Oid[2:4], v.Oid[4:len(v.Oid)])
  1410. err = os.Remove(filepath.Join(setting.LFS.ContentPath, oidPath))
  1411. if err != nil {
  1412. return err
  1413. }
  1414. }
  1415. if _, err := sess.Delete(&LFSMetaObject{RepositoryID: repoID}); err != nil {
  1416. return err
  1417. }
  1418. if repo.NumForks > 0 {
  1419. if _, err = sess.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
  1420. log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
  1421. }
  1422. }
  1423. if err = sess.Commit(); err != nil {
  1424. return fmt.Errorf("Commit: %v", err)
  1425. }
  1426. return nil
  1427. }
  1428. // GetRepositoryByRef returns a Repository specified by a GFM reference.
  1429. // See https://help.github.com/articles/writing-on-github#references for more information on the syntax.
  1430. func GetRepositoryByRef(ref string) (*Repository, error) {
  1431. n := strings.IndexByte(ref, byte('/'))
  1432. if n < 2 {
  1433. return nil, ErrInvalidReference
  1434. }
  1435. userName, repoName := ref[:n], ref[n+1:]
  1436. user, err := GetUserByName(userName)
  1437. if err != nil {
  1438. return nil, err
  1439. }
  1440. return GetRepositoryByName(user.ID, repoName)
  1441. }
  1442. // GetRepositoryByName returns the repository by given name under user if exists.
  1443. func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
  1444. repo := &Repository{
  1445. OwnerID: ownerID,
  1446. LowerName: strings.ToLower(name),
  1447. }
  1448. has, err := x.Get(repo)
  1449. if err != nil {
  1450. return nil, err
  1451. } else if !has {
  1452. return nil, ErrRepoNotExist{0, ownerID, name}
  1453. }
  1454. return repo, err
  1455. }
  1456. func getRepositoryByID(e Engine, id int64) (*Repository, error) {
  1457. repo := new(Repository)
  1458. has, err := e.Id(id).Get(repo)
  1459. if err != nil {
  1460. return nil, err
  1461. } else if !has {
  1462. return nil, ErrRepoNotExist{id, 0, ""}
  1463. }
  1464. return repo, nil
  1465. }
  1466. // GetRepositoryByID returns the repository by given id if exists.
  1467. func GetRepositoryByID(id int64) (*Repository, error) {
  1468. return getRepositoryByID(x, id)
  1469. }
  1470. // GetUserRepositories returns a list of repositories of given user.
  1471. func GetUserRepositories(userID int64, private bool, page, pageSize int, orderBy string) ([]*Repository, error) {
  1472. if len(orderBy) == 0 {
  1473. orderBy = "updated_unix DESC"
  1474. }
  1475. sess := x.
  1476. Where("owner_id = ?", userID).
  1477. OrderBy(orderBy)
  1478. if !private {
  1479. sess.And("is_private=?", false)
  1480. }
  1481. if page <= 0 {
  1482. page = 1
  1483. }
  1484. sess.Limit(pageSize, (page-1)*pageSize)
  1485. repos := make([]*Repository, 0, pageSize)
  1486. return repos, sess.Find(&repos)
  1487. }
  1488. // GetUserMirrorRepositories returns a list of mirror repositories of given user.
  1489. func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
  1490. repos := make([]*Repository, 0, 10)
  1491. return repos, x.
  1492. Where("owner_id = ?", userID).
  1493. And("is_mirror = ?", true).
  1494. Find(&repos)
  1495. }
  1496. // GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
  1497. func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList, _ int64, _ error) {
  1498. var cond = builder.NewCond()
  1499. if len(opts.OrderBy) == 0 {
  1500. opts.OrderBy = "updated_unix DESC"
  1501. }
  1502. if !opts.Private {
  1503. cond = builder.Eq{
  1504. "is_private": false,
  1505. }
  1506. }
  1507. if opts.Searcher != nil && !opts.Searcher.IsAdmin {
  1508. var ownerIds []int64
  1509. ownerIds = append(ownerIds, opts.Searcher.ID)
  1510. err := opts.Searcher.GetOrganizations(true)
  1511. if err != nil {
  1512. return nil, 0, fmt.Errorf("Organization: %v", err)
  1513. }
  1514. for _, org := range opts.Searcher.Orgs {
  1515. ownerIds = append(ownerIds, org.ID)
  1516. }
  1517. cond = cond.Or(builder.In("owner_id", ownerIds))
  1518. }
  1519. count, err := x.Where(cond).Count(new(Repository))
  1520. if err != nil {
  1521. return nil, 0, fmt.Errorf("Count: %v", err)
  1522. }
  1523. if err = x.Where(cond).
  1524. Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
  1525. Limit(opts.PageSize).
  1526. OrderBy(opts.OrderBy).
  1527. Find(&repos); err != nil {
  1528. return nil, 0, fmt.Errorf("Repo: %v", err)
  1529. }
  1530. if err = repos.loadAttributes(x); err != nil {
  1531. return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
  1532. }
  1533. return repos, count, nil
  1534. }
  1535. func getRepositoryCount(e Engine, u *User) (int64, error) {
  1536. return x.Count(&Repository{OwnerID: u.ID})
  1537. }
  1538. func getPublicRepositoryCount(e Engine, u *User) (int64, error) {
  1539. return x.Where("is_private = ?", false).Count(&Repository{OwnerID: u.ID})
  1540. }
  1541. func getPrivateRepositoryCount(e Engine, u *User) (int64, error) {
  1542. return x.Where("is_private = ?", true).Count(&Repository{OwnerID: u.ID})
  1543. }
  1544. // GetRepositoryCount returns the total number of repositories of user.
  1545. func GetRepositoryCount(u *User) (int64, error) {
  1546. return getRepositoryCount(x, u)
  1547. }
  1548. // GetPublicRepositoryCount returns the total number of public repositories of user.
  1549. func GetPublicRepositoryCount(u *User) (int64, error) {
  1550. return getPublicRepositoryCount(x, u)
  1551. }
  1552. // GetPrivateRepositoryCount returns the total number of private repositories of user.
  1553. func GetPrivateRepositoryCount(u *User) (int64, error) {
  1554. return getPrivateRepositoryCount(x, u)
  1555. }
  1556. // SearchRepoOptions holds the search options
  1557. type SearchRepoOptions struct {
  1558. Keyword string
  1559. OwnerID int64
  1560. Searcher *User //ID of the person who's seeking
  1561. OrderBy string
  1562. Private bool // Include private repositories in results
  1563. Starred bool
  1564. Page int
  1565. IsProfile bool
  1566. PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
  1567. }
  1568. // SearchRepositoryByName takes keyword and part of repository name to search,
  1569. // it returns results in given range and number of total results.
  1570. func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, count int64, err error) {
  1571. var (
  1572. sess *xorm.Session
  1573. cond = builder.NewCond()
  1574. )
  1575. if len(opts.Keyword) == 0 {
  1576. return repos, 0, nil
  1577. }
  1578. opts.Keyword = strings.ToLower(opts.Keyword)
  1579. if opts.Page <= 0 {
  1580. opts.Page = 1
  1581. }
  1582. repos = make([]*Repository, 0, opts.PageSize)
  1583. if opts.Starred && opts.OwnerID > 0 {
  1584. cond = builder.Eq{
  1585. "star.uid": opts.OwnerID,
  1586. }
  1587. }
  1588. cond = cond.And(builder.Like{"lower_name", opts.Keyword})
  1589. // Append conditions
  1590. if !opts.Starred && opts.OwnerID > 0 {
  1591. cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
  1592. }
  1593. if !opts.Private {
  1594. cond = cond.And(builder.Eq{"is_private": false})
  1595. }
  1596. if opts.Searcher != nil {
  1597. var ownerIds []int64
  1598. ownerIds = append(ownerIds, opts.Searcher.ID)
  1599. err = opts.Searcher.GetOrganizations(true)
  1600. if err != nil {
  1601. return nil, 0, fmt.Errorf("Organization: %v", err)
  1602. }
  1603. for _, org := range opts.Searcher.Orgs {
  1604. ownerIds = append(ownerIds, org.ID)
  1605. }
  1606. cond = cond.Or(builder.And(builder.Like{"lower_name", opts.Keyword}, builder.In("owner_id", ownerIds)))
  1607. }
  1608. if len(opts.OrderBy) == 0 {
  1609. opts.OrderBy = "name ASC"
  1610. }
  1611. if opts.Starred && opts.OwnerID > 0 {
  1612. sess = x.
  1613. Join("INNER", "star", "star.repo_id = repository.id").
  1614. Where(cond)
  1615. count, err = x.
  1616. Join("INNER", "star", "star.repo_id = repository.id").
  1617. Where(cond).
  1618. Count(new(Repository))
  1619. if err != nil {
  1620. return nil, 0, fmt.Errorf("Count: %v", err)
  1621. }
  1622. } else {
  1623. sess = x.Where(cond)
  1624. count, err = x.
  1625. Where(cond).
  1626. Count(new(Repository))
  1627. if err != nil {
  1628. return nil, 0, fmt.Errorf("Count: %v", err)
  1629. }
  1630. }
  1631. if err = sess.
  1632. Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
  1633. OrderBy(opts.OrderBy).
  1634. Find(&repos); err != nil {
  1635. return nil, 0, fmt.Errorf("Repo: %v", err)
  1636. }
  1637. if !opts.IsProfile {
  1638. if err = repos.loadAttributes(x); err != nil {
  1639. return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
  1640. }
  1641. }
  1642. return
  1643. }
  1644. // DeleteRepositoryArchives deletes all repositories' archives.
  1645. func DeleteRepositoryArchives() error {
  1646. return x.
  1647. Where("id > 0").
  1648. Iterate(new(Repository),
  1649. func(idx int, bean interface{}) error {
  1650. repo := bean.(*Repository)
  1651. return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
  1652. })
  1653. }
  1654. // DeleteOldRepositoryArchives deletes old repository archives.
  1655. func DeleteOldRepositoryArchives() {
  1656. if taskStatusTable.IsRunning(archiveCleanup) {
  1657. return
  1658. }
  1659. taskStatusTable.Start(archiveCleanup)
  1660. defer taskStatusTable.Stop(archiveCleanup)
  1661. log.Trace("Doing: ArchiveCleanup")
  1662. if err := x.Where("id > 0").Iterate(new(Repository), deleteOldRepositoryArchives); err != nil {
  1663. log.Error(4, "ArchiveClean: %v", err)
  1664. }
  1665. }
  1666. func deleteOldRepositoryArchives(idx int, bean interface{}) error {
  1667. repo := bean.(*Repository)
  1668. basePath := filepath.Join(repo.RepoPath(), "archives")
  1669. for _, ty := range []string{"zip", "targz"} {
  1670. path := filepath.Join(basePath, ty)
  1671. file, err := os.Open(path)
  1672. if err != nil {
  1673. if !os.IsNotExist(err) {
  1674. log.Warn("Unable to open directory %s: %v", path, err)
  1675. return err
  1676. }
  1677. // If the directory doesn't exist, that's okay.
  1678. continue
  1679. }
  1680. files, err := file.Readdir(0)
  1681. file.Close()
  1682. if err != nil {
  1683. log.Warn("Unable to read directory %s: %v", path, err)
  1684. return err
  1685. }
  1686. minimumOldestTime := time.Now().Add(-setting.Cron.ArchiveCleanup.OlderThan)
  1687. for _, info := range files {
  1688. if info.ModTime().Before(minimumOldestTime) && !info.IsDir() {
  1689. toDelete := filepath.Join(path, info.Name())
  1690. // This is a best-effort purge, so we do not check error codes to confirm removal.
  1691. if err = os.Remove(toDelete); err != nil {
  1692. log.Trace("Unable to delete %s, but proceeding: %v", toDelete, err)
  1693. }
  1694. }
  1695. }
  1696. }
  1697. return nil
  1698. }
  1699. func gatherMissingRepoRecords() ([]*Repository, error) {
  1700. repos := make([]*Repository, 0, 10)
  1701. if err := x.
  1702. Where("id > 0").
  1703. Iterate(new(Repository),
  1704. func(idx int, bean interface{}) error {
  1705. repo := bean.(*Repository)
  1706. if !com.IsDir(repo.RepoPath()) {
  1707. repos = append(repos, repo)
  1708. }
  1709. return nil
  1710. }); err != nil {
  1711. if err2 := CreateRepositoryNotice(fmt.Sprintf("gatherMissingRepoRecords: %v", err)); err2 != nil {
  1712. return nil, fmt.Errorf("CreateRepositoryNotice: %v", err)
  1713. }
  1714. }
  1715. return repos, nil
  1716. }
  1717. // DeleteMissingRepositories deletes all repository records that lost Git files.
  1718. func DeleteMissingRepositories() error {
  1719. repos, err := gatherMissingRepoRecords()
  1720. if err != nil {
  1721. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1722. }
  1723. if len(repos) == 0 {
  1724. return nil
  1725. }
  1726. for _, repo := range repos {
  1727. log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
  1728. if err := DeleteRepository(repo.OwnerID, repo.ID); err != nil {
  1729. if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1730. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1731. }
  1732. }
  1733. }
  1734. return nil
  1735. }
  1736. // ReinitMissingRepositories reinitializes all repository records that lost Git files.
  1737. func ReinitMissingRepositories() error {
  1738. repos, err := gatherMissingRepoRecords()
  1739. if err != nil {
  1740. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1741. }
  1742. if len(repos) == 0 {
  1743. return nil
  1744. }
  1745. for _, repo := range repos {
  1746. log.Trace("Initializing %d/%d...", repo.OwnerID, repo.ID)
  1747. if err := git.InitRepository(repo.RepoPath(), true); err != nil {
  1748. if err2 := CreateRepositoryNotice(fmt.Sprintf("InitRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1749. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1750. }
  1751. }
  1752. }
  1753. return nil
  1754. }
  1755. // SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks
  1756. // to make sure the binary and custom conf path are up-to-date.
  1757. func SyncRepositoryHooks() error {
  1758. return x.Where("id > 0").Iterate(new(Repository),
  1759. func(idx int, bean interface{}) error {
  1760. if err := createDelegateHooks(bean.(*Repository).RepoPath()); err != nil {
  1761. return fmt.Errorf("SyncRepositoryHook: %v", err)
  1762. }
  1763. return nil
  1764. })
  1765. }
  1766. // Prevent duplicate running tasks.
  1767. var taskStatusTable = sync.NewStatusTable()
  1768. const (
  1769. mirrorUpdate = "mirror_update"
  1770. gitFsck = "git_fsck"
  1771. checkRepos = "check_repos"
  1772. archiveCleanup = "archive_cleanup"
  1773. )
  1774. // GitFsck calls 'git fsck' to check repository health.
  1775. func GitFsck() {
  1776. if taskStatusTable.IsRunning(gitFsck) {
  1777. return
  1778. }
  1779. taskStatusTable.Start(gitFsck)
  1780. defer taskStatusTable.Stop(gitFsck)
  1781. log.Trace("Doing: GitFsck")
  1782. if err := x.
  1783. Where("id>0").
  1784. Iterate(new(Repository),
  1785. func(idx int, bean interface{}) error {
  1786. repo := bean.(*Repository)
  1787. repoPath := repo.RepoPath()
  1788. if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
  1789. desc := fmt.Sprintf("Failed to health check repository (%s): %v", repoPath, err)
  1790. log.Warn(desc)
  1791. if err = CreateRepositoryNotice(desc); err != nil {
  1792. log.Error(4, "CreateRepositoryNotice: %v", err)
  1793. }
  1794. }
  1795. return nil
  1796. }); err != nil {
  1797. log.Error(4, "GitFsck: %v", err)
  1798. }
  1799. }
  1800. // GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository
  1801. func GitGcRepos() error {
  1802. args := append([]string{"gc"}, setting.Git.GCArgs...)
  1803. return x.
  1804. Where("id > 0").
  1805. Iterate(new(Repository),
  1806. func(idx int, bean interface{}) error {
  1807. repo := bean.(*Repository)
  1808. if err := repo.GetOwner(); err != nil {
  1809. return err
  1810. }
  1811. _, stderr, err := process.GetManager().ExecDir(
  1812. time.Duration(setting.Git.Timeout.GC)*time.Second,
  1813. RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection",
  1814. "git", args...)
  1815. if err != nil {
  1816. return fmt.Errorf("%v: %v", err, stderr)
  1817. }
  1818. return nil
  1819. })
  1820. }
  1821. type repoChecker struct {
  1822. querySQL, correctSQL string
  1823. desc string
  1824. }
  1825. func repoStatsCheck(checker *repoChecker) {
  1826. results, err := x.Query(checker.querySQL)
  1827. if err != nil {
  1828. log.Error(4, "Select %s: %v", checker.desc, err)
  1829. return
  1830. }
  1831. for _, result := range results {
  1832. id := com.StrTo(result["id"]).MustInt64()
  1833. log.Trace("Updating %s: %d", checker.desc, id)
  1834. _, err = x.Exec(checker.correctSQL, id, id)
  1835. if err != nil {
  1836. log.Error(4, "Update %s[%d]: %v", checker.desc, id, err)
  1837. }
  1838. }
  1839. }
  1840. // CheckRepoStats checks the repository stats
  1841. func CheckRepoStats() {
  1842. if taskStatusTable.IsRunning(checkRepos) {
  1843. return
  1844. }
  1845. taskStatusTable.Start(checkRepos)
  1846. defer taskStatusTable.Stop(checkRepos)
  1847. log.Trace("Doing: CheckRepoStats")
  1848. checkers := []*repoChecker{
  1849. // Repository.NumWatches
  1850. {
  1851. "SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id)",
  1852. "UPDATE `repository` SET num_watches=(SELECT COUNT(*) FROM `watch` WHERE repo_id=?) WHERE id=?",
  1853. "repository count 'num_watches'",
  1854. },
  1855. // Repository.NumStars
  1856. {
  1857. "SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)",
  1858. "UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?",
  1859. "repository count 'num_stars'",
  1860. },
  1861. // Label.NumIssues
  1862. {
  1863. "SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)",
  1864. "UPDATE `label` SET num_issues=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=?) WHERE id=?",
  1865. "label count 'num_issues'",
  1866. },
  1867. // User.NumRepos
  1868. {
  1869. "SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)",
  1870. "UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?",
  1871. "user count 'num_repos'",
  1872. },
  1873. // Issue.NumComments
  1874. {
  1875. "SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND type=0)",
  1876. "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND type=0) WHERE id=?",
  1877. "issue count 'num_comments'",
  1878. },
  1879. }
  1880. for i := range checkers {
  1881. repoStatsCheck(checkers[i])
  1882. }
  1883. // ***** START: Repository.NumClosedIssues *****
  1884. desc := "repository count 'num_closed_issues'"
  1885. results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false)
  1886. if err != nil {
  1887. log.Error(4, "Select %s: %v", desc, err)
  1888. } else {
  1889. for _, result := range results {
  1890. id := com.StrTo(result["id"]).MustInt64()
  1891. log.Trace("Updating %s: %d", desc, id)
  1892. _, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id)
  1893. if err != nil {
  1894. log.Error(4, "Update %s[%d]: %v", desc, id, err)
  1895. }
  1896. }
  1897. }
  1898. // ***** END: Repository.NumClosedIssues *****
  1899. // FIXME: use checker when stop supporting old fork repo format.
  1900. // ***** START: Repository.NumForks *****
  1901. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
  1902. if err != nil {
  1903. log.Error(4, "Select repository count 'num_forks': %v", err)
  1904. } else {
  1905. for _, result := range results {
  1906. id := com.StrTo(result["id"]).MustInt64()
  1907. log.Trace("Updating repository count 'num_forks': %d", id)
  1908. repo, err := GetRepositoryByID(id)
  1909. if err != nil {
  1910. log.Error(4, "GetRepositoryByID[%d]: %v", id, err)
  1911. continue
  1912. }
  1913. rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
  1914. if err != nil {
  1915. log.Error(4, "Select count of forks[%d]: %v", repo.ID, err)
  1916. continue
  1917. }
  1918. repo.NumForks = int(parseCountResult(rawResult))
  1919. if err = UpdateRepository(repo, false); err != nil {
  1920. log.Error(4, "UpdateRepository[%d]: %v", id, err)
  1921. continue
  1922. }
  1923. }
  1924. }
  1925. // ***** END: Repository.NumForks *****
  1926. }
  1927. // RepositoryList contains a list of repositories
  1928. type RepositoryList []*Repository
  1929. func (repos RepositoryList) loadAttributes(e Engine) error {
  1930. if len(repos) == 0 {
  1931. return nil
  1932. }
  1933. // Load owners.
  1934. set := make(map[int64]*User)
  1935. for i := range repos {
  1936. set[repos[i].OwnerID] = nil
  1937. }
  1938. userIDs := make([]int64, 0, len(set))
  1939. for userID := range set {
  1940. userIDs = append(userIDs, userID)
  1941. }
  1942. users := make([]*User, 0, len(userIDs))
  1943. if err := e.
  1944. Where("id > 0").
  1945. In("id", userIDs).
  1946. Find(&users); err != nil {
  1947. return fmt.Errorf("find users: %v", err)
  1948. }
  1949. for i := range users {
  1950. set[users[i].ID] = users[i]
  1951. }
  1952. for i := range repos {
  1953. repos[i].Owner = set[repos[i].OwnerID]
  1954. }
  1955. return nil
  1956. }
  1957. // LoadAttributes loads the attributes for the given RepositoryList
  1958. func (repos RepositoryList) LoadAttributes() error {
  1959. return repos.loadAttributes(x)
  1960. }
  1961. // MirrorRepositoryList contains the mirror repositories
  1962. type MirrorRepositoryList []*Repository
  1963. func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
  1964. if len(repos) == 0 {
  1965. return nil
  1966. }
  1967. // Load mirrors.
  1968. repoIDs := make([]int64, 0, len(repos))
  1969. for i := range repos {
  1970. if !repos[i].IsMirror {
  1971. continue
  1972. }
  1973. repoIDs = append(repoIDs, repos[i].ID)
  1974. }
  1975. mirrors := make([]*Mirror, 0, len(repoIDs))
  1976. if err := e.
  1977. Where("id > 0").
  1978. In("repo_id", repoIDs).
  1979. Find(&mirrors); err != nil {
  1980. return fmt.Errorf("find mirrors: %v", err)
  1981. }
  1982. set := make(map[int64]*Mirror)
  1983. for i := range mirrors {
  1984. set[mirrors[i].RepoID] = mirrors[i]
  1985. }
  1986. for i := range repos {
  1987. repos[i].Mirror = set[repos[i].ID]
  1988. }
  1989. return nil
  1990. }
  1991. // LoadAttributes loads the attributes for the given MirrorRepositoryList
  1992. func (repos MirrorRepositoryList) LoadAttributes() error {
  1993. return repos.loadAttributes(x)
  1994. }
  1995. // ___________ __
  1996. // \_ _____/__________| | __
  1997. // | __)/ _ \_ __ \ |/ /
  1998. // | \( <_> ) | \/ <
  1999. // \___ / \____/|__| |__|_ \
  2000. // \/ \/
  2001. // HasForkedRepo checks if given user has already forked a repository with given ID.
  2002. func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
  2003. repo := new(Repository)
  2004. has, _ := x.
  2005. Where("owner_id=? AND fork_id=?", ownerID, repoID).
  2006. Get(repo)
  2007. return repo, has
  2008. }
  2009. // ForkRepository forks a repository
  2010. func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
  2011. forkedRepo, err := oldRepo.GetUserFork(u.ID)
  2012. if err != nil {
  2013. return nil, err
  2014. }
  2015. if forkedRepo != nil {
  2016. return nil, ErrRepoAlreadyExist{
  2017. Uname: u.Name,
  2018. Name: forkedRepo.Name,
  2019. }
  2020. }
  2021. repo := &Repository{
  2022. OwnerID: u.ID,
  2023. Owner: u,
  2024. Name: name,
  2025. LowerName: strings.ToLower(name),
  2026. Description: desc,
  2027. DefaultBranch: oldRepo.DefaultBranch,
  2028. IsPrivate: oldRepo.IsPrivate,
  2029. IsFork: true,
  2030. ForkID: oldRepo.ID,
  2031. }
  2032. sess := x.NewSession()
  2033. defer sessionRelease(sess)
  2034. if err = sess.Begin(); err != nil {
  2035. return nil, err
  2036. }
  2037. if err = createRepository(sess, u, repo); err != nil {
  2038. return nil, err
  2039. }
  2040. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
  2041. return nil, err
  2042. }
  2043. repoPath := RepoPath(u.Name, repo.Name)
  2044. _, stderr, err := process.GetManager().ExecTimeout(10*time.Minute,
  2045. fmt.Sprintf("ForkRepository(git clone): %s/%s", u.Name, repo.Name),
  2046. "git", "clone", "--bare", oldRepo.RepoPath(), repoPath)
  2047. if err != nil {
  2048. return nil, fmt.Errorf("git clone: %v", stderr)
  2049. }
  2050. _, stderr, err = process.GetManager().ExecDir(-1,
  2051. repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath),
  2052. "git", "update-server-info")
  2053. if err != nil {
  2054. return nil, fmt.Errorf("git update-server-info: %v", stderr)
  2055. }
  2056. if err = createDelegateHooks(repoPath); err != nil {
  2057. return nil, fmt.Errorf("createDelegateHooks: %v", err)
  2058. }
  2059. //Commit repo to get Fork ID
  2060. err = sess.Commit()
  2061. if err != nil {
  2062. return nil, err
  2063. }
  2064. // Copy LFS meta objects in new session
  2065. sess2 := x.NewSession()
  2066. defer sessionRelease(sess2)
  2067. if err = sess2.Begin(); err != nil {
  2068. return nil, err
  2069. }
  2070. var lfsObjects []*LFSMetaObject
  2071. if err = sess2.Where("repository_id=?", oldRepo.ID).Find(&lfsObjects); err != nil {
  2072. return nil, err
  2073. }
  2074. for _, v := range lfsObjects {
  2075. v.ID = 0
  2076. v.RepositoryID = repo.ID
  2077. if _, err = sess2.Insert(v); err != nil {
  2078. return nil, err
  2079. }
  2080. }
  2081. return repo, sess2.Commit()
  2082. }
  2083. // GetForks returns all the forks of the repository
  2084. func (repo *Repository) GetForks() ([]*Repository, error) {
  2085. forks := make([]*Repository, 0, repo.NumForks)
  2086. return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
  2087. }
  2088. // GetUserFork return user forked repository from this repository, if not forked return nil
  2089. func (repo *Repository) GetUserFork(userID int64) (*Repository, error) {
  2090. var forkedRepo Repository
  2091. has, err := x.Where("fork_id = ?", repo.ID).And("owner_id = ?", userID).Get(&forkedRepo)
  2092. if err != nil {
  2093. return nil, err
  2094. }
  2095. if !has {
  2096. return nil, nil
  2097. }
  2098. return &forkedRepo, nil
  2099. }
  2100. // __________ .__
  2101. // \______ \____________ ____ ____ | |__
  2102. // | | _/\_ __ \__ \ / \_/ ___\| | \
  2103. // | | \ | | \// __ \| | \ \___| Y \
  2104. // |______ / |__| (____ /___| /\___ >___| /
  2105. // \/ \/ \/ \/ \/
  2106. //
  2107. // CreateNewBranch creates a new repository branch
  2108. func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
  2109. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  2110. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  2111. localPath := repo.LocalCopyPath()
  2112. if err = discardLocalRepoBranchChanges(localPath, oldBranchName); err != nil {
  2113. return fmt.Errorf("discardLocalRepoChanges: %v", err)
  2114. } else if err = repo.UpdateLocalCopyBranch(oldBranchName); err != nil {
  2115. return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
  2116. }
  2117. if err = repo.CheckoutNewBranch(oldBranchName, branchName); err != nil {
  2118. return fmt.Errorf("CreateNewBranch: %v", err)
  2119. }
  2120. if err = git.Push(localPath, "origin", branchName); err != nil {
  2121. return fmt.Errorf("Push: %v", err)
  2122. }
  2123. return nil
  2124. }