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

repo.go 72 kB

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