# [BUG] Problem with "stgit push" causing data loss

4 messages from 2007-01-20 to 2007-01-21. Participants: Yann Dirson, Catalin Marinas.
Thread: https://gitlist.dev/t/6453

## Yann Dirson, 2007-01-20 15:01

Subject: [BUG] Problem with "stgit push" causing data loss
Message-ID: <20070120150113.GB4665@nan92-1-81-57-214-146.fbx.proxad.net>
URL: https://gitlist.dev/e/20070120150113.GB4665%40nan92-1-81-57-214-146.fbx.proxad.net

```
Well, "data loss" is a bit strong, since the data is still available
to find using git-lost-found.

I first tried to reproduce with a simple test-case, but could not, so
here is my way to reproduce it, on a clone of the stgit official
workspace.

stgit$ stg branch --create test origin
Branch "test" created.

 The test patch is my previous work on "pull --to", now superceded
 by "rebase".  Patch to reproduce attached to this mail - I just use
 "pick" since it's easier for me:

stgit$ ./stg pick -n pull-to 9abaec589753ab190d378b534ceaa6a5af5d0dd3
Checking for changes in the working directory... done
Importing commit 9abaec589753ab190d378b534ceaa6a5af5d0dd3... done
Now at patch "pull-to"
stgit$ stg files pull-to
M stgit/commands/pull.py
A t/t2100-pull-to.sh

 Now move the testcase in a new patch below, using my
 stg-fold-files-from already sent to the list:

stgit$ stg pop
Popping patch "pull-to"... done
No patches applied
stgit$ stg new test -m test
stgit$ stg-fold-files-from pull-to 't/*'
Folding patch from stdin... done
stgit$ stg refresh
Refreshing patch "test"... done
stgit$ stg files
A t/t2100-pull-to.sh

 And then push the old file over that:

$ stg push
Pushing patch "pull-to"...
Traceback (most recent call last):
  File "/usr/bin/stg", line 43, in ?
    main()
  File "/var/lib/python-support/python2.4/stgit/main.py", line 261, in main
    command.func(parser, options, args)
  File "/var/lib/python-support/python2.4/stgit/commands/push.py", line 101, in func
    push_patches(patches, options.merged)
  File "/var/lib/python-support/python2.4/stgit/commands/common.py", line 190, in push_patches
    modified = crt_series.push_patch(p)
  File "/var/lib/python-support/python2.4/stgit/stack.py", line 916, in push_patch
    git.merge(bottom, head, top)
  File "/var/lib/python-support/python2.4/stgit/git.py", line 535, in merge
    stages['2'][0], stages['3'][0]) != 0:
  File "/var/lib/python-support/python2.4/stgit/gitmergeonefile.py", line 203, in merge
    print >> sys.stderr, \
TypeError: not all arguments converted during string formatting

 State of things now:

stgit$ stg status
? t/t2100-pull-to.sh.current
? t/t2100-pull-to.sh.patched
M stgit/commands/pull.py
stgit$ diff t/t2100-pull-to.sh.*; echo $?
0
stgit$ stg files pull-to
stgit$ stg top
test

 As you can see, the pull-to patch is now in a situation that's not
 obvious to untangle by hand.  Also "stg push -m" exhibits the same
 issue.

Best regards,
-- 
Yann.

```

## Yann Dirson, 2007-01-20 15:09

Subject: Re: [BUG] Problem with "stgit push" causing data loss
Message-ID: <20070120150949.GB4684@nan92-1-81-57-214-146.fbx.proxad.net>
URL: https://gitlist.dev/e/20070120150949.GB4684%40nan92-1-81-57-214-146.fbx.proxad.net
In-Reply-To: <20070120150113.GB4665@nan92-1-81-57-214-146.fbx.proxad.net>

```
On Sat, Jan 20, 2007 at 04:01:13PM +0100, Yann Dirson wrote:
>  The test patch is my previous work on "pull --to", now superceded
>  by "rebase".  Patch to reproduce attached to this mail

Well... to *this* mail indeed :}


commit 9abaec589753ab190d378b534ceaa6a5af5d0dd3
Author: Yann Dirson <ydirson@altern.org>
Date:   Wed Jan 17 22:11:58 2007 +0100

    Pull to arbitrary commit

diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py
index 7c5db22..865bfd6 100644
--- a/stgit/commands/pull.py
+++ b/stgit/commands/pull.py
@@ -42,7 +42,9 @@ options = [make_option('-n', '--nopush',
                        action = 'store_true'),
            make_option('-m', '--merged',
                        help = 'check for patches merged upstream',
-                       action = 'store_true')]
+                       action = 'store_true'),
+           make_option('--to', metavar = 'COMMITID',
+                       help = 'move the stack base to COMMITID')]
 
 def func(parser, options, args):
     """Pull the changes from a remote repository
@@ -78,10 +80,15 @@ def func(parser, options, args):
         crt_series.pop_patch(applied[0])
         print 'done'
 
-    # pull the remote changes
-    print 'Pulling from "%s"...' % repository
-    git.pull(repository, refspec)
-    print 'done'
+    # FIXME: check git_id/rev_parse(options.to) first and maybe try to fetch if not found
+    if options.to:
+        print 'Rebasing to "%s"...' % options.to
+        git.move_branch(options.to)
+    else:
+        # pull the remote changes
+        print 'Pulling from "%s"...' % repository
+        git.pull(repository, refspec)
+        print 'done'
 
     # push the patches back
     if not options.nopush:
diff --git a/t/t2100-pull-to.sh b/t/t2100-pull-to.sh
new file mode 100755
index 0000000..0bf5f16
--- /dev/null
+++ b/t/t2100-pull-to.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Yann Dirson
+#
+
+test_description='Test the "pull --to" command.'
+
+. ./test-lib.sh
+
+# don't need this repo, but better not drop it, see t1100
+#rm -rf .git
+
+# Need a repo to clone
+test_create_repo foo
+
+test_expect_success \
+    'Setup and clone tree, and setup changes' \
+    'cd foo &&
+      stg init && stg new patch -m . &&
+      printf "a\nb\n" > file && stg add file && stg refresh &&
+      cd .. &&
+     stg clone foo bar &&
+     cd bar &&
+      stg new p1 -m p1 &&
+      echo "c" > file2 && stg add file2 && stg refresh &&
+      cd .. &&
+     cp -a bar bar2
+'
+
+test_expect_success \
+    'Modify original stack' \
+    '(cd foo && echo "c" >> file && stg refresh)'
+
+#test_debug bash
+#test_done
+
+#test_debug "cd foo && gitk --all && cd .."
+
+test_expect_success \
+    'Pull without --to' \
+    '(cd bar &&
+     a=$(git rev-parse HEAD) &&
+     stg pull &&
+     test "$a" == $(git rev-parse HEAD))'
+
+#test_debug "cd bar && gitk --all && cd .."
+
+test_expect_success \
+    'Pull with --to' \
+    '(cd bar2 &&
+     a=$(git rev-parse HEAD) &&
+     git fetch origin +refs/heads/master:refs/heads/origin &&
+     stg pull --to origin &&
+     test "$a" != $(git rev-parse HEAD) )'
+
+test_debug "cd bar2 && gitk --all && cd .."
+
+test_done

```

## Catalin Marinas, 2007-01-21 22:42

Subject: Re: [BUG] Problem with "stgit push" causing data loss
Message-ID: <b0943d9e0701211442q503396ack2bf2d088325fc4a0@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e0701211442q503396ack2bf2d088325fc4a0%40mail.gmail.com
In-Reply-To: <20070120150113.GB4665@nan92-1-81-57-214-146.fbx.proxad.net>

```
On 20/01/07, Yann Dirson <ydirson@altern.org> wrote:
> Well, "data loss" is a bit strong, since the data is still available
> to find using git-lost-found.
>
> I first tried to reproduce with a simple test-case, but could not, so
> here is my way to reproduce it, on a clone of the stgit official
> workspace.

I tried to somehow emulate this without the fold script but didn't
manage to trigger the bug. I'll try with your script tomorrow but
first:

Do you use the latest HEAD in the StGIT repository? I'm asking because
the line numbers reported in your backtrace are different from mine. I
also made some changes in this area in the past couple of weeks which
might have fixed or broken things.

-- 
Catalin

```

## Yann Dirson, 2007-01-21 23:27

Subject: Re: [BUG] Problem with "stgit push" causing data loss
Message-ID: <20070121232745.GE4665@nan92-1-81-57-214-146.fbx.proxad.net>
URL: https://gitlist.dev/e/20070121232745.GE4665%40nan92-1-81-57-214-146.fbx.proxad.net
In-Reply-To: <b0943d9e0701211442q503396ack2bf2d088325fc4a0@mail.gmail.com>

```
On Sun, Jan 21, 2007 at 10:42:18PM +0000, Catalin Marinas wrote:
> On 20/01/07, Yann Dirson <ydirson@altern.org> wrote:
> >Well, "data loss" is a bit strong, since the data is still available
> >to find using git-lost-found.
> >
> >I first tried to reproduce with a simple test-case, but could not, so
> >here is my way to reproduce it, on a clone of the stgit official
> >workspace.
> 
> I tried to somehow emulate this without the fold script but didn't
> manage to trigger the bug. I'll try with your script tomorrow but
> first:
> 
> Do you use the latest HEAD in the StGIT repository? I'm asking because
> the line numbers reported in your backtrace are different from mine. I
> also made some changes in this area in the past couple of weeks which
> might have fixed or broken things.

Here is where I am:

stgit$ git-rev-parse origin
0f4eba6a37c1a5454560b097873e5a22bfcde908

```
