Skip to content

Commit b55d0ac

Browse files
committed
Fix the issue of whether the submission has been synchronized with the remote.
1 parent 4713f8d commit b55d0ac

File tree

7 files changed

+54
-33
lines changed

7 files changed

+54
-33
lines changed

frontend/src/components/branch/Index.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ import {State} from "../../store";
44
import React, {useState, useRef, useMemo, useEffect} from "react";
55
import {useDispatch, useSelector} from "react-redux";
66
import {Button, Input, Space, Drawer, Empty} from "antd";
7-
import {AddBranch,GetAllBranch} from "../../../wailsjs/go/repository/Repository"
7+
import {AddBranch, GetAllBranch, GetLocalBranch} from "../../../wailsjs/go/repository/Repository"
88
import {repository} from "../../../wailsjs/go/models"
99
import {setOpenRepositoryBranch} from "../../store/sliceSetting";
1010
import {warning} from "../../utils/common"
1111
import MergeDialog from "./mergeDialog"
12+
import {setAllBranch} from "../../store/sliceMain";
1213

1314

1415
const Branch = () => {
1516
const limit = 20
1617

1718
const dispatch = useDispatch();
18-
const [branch,setBranch] = useState<repository.Branch[]>([]);
19-
19+
// const [branch,setBranch] = useState<repository.Branch[]>([]);
20+
const branch = useSelector((state: State) => state.main.currentlyRepositoryLocalBranch);
2021
const selectedRepositoryId = useSelector((state: State) => state.main.selectedRepositoryId);
2122
const showRepositoryBranch = useSelector((state: State) => state.setting.showRepositoryBranch);
2223
const mergeDialogComponentRef = useRef<{ OpenMergeDialog: (branchName: string) => void }>(null);
@@ -25,25 +26,26 @@ const Branch = () => {
2526
const [keyword,setKeyword] = useState<string>("")
2627
const computedBranch = useMemo(() => (branch.filter(r=>r.name.indexOf(keyword)!==-1)), [keyword,branch]);
2728

28-
const getAllBranch = () => {
29-
if(!selectedRepositoryId){
30-
return
31-
}
32-
GetAllBranch().then(b=>{
33-
setBranch(b||[])
34-
}).catch(e=>{
35-
warning(JSON.stringify(e))
36-
})
37-
}
38-
useEffect(() => {
39-
getAllBranch()
40-
}, [selectedRepositoryId]);
29+
// const getAllBranch = () => {
30+
// if(!selectedRepositoryId){
31+
// return
32+
// }
33+
// GetAllBranch().then(b=>{
34+
// setBranch(b||[])
35+
// }).catch(e=>{
36+
// warning(JSON.stringify(e))
37+
// })
38+
// }
39+
// useEffect(() => {
40+
// getAllBranch()
41+
// }, [selectedRepositoryId]);
4142

4243

4344
const addBranch = async () => {
4445
try {
4546
await AddBranch(branchName)
46-
getAllBranch()
47+
const b = await GetLocalBranch()
48+
dispatch(setAllBranch(b))
4749
setBranchName("")
4850
} catch (e) {
4951
console.log(e)

frontend/src/components/history/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const Item = (props: { l: repository.Commit, nextHash: string }) => {
4242
size="small"
4343
className={props.l.hash === commitId ? 'active-history-card-head' : ''}
4444
headStyle={{background: props.l.hash === commitId ? themeColor : "#fff"}}
45-
title={<Badge status={props.l.unRemoteSync ? 'warning':'success'} text={props.l.hash.substring(0, hashLength)}/>}
45+
title={<Badge status={props.l.isRemoteSync ? 'success':'warning'} text={props.l.hash.substring(0, hashLength)}/>}
4646
extra={extra}
4747
style={{marginBottom: 10}}
4848
>

frontend/wailsjs/go/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export namespace repository {
5757
message: string;
5858
treeHash: string;
5959
parentHashes: string;
60-
unRemoteSync: boolean;
60+
isRemoteSync: boolean;
6161

6262
static createFrom(source: any = {}) {
6363
return new Commit(source);
@@ -71,7 +71,7 @@ export namespace repository {
7171
this.message = source["message"];
7272
this.treeHash = source["treeHash"];
7373
this.parentHashes = source["parentHashes"];
74-
this.unRemoteSync = source["unRemoteSync"];
74+
this.isRemoteSync = source["isRemoteSync"];
7575
}
7676

7777
convertValues(a: any, classs: any, asMap: boolean = false): any {

frontend/wailsjs/go/repository/Repository.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export function GitPull():Promise<string>;
3838

3939
export function GitPush():Promise<string>;
4040

41+
export function IsRemoteRepo():Promise<boolean>;
42+
4143
export function MergeCommit(arg1:string,arg2:string):Promise<string>;
4244

4345
export function MergeRebase(arg1:string,arg2:string):Promise<string>;

frontend/wailsjs/go/repository/Repository.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export function GitPush() {
7474
return window['go']['repository']['Repository']['GitPush']();
7575
}
7676

77+
export function IsRemoteRepo() {
78+
return window['go']['repository']['Repository']['IsRemoteRepo']();
79+
}
80+
7781
export function MergeCommit(arg1, arg2) {
7882
return window['go']['repository']['Repository']['MergeCommit'](arg1, arg2);
7983
}

repository/commit.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,33 @@ type Commit struct {
2020
Message string `json:"message"`
2121
TreeHash string `json:"treeHash"`
2222
ParentHashes string `json:"parentHashes"`
23-
UnRemoteSync bool `json:"unRemoteSync"`
23+
IsRemoteSync bool `json:"isRemoteSync"`
2424
}
2525

2626
func (r *Repository) Commits(branch string) ([]Commit, error) {
2727
if branch == "" {
2828
return nil, errors.New("branch name error")
2929
}
30-
fmt.Println(branch)
30+
3131
var logs []Commit
3232
//f := fmt.Sprintf("--format=format:%s", `{"hash":"%H","author":"%an","message":"%s","treeHash":"%T","parentHashes":"%P","committer":{"name":"%cn","email":"%ce","when":"%cr"}},`)
3333
f := fmt.Sprintf("--format=format:%s", `%H<||>%an<||>%s<||>%T<||>%P<||>%cn<||>%ce<||>%cr<|n|>`)
3434
out, err := utils.RunCmdByPath(r.Path, "git", "log", branch, f, "-n 60")
3535
if err != nil {
3636
return nil, err
3737
}
38-
39-
unRemoteSyncOut, err := utils.RunCmdByPath(r.Path, "git", "remote", "-v")
38+
isRemoteRepo, err := r.IsRemoteRepo()
4039
if err != nil {
4140
return nil, err
4241
}
43-
if strings.TrimSpace(unRemoteSyncOut) != "" {
42+
var noRemoteSyncHash string
43+
if isRemoteRepo {
4444
arg := fmt.Sprintf("origin/%s...%s", branch, branch)
45-
unRemoteSyncOut, err = utils.RunCmdByPath(r.Path, "git", "log", `--pretty=format:"%H"`, arg)
45+
noRemoteSyncHash, err = utils.RunCmdByPath(r.Path, "git", "log", `--pretty=format:"%H"`, arg)
4646
if err != nil {
4747
return nil, err
4848
}
4949
}
50-
//jsonStr := fmt.Sprintf("[%s]", strings.TrimRight(out, ","))
51-
52-
//err = json.Unmarshal([]byte(jsonStr), &logs)
53-
//if err != nil {
54-
// return nil, err
55-
//}
5650
outs := strings.Split(out, "<|n|>")
5751
for _, r := range outs {
5852
rows := strings.Split(strings.TrimSpace(r), "<||>")
@@ -61,6 +55,12 @@ func (r *Repository) Commits(branch string) ([]Commit, error) {
6155
}
6256
//`{"hash":"%H","author":"%an","message":"%s","treeHash":"%T","parentHashes":"%P","committer":{"name":"%cn","email":"%ce","when":"%cr"}},`
6357
hash := strings.TrimSpace(rows[0])
58+
59+
var isRemoteSync bool
60+
if isRemoteRepo {
61+
isRemoteSync = !strings.Contains(noRemoteSyncHash, hash)
62+
}
63+
6464
logs = append(logs, Commit{
6565
Hash: hash,
6666
Author: rows[1],
@@ -72,7 +72,7 @@ func (r *Repository) Commits(branch string) ([]Commit, error) {
7272
Email: rows[6],
7373
When: rows[7],
7474
},
75-
UnRemoteSync: strings.Contains(unRemoteSyncOut, hash),
75+
IsRemoteSync: isRemoteSync,
7676
})
7777
}
7878

repository/utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"git-helper/utils"
66
"os/exec"
77
sysRuntime "runtime"
8+
"strings"
89
)
910

1011
func (r *Repository) OpenTerminal() error {
@@ -49,3 +50,15 @@ func (r *Repository) OpenFileManage() error {
4950
func (r *Repository) RunCmdInRepository(cmd string, arg []string) (string, error) {
5051
return utils.RunCmdByPath(r.Path, cmd, arg...)
5152
}
53+
func (r *Repository) IsRemoteRepo() (bool, error) {
54+
55+
out, err := utils.RunCmdByPath(r.Path, "git", "remote", "-v")
56+
if err != nil {
57+
return false, err
58+
}
59+
60+
if strings.TrimSpace(out) == "" {
61+
return false, nil
62+
}
63+
return true, nil
64+
}

0 commit comments

Comments
 (0)