Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
conv: rebuild to fix permission problem
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Oct 8, 2020
1 parent 92dbb61 commit 29cb3a5
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/fgit.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bytes"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -96,35 +95,26 @@ func convertToGitHub() bool {
}

func convertHelper(oldPrefixValue, newPrefixValue string) bool {
fi, err := os.Open(path.Join(".git", "config"))
checkErr(err, "This is not a git path! Cannot push!", 1)
defer fi.Close()

gitConfigByte, err := ioutil.ReadFile(path.Join(".git", "config"))
checkErr(err, "Cannot read .git config file!", 3)
gitConfig := string(gitConfigByte)

isReplaceDo := false
sb := new(bytes.Buffer)
iniArray := strings.Split(gitConfig, "\n")

iniNewStr := ""

for i := range iniArray {
if strings.Trim(iniArray[i], "") == "" {
// drop useless lines
// sb.WriteString(iniArray[i] + "\n")
continue
}
iniNewStr = strings.Replace(iniArray[i], oldPrefixValue, newPrefixValue, 1)
if iniArray[i] != iniNewStr {
iniArray[i] = iniNewStr
isReplaceDo = true
cmd := exec.Command("git", "remote", "-v")
buf, err := cmd.Output()
sBuf := string(buf)
originUrl := ""
checkErr(err, "Convert failed.", 8)
tmp := strings.Split(strings.Replace(strings.Replace(sBuf, "\t", " ", -1), " ", " ", -1), " ")
for i := range tmp {
if strings.HasPrefix(tmp[i], oldPrefixValue) {
originUrl = tmp[i]
break
}
sb.WriteString(iniArray[i] + "\n")
}
fi.Write(sb.Bytes())
return isReplaceDo
if originUrl == "" {
return false
}
fmt.Println(originUrl)
cmd = exec.Command("git", "remote", "set-url", "origin", strings.Replace(originUrl, oldPrefixValue, newPrefixValue, 1))
_, err = cmd.Output()
checkErr(err, "Convert failed.", 8)
return true
}

func checkErr(err error, msg string, exitCode int) {
Expand Down

0 comments on commit 29cb3a5

Please sign in to comment.