Check if a patch has been applied

This Patch Does Not Apply To The Current Repository
guest@senary.lopeos.org submitted a patch request Feb 15, 2025 22:17
  • Title: Check if a Patch has been applied. Nicer Client Side Validation
  • Author: Sarah Jamie Lewis <sarah@openprivacy.ca>

repo/patch.go

@@ -24,6 +24,14 @@ func (ph *PatchHandler) CheckApply(patchfile string) ([]byte, error) {
  	return output, err

              }

              

            +func (ph *PatchHandler) CheckApplied(patchfile string) ([]byte, error) {

            +	patchFileAbs, _ := filepath.Abs(patchfile)

            +	cmd := exec.Command("git", "apply", "--reverse", "--check", patchFileAbs)

            +	cmd.Dir = ph.RepoPath

            +	output, err := cmd.CombinedOutput()

            +	return output, err

            +}

            +

              func (ph *PatchHandler) Apply(patchfile string) error {

              	patchFileAbs, _ := filepath.Abs(patchfile)

              	cmd := exec.Command("git", "am", "--keep-cr", patchFileAbs)

            

repo/requests.go

@@ -69,10 +69,18 @@ func (rm *RequestManager) ApplyPatch(w http.ResponseWriter, r *http.Request) {
  		patchHash := r.PathValue("patch")

              		err := rm.patchHandler.Apply(rm.RequestIssueElement(idString, patchHash))

              		if err == nil {

            -			rm.patchHandler.Upstream()

            -			rm.patchHandler.Rebuild()

            +			err := rm.patchHandler.Upstream()

            +			if err != nil {

            +				fmt.Printf("could not upstream: %v\n", err)

            +			}

            +			err = rm.patchHandler.Rebuild()

            +			if err != nil {

            +				fmt.Printf("could not rebuild: %v\n", err)

            +			}

              			http.Redirect(w, r, r.Header.Get("Referer"), 302)

              			return

            +		} else {

            +			fmt.Printf("could not apply patch: %v\n", err)

              		}

              	}

              	http.Redirect(w, r, "/404", 404)

            
@@ -236,7 +244,11 @@ func (rm *RequestManager) LoadIssues(logpath string, loadfn func(hash string) (*
  								issue.PatchInfo = patchSummary

              

              								if _, err := rm.patchHandler.CheckApply(rm.RequestIssueElement(le.Hash, issue.PatchRef)); err != nil {

            -									warningCallback(WARN, "This Patch Does Not Apply To The Current Repository")

            +									if _, err := rm.patchHandler.CheckApplied(rm.RequestIssueElement(le.Hash, issue.PatchRef)); err != nil {

            +										warningCallback(WARN, "This Patch Does Not Apply To The Current Repository")

            +									} else {

            +										warningCallback(INFO, "This Patch Has Been Applied")

            +									}

              								} else {

              									warningCallback(INFO, "This Patch Can Be Applied To The Current Repository")

              									issue.PatchInfo.CanBeApplied = true

            

templates/request.list.tpl.html

@@ -21,6 +21,8 @@
  </tr>

              {{$p := .}}

              {{range .Requests}}

            +

            +        {{if .Approved}}

                  <tr><td><a href="./{{.ID}}">{{.Summary}}</a></td><td>{{.Created.Format "Jan 02, 2006 15:04" }}</td>

                  

                      {{if eq $p.User.IsMaintainer true}}

            
@@ -39,6 +41,7 @@
  

                      </td>

                      {{end}}

            +        {{end}}

                  </tr>

              {{end}}

              </table>

            

templates/request.new.tpl.html

@@ -17,6 +17,7 @@
        <input

                      name="summary"

                      placeholder="A one line summary of the issue/request"

            +        minlength="10"

                    />

                  </label>

                  <label>

            
@@ -24,6 +25,7 @@
        <textarea

                      name="description"

                      placeholder="Please outline the issue/change request in full."

            +        minlength="100"

                    ></textarea>

                  </label>

                </fieldset>

            

templates/request.newpatch.tpl.html

@@ -18,6 +18,7 @@
        <input

                      name="summary"

                      placeholder="A one line summary of the issue/request"

            +          minlength="10"

                    />

                  </label>

                      <label>

            
@@ -25,6 +26,7 @@
        <input

                      type="file"

                      name="patchfile"

            +        required

                    />

                  </label>