Skip to content

Commit

Permalink
WIP: Initialize git repository (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mittalyashu committed May 21, 2019
1 parent edeff6b commit 28b4c23
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/renderer/App.vue
Expand Up @@ -9,6 +9,7 @@
<about />
<exportCommitData />
<newRemote />
<initalizeGitRepository />
<cloneRepository />
</div>
</div>
Expand All @@ -22,6 +23,7 @@ import addLocalRepository from "./components/model/addLocalRepository";
import about from "./components/model/about";
import exportCommitData from "./components/model/exportCommitData";
import newRemote from "./components/model/newRemote";
import initalizeGitRepository from "./components/model/initalizeGitRepository";
import cloneRepository from './components/model/cloneRepository';
export default {
Expand All @@ -33,7 +35,8 @@ export default {
about,
exportCommitData,
newRemote,
cloneRepository
initalizeGitRepository,
cloneRepository
},
beforeCreate() {
this.$store.commit("repository/getRepositoryList");
Expand Down
76 changes: 76 additions & 0 deletions src/renderer/components/model/initalizeGitRepository.vue
@@ -0,0 +1,76 @@
<template>
<div
v-if="isGitRepository"
class="model--small isgit"
>
<div class="model__section model__header">
<h6 class="model__header__title">
Git not found
</h6>
</div>
<div class="model__section model__body">
By default git will be initalized at the root of the project.
</div>
<div class="model__section model__footer">
<outlineButton
text="Go back"
appearance="outline"
border-color="00adb5"
margin-left="auto"
@click.native="switchRepository"
/>
<primaryButton
text="Initalize git"
margin-left=".5rem"
@click.native="initalizeGit"
/>
</div>
</div>
</template>

<script>
import primaryButton from "../buttons/primaryButton";
import outlineButton from "../buttons/outlineButton";
import gitInit from "../../git/init";
export default {
name: "InitalizeGitRepository",
components: {
primaryButton,
outlineButton
},
computed: {
currentRepository() {
return this.$store.getters["workspace/currentRepository"];
},
isGitRepository() {
return (this.$router.history.current.matched[0].path.slice(1) === "repository") && (this.currentRepository.isGit === false);
}
},
methods: {
switchRepository() {
this.$store.commit("model/toggleModelPlaceholder");
this.$store.dispatch("workspace/switchWorkspaceRepository");
this.$router.push({ name: "welcome" });
},
initalizeGit() {
gitInit(this.currentRepository.path);
this.$store.commit("model/toggleModelPlaceholder");
this.$store.dispatch({
type: "repository/updateIsGit",
isGit: true
});
}
}
};
</script>

<style lang="sass">
.model
&__header
border-bottom: 1px solid #eee
&__body
border-bottom: 1px solid #eee
</style>
8 changes: 8 additions & 0 deletions src/renderer/git/init.js
@@ -0,0 +1,8 @@
import git from "simple-git/promise";

const init = async (path) => {
let initaliseRepository = git(path);
await initaliseRepository.init();
};

export default init;
14 changes: 14 additions & 0 deletions src/renderer/mixins/addRepository.js
Expand Up @@ -5,8 +5,21 @@ export default {
getRepositoryName(path) {
return path.split("/")[path.split("/").length - 1];
},
async isGitRepository(path) {
const validateGitRepository = git(path);
const isGit = await validateGitRepository.checkIsRepo();
try {
return isGit;
} catch (error) {
console.log(error);
}
},
async localRepository(path) {
let listRemote;
let isGitRepo;
this.isGitRepository(path).then((result) => {
isGitRepo = result;
});
try {
listRemote = await git(path).listRemote(["--get-url"]);
if (listRemote.slice(-4, -1) === "git") {
Expand All @@ -23,6 +36,7 @@ export default {
name: this.getRepositoryName(path),
path: path,
remote: listRemote,
isGit: isGitRepo,
commits: true,
remotes: true
});
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/pages/repository/index.vue
Expand Up @@ -17,6 +17,11 @@ export default {
components: {
navbar,
sidebar
},
mounted() {
if ((this.$router.history.current.matched[0].path.slice(1) === "repository") && (this.$store.getters["workspace/currentRepository"].isGit === false)) {
this.$store.commit("model/toggleModelPlaceholder");
}
}
};
</script>
Expand Down
16 changes: 15 additions & 1 deletion src/renderer/store/modules/repository.js
Expand Up @@ -19,6 +19,7 @@ const mutations = {
path: payload.path,
name: payload.name,
remote: payload.remote,
isGit: payload.isGit,
features: {
commit: payload.commits,
remote: payload.remotes
Expand Down Expand Up @@ -48,10 +49,23 @@ const mutations = {
state.repositoryList[
workspace.state.workspaceRepository.index
].features.remote = payload.remotes;
},
toggleIsGit(state, payload) {
state.repositoryList[
workspace.state.workspaceRepository.index
].isGit = payload.isGit;
}
};

const actions = {};
const actions = {
updateIsGit: ({ commit }, payload) => {
commit({
type: "toggleIsGit",
isGit: payload.isGit
});
localStorage.setItem("repository", JSON.stringify(state.repositoryList));
}
};

export default {
namespaced: true,
Expand Down

0 comments on commit 28b4c23

Please sign in to comment.