{"thread":{"id":"43513","subject":"RFC PATCH: support for default remote in StGIT","startedAt":"2006-12-09T09:23:25Z","lastAt":"2006-12-09T13:36:18Z","messageCount":2,"participants":["Pavel Roskin","Yann Dirson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"295229","messageId":"1165656205.2816.47.camel@portland.localdomain","threadId":"43513","inReplyTo":null,"subject":"RFC PATCH: support for default remote in StGIT","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-12-09T09:23:25Z","receivedAt":"2006-12-09T09:23:25Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello, Catalin!\n\nIt's very important for me to have default remote support in StGIT.  I'm\ntrying to track different Linux branches, and I don't want to remember\nwhat branch I'm on when I run \"stg pull\".\n\nI have tried two approaches, and both work, but I'm not particular fond\nof either of them, so I think I'll just send both, and maybe we'll come\nto a satisfactory solution.\n\nOne approach is to leave the default remote selection completely to git.\nThe downside is that StGIT prints the remote it's pulling from.  Now\nStGIT will have to print common words that it's pulling something.  Or\nmaybe it shouldn't print anything?\n\nAlso, git-pull doesn't allow to specify the refspec without the remote.\nThis limitation seems artificial to me, but we have to pass this\nlimitation to the StGIT users.\n\nThe positive side if that StGIT is completely unaware of the word\n\"origin\", and any changes in git handling of the default remote will\npropagate to StGIT immediately.\n\n\ndiff --git a/stgit/commands/pull.py b/stgit/commands/pull.py\nindex 227249e..3ef582e 100644\n--- a/stgit/commands/pull.py\n+++ b/stgit/commands/pull.py\n@@ -50,7 +50,7 @@ def func(parser, options, args):\n     if len(args) > 2:\n         parser.error('incorrect number of arguments')\n \n-    repository = 'origin'\n+    repository = None\n     refspec = None\n     if len(args) >= 1:\n         repository = args[0]\n@@ -73,7 +73,11 @@ def func(parser, options, args):\n         print 'done'\n \n     # pull the remote changes\n-    print 'Pulling from \"%s\"...' % repository\n+    if repository:\n+        print 'Pulling from \"%s\"...' % repository\n+    else:\n+        print 'Pulling from the default repository'\n+\n     git.pull(repository, refspec)\n     print 'done'\n \ndiff --git a/stgit/git.py b/stgit/git.py\nindex eb8da4e..7aed357 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -790,14 +790,20 @@ def reset(files = None, tree_id = None, check_out = True):\n     if not files:\n         __set_head(tree_id)\n \n-def pull(repository = 'origin', refspec = None):\n+def pull(repository = None, refspec = None):\n     \"\"\"Pull changes from the remote repository. At the moment, just\n     use the 'git-pull' command\n     \"\"\"\n     # 'git-pull' updates the HEAD\n     __clear_head_cache()\n \n-    args = [repository]\n+    if repository:\n+        args = [repository]\n+    else:\n+\tif refspec:\n+            raise GitException, 'git-pull requires repository with refspec'\n+        args = []\n+\n     if refspec:\n         args.append(refspec)\n \n\nThe other approach is to calculate the default remote in StGIT.  This\nwould allow StGIT to tell the user where it's pulling from.\n\nHowever, I had to introduce a function that ignores errors except there\nis any output on stderr.  This is because git-repo-config returns error\ncode 1 if it cannot find the key.  Maybe git-repo-config should have an\noption not to fail in this case?  Perhaps a default value to return?\n\n\ndiff --git a/stgit/commands/pull.py b/stgit/commands/pull.py\nindex 227249e..7824dc3 100644\n--- a/stgit/commands/pull.py\n+++ b/stgit/commands/pull.py\n@@ -54,6 +54,9 @@ def func(parser, options, args):\n     refspec = None\n     if len(args) >= 1:\n         repository = args[0]\n+    else:\n+        repository = git.get_default_remote()\n+\n     if len(args) == 2:\n         refspec = args[1]\n \ndiff --git a/stgit/git.py b/stgit/git.py\nindex eb8da4e..ed08d7d 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -186,6 +186,20 @@ def _output_one_line(cmd, file_desc = None):\n                                                 p.childerr.read().strip())\n     return output\n \n+def _output_one_line_try(cmd, file_desc = None):\n+    \"\"\" Read one line of cmd output, fail only on stderr messages\n+    \"\"\"\n+    p=popen2.Popen3(cmd, True)\n+    if file_desc != None:\n+        for line in file_desc:\n+            p.tochild.write(line)\n+        p.tochild.close()\n+    output = p.fromchild.readline().strip()\n+    errors = p.childerr.read().strip()\n+    if errors:\n+        raise GitException, '%s failed (%s)' % (str(cmd), errors)\n+    return output\n+\n def _output_lines(cmd):\n     p=popen2.Popen3(cmd, True)\n     lines = p.fromchild.readlines()\n@@ -285,6 +299,20 @@ def get_head_file():\n     return strip_prefix('refs/heads/',\n                         _output_one_line('git-symbolic-ref HEAD'))\n \n+def get_default_remote():\n+    \"\"\"Returns default remote to pull\n+    \"\"\"\n+    branch = get_head_file()\n+\n+    repository = _output_one_line_try(['git-repo-config', '--get',\n+                                       'branch.%s.remote' % branch])\n+\n+    if not repository:\n+        repository = 'origin'\n+\n+    return repository\n+\n+\n def set_head_file(ref):\n     \"\"\"Resets HEAD to point to a new ref\n     \"\"\"\n\n\n-- \nRegards,\n"},{"id":"297982","messageId":"20061209133618.GB17132@nan92-1-81-57-214-146.fbx.proxad.net","threadId":"43513","inReplyTo":"1165656205.2816.47.camel@portland.localdomain","subject":"Re: RFC PATCH: support for default remote in StGIT","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2006-12-09T13:36:18Z","receivedAt":"2006-12-09T13:36:18Z","isPatch":false,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Hi Pavel,\n\nThis is quite related to the subject of the \"Handling of branches in\nstgit\" thread I launched recently (Nov 30th).\n\nOn Sat, Dec 09, 2006 at 04:23:25AM -0500, Pavel Roskin wrote:\n> It's very important for me to have default remote support in StGIT.  I'm\n> trying to track different Linux branches, and I don't want to remember\n> what branch I'm on when I run \"stg pull\".\n\nRight, that's the main problem with the current implementation.\n\n> One approach is to leave the default remote selection completely to git.\n> The downside is that StGIT prints the remote it's pulling from.  Now\n> StGIT will have to print common words that it's pulling something.  Or\n> maybe it shouldn't print anything?\n\nIt could just print a generic message and let GIT print out\nthe details.\n\n> Also, git-pull doesn't allow to specify the refspec without the remote.\n> This limitation seems artificial to me, but we have to pass this\n> limitation to the StGIT users.\n\nIn which situtation do you need to pass a refspec ?  I thought all\nnecessary refspecs should already be part of a remote's definition.\n\n> The positive side if that StGIT is completely unaware of the word\n> \"origin\", and any changes in git handling of the default remote will\n> propagate to StGIT immediately.\n\nIndeed.\n\n\n> The other approach is to calculate the default remote in StGIT.  This\n> would allow StGIT to tell the user where it's pulling from.\n\nDoing so would probably require to teach StGIT about every new way of\nfetching a branch (we already have 3 ways, as outlined in my initial\nmail).  OTOH, it may be the only way to present the user with a\nuniform way of working, independently of the way we update the parent\nbranch.\n\n\nIndeed, we may just want to distinguish whether the parent branch is a\nremote one or not.  Then if it's a remote one, git-fetch already has\nenough info to do its work updating the parent branch (whether using\n.git/remotes or .git/branches).  If it's not a remote branch, there's\njust nothing to do at this step.\n\nThen, we just have to \"pop -a\" and move the stack base, without\nrelying on \"pull\".  That would also transparently give support for\nbranching off a non-forwarding branch (like git's \"next\" and \"pu\", or\nlike any stgit managed branch).  Would anyone miss the \"git-pull\" call ?\n\nBest regards,\n-- \n"}]}