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.

repo.go 64KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
8 years ago
9 years ago
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
8 years ago
10 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
10 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
8 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
10 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
7 years ago
9 years ago
7 years ago
7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
7 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
8 years ago
10 years ago
8 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237
  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. default:
  727. return []byte{}, fmt.Errorf("Invalid init file type")
  728. }
  729. }
  730. func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
  731. // Clone to temprory path and do the init commit.
  732. _, stderr, err := process.Exec(
  733. fmt.Sprintf("initRepository(git clone): %s", repoPath), "git", "clone", repoPath, tmpDir)
  734. if err != nil {
  735. return fmt.Errorf("git clone: %v - %s", err, stderr)
  736. }
  737. // README
  738. data, err := getRepoInitFile("readme", opts.Readme)
  739. if err != nil {
  740. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
  741. }
  742. cloneLink := repo.CloneLink()
  743. match := map[string]string{
  744. "Name": repo.Name,
  745. "Description": repo.Description,
  746. "CloneURL.SSH": cloneLink.SSH,
  747. "CloneURL.HTTPS": cloneLink.HTTPS,
  748. }
  749. if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
  750. []byte(com.Expand(string(data), match)), 0644); err != nil {
  751. return fmt.Errorf("write README.md: %v", err)
  752. }
  753. // .gitignore
  754. if len(opts.Gitignores) > 0 {
  755. var buf bytes.Buffer
  756. names := strings.Split(opts.Gitignores, ",")
  757. for _, name := range names {
  758. data, err = getRepoInitFile("gitignore", name)
  759. if err != nil {
  760. return fmt.Errorf("getRepoInitFile[%s]: %v", name, err)
  761. }
  762. buf.WriteString("# ---> " + name + "\n")
  763. buf.Write(data)
  764. buf.WriteString("\n")
  765. }
  766. if buf.Len() > 0 {
  767. if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
  768. return fmt.Errorf("write .gitignore: %v", err)
  769. }
  770. }
  771. }
  772. // LICENSE
  773. if len(opts.License) > 0 {
  774. data, err = getRepoInitFile("license", opts.License)
  775. if err != nil {
  776. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
  777. }
  778. if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
  779. return fmt.Errorf("write LICENSE: %v", err)
  780. }
  781. }
  782. return nil
  783. }
  784. // InitRepository initializes README and .gitignore if needed.
  785. func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts CreateRepoOptions) (err error) {
  786. // Somehow the directory could exist.
  787. if com.IsExist(repoPath) {
  788. return fmt.Errorf("initRepository: path already exists: %s", repoPath)
  789. }
  790. // Init bare new repository.
  791. if err = git.InitRepository(repoPath, true); err != nil {
  792. return fmt.Errorf("InitRepository: %v", err)
  793. } else if err = createUpdateHook(repoPath); err != nil {
  794. return fmt.Errorf("createUpdateHook: %v", err)
  795. }
  796. tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  797. // Initialize repository according to user's choice.
  798. if opts.AutoInit {
  799. if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
  800. return fmt.Errorf("Fail to create dir %s: %v", tmpDir, err)
  801. }
  802. defer os.RemoveAll(tmpDir)
  803. if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
  804. return fmt.Errorf("prepareRepoCommit: %v", err)
  805. }
  806. // Apply changes and commit.
  807. if err = initRepoCommit(tmpDir, u.NewGitSig()); err != nil {
  808. return fmt.Errorf("initRepoCommit: %v", err)
  809. }
  810. }
  811. // Re-fetch the repository from database before updating it (else it would
  812. // override changes that were done earlier with sql)
  813. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  814. return fmt.Errorf("getRepositoryByID: %v", err)
  815. }
  816. if !opts.AutoInit {
  817. repo.IsBare = true
  818. }
  819. repo.DefaultBranch = "master"
  820. if err = updateRepository(e, repo, false); err != nil {
  821. return fmt.Errorf("updateRepository: %v", err)
  822. }
  823. return nil
  824. }
  825. var (
  826. reservedRepoNames = []string{".", ".."}
  827. reservedRepoPatterns = []string{"*.git", "*.wiki"}
  828. )
  829. // IsUsableRepoName returns true when repository is usable
  830. func IsUsableRepoName(name string) error {
  831. return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
  832. }
  833. func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
  834. if err = IsUsableRepoName(repo.Name); err != nil {
  835. return err
  836. }
  837. has, err := isRepositoryExist(e, u, repo.Name)
  838. if err != nil {
  839. return fmt.Errorf("IsRepositoryExist: %v", err)
  840. } else if has {
  841. return ErrRepoAlreadyExist{u.Name, repo.Name}
  842. }
  843. if _, err = e.Insert(repo); err != nil {
  844. return err
  845. }
  846. u.NumRepos++
  847. // Remember visibility preference.
  848. u.LastRepoVisibility = repo.IsPrivate
  849. if err = updateUser(e, u); err != nil {
  850. return fmt.Errorf("updateUser: %v", err)
  851. }
  852. // Give access to all members in owner team.
  853. if u.IsOrganization() {
  854. t, err := u.getOwnerTeam(e)
  855. if err != nil {
  856. return fmt.Errorf("getOwnerTeam: %v", err)
  857. } else if err = t.addRepository(e, repo); err != nil {
  858. return fmt.Errorf("addRepository: %v", err)
  859. }
  860. } else {
  861. // Organization automatically called this in addRepository method.
  862. if err = repo.recalculateAccesses(e); err != nil {
  863. return fmt.Errorf("recalculateAccesses: %v", err)
  864. }
  865. }
  866. if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
  867. return fmt.Errorf("watchRepo: %v", err)
  868. } else if err = newRepoAction(e, u, repo); err != nil {
  869. return fmt.Errorf("newRepoAction: %v", err)
  870. }
  871. return nil
  872. }
  873. // CreateRepository creates a repository for given user or organization.
  874. func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error) {
  875. if !u.CanCreateRepo() {
  876. return nil, ErrReachLimitOfRepo{u.MaxRepoCreation}
  877. }
  878. repo := &Repository{
  879. OwnerID: u.ID,
  880. Owner: u,
  881. Name: opts.Name,
  882. LowerName: strings.ToLower(opts.Name),
  883. Description: opts.Description,
  884. IsPrivate: opts.IsPrivate,
  885. EnableWiki: true,
  886. EnableIssues: true,
  887. EnablePulls: true,
  888. }
  889. sess := x.NewSession()
  890. defer sessionRelease(sess)
  891. if err = sess.Begin(); err != nil {
  892. return nil, err
  893. }
  894. if err = createRepository(sess, u, repo); err != nil {
  895. return nil, err
  896. }
  897. // No need for init mirror.
  898. if !opts.IsMirror {
  899. repoPath := RepoPath(u.Name, repo.Name)
  900. if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
  901. if err2 := os.RemoveAll(repoPath); err2 != nil {
  902. log.Error(4, "initRepository: %v", err)
  903. return nil, fmt.Errorf(
  904. "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
  905. }
  906. return nil, fmt.Errorf("initRepository: %v", err)
  907. }
  908. _, stderr, err := process.ExecDir(-1,
  909. repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath),
  910. "git", "update-server-info")
  911. if err != nil {
  912. return nil, errors.New("CreateRepository(git update-server-info): " + stderr)
  913. }
  914. }
  915. return repo, sess.Commit()
  916. }
  917. func countRepositories(userID int64, private bool) int64 {
  918. sess := x.Where("id > 0")
  919. if userID > 0 {
  920. sess.And("owner_id = ?", userID)
  921. }
  922. if !private {
  923. sess.And("is_private=?", false)
  924. }
  925. count, err := sess.Count(new(Repository))
  926. if err != nil {
  927. log.Error(4, "countRepositories: %v", err)
  928. }
  929. return count
  930. }
  931. // CountRepositories returns number of repositories.
  932. // Argument private only takes effect when it is false,
  933. // set it true to count all repositories.
  934. func CountRepositories(private bool) int64 {
  935. return countRepositories(-1, private)
  936. }
  937. // CountUserRepositories returns number of repositories user owns.
  938. // Argument private only takes effect when it is false,
  939. // set it true to count all repositories.
  940. func CountUserRepositories(userID int64, private bool) int64 {
  941. return countRepositories(userID, private)
  942. }
  943. // Repositories returns all repositories
  944. func Repositories(page, pageSize int) (_ []*Repository, err error) {
  945. repos := make([]*Repository, 0, pageSize)
  946. return repos, x.Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&repos)
  947. }
  948. // RepositoriesWithUsers returns number of repos in given page.
  949. func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) {
  950. repos, err := Repositories(page, pageSize)
  951. if err != nil {
  952. return nil, fmt.Errorf("Repositories: %v", err)
  953. }
  954. for i := range repos {
  955. if err = repos[i].GetOwner(); err != nil {
  956. return nil, err
  957. }
  958. }
  959. return repos, nil
  960. }
  961. // RepoPath returns repository path by given user and repository name.
  962. func RepoPath(userName, repoName string) string {
  963. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  964. }
  965. // TransferOwnership transfers all corresponding setting from old user to new one.
  966. func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error {
  967. newOwner, err := GetUserByName(newOwnerName)
  968. if err != nil {
  969. return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
  970. }
  971. // Check if new owner has repository with same name.
  972. has, err := IsRepositoryExist(newOwner, repo.Name)
  973. if err != nil {
  974. return fmt.Errorf("IsRepositoryExist: %v", err)
  975. } else if has {
  976. return ErrRepoAlreadyExist{newOwnerName, repo.Name}
  977. }
  978. sess := x.NewSession()
  979. defer sessionRelease(sess)
  980. if err = sess.Begin(); err != nil {
  981. return fmt.Errorf("sess.Begin: %v", err)
  982. }
  983. owner := repo.Owner
  984. // Note: we have to set value here to make sure recalculate accesses is based on
  985. // new owner.
  986. repo.OwnerID = newOwner.ID
  987. repo.Owner = newOwner
  988. // Update repository.
  989. if _, err := sess.Id(repo.ID).Update(repo); err != nil {
  990. return fmt.Errorf("update owner: %v", err)
  991. }
  992. // Remove redundant collaborators.
  993. collaborators, err := repo.getCollaborators(sess)
  994. if err != nil {
  995. return fmt.Errorf("getCollaborators: %v", err)
  996. }
  997. // Dummy object.
  998. collaboration := &Collaboration{RepoID: repo.ID}
  999. for _, c := range collaborators {
  1000. collaboration.UserID = c.ID
  1001. if c.ID == newOwner.ID || newOwner.IsOrgMember(c.ID) {
  1002. if _, err = sess.Delete(collaboration); err != nil {
  1003. return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
  1004. }
  1005. }
  1006. }
  1007. // Remove old team-repository relations.
  1008. if owner.IsOrganization() {
  1009. if err = owner.getTeams(sess); err != nil {
  1010. return fmt.Errorf("getTeams: %v", err)
  1011. }
  1012. for _, t := range owner.Teams {
  1013. if !t.hasRepository(sess, repo.ID) {
  1014. continue
  1015. }
  1016. t.NumRepos--
  1017. if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil {
  1018. return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
  1019. }
  1020. }
  1021. if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
  1022. return fmt.Errorf("removeOrgRepo: %v", err)
  1023. }
  1024. }
  1025. if newOwner.IsOrganization() {
  1026. t, err := newOwner.getOwnerTeam(sess)
  1027. if err != nil {
  1028. return fmt.Errorf("getOwnerTeam: %v", err)
  1029. } else if err = t.addRepository(sess, repo); err != nil {
  1030. return fmt.Errorf("add to owner team: %v", err)
  1031. }
  1032. } else {
  1033. // Organization called this in addRepository method.
  1034. if err = repo.recalculateAccesses(sess); err != nil {
  1035. return fmt.Errorf("recalculateAccesses: %v", err)
  1036. }
  1037. }
  1038. // Update repository count.
  1039. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
  1040. return fmt.Errorf("increase new owner repository count: %v", err)
  1041. } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
  1042. return fmt.Errorf("decrease old owner repository count: %v", err)
  1043. }
  1044. if err = watchRepo(sess, newOwner.ID, repo.ID, true); err != nil {
  1045. return fmt.Errorf("watchRepo: %v", err)
  1046. } else if err = transferRepoAction(sess, doer, owner, repo); err != nil {
  1047. return fmt.Errorf("transferRepoAction: %v", err)
  1048. }
  1049. // Rename remote repository to new path and delete local copy.
  1050. dir := UserPath(newOwner.Name)
  1051. if err := os.MkdirAll(dir, os.ModePerm); err != nil {
  1052. return fmt.Errorf("Fail to create dir %s: %v", dir, err)
  1053. }
  1054. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
  1055. return fmt.Errorf("rename repository directory: %v", err)
  1056. }
  1057. RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath())
  1058. // Rename remote wiki repository to new path and delete local copy.
  1059. wikiPath := WikiPath(owner.Name, repo.Name)
  1060. if com.IsExist(wikiPath) {
  1061. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1062. if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
  1063. return fmt.Errorf("rename repository wiki: %v", err)
  1064. }
  1065. }
  1066. return sess.Commit()
  1067. }
  1068. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  1069. func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) {
  1070. oldRepoName = strings.ToLower(oldRepoName)
  1071. newRepoName = strings.ToLower(newRepoName)
  1072. if err = IsUsableRepoName(newRepoName); err != nil {
  1073. return err
  1074. }
  1075. has, err := IsRepositoryExist(u, newRepoName)
  1076. if err != nil {
  1077. return fmt.Errorf("IsRepositoryExist: %v", err)
  1078. } else if has {
  1079. return ErrRepoAlreadyExist{u.Name, newRepoName}
  1080. }
  1081. repo, err := GetRepositoryByName(u.ID, oldRepoName)
  1082. if err != nil {
  1083. return fmt.Errorf("GetRepositoryByName: %v", err)
  1084. }
  1085. // Change repository directory name.
  1086. if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
  1087. return fmt.Errorf("rename repository directory: %v", err)
  1088. }
  1089. wikiPath := repo.WikiPath()
  1090. if com.IsExist(wikiPath) {
  1091. if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
  1092. return fmt.Errorf("rename repository wiki: %v", err)
  1093. }
  1094. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1095. }
  1096. return nil
  1097. }
  1098. func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {
  1099. repos := make([]*Repository, 0, 10)
  1100. return repos, e.
  1101. Where("fork_id=?", forkID).
  1102. Find(&repos)
  1103. }
  1104. // GetRepositoriesByForkID returns all repositories with given fork ID.
  1105. func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
  1106. return getRepositoriesByForkID(x, forkID)
  1107. }
  1108. func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
  1109. repo.LowerName = strings.ToLower(repo.Name)
  1110. if len(repo.Description) > 255 {
  1111. repo.Description = repo.Description[:255]
  1112. }
  1113. if len(repo.Website) > 255 {
  1114. repo.Website = repo.Website[:255]
  1115. }
  1116. if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
  1117. return fmt.Errorf("update: %v", err)
  1118. }
  1119. if visibilityChanged {
  1120. if err = repo.getOwner(e); err != nil {
  1121. return fmt.Errorf("getOwner: %v", err)
  1122. }
  1123. if repo.Owner.IsOrganization() {
  1124. // Organization repository need to recalculate access table when visivility is changed.
  1125. if err = repo.recalculateTeamAccesses(e, 0); err != nil {
  1126. return fmt.Errorf("recalculateTeamAccesses: %v", err)
  1127. }
  1128. }
  1129. // Create/Remove git-daemon-export-ok for git-daemon...
  1130. daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
  1131. if repo.IsPrivate && com.IsExist(daemonExportFile) {
  1132. if err = os.Remove(daemonExportFile); err != nil {
  1133. log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
  1134. }
  1135. } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
  1136. if f, err := os.Create(daemonExportFile); err != nil {
  1137. log.Error(4, "Failed to create %s: %v", daemonExportFile, err)
  1138. } else {
  1139. f.Close()
  1140. }
  1141. }
  1142. forkRepos, err := getRepositoriesByForkID(e, repo.ID)
  1143. if err != nil {
  1144. return fmt.Errorf("getRepositoriesByForkID: %v", err)
  1145. }
  1146. for i := range forkRepos {
  1147. forkRepos[i].IsPrivate = repo.IsPrivate
  1148. if err = updateRepository(e, forkRepos[i], true); err != nil {
  1149. return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
  1150. }
  1151. }
  1152. }
  1153. return nil
  1154. }
  1155. // UpdateRepository updates a repository
  1156. func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
  1157. sess := x.NewSession()
  1158. defer sessionRelease(sess)
  1159. if err = sess.Begin(); err != nil {
  1160. return err
  1161. }
  1162. if err = updateRepository(x, repo, visibilityChanged); err != nil {
  1163. return fmt.Errorf("updateRepository: %v", err)
  1164. }
  1165. return sess.Commit()
  1166. }
  1167. // DeleteRepository deletes a repository for a user or organization.
  1168. func DeleteRepository(uid, repoID int64) error {
  1169. repo := &Repository{ID: repoID, OwnerID: uid}
  1170. has, err := x.Get(repo)
  1171. if err != nil {
  1172. return err
  1173. } else if !has {
  1174. return ErrRepoNotExist{repoID, uid, ""}
  1175. }
  1176. // In case is a organization.
  1177. org, err := GetUserByID(uid)
  1178. if err != nil {
  1179. return err
  1180. }
  1181. if org.IsOrganization() {
  1182. if err = org.GetTeams(); err != nil {
  1183. return err
  1184. }
  1185. }
  1186. sess := x.NewSession()
  1187. defer sessionRelease(sess)
  1188. if err = sess.Begin(); err != nil {
  1189. return err
  1190. }
  1191. if org.IsOrganization() {
  1192. for _, t := range org.Teams {
  1193. if !t.hasRepository(sess, repoID) {
  1194. continue
  1195. } else if err = t.removeRepository(sess, repo, false); err != nil {
  1196. return err
  1197. }
  1198. }
  1199. }
  1200. if err = deleteBeans(sess,
  1201. &Repository{ID: repoID},
  1202. &Access{RepoID: repo.ID},
  1203. &Action{RepoID: repo.ID},
  1204. &Watch{RepoID: repoID},
  1205. &Star{RepoID: repoID},
  1206. &Mirror{RepoID: repoID},
  1207. &IssueUser{RepoID: repoID},
  1208. &Milestone{RepoID: repoID},
  1209. &Release{RepoID: repoID},
  1210. &Collaboration{RepoID: repoID},
  1211. &PullRequest{BaseRepoID: repoID},
  1212. ); err != nil {
  1213. return fmt.Errorf("deleteBeans: %v", err)
  1214. }
  1215. // Delete comments and attachments.
  1216. issues := make([]*Issue, 0, 25)
  1217. attachmentPaths := make([]string, 0, len(issues))
  1218. if err = sess.
  1219. Where("repo_id=?", repoID).
  1220. Find(&issues); err != nil {
  1221. return err
  1222. }
  1223. for i := range issues {
  1224. if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil {
  1225. return err
  1226. }
  1227. attachments := make([]*Attachment, 0, 5)
  1228. if err = sess.
  1229. Where("issue_id=?", issues[i].ID).
  1230. Find(&attachments); err != nil {
  1231. return err
  1232. }
  1233. for j := range attachments {
  1234. attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
  1235. }
  1236. if _, err = sess.Delete(&Attachment{IssueID: issues[i].ID}); err != nil {
  1237. return err
  1238. }
  1239. }
  1240. if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
  1241. return err
  1242. }
  1243. if repo.IsFork {
  1244. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
  1245. return fmt.Errorf("decrease fork count: %v", err)
  1246. }
  1247. }
  1248. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
  1249. return err
  1250. }
  1251. // Remove repository files.
  1252. repoPath := repo.repoPath(sess)
  1253. RemoveAllWithNotice("Delete repository files", repoPath)
  1254. repo.DeleteWiki()
  1255. // Remove attachment files.
  1256. for i := range attachmentPaths {
  1257. RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
  1258. }
  1259. if err = sess.Commit(); err != nil {
  1260. return fmt.Errorf("Commit: %v", err)
  1261. }
  1262. if repo.NumForks > 0 {
  1263. if _, err = x.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
  1264. log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
  1265. }
  1266. }
  1267. return nil
  1268. }
  1269. // GetRepositoryByRef returns a Repository specified by a GFM reference.
  1270. // See https://help.github.com/articles/writing-on-github#references for more information on the syntax.
  1271. func GetRepositoryByRef(ref string) (*Repository, error) {
  1272. n := strings.IndexByte(ref, byte('/'))
  1273. if n < 2 {
  1274. return nil, ErrInvalidReference
  1275. }
  1276. userName, repoName := ref[:n], ref[n+1:]
  1277. user, err := GetUserByName(userName)
  1278. if err != nil {
  1279. return nil, err
  1280. }
  1281. return GetRepositoryByName(user.ID, repoName)
  1282. }
  1283. // GetRepositoryByName returns the repository by given name under user if exists.
  1284. func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
  1285. repo := &Repository{
  1286. OwnerID: ownerID,
  1287. LowerName: strings.ToLower(name),
  1288. }
  1289. has, err := x.Get(repo)
  1290. if err != nil {
  1291. return nil, err
  1292. } else if !has {
  1293. return nil, ErrRepoNotExist{0, ownerID, name}
  1294. }
  1295. return repo, err
  1296. }
  1297. func getRepositoryByID(e Engine, id int64) (*Repository, error) {
  1298. repo := new(Repository)
  1299. has, err := e.Id(id).Get(repo)
  1300. if err != nil {
  1301. return nil, err
  1302. } else if !has {
  1303. return nil, ErrRepoNotExist{id, 0, ""}
  1304. }
  1305. return repo, nil
  1306. }
  1307. // GetRepositoryByID returns the repository by given id if exists.
  1308. func GetRepositoryByID(id int64) (*Repository, error) {
  1309. return getRepositoryByID(x, id)
  1310. }
  1311. // GetUserRepositories returns a list of repositories of given user.
  1312. func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) {
  1313. sess := x.
  1314. Where("owner_id = ?", userID).
  1315. Desc("updated_unix")
  1316. if !private {
  1317. sess.And("is_private=?", false)
  1318. }
  1319. if page <= 0 {
  1320. page = 1
  1321. }
  1322. sess.Limit(pageSize, (page-1)*pageSize)
  1323. repos := make([]*Repository, 0, pageSize)
  1324. return repos, sess.Find(&repos)
  1325. }
  1326. // GetUserMirrorRepositories returns a list of mirror repositories of given user.
  1327. func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
  1328. repos := make([]*Repository, 0, 10)
  1329. return repos, x.
  1330. Where("owner_id = ?", userID).
  1331. And("is_mirror = ?", true).
  1332. Find(&repos)
  1333. }
  1334. // GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
  1335. func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err error) {
  1336. return repos, x.
  1337. Limit(pageSize, (page-1)*pageSize).
  1338. Where("is_private=?", false).
  1339. Limit(pageSize).
  1340. Desc("updated_unix").
  1341. Find(&repos)
  1342. }
  1343. func getRepositoryCount(e Engine, u *User) (int64, error) {
  1344. return x.Count(&Repository{OwnerID: u.ID})
  1345. }
  1346. // GetRepositoryCount returns the total number of repositories of user.
  1347. func GetRepositoryCount(u *User) (int64, error) {
  1348. return getRepositoryCount(x, u)
  1349. }
  1350. // SearchRepoOptions holds the search options
  1351. type SearchRepoOptions struct {
  1352. Keyword string
  1353. OwnerID int64
  1354. OrderBy string
  1355. Private bool // Include private repositories in results
  1356. Page int
  1357. PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
  1358. }
  1359. // SearchRepositoryByName takes keyword and part of repository name to search,
  1360. // it returns results in given range and number of total results.
  1361. func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int64, _ error) {
  1362. if len(opts.Keyword) == 0 {
  1363. return repos, 0, nil
  1364. }
  1365. opts.Keyword = strings.ToLower(opts.Keyword)
  1366. if opts.Page <= 0 {
  1367. opts.Page = 1
  1368. }
  1369. repos = make([]*Repository, 0, opts.PageSize)
  1370. // Append conditions
  1371. sess := x.Where("LOWER(lower_name) LIKE ?", "%"+opts.Keyword+"%")
  1372. if opts.OwnerID > 0 {
  1373. sess.And("owner_id = ?", opts.OwnerID)
  1374. }
  1375. if !opts.Private {
  1376. sess.And("is_private=?", false)
  1377. }
  1378. var countSess xorm.Session
  1379. countSess = *sess
  1380. count, err := countSess.Count(new(Repository))
  1381. if err != nil {
  1382. return nil, 0, fmt.Errorf("Count: %v", err)
  1383. }
  1384. if len(opts.OrderBy) > 0 {
  1385. sess.OrderBy(opts.OrderBy)
  1386. }
  1387. return repos, count, sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Find(&repos)
  1388. }
  1389. // DeleteRepositoryArchives deletes all repositories' archives.
  1390. func DeleteRepositoryArchives() error {
  1391. return x.
  1392. Where("id > 0").
  1393. Iterate(new(Repository),
  1394. func(idx int, bean interface{}) error {
  1395. repo := bean.(*Repository)
  1396. return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
  1397. })
  1398. }
  1399. func gatherMissingRepoRecords() ([]*Repository, error) {
  1400. repos := make([]*Repository, 0, 10)
  1401. if err := x.
  1402. Where("id > 0").
  1403. Iterate(new(Repository),
  1404. func(idx int, bean interface{}) error {
  1405. repo := bean.(*Repository)
  1406. if !com.IsDir(repo.RepoPath()) {
  1407. repos = append(repos, repo)
  1408. }
  1409. return nil
  1410. }); err != nil {
  1411. if err2 := CreateRepositoryNotice(fmt.Sprintf("gatherMissingRepoRecords: %v", err)); err2 != nil {
  1412. return nil, fmt.Errorf("CreateRepositoryNotice: %v", err)
  1413. }
  1414. }
  1415. return repos, nil
  1416. }
  1417. // DeleteMissingRepositories deletes all repository records that lost Git files.
  1418. func DeleteMissingRepositories() error {
  1419. repos, err := gatherMissingRepoRecords()
  1420. if err != nil {
  1421. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1422. }
  1423. if len(repos) == 0 {
  1424. return nil
  1425. }
  1426. for _, repo := range repos {
  1427. log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
  1428. if err := DeleteRepository(repo.OwnerID, repo.ID); err != nil {
  1429. if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1430. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1431. }
  1432. }
  1433. }
  1434. return nil
  1435. }
  1436. // ReinitMissingRepositories reinitializes all repository records that lost Git files.
  1437. func ReinitMissingRepositories() error {
  1438. repos, err := gatherMissingRepoRecords()
  1439. if err != nil {
  1440. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1441. }
  1442. if len(repos) == 0 {
  1443. return nil
  1444. }
  1445. for _, repo := range repos {
  1446. log.Trace("Initializing %d/%d...", repo.OwnerID, repo.ID)
  1447. if err := git.InitRepository(repo.RepoPath(), true); err != nil {
  1448. if err2 := CreateRepositoryNotice(fmt.Sprintf("InitRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1449. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1450. }
  1451. }
  1452. }
  1453. return nil
  1454. }
  1455. // RewriteRepositoryUpdateHook rewrites all repositories' update hook.
  1456. func RewriteRepositoryUpdateHook() error {
  1457. return x.
  1458. Where("id > 0").
  1459. Iterate(new(Repository),
  1460. func(idx int, bean interface{}) error {
  1461. repo := bean.(*Repository)
  1462. return createUpdateHook(repo.RepoPath())
  1463. })
  1464. }
  1465. // Prevent duplicate running tasks.
  1466. var taskStatusTable = sync.NewStatusTable()
  1467. const (
  1468. mirrorUpdate = "mirror_update"
  1469. gitFsck = "git_fsck"
  1470. checkRepos = "check_repos"
  1471. )
  1472. // GitFsck calls 'git fsck' to check repository health.
  1473. func GitFsck() {
  1474. if taskStatusTable.IsRunning(gitFsck) {
  1475. return
  1476. }
  1477. taskStatusTable.Start(gitFsck)
  1478. defer taskStatusTable.Stop(gitFsck)
  1479. log.Trace("Doing: GitFsck")
  1480. if err := x.
  1481. Where("id>0").
  1482. Iterate(new(Repository),
  1483. func(idx int, bean interface{}) error {
  1484. repo := bean.(*Repository)
  1485. repoPath := repo.RepoPath()
  1486. if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
  1487. desc := fmt.Sprintf("Fail to health check repository (%s): %v", repoPath, err)
  1488. log.Warn(desc)
  1489. if err = CreateRepositoryNotice(desc); err != nil {
  1490. log.Error(4, "CreateRepositoryNotice: %v", err)
  1491. }
  1492. }
  1493. return nil
  1494. }); err != nil {
  1495. log.Error(4, "GitFsck: %v", err)
  1496. }
  1497. }
  1498. // GitGcRepos calls 'git gc' to remove unnecessary files and optimize the local repository
  1499. func GitGcRepos() error {
  1500. args := append([]string{"gc"}, setting.Git.GCArgs...)
  1501. return x.
  1502. Where("id > 0").
  1503. Iterate(new(Repository),
  1504. func(idx int, bean interface{}) error {
  1505. repo := bean.(*Repository)
  1506. if err := repo.GetOwner(); err != nil {
  1507. return err
  1508. }
  1509. _, stderr, err := process.ExecDir(
  1510. time.Duration(setting.Git.Timeout.GC)*time.Second,
  1511. RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection",
  1512. "git", args...)
  1513. if err != nil {
  1514. return fmt.Errorf("%v: %v", err, stderr)
  1515. }
  1516. return nil
  1517. })
  1518. }
  1519. type repoChecker struct {
  1520. querySQL, correctSQL string
  1521. desc string
  1522. }
  1523. func repoStatsCheck(checker *repoChecker) {
  1524. results, err := x.Query(checker.querySQL)
  1525. if err != nil {
  1526. log.Error(4, "Select %s: %v", checker.desc, err)
  1527. return
  1528. }
  1529. for _, result := range results {
  1530. id := com.StrTo(result["id"]).MustInt64()
  1531. log.Trace("Updating %s: %d", checker.desc, id)
  1532. _, err = x.Exec(checker.correctSQL, id, id)
  1533. if err != nil {
  1534. log.Error(4, "Update %s[%d]: %v", checker.desc, id, err)
  1535. }
  1536. }
  1537. }
  1538. // CheckRepoStats checks the repository stats
  1539. func CheckRepoStats() {
  1540. if taskStatusTable.IsRunning(checkRepos) {
  1541. return
  1542. }
  1543. taskStatusTable.Start(checkRepos)
  1544. defer taskStatusTable.Stop(checkRepos)
  1545. log.Trace("Doing: CheckRepoStats")
  1546. checkers := []*repoChecker{
  1547. // Repository.NumWatches
  1548. {
  1549. "SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id)",
  1550. "UPDATE `repository` SET num_watches=(SELECT COUNT(*) FROM `watch` WHERE repo_id=?) WHERE id=?",
  1551. "repository count 'num_watches'",
  1552. },
  1553. // Repository.NumStars
  1554. {
  1555. "SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)",
  1556. "UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?",
  1557. "repository count 'num_stars'",
  1558. },
  1559. // Label.NumIssues
  1560. {
  1561. "SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)",
  1562. "UPDATE `label` SET num_issues=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=?) WHERE id=?",
  1563. "label count 'num_issues'",
  1564. },
  1565. // User.NumRepos
  1566. {
  1567. "SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)",
  1568. "UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?",
  1569. "user count 'num_repos'",
  1570. },
  1571. // Issue.NumComments
  1572. {
  1573. "SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND type=0)",
  1574. "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND type=0) WHERE id=?",
  1575. "issue count 'num_comments'",
  1576. },
  1577. }
  1578. for i := range checkers {
  1579. repoStatsCheck(checkers[i])
  1580. }
  1581. // ***** START: Repository.NumClosedIssues *****
  1582. desc := "repository count 'num_closed_issues'"
  1583. 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)
  1584. if err != nil {
  1585. log.Error(4, "Select %s: %v", desc, err)
  1586. } else {
  1587. for _, result := range results {
  1588. id := com.StrTo(result["id"]).MustInt64()
  1589. log.Trace("Updating %s: %d", desc, id)
  1590. _, 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)
  1591. if err != nil {
  1592. log.Error(4, "Update %s[%d]: %v", desc, id, err)
  1593. }
  1594. }
  1595. }
  1596. // ***** END: Repository.NumClosedIssues *****
  1597. // FIXME: use checker when stop supporting old fork repo format.
  1598. // ***** START: Repository.NumForks *****
  1599. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
  1600. if err != nil {
  1601. log.Error(4, "Select repository count 'num_forks': %v", err)
  1602. } else {
  1603. for _, result := range results {
  1604. id := com.StrTo(result["id"]).MustInt64()
  1605. log.Trace("Updating repository count 'num_forks': %d", id)
  1606. repo, err := GetRepositoryByID(id)
  1607. if err != nil {
  1608. log.Error(4, "GetRepositoryByID[%d]: %v", id, err)
  1609. continue
  1610. }
  1611. rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
  1612. if err != nil {
  1613. log.Error(4, "Select count of forks[%d]: %v", repo.ID, err)
  1614. continue
  1615. }
  1616. repo.NumForks = int(parseCountResult(rawResult))
  1617. if err = UpdateRepository(repo, false); err != nil {
  1618. log.Error(4, "UpdateRepository[%d]: %v", id, err)
  1619. continue
  1620. }
  1621. }
  1622. }
  1623. // ***** END: Repository.NumForks *****
  1624. }
  1625. // RepositoryList contains a list of repositories
  1626. type RepositoryList []*Repository
  1627. func (repos RepositoryList) loadAttributes(e Engine) error {
  1628. if len(repos) == 0 {
  1629. return nil
  1630. }
  1631. // Load owners.
  1632. set := make(map[int64]*User)
  1633. for i := range repos {
  1634. set[repos[i].OwnerID] = nil
  1635. }
  1636. userIDs := make([]int64, 0, len(set))
  1637. for userID := range set {
  1638. userIDs = append(userIDs, userID)
  1639. }
  1640. users := make([]*User, 0, len(userIDs))
  1641. if err := e.
  1642. Where("id > 0").
  1643. In("id", userIDs).
  1644. Find(&users); err != nil {
  1645. return fmt.Errorf("find users: %v", err)
  1646. }
  1647. for i := range users {
  1648. set[users[i].ID] = users[i]
  1649. }
  1650. for i := range repos {
  1651. repos[i].Owner = set[repos[i].OwnerID]
  1652. }
  1653. return nil
  1654. }
  1655. // LoadAttributes loads the attributes for the given RepositoryList
  1656. func (repos RepositoryList) LoadAttributes() error {
  1657. return repos.loadAttributes(x)
  1658. }
  1659. // MirrorRepositoryList contains the mirror repositories
  1660. type MirrorRepositoryList []*Repository
  1661. func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
  1662. if len(repos) == 0 {
  1663. return nil
  1664. }
  1665. // Load mirrors.
  1666. repoIDs := make([]int64, 0, len(repos))
  1667. for i := range repos {
  1668. if !repos[i].IsMirror {
  1669. continue
  1670. }
  1671. repoIDs = append(repoIDs, repos[i].ID)
  1672. }
  1673. mirrors := make([]*Mirror, 0, len(repoIDs))
  1674. if err := e.
  1675. Where("id > 0").
  1676. In("repo_id", repoIDs).
  1677. Find(&mirrors); err != nil {
  1678. return fmt.Errorf("find mirrors: %v", err)
  1679. }
  1680. set := make(map[int64]*Mirror)
  1681. for i := range mirrors {
  1682. set[mirrors[i].RepoID] = mirrors[i]
  1683. }
  1684. for i := range repos {
  1685. repos[i].Mirror = set[repos[i].ID]
  1686. }
  1687. return nil
  1688. }
  1689. // LoadAttributes loads the attributes for the given MirrorRepositoryList
  1690. func (repos MirrorRepositoryList) LoadAttributes() error {
  1691. return repos.loadAttributes(x)
  1692. }
  1693. // __ __ __ .__
  1694. // / \ / \_____ _/ |_ ____ | |__
  1695. // \ \/\/ /\__ \\ __\/ ___\| | \
  1696. // \ / / __ \| | \ \___| Y \
  1697. // \__/\ / (____ /__| \___ >___| /
  1698. // \/ \/ \/ \/
  1699. // Watch is connection request for receiving repository notification.
  1700. type Watch struct {
  1701. ID int64 `xorm:"pk autoincr"`
  1702. UserID int64 `xorm:"UNIQUE(watch)"`
  1703. RepoID int64 `xorm:"UNIQUE(watch)"`
  1704. }
  1705. func isWatching(e Engine, userID, repoID int64) bool {
  1706. has, _ := e.Get(&Watch{0, userID, repoID})
  1707. return has
  1708. }
  1709. // IsWatching checks if user has watched given repository.
  1710. func IsWatching(userID, repoID int64) bool {
  1711. return isWatching(x, userID, repoID)
  1712. }
  1713. func watchRepo(e Engine, userID, repoID int64, watch bool) (err error) {
  1714. if watch {
  1715. if isWatching(e, userID, repoID) {
  1716. return nil
  1717. }
  1718. if _, err = e.Insert(&Watch{RepoID: repoID, UserID: userID}); err != nil {
  1719. return err
  1720. }
  1721. _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoID)
  1722. } else {
  1723. if !isWatching(e, userID, repoID) {
  1724. return nil
  1725. }
  1726. if _, err = e.Delete(&Watch{0, userID, repoID}); err != nil {
  1727. return err
  1728. }
  1729. _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoID)
  1730. }
  1731. return err
  1732. }
  1733. // WatchRepo watch or unwatch repository.
  1734. func WatchRepo(userID, repoID int64, watch bool) (err error) {
  1735. return watchRepo(x, userID, repoID, watch)
  1736. }
  1737. func getWatchers(e Engine, repoID int64) ([]*Watch, error) {
  1738. watches := make([]*Watch, 0, 10)
  1739. return watches, e.Find(&watches, &Watch{RepoID: repoID})
  1740. }
  1741. // GetWatchers returns all watchers of given repository.
  1742. func GetWatchers(repoID int64) ([]*Watch, error) {
  1743. return getWatchers(x, repoID)
  1744. }
  1745. // GetWatchers returns range of users watching given repository.
  1746. func (repo *Repository) GetWatchers(page int) ([]*User, error) {
  1747. users := make([]*User, 0, ItemsPerPage)
  1748. sess := x.
  1749. Limit(ItemsPerPage, (page-1)*ItemsPerPage).
  1750. Where("watch.repo_id=?", repo.ID)
  1751. if setting.UsePostgreSQL {
  1752. sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`)
  1753. } else {
  1754. sess = sess.Join("LEFT", "watch", "user.id=watch.user_id")
  1755. }
  1756. return users, sess.Find(&users)
  1757. }
  1758. func notifyWatchers(e Engine, act *Action) error {
  1759. // Add feeds for user self and all watchers.
  1760. watches, err := getWatchers(e, act.RepoID)
  1761. if err != nil {
  1762. return fmt.Errorf("get watchers: %v", err)
  1763. }
  1764. // Add feed for actioner.
  1765. act.UserID = act.ActUserID
  1766. if _, err = e.InsertOne(act); err != nil {
  1767. return fmt.Errorf("insert new actioner: %v", err)
  1768. }
  1769. for i := range watches {
  1770. if act.ActUserID == watches[i].UserID {
  1771. continue
  1772. }
  1773. act.ID = 0
  1774. act.UserID = watches[i].UserID
  1775. if _, err = e.InsertOne(act); err != nil {
  1776. return fmt.Errorf("insert new action: %v", err)
  1777. }
  1778. }
  1779. return nil
  1780. }
  1781. // NotifyWatchers creates batch of actions for every watcher.
  1782. func NotifyWatchers(act *Action) error {
  1783. return notifyWatchers(x, act)
  1784. }
  1785. // _________ __
  1786. // / _____// |______ _______
  1787. // \_____ \\ __\__ \\_ __ \
  1788. // / \| | / __ \| | \/
  1789. // /_______ /|__| (____ /__|
  1790. // \/ \/
  1791. // Star contains the star information
  1792. type Star struct {
  1793. ID int64 `xorm:"pk autoincr"`
  1794. UID int64 `xorm:"UNIQUE(s)"`
  1795. RepoID int64 `xorm:"UNIQUE(s)"`
  1796. }
  1797. // StarRepo star or unstar repository.
  1798. func StarRepo(userID, repoID int64, star bool) (err error) {
  1799. if star {
  1800. if IsStaring(userID, repoID) {
  1801. return nil
  1802. }
  1803. if _, err = x.Insert(&Star{UID: userID, RepoID: repoID}); err != nil {
  1804. return err
  1805. } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoID); err != nil {
  1806. return err
  1807. }
  1808. _, err = x.Exec("UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", userID)
  1809. } else {
  1810. if !IsStaring(userID, repoID) {
  1811. return nil
  1812. }
  1813. if _, err = x.Delete(&Star{0, userID, repoID}); err != nil {
  1814. return err
  1815. } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoID); err != nil {
  1816. return err
  1817. }
  1818. _, err = x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID)
  1819. }
  1820. return err
  1821. }
  1822. // IsStaring checks if user has starred given repository.
  1823. func IsStaring(userID, repoID int64) bool {
  1824. has, _ := x.Get(&Star{0, userID, repoID})
  1825. return has
  1826. }
  1827. // GetStargazers returns the users who gave stars to this repository
  1828. func (repo *Repository) GetStargazers(page int) ([]*User, error) {
  1829. users := make([]*User, 0, ItemsPerPage)
  1830. sess := x.
  1831. Limit(ItemsPerPage, (page-1)*ItemsPerPage).
  1832. Where("star.repo_id=?", repo.ID)
  1833. if setting.UsePostgreSQL {
  1834. sess = sess.Join("LEFT", "star", `"user".id=star.uid`)
  1835. } else {
  1836. sess = sess.Join("LEFT", "star", "user.id=star.uid")
  1837. }
  1838. return users, sess.Find(&users)
  1839. }
  1840. // ___________ __
  1841. // \_ _____/__________| | __
  1842. // | __)/ _ \_ __ \ |/ /
  1843. // | \( <_> ) | \/ <
  1844. // \___ / \____/|__| |__|_ \
  1845. // \/ \/
  1846. // HasForkedRepo checks if given user has already forked a repository with given ID.
  1847. func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
  1848. repo := new(Repository)
  1849. has, _ := x.
  1850. Where("owner_id=? AND fork_id=?", ownerID, repoID).
  1851. Get(repo)
  1852. return repo, has
  1853. }
  1854. // ForkRepository forks a repository
  1855. func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
  1856. repo := &Repository{
  1857. OwnerID: u.ID,
  1858. Owner: u,
  1859. Name: name,
  1860. LowerName: strings.ToLower(name),
  1861. Description: desc,
  1862. DefaultBranch: oldRepo.DefaultBranch,
  1863. IsPrivate: oldRepo.IsPrivate,
  1864. IsFork: true,
  1865. ForkID: oldRepo.ID,
  1866. }
  1867. sess := x.NewSession()
  1868. defer sessionRelease(sess)
  1869. if err = sess.Begin(); err != nil {
  1870. return nil, err
  1871. }
  1872. if err = createRepository(sess, u, repo); err != nil {
  1873. return nil, err
  1874. }
  1875. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
  1876. return nil, err
  1877. }
  1878. repoPath := RepoPath(u.Name, repo.Name)
  1879. _, stderr, err := process.ExecTimeout(10*time.Minute,
  1880. fmt.Sprintf("ForkRepository(git clone): %s/%s", u.Name, repo.Name),
  1881. "git", "clone", "--bare", oldRepo.RepoPath(), repoPath)
  1882. if err != nil {
  1883. return nil, fmt.Errorf("git clone: %v", stderr)
  1884. }
  1885. _, stderr, err = process.ExecDir(-1,
  1886. repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath),
  1887. "git", "update-server-info")
  1888. if err != nil {
  1889. return nil, fmt.Errorf("git update-server-info: %v", stderr)
  1890. }
  1891. if err = createUpdateHook(repoPath); err != nil {
  1892. return nil, fmt.Errorf("createUpdateHook: %v", err)
  1893. }
  1894. return repo, sess.Commit()
  1895. }
  1896. // GetForks returns all the forks of the repository
  1897. func (repo *Repository) GetForks() ([]*Repository, error) {
  1898. forks := make([]*Repository, 0, repo.NumForks)
  1899. return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
  1900. }
  1901. // __________ .__
  1902. // \______ \____________ ____ ____ | |__
  1903. // | | _/\_ __ \__ \ / \_/ ___\| | \
  1904. // | | \ | | \// __ \| | \ \___| Y \
  1905. // |______ / |__| (____ /___| /\___ >___| /
  1906. // \/ \/ \/ \/ \/
  1907. //
  1908. // CreateNewBranch creates a new repository branch
  1909. func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
  1910. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  1911. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  1912. localPath := repo.LocalCopyPath()
  1913. if err = discardLocalRepoBranchChanges(localPath, oldBranchName); err != nil {
  1914. return fmt.Errorf("discardLocalRepoChanges: %v", err)
  1915. } else if err = repo.UpdateLocalCopyBranch(oldBranchName); err != nil {
  1916. return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
  1917. }
  1918. if err = repo.CheckoutNewBranch(oldBranchName, branchName); err != nil {
  1919. return fmt.Errorf("CreateNewBranch: %v", err)
  1920. }
  1921. if err = git.Push(localPath, "origin", branchName); err != nil {
  1922. return fmt.Errorf("Push: %v", err)
  1923. }
  1924. return nil
  1925. }