--- /dev/null
+__copyright__ = """
+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys, os
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'pull the changes from the remote repository'
+usage = '%prog [options]'
+
+options = [make_option('-n', '--nopush',
+ help = 'do not push the patches back after pulling',
+ action = 'store_true'),
+ make_option('--head', metavar='OTHER_HEAD',
+ help = 'pull OTHER_HEAD instead of HEAD'),
+ make_option('--tag',
+ help = 'pull TAG')]
+
+
+def func(parser, options, args):
+ """Pull the changes from a remote repository
+ """
+ if len(args) != 0:
+ parser.error('incorrect number of arguments')
+
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal()
+
+ branch = git.get_head_file()
+ location = read_string(os.path.join(git.base_dir, 'branches', branch))
+
+ print 'Pulling from "%s"...' % location
+ new_head = git.fetch(location, options.head, options.tag)
+ print 'done'
+
+ if new_head == git_id('base'):
+ print 'Branch already up-to-date'
+ else:
+ applied = crt_series.get_applied()
+
+ if len(applied) > 0:
+ print 'Popping all patches...',
+ sys.stdout.flush()
+ crt_series.pop_patch(applied[0])
+ print 'done'
+
+ git.switch(new_head)
+
+ if options.nopush:
+ applied = []
+ for p in applied:
+ print 'Pushing patch "%s"...' % p,
+ sys.stdout.flush()
+ crt_series.push_patch(p)
+ if crt_series.empty_patch(p):
+ print 'done (empty patch)'
+ else:
+ print 'done'
+
+ print_crt_patch()
# checkout doesn't remove files
for fs in to_delete:
os.remove(fs[1])
+
+def fetch(location, head = None, tag = None):
+ """Fetch changes from the remote repository. At the moment, just
+ use the 'git fetch' scripts
+ """
+ args = [location]
+ if head:
+ args += [head]
+ elif tag:
+ args += ['tag', tag]
+
+ if __run('git fetch', args) != 0:
+ raise GitException, 'Failed "git fetch %s"' % location
+
+ return read_string(os.path.join(base_dir, 'FETCH_HEAD'))
import stgit.commands.mail
import stgit.commands.new
import stgit.commands.pop
+import stgit.commands.pull
import stgit.commands.push
import stgit.commands.refresh
import stgit.commands.resolved
'mail': stgit.commands.mail,
'new': stgit.commands.new,
'pop': stgit.commands.pop,
+ 'pull': stgit.commands.pull,
'push': stgit.commands.push,
'refresh': stgit.commands.refresh,
'resolved': stgit.commands.resolved,
"""
if len(self.get_applied()) == 0:
head = git.get_head()
- if os.path.exists(self.__base_file):
- raise StackException, 'stack empty but the base file exists'
write_string(self.__base_file, head)
def __end_stack_check(self):
- """Remove .git/refs/heads/base if the stack is empty
+ """Remove .git/refs/heads/base if the stack is empty.
+ This warning should never happen
"""
- if len(self.get_applied()) == 0:
- if not os.path.exists(self.__base_file):
- print 'Warning: stack empty but the base file is missing'
- else:
- os.remove(self.__base_file)
+ if len(self.get_applied()) == 0 \
+ and read_string(self.__base_file) != git.get_head():
+ print 'Warning: stack empty but the HEAD and base are different'
def head_top_equal(self):
"""Return true if the head and the top are the same