Skip to content

Commit 34e11f1

Browse files
committed
Save json:
1 parent 251f918 commit 34e11f1

File tree

16 files changed

+280
-74
lines changed

16 files changed

+280
-74
lines changed

Diff for: Data.json

-1
This file was deleted.

Diff for: app.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"github.com/wailsapp/wails/v2/pkg/menu"
88
"github.com/wailsapp/wails/v2/pkg/menu/keys"
99
"github.com/wailsapp/wails/v2/pkg/runtime"
10+
"os/user"
1011
)
1112

1213
// App struct
1314
type App struct {
14-
ctx context.Context
15-
repository *git.Repository
15+
ctx context.Context
16+
repository *git.Repository
17+
dataSaveJson string
1618
}
1719

1820
// NewApp creates a new App application struct
@@ -24,6 +26,11 @@ func NewApp() *App {
2426
// so we can call the runtime methods
2527
func (a *App) startup(ctx context.Context) {
2628
a.ctx = ctx
29+
u, err := user.Current()
30+
if err != nil {
31+
panic(err)
32+
}
33+
a.dataSaveJson = u.HomeDir + "/Git_Helper.json"
2734
}
2835

2936
// Greet returns a greeting for the given name

Diff for: build/488-git.png

-50.6 KB
Binary file not shown.

Diff for: build/appicon.png

-5.87 KB
Loading

Diff for: common.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
)
1010

11-
const JsonDataPath = "./Data.json"
1211
const TimeLayout = "2006-01-02 15:04:05"
1312

1413
func (a *App) Sha256(s string) string {
@@ -23,10 +22,10 @@ func (a *App) MessageDialog(title string, message string) {
2322
}
2423
func (a *App) SaveJsonFile(t string) error {
2524

26-
if err := utils.RemoveFile(JsonDataPath); err != nil {
25+
if err := utils.RemoveFile(a.dataSaveJson); err != nil {
2726
return err
2827
}
29-
err := ioutil.WriteFile(JsonDataPath, []byte(t), 0666)
28+
err := ioutil.WriteFile(a.dataSaveJson, []byte(t), 0666)
3029

3130
if err != nil {
3231
return err
@@ -35,7 +34,7 @@ func (a *App) SaveJsonFile(t string) error {
3534
}
3635
func (a *App) ReadJsonFile() (string, error) {
3736

38-
b, err := ioutil.ReadFile(JsonDataPath)
37+
b, err := ioutil.ReadFile(a.dataSaveJson)
3938
if err != nil {
4039
return "", err
4140
}

Diff for: frontend/src/components/branch/Index.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import "./style.scss"
22
import Item from "./Item"
33
import {State} from "../../store";
4-
import React, {useState} from "react";
4+
import React, {useState,useRef} from "react";
55
import {useDispatch, useSelector} from "react-redux";
66
import {Button, Input, Space,Drawer,Empty} from "antd";
77
import { AddBranch,GetBranch } from "../../../wailsjs/go/main/App"
88
import {setOpenRepositoryBranch} from "../../store/sliceSetting";
99
import {setAllBranch} from "../../store/sliceMain";
1010
import { warning } from "../../utils/common"
11+
import MergeDialog from "./mergeDialog"
12+
1113

1214
const Branch = () => {
1315
const dispatch = useDispatch();
1416
const branch = useSelector((state: State) => state.main.currentlyRepositoryAllBranch);
1517
const selectedRepositoryId = useSelector((state: State) => state.main.selectedRepositoryId);
1618
const showRepositoryBranch = useSelector((state: State) => state.setting.showRepositoryBranch);
17-
19+
const mergeDialogComponentRef = useRef<{OpenMergeDialog:(branchName:string)=>void}>(null);
1820
const [branchName,setBranchName] = useState<string>("")
1921

2022
const addBranch = async () => {
@@ -45,12 +47,15 @@ const Branch = () => {
4547

4648
const content = <>
4749
<div style={{flex:1,overflowY:"auto",padding:20}}>
48-
{ branch.map(r=><Item b={r} key={r.hash} />)}
50+
{ branch.map(r=><Item merge={()=>{mergeDialogComponentRef.current?.OpenMergeDialog(r.name)}} b={r} key={r.name} />)}
4951
</div>
5052
<div style={{padding:20}}>
5153
{bottom}
5254
</div>
5355
</>
56+
57+
58+
5459
return (
5560
<Drawer
5661
title="Branch manage"
@@ -59,6 +64,7 @@ const Branch = () => {
5964
onClose={onCloseBranch}
6065
open={showRepositoryBranch}
6166
>
67+
<MergeDialog ref={mergeDialogComponentRef}/>
6268
{selectedRepositoryId?content:<Empty style={{marginTop:200}} description="please select a git repository first" />}
6369
</Drawer>
6470
);

Diff for: frontend/src/components/branch/Item.tsx

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {State} from "../../store";
1313
dayjs.extend(relativeTime)
1414

1515

16-
const Item = (props: { b: main.Branch }) => {
16+
const Item = (props: { b: main.Branch,merge:()=>void }) => {
1717
const sledBranch = useSelector((state: State) => state.main.selectedRepositoryBranch);
1818

1919
const dispatch = useDispatch();
@@ -41,17 +41,13 @@ const Item = (props: { b: main.Branch }) => {
4141
}
4242

4343
const merge = async () => {
44-
try {
45-
const hash = await GetLastCommit(sledBranch)
46-
console.log(hash)
47-
console.log(props.b.hash)
48-
const result = await PreMergeResult(hash,props.b.hash)
49-
console.log(result)
50-
}catch (e) {
51-
console.log(e)
52-
warning(JSON.stringify(e))
44+
if(!sledBranch){
45+
warning("please select a branch first")
46+
return
5347
}
48+
props.merge()
5449
}
50+
5551
const extra = <Space>
5652
{
5753
(sledBranch != props.b.name ) && <ArrowLeftOutlined onClick={merge} style={{cursor: "pointer", opacity: 0.45}} />

Diff for: frontend/src/components/branch/mergeDialog.tsx

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import {Button, Modal, Result} from 'antd';
2+
import { LoadingOutlined } from "@ant-design/icons"
3+
import {useDispatch, useSelector} from "react-redux";
4+
import {State} from "../../store";
5+
import {useState, useImperativeHandle, forwardRef} from "react";
6+
import {success, warning} from "../../utils/common";
7+
import {GetLastCommit, PreMergeResult, MergeCommit, MergeRebase, MergeSquash, Log} from "../../../wailsjs/go/main/App";
8+
import {main} from "../../../wailsjs/go/models";
9+
import {warningNotification} from "../../utils/notification";
10+
import {setLog} from "../../store/sliceMain";
11+
12+
13+
const MergeDialog = (props: {}, ref: any) => {
14+
const dispatch = useDispatch();
15+
const currentBranchName = useSelector((state: State) => state.main.selectedRepositoryBranch);
16+
const [openMerge, setOpenMerge] = useState(false);
17+
const [loading, setLoading] = useState(false);
18+
19+
const [preMergeResult, setPreMergeResult] = useState<main.MergeResult | null>(null);
20+
21+
const [mergeContent, setMergeContent] = useState({
22+
ourBranchHash: "",
23+
ourBranchName: "",
24+
theirBranchHash: "",
25+
theirBranchName: "",
26+
});
27+
28+
const OpenMergeDialog = async (mergeName: string) => {
29+
setOpenMerge(true)
30+
setLoading(true)
31+
try {
32+
let ourBranchHash = await GetLastCommit(currentBranchName)
33+
let theirBranchHash = await GetLastCommit(mergeName)
34+
setMergeContent({
35+
ourBranchHash,
36+
ourBranchName: currentBranchName,
37+
theirBranchHash,
38+
theirBranchName: mergeName,
39+
})
40+
41+
const result = await PreMergeResult(ourBranchHash, theirBranchHash)
42+
setPreMergeResult(result)
43+
44+
} catch (e) {
45+
console.log(e)
46+
warning(JSON.stringify(e))
47+
}finally {
48+
setTimeout(()=>{setLoading(false)},500)
49+
}
50+
51+
}
52+
53+
54+
useImperativeHandle(ref, () => ({OpenMergeDialog}))
55+
56+
57+
const subTitle = () => {
58+
if(preMergeResult?.kind === 1){
59+
return <div>There will be <strong>{preMergeResult.count}</strong> conflicted file when merging <strong>{mergeContent.theirBranchName}</strong> into <strong>{mergeContent.ourBranchName}</strong></div>
60+
}
61+
if(preMergeResult?.kind === 2){
62+
if(preMergeResult?.count === 0){
63+
return <div>This branch is up to date with <strong>{mergeContent.theirBranchName}</strong></div>
64+
}else {
65+
return <div>
66+
This will merge <strong>{preMergeResult?.count}</strong> commit{preMergeResult?.count >=2 ?'s':''} from <strong>{mergeContent.theirBranchName}</strong> into <strong>{mergeContent.ourBranchName}</strong></div>
67+
}
68+
}
69+
return
70+
}
71+
72+
73+
const rebaseMerge = () => {
74+
MergeRebase(mergeContent.ourBranchName,mergeContent.theirBranchName).then(out=>{
75+
success(out)
76+
return Log()
77+
}).then(l=>{
78+
dispatch(setLog(l))
79+
setOpenMerge(false)
80+
}).catch(e=>{
81+
warningNotification(e,{width:500})
82+
})
83+
84+
}
85+
const squashMerge = () => {
86+
MergeSquash(mergeContent.ourBranchName,mergeContent.theirBranchName).then(out=>{
87+
success(out)
88+
return Log()
89+
}).then(l=>{
90+
dispatch(setLog(l))
91+
setOpenMerge(false)
92+
}).catch(e=>{
93+
warningNotification(e,{width:500})
94+
})
95+
}
96+
const commitMerge = () => {
97+
MergeCommit(mergeContent.ourBranchName,mergeContent.theirBranchName).then(out=>{
98+
success(out)
99+
return Log()
100+
}).then(l=>{
101+
dispatch(setLog(l))
102+
setOpenMerge(false)
103+
}).catch(e=>{
104+
warningNotification(e,{width:500})
105+
})
106+
}
107+
108+
return <Modal
109+
width={600}
110+
open={openMerge}
111+
title={`Merge branch ${mergeContent.theirBranchName} into ${mergeContent.ourBranchName}.`}
112+
onCancel={() => {
113+
setOpenMerge(false)
114+
setPreMergeResult(null)
115+
}}
116+
footer={[
117+
<Button key="rebase" type="primary" onClick={rebaseMerge}>
118+
Rebase
119+
</Button>,
120+
<Button key="squash" type="primary" onClick={squashMerge}>
121+
Squash and merge
122+
</Button>,
123+
<Button key="submit" type="primary" onClick={commitMerge}>
124+
Create a merge commit
125+
</Button>,
126+
]}
127+
>
128+
<Result
129+
status={preMergeResult?.kind === 1 ? 'warning' : 'success'}
130+
icon={loading ? <LoadingOutlined /> :''}
131+
subTitle={subTitle()}/>
132+
</Modal>
133+
}
134+
135+
export default forwardRef(MergeDialog)
136+
137+

Diff for: frontend/src/components/changes/Index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Changes = () => {
4848
success("Commit hash:"+hash)
4949
setCommitName("")
5050
setCommitMessage("")
51+
setCheckedList([])
5152
await updateWorkZone(selectedRepositoryId)
5253
dispatch(resetState())
5354
}catch (e) {
@@ -95,7 +96,8 @@ const Changes = () => {
9596
</Space>
9697
</div>
9798

98-
const action = <Space direction="vertical" size="middle" style={{display: 'flex'}}>
99+
const action = <Space size="middle" style={{display: 'flex'}}>
100+
<div>{checkedList.length}</div>
99101
<Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
100102
Check all
101103
</Checkbox>

Diff for: frontend/src/components/topBar/action/Action.tsx

+9-41
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {useDispatch} from "react-redux";
22
import {Button, message, notification, Space} from 'antd';
33
import {warning} from "../../../utils/common";
4+
import {warningNotification,successNotification} from "../../../utils/notification";
45
import {OpenFileManage, OpenTerminal, GitPull, GitPush} from "../../../../wailsjs/go/main/App"
5-
import {setOpenRepositoryTag, setOpenRepositoryBranch, setOpenMoreHelper} from "../../../store/sliceSetting";
6+
import {setOpenRepositoryTag, setOpenRepositoryBranch} from "../../../store/sliceSetting";
67
import {
78
ArrowUpOutlined,
89
ArrowDownOutlined,
910
CodeOutlined,
1011
FolderOpenOutlined,
1112
TagOutlined,
1213
BranchesOutlined,
13-
// MoreOutlined
1414
} from '@ant-design/icons';
1515
import React, {useState} from "react";
1616

@@ -41,55 +41,23 @@ const Action = () => {
4141
dispatch(setOpenRepositoryBranch(true))
4242

4343
}
44-
const openMoreHelper = () => {
45-
dispatch(setOpenMoreHelper(true))
46-
}
44+
// const openMoreHelper = () => {
45+
// dispatch(setOpenMoreHelper(true))
46+
// }
4747
const pushRepo = () => {
4848
setPushLoading(true)
4949
GitPush().then(out => {
50-
notification.success({
51-
message: `Out`,
52-
description: <div style={{whiteSpace: "pre-wrap"}}>{out}</div>,
53-
placement: "bottomRight",
54-
style: {
55-
width: 500,
56-
top: 40,
57-
},
58-
});
50+
successNotification(out,{width:500})
5951
}).catch(e => {
60-
notification.warning({
61-
message: `Tip`,
62-
description: <div style={{whiteSpace: "pre-wrap"}}>{e}</div>,
63-
placement: "bottomRight",
64-
style: {
65-
width: 500,
66-
top: 40,
67-
},
68-
});
52+
warningNotification(e,{width:500})
6953
}).finally(()=>{setPushLoading(false)})
7054
}
7155
const pullRepo = () => {
7256
setPullLoading(true)
7357
GitPull().then(out => {
74-
notification.success({
75-
message: `Out`,
76-
description: <div style={{whiteSpace: "pre-wrap"}}>{out}</div>,
77-
placement: "bottomRight",
78-
style: {
79-
width: 500,
80-
top: 40,
81-
},
82-
});
58+
successNotification(out,{width:500})
8359
}).catch(e => {
84-
notification.warning({
85-
message: `Tip`,
86-
description: <div style={{whiteSpace: "pre-wrap"}}>{e}</div>,
87-
placement: "bottomRight",
88-
style: {
89-
width: 500,
90-
top: 40,
91-
},
92-
});
60+
warningNotification(e,{width:500})
9361
}).finally(()=>{setPullLoading(false)})
9462
}
9563
return (

0 commit comments

Comments
 (0)