git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 3/5] Do not create an empty patch if import failed without --reject

From
CMCatalin Marinas <catalin.marinas@gmail.com>
Date
Sep 16, 2009, 21:41 UTC
Message-ID
<20090916214105.6622.24307.stgit@toshiba-laptop>
In-Reply-To
<20090916214049.6622.44662.stgit@toshiba-laptop>

If the import failed, do not leave an empty patch on the stack. If this is required, the --reject option should be passed. The patch also fixes a lowercase typo in the --reject option description.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/imprt.py |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index aa75065..de77635 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -68,7 +68,7 @@ options = [
     opt('-b', '--base', args = [argparse.commit],
         short = 'Use BASE instead of HEAD for file importing'),
     opt('--reject', action = 'store_true',
-        short = 'leave the rejected hunks in corresponding *.rej files'),
+        short = 'Leave the rejected hunks in corresponding *.rej files'),
     opt('-e', '--edit', action = 'store_true',
         short = 'Invoke an editor for the patch description'),
     opt('-d', '--showdiff', action = 'store_true',
@@ -154,8 +154,13 @@ def __create_patch(filename, message, author_name, author_email,
             base = git_id(crt_series, options.base)
         else:
             base = None
-        git.apply_patch(diff = diff, base = base, reject = options.reject,
-                        strip = options.strip)
+        try:
+            git.apply_patch(diff = diff, base = base, reject = options.reject,
+                            strip = options.strip)
+        except git.GitException:
+            if not options.reject:
+                crt_series.delete_patch(patch)
+            raise
         crt_series.refresh_patch(edit = options.edit,
                                  show_patch = options.showdiff,
                                  author_date = author_date,
Previous: Catalin MarinasNext: Catalin Marinas
Message 4 of 6 in “More UI clean-up”
  1. 0/5 More UI clean-upCatalin Marinas, Sep 16, 2009
  2. 1/5 Remove the 'fail_dump' argument to git.apply_patch()Catalin Marinas, Sep 16, 2009
  3. 2/5 Add the --reject option to foldCatalin Marinas, Sep 16, 2009
  4. 3/5 Do not create an empty patch if import failed without --rejectCatalin Marinas, Sep 16, 2009
  5. 4/5 Add the -p option to foldCatalin Marinas, Sep 16, 2009
  6. 5/5 Autosign imported patchesCatalin Marinas, Sep 16, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.