This commit is contained in:
Mustafa Gezen 2020-12-14 04:51:03 +01:00
parent 18ea4b95fc
commit 18bd2993cc

View File

@ -102,7 +102,6 @@ func ProcessRPM(pd *ProcessData) {
}
// this will be set later
specFileName := ""
var specBts []byte
// read the rpm in cpio format
@ -121,13 +120,11 @@ func ProcessRPM(pd *ProcessData) {
// set spec file name
if filepath.Ext(hdr.Name) == ".spec" {
specFileName = hdr.Name
var err error
specBts, err = ioutil.ReadAll(r)
if err != nil {
log.Fatalf("could not read spec: %v", err)
}
continue
}
bts, err := ioutil.ReadAll(r)
@ -163,14 +160,6 @@ func ProcessRPM(pd *ProcessData) {
// read spec and remove remote files
spec := parseSpecFile(specBts, rpmFile.Source())
specFile, err := w.Filesystem.Create(filepath.Join("SPECS", specFileName))
if err != nil {
log.Fatalf("could not create spec file: %v", err)
}
_, err = specFile.Write(specBts)
if err != nil {
log.Fatalf("could not write spec file: %v", err)
}
// create a new remote
remoteUrl := fmt.Sprintf("%s/dist/%s.git", pd.UpstreamPrefix, rpmFile.Name())
@ -227,7 +216,12 @@ func ProcessRPM(pd *ProcessData) {
// TODO: Remove dangling files
for fileName, contents := range fileWrites {
newPath := filepath.Join("SOURCES", fileName)
var newPath string
if filepath.Ext(fileName) == ".spec" {
newPath = filepath.Join("SPECS", fileName)
} else {
newPath = filepath.Join("SOURCES", fileName)
}
// add the file to the virtual filesystem
// we will move it to correct destination later
@ -382,11 +376,19 @@ func ProcessRPM(pd *ProcessData) {
status, _ := w.Status()
log.Printf("successfully processed:\n%s", status)
var hashes []plumbing.Hash
var pushRefspecs []config.RefSpec
head, err := repo.Head()
if err != nil {
log.Fatalf("could not get ref: %v", err)
}
hashes = nil
pushRefspecs = nil
} else {
log.Printf("tip %s", head.String())
hashes = append(hashes, head.Hash())
refOrigin := "refs/heads/" + pd.Branch
pushRefspecs = append(pushRefspecs, config.RefSpec(fmt.Sprintf("HEAD:%s", refOrigin)))
}
// we are now finished with the tree and are going to push it to the src repo
// create import commit
@ -396,7 +398,7 @@ func ProcessRPM(pd *ProcessData) {
Email: "mustafa@bycrates.com",
When: time.Now(),
},
Parents: []plumbing.Hash{head.Hash()},
Parents: hashes,
})
if err != nil {
log.Fatalf("could not commit object: %v", err)
@ -409,11 +411,10 @@ func ProcessRPM(pd *ProcessData) {
log.Printf("committed:\n%s", obj.String())
refOrigin := "refs/heads/" + pd.Branch
err = repo.Push(&git.PushOptions{
RemoteName: "origin",
Auth: authenticator,
RefSpecs: []config.RefSpec{config.RefSpec(fmt.Sprintf("HEAD:%s", refOrigin))},
RefSpecs: pushRefspecs,
})
if err != nil {
log.Fatalf("could not push to remote: %v", err)