Skip to contentSkip to conversation

stop it from failing silently when git apply patch and show err info

PATCH In review simon gao 1 participant 2 messages Jul 25, 2019

lore
Share & tools
lore

simon gao

author
#0 lore raw

PATCH 1/1 stop it from failing silently when git apply patch and show err info

---
 apply.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
apply.c +3 -1
index 4992eca..47b16aa 100644
@@ -2093,8 +2093,10 @@ static int use_patch(struct apply_state *state, struct patch *p)
 	/* Paths outside are not touched regardless of "--include" */
 	if (state->prefix && *state->prefix) {
 		const char *rest;
-		if (!skip_prefix(pathname, state->prefix, &rest) || !*rest)
+		if (!skip_prefix(pathname, state->prefix, &rest) || !*rest){
+			error(_("%s doesn't contain the prefix(%s)"), pathname, state->prefix);
 			return 0;
+		}
 	}
 
 	/* See if it matches any of exclude/include rule */
Signature · 1 line
1.8.3.1
author
#1 lore raw

I create 001.patch in dir, ceph_master

ceph_master

|--- .git
|--- src
|--- tools
|--- ...

local project directory:
storage
|---.git
|---ceph_**.*.**

    |--- src
    |--- tools
    |--- ...

I'm trying to apply the patch, and git apply patch doesn't give me any errors. like this
cd storage/ceph_**.*.** && git apply 001.patch
I check code and I find that root directory need to be set using "--directory" I think we need show some info about it.

thinks

Quoted 25 lines · simon gao <[email protected]> 于2019年7月25日周四 下午6:43写道:
---
 apply.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
apply.c +3 -2
index 4992eca..47b16aa 100644
@@ -2093,8 +2093,10 @@ static int use_patch(struct apply_state *state, struct patch *p)
        /* Paths outside are not touched regardless of "--include" */
        if (state->prefix && *state->prefix) {
                const char *rest;
-               if (!skip_prefix(pathname, state->prefix, &rest) || !*rest)
+               if (!skip_prefix(pathname, state->prefix, &rest) || !*rest){
+                       error(_("%s doesn't contain the prefix(%s)"), pathname, state->prefix);
                        return 0;
+               }
        }
 
        /* See if it matches any of exclude/include rule */
--

1.8.3.1