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

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

From
Yann Dirson <ydirson@altern.org>
Date
Jan 20, 2007, 15:09 UTC
Message-ID
<20070120150949.GB4684@nan92-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
Previous: Yann DirsonNext: Catalin Marinas
Message 2 of 4 in “[BUG] Problem with "stgit push" causing data loss”
  1. Yann DirsonJan 20, 2007
  2. Yann DirsonJan 20, 2007
  3. Catalin MarinasJan 21, 2007
  4. Yann DirsonJan 21, 2007

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.