Re: [BUG] Problem with "stgit push" causing data loss

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]