Skip to content

Commit 28b4c23

Browse files
authoredMay 21, 2019
WIP: Initialize git repository (#4)
* Function initialise git repository * Add isGit to repository settings object * Create model for initializing git repository * Import initalizeGitRepository model * Toggle git intialize model with some conditionals * Create function for validating git repository * Rename params name to path * Move git init function to git directory * Remove dots from initalizeGitRepositoy modal title * Run action to update vuex store and localStorage * Save the isGit value to new repository object * Change "Go back" button to outlineButton * Fix codacy review issues https://app.codacy.com/app/thermal/thermal/pullRequest?prid=3606025
1 parent edeff6b commit 28b4c23

File tree

6 files changed

+122
-2
lines changed

6 files changed

+122
-2
lines changed
 

‎src/renderer/App.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<about />
1010
<exportCommitData />
1111
<newRemote />
12+
<initalizeGitRepository />
1213
<cloneRepository />
1314
</div>
1415
</div>
@@ -22,6 +23,7 @@ import addLocalRepository from "./components/model/addLocalRepository";
2223
import about from "./components/model/about";
2324
import exportCommitData from "./components/model/exportCommitData";
2425
import newRemote from "./components/model/newRemote";
26+
import initalizeGitRepository from "./components/model/initalizeGitRepository";
2527
import cloneRepository from './components/model/cloneRepository';
2628
2729
export default {
@@ -33,7 +35,8 @@ export default {
3335
about,
3436
exportCommitData,
3537
newRemote,
36-
cloneRepository
38+
initalizeGitRepository,
39+
cloneRepository
3740
},
3841
beforeCreate() {
3942
this.$store.commit("repository/getRepositoryList");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<template>
2+
<div
3+
v-if="isGitRepository"
4+
class="model--small isgit"
5+
>
6+
<div class="model__section model__header">
7+
<h6 class="model__header__title">
8+
Git not found
9+
</h6>
10+
</div>
11+
<div class="model__section model__body">
12+
By default git will be initalized at the root of the project.
13+
</div>
14+
<div class="model__section model__footer">
15+
<outlineButton
16+
text="Go back"
17+
appearance="outline"
18+
border-color="00adb5"
19+
margin-left="auto"
20+
@click.native="switchRepository"
21+
/>
22+
<primaryButton
23+
text="Initalize git"
24+
margin-left=".5rem"
25+
@click.native="initalizeGit"
26+
/>
27+
</div>
28+
</div>
29+
</template>
30+
31+
<script>
32+
import primaryButton from "../buttons/primaryButton";
33+
import outlineButton from "../buttons/outlineButton";
34+
import gitInit from "../../git/init";
35+
36+
export default {
37+
name: "InitalizeGitRepository",
38+
components: {
39+
primaryButton,
40+
outlineButton
41+
},
42+
computed: {
43+
currentRepository() {
44+
return this.$store.getters["workspace/currentRepository"];
45+
},
46+
isGitRepository() {
47+
return (this.$router.history.current.matched[0].path.slice(1) === "repository") && (this.currentRepository.isGit === false);
48+
}
49+
},
50+
methods: {
51+
switchRepository() {
52+
this.$store.commit("model/toggleModelPlaceholder");
53+
this.$store.dispatch("workspace/switchWorkspaceRepository");
54+
this.$router.push({ name: "welcome" });
55+
},
56+
initalizeGit() {
57+
gitInit(this.currentRepository.path);
58+
this.$store.commit("model/toggleModelPlaceholder");
59+
this.$store.dispatch({
60+
type: "repository/updateIsGit",
61+
isGit: true
62+
});
63+
}
64+
}
65+
};
66+
</script>
67+
68+
<style lang="sass">
69+
.model
70+
71+
&__header
72+
border-bottom: 1px solid #eee
73+
74+
&__body
75+
border-bottom: 1px solid #eee
76+
</style>

‎src/renderer/git/init.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import git from "simple-git/promise";
2+
3+
const init = async (path) => {
4+
let initaliseRepository = git(path);
5+
await initaliseRepository.init();
6+
};
7+
8+
export default init;

‎src/renderer/mixins/addRepository.js

+14
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ export default {
55
getRepositoryName(path) {
66
return path.split("/")[path.split("/").length - 1];
77
},
8+
async isGitRepository(path) {
9+
const validateGitRepository = git(path);
10+
const isGit = await validateGitRepository.checkIsRepo();
11+
try {
12+
return isGit;
13+
} catch (error) {
14+
console.log(error);
15+
}
16+
},
817
async localRepository(path) {
918
let listRemote;
19+
let isGitRepo;
20+
this.isGitRepository(path).then((result) => {
21+
isGitRepo = result;
22+
});
1023
try {
1124
listRemote = await git(path).listRemote(["--get-url"]);
1225
if (listRemote.slice(-4, -1) === "git") {
@@ -23,6 +36,7 @@ export default {
2336
name: this.getRepositoryName(path),
2437
path: path,
2538
remote: listRemote,
39+
isGit: isGitRepo,
2640
commits: true,
2741
remotes: true
2842
});

‎src/renderer/pages/repository/index.vue

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export default {
1717
components: {
1818
navbar,
1919
sidebar
20+
},
21+
mounted() {
22+
if ((this.$router.history.current.matched[0].path.slice(1) === "repository") && (this.$store.getters["workspace/currentRepository"].isGit === false)) {
23+
this.$store.commit("model/toggleModelPlaceholder");
24+
}
2025
}
2126
};
2227
</script>

‎src/renderer/store/modules/repository.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const mutations = {
1919
path: payload.path,
2020
name: payload.name,
2121
remote: payload.remote,
22+
isGit: payload.isGit,
2223
features: {
2324
commit: payload.commits,
2425
remote: payload.remotes
@@ -48,10 +49,23 @@ const mutations = {
4849
state.repositoryList[
4950
workspace.state.workspaceRepository.index
5051
].features.remote = payload.remotes;
52+
},
53+
toggleIsGit(state, payload) {
54+
state.repositoryList[
55+
workspace.state.workspaceRepository.index
56+
].isGit = payload.isGit;
5157
}
5258
};
5359

54-
const actions = {};
60+
const actions = {
61+
updateIsGit: ({ commit }, payload) => {
62+
commit({
63+
type: "toggleIsGit",
64+
isGit: payload.isGit
65+
});
66+
localStorage.setItem("repository", JSON.stringify(state.repositoryList));
67+
}
68+
};
5569

5670
export default {
5771
namespaced: true,

0 commit comments

Comments
 (0)
Please sign in to comment.