Code

Merge branch 'jc/maint-rebase-rewrite-last-skip' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 28 Dec 2010 21:43:10 +0000 (13:43 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Dec 2010 21:43:10 +0000 (13:43 -0800)
* jc/maint-rebase-rewrite-last-skip:
  rebase --skip: correctly wrap-up when skipping the last patch

git-am.sh
t/t3404-rebase-interactive.sh
t/t4151-am-abort.sh
t/test-lib.sh
wt-status.c
xdiff-interface.c

index 69474e5da29c1bb121ae69432c06b63095b5bee6..f4db17d93424c18c1db53e9bf84cdeee8219fa10 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -68,9 +68,31 @@ sq () {
 
 stop_here () {
     echo "$1" >"$dotest/next"
+    git rev-parse --verify -q HEAD >"$dotest/abort-safety"
     exit 1
 }
 
+safe_to_abort () {
+       if test -f "$dotest/dirtyindex"
+       then
+               return 1
+       fi
+
+       if ! test -s "$dotest/abort-safety"
+       then
+               return 0
+       fi
+
+       abort_safety=$(cat "$dotest/abort-safety")
+       if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety"
+       then
+               return 0
+       fi
+       echo >&2 "You seem to have moved HEAD since the last 'am' failure."
+       echo >&2 "Not rewinding to ORIG_HEAD"
+       return 1
+}
+
 stop_here_user_resolve () {
     if [ -n "$resolvemsg" ]; then
            printf '%s\n' "$resolvemsg"
@@ -419,10 +441,11 @@ then
                        exec git rebase --abort
                fi
                git rerere clear
-               test -f "$dotest/dirtyindex" || {
+               if safe_to_abort
+               then
                        git read-tree --reset -u HEAD ORIG_HEAD
                        git reset ORIG_HEAD
-               }
+               fi
                rm -fr "$dotest"
                exit ;;
        esac
index 7d20a74c5ca1331ff241d1596bcb114e48a5907d..9e9474e9447c8835eb4ef30714b577896a06924d 100755 (executable)
@@ -67,8 +67,9 @@ test_expect_success 'setup' '
 # "exec" commands are ran with the user shell by default, but this may
 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
 # to create a file. Unseting SHELL avoids such non-portable behavior
-# in tests.
+# in tests. It must be exported for it to take effect where needed.
 SHELL=
+export SHELL
 
 test_expect_success 'rebase -i with the exec command' '
        git checkout master &&
index b55c4117884744db8eda17e42fe05e0e65216215..c95c4ccc393d0863ad53b6a2a684893282d7d9e6 100755 (executable)
@@ -62,4 +62,13 @@ do
 
 done
 
+test_expect_success 'am --abort will keep the local commits intact' '
+       test_must_fail git am 0004-*.patch &&
+       test_commit unrelated &&
+       git rev-parse HEAD >expect &&
+       git am --abort &&
+       git rev-parse HEAD >actual &&
+       test_cmp expect actual
+'
+
 test_done
index c6afebb00d02808f2a990347c8b0479d825cce5b..1fb76abd14e358afb42774f0ffe1d4e70b749074 100644 (file)
@@ -260,7 +260,7 @@ test_decode_color () {
                        if (n == 47) return "BWHITE";
                }
                {
-                       while (match($0, /\x1b\[[0-9;]*m/) != 0) {
+                       while (match($0, /\033\[[0-9;]*m/) != 0) {
                                printf "%s<", substr($0, 1, RSTART-1);
                                codes = substr($0, RSTART+2, RLENGTH-3);
                                if (length(codes) == 0)
index fc2438f60b0e0e87772db2a9f3e407f351bb03d0..9624865e21739139a9fef5ebc31196cbcd22011a 100644 (file)
@@ -744,10 +744,20 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
                const char *one;
                if (d->head_path) {
                        one = quote_path(d->head_path, -1, &onebuf, s->prefix);
+                       if (*one != '"' && strchr(one, ' ') != NULL) {
+                               putchar('"');
+                               strbuf_addch(&onebuf, '"');
+                               one = onebuf.buf;
+                       }
                        printf("%s -> ", one);
                        strbuf_release(&onebuf);
                }
                one = quote_path(it->string, -1, &onebuf, s->prefix);
+               if (*one != '"' && strchr(one, ' ') != NULL) {
+                       putchar('"');
+                       strbuf_addch(&onebuf, '"');
+                       one = onebuf.buf;
+               }
                printf("%s\n", one);
                strbuf_release(&onebuf);
        }
index e1e054e4d982de30d8a9c8c4109c6d62448f62a9..164581f87f49935f0d1b1885420960a4d11dea56 100644 (file)
@@ -212,8 +212,10 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
                return error("Could not open %s", filename);
        sz = xsize_t(st.st_size);
        ptr->ptr = xmalloc(sz ? sz : 1);
-       if (sz && fread(ptr->ptr, sz, 1, f) != 1)
+       if (sz && fread(ptr->ptr, sz, 1, f) != 1) {
+               fclose(f);
                return error("Could not read %s", filename);
+       }
        fclose(f);
        ptr->size = sz;
        return 0;