Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
32c50eea
Commit
32c50eea
authored
Aug 24, 2016
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Git fetch + merge
parent
d49f56e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
49 deletions
+135
-49
config.sample.yml
config.sample.yml
+11
-5
git.js
models/git.js
+124
-44
No files found.
config.sample.yml
View file @
32c50eea
...
...
@@ -26,7 +26,6 @@ port: 80
# -------------------------------------------------
datadir
:
repo
:
./repo
db
:
./data
uploads
:
./uploads
...
...
@@ -36,9 +35,10 @@ datadir:
# Full explanation + examples in the documentation (https://requarks-wiki.readme.io/)
git
:
path
:
aut
o
mode
:
remot
e
path
:
./rep
o
remote
:
tru
e
url
:
https://github.com/Organization/Repo
branch
:
master
auth
:
type
:
ssh
user
:
gitusername
...
...
@@ -66,4 +66,10 @@ sessionSecret: 1234567890abcdefghijklmnopqrstuvxyz
# An account will be created using the email specified here.
# The password is set to "admin123" by default. Change it immediately upon login!!!
admin
:
admin@company.com
\ No newline at end of file
admin
:
admin@company.com
# -------------------------------------------------
# Default page for Home
# -------------------------------------------------
homepage
:
Home.md
\ No newline at end of file
models/git.js
View file @
32c50eea
...
...
@@ -15,8 +15,14 @@ module.exports = {
_git
:
null
,
_repo
:
{
path
:
''
,
branch
:
'master'
,
exists
:
false
,
inst
:
null
inst
:
null
,
sync
:
true
},
_opts
:
{
clone
:
{},
push
:
{}
},
/**
...
...
@@ -41,6 +47,11 @@ module.exports = {
self
.
_initRepo
(
appconfig
).
then
((
repo
)
=>
{
self
.
_repo
.
inst
=
repo
;
if
(
self
.
_repo
.
sync
)
{
self
.
resync
();
}
});
return
self
;
...
...
@@ -80,17 +91,20 @@ module.exports = {
//-> Init repository
let
repoInitOperation
=
null
;
self
.
_repo
.
branch
=
appconfig
.
git
.
branch
;
self
.
_repo
.
sync
=
appconfig
.
git
.
remote
;
self
.
_opts
.
clone
=
self
.
_generateCloneOptions
(
appconfig
);
self
.
_opts
.
push
=
self
.
_generatePushOptions
(
appconfig
);
if
(
self
.
_repo
.
exists
)
{
winston
.
info
(
'[GIT] Using existing repository...'
);
repoInitOperation
=
NodeGit
.
Repository
.
open
(
self
.
_repo
.
path
);
}
else
if
(
appconfig
.
git
.
mode
===
'remote'
)
{
}
else
if
(
appconfig
.
git
.
remote
)
{
winston
.
info
(
'[GIT] Cloning remote repository for first time...'
);
let
cloneOptions
=
self
.
_generateCloneOptions
(
appconfig
);
repoInitOperation
=
NodeGit
.
Clone
(
appconfig
.
git
.
url
,
self
.
_repo
.
path
,
cloneOptions
);
repoInitOperation
=
NodeGit
.
Clone
(
appconfig
.
git
.
url
,
self
.
_repo
.
path
,
self
.
_opts
.
clone
);
}
else
{
...
...
@@ -106,7 +120,11 @@ module.exports = {
winston
.
error
(
err
);
}).
then
((
repo
)
=>
{
self
.
_repo
.
inst
=
repo
;
if
(
self
.
_repo
.
sync
)
{
NodeGit
.
Remote
.
setPushurl
(
repo
,
'origin'
,
appconfig
.
git
.
url
);
}
return
repo
;
winston
.
info
(
'[GIT] Git repository is now ready.'
);
});
...
...
@@ -121,49 +139,111 @@ module.exports = {
*/
_generateCloneOptions
(
appconfig
)
{
let
cloneOptions
=
{};
cloneOptions
.
fetchOpts
=
{
callbacks
:
{
credentials
:
()
=>
{
let
cred
=
null
;
switch
(
appconfig
.
git
.
auth
.
type
)
{
case
'basic'
:
cred
=
NodeGit
.
Cred
.
userpassPlaintextNew
(
appconfig
.
git
.
auth
.
user
,
appconfig
.
git
.
auth
.
pass
);
break
;
case
'oauth'
:
cred
=
NodeGit
.
Cred
.
userpassPlaintextNew
(
appconfig
.
git
.
auth
.
token
,
"x-oauth-basic"
);
break
;
case
'ssh'
:
cred
=
NodeGit
.
Cred
.
sshKeyNew
(
appconfig
.
git
.
auth
.
user
,
appconfig
.
git
.
auth
.
publickey
,
appconfig
.
git
.
auth
.
privatekey
,
appconfig
.
git
.
auth
.
passphrase
);
break
;
default
:
cred
=
NodeGit
.
Cred
.
defaultNew
();
break
;
}
return
cred
;
}
}
};
let
cloneOptions
=
new
NodeGit
.
CloneOptions
();
cloneOptions
.
fetchOpts
=
this
.
_generateFetchOptions
(
appconfig
);
return
cloneOptions
;
},
_generateFetchOptions
(
appconfig
)
{
let
fetchOptions
=
new
NodeGit
.
FetchOptions
();
fetchOptions
.
callbacks
=
this
.
_generateRemoteCallbacks
(
appconfig
);
return
fetchOptions
;
},
_generatePushOptions
(
appconfig
)
{
let
pushOptions
=
new
NodeGit
.
PushOptions
();
pushOptions
.
callbacks
=
this
.
_generateRemoteCallbacks
(
appconfig
);
return
pushOptions
;
},
_generateRemoteCallbacks
(
appconfig
)
{
let
remoteCallbacks
=
new
NodeGit
.
RemoteCallbacks
();
let
credFunc
=
this
.
_generateCredentials
(
appconfig
);
remoteCallbacks
.
credentials
=
()
=>
{
return
credFunc
;
};
if
(
os
.
type
()
===
'Darwin'
)
{
cloneOptions
.
fetchOpts
.
c
allbacks
.
certificateCheck
=
()
=>
{
return
1
;
};
// Bug in OS X, bypass certs check workaround
remoteC
allbacks
.
certificateCheck
=
()
=>
{
return
1
;
};
// Bug in OS X, bypass certs check workaround
}
return
cloneOptions
;
return
remoteCallbacks
;
},
_generateCredentials
(
appconfig
)
{
let
cred
=
null
;
switch
(
appconfig
.
git
.
auth
.
type
)
{
case
'basic'
:
cred
=
NodeGit
.
Cred
.
userpassPlaintextNew
(
appconfig
.
git
.
auth
.
user
,
appconfig
.
git
.
auth
.
pass
);
break
;
case
'oauth'
:
cred
=
NodeGit
.
Cred
.
userpassPlaintextNew
(
appconfig
.
git
.
auth
.
token
,
"x-oauth-basic"
);
break
;
case
'ssh'
:
cred
=
NodeGit
.
Cred
.
sshKeyNew
(
appconfig
.
git
.
auth
.
user
,
appconfig
.
git
.
auth
.
publickey
,
appconfig
.
git
.
auth
.
privatekey
,
appconfig
.
git
.
auth
.
passphrase
);
break
;
default
:
cred
=
NodeGit
.
Cred
.
defaultNew
();
break
;
}
return
cred
;
},
resync
()
{
let
self
=
this
;
// Fetch
return
self
.
_repo
.
inst
.
fetch
(
'origin'
,
self
.
_opts
.
clone
.
fetchOpts
)
.
catch
((
err
)
=>
{
winston
.
error
(
'Unable to fetch from git origin!'
+
err
);
})
// Merge
.
then
(()
=>
{
return
self
.
_repo
.
inst
.
mergeBranches
(
self
.
_repo
.
branch
,
'origin/'
+
self
.
_repo
.
branch
);
})
.
catch
((
err
)
=>
{
winston
.
error
(
'Unable to merge from remote head!'
+
err
);
})
// Push
.
then
(()
=>
{
return
self
.
_repo
.
inst
.
getRemote
(
'origin'
).
then
((
remote
)
=>
{
self
.
_repo
.
inst
.
getStatus
().
then
(
function
(
arrayStatusFile
)
{
console
.
log
(
arrayStatusFile
[
0
].
status
());
});
/*remote.push( ["refs/heads/master:refs/heads/master"], self._opts.push ).then((errNum) => {
console.log('DUDE' + errNum);
}).catch((err) => {
console.log(err);
});*/
});
}).
catch
((
err
)
=>
{
winston
.
error
(
'Unable to push to git origin!'
+
err
);
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment