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

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