#pager = ~/share/stgit/contrib/diffcol.sh
#pager = filterdiff --annotate | colordiff | less -FRX
- # GIT pull command (should take the same arguments as
+ # GIT pull and fetch commands (should take the same arguments as
# git-fetch or git-pull). By default:
- #pullcmd = git-fetch
- #pull-does-rebase = yes
- # Alternative (old behaviour), less intuitive but maybe useful
- # for some workflows:
#pullcmd = git-pull
- #pull-does-rebase = no
+ #fetchcmd = git-fetch
+
+ # "stg pull" policy. This is the repository default, which can be
+ # overriden on a per-branch basis using branch.*.stgit.pull-policy
+ # By default:
+ #pull-policy = pull
+ # To support remote rewinding parent branches:
+ #pull-policy = fetch-rebase
+ # To support local parent branches:
+ #pull-policy = rebase
# The three-way merge tool. Note that the 'output' file contains the
# same data as 'branch1'. This is useful for tools that do not take an
check_conflicts()
check_head_top_equal()
- must_rebase = (config.get('stgit.pull-does-rebase') == 'yes')
+ policy = config.get('branch.%s.stgit.pull-policy' % crt_series.get_branch()) or \
+ config.get('stgit.pull-policy')
+ if policy == 'pull':
+ must_rebase = 0
+ elif policy == 'fetch-rebase':
+ must_rebase = 1
+ elif policy == 'rebase':
+ must_rebase = 1
+ else:
+ raise config.ConfigException, 'Unsupported pull-policy "%s"' % policy
+
applied = prepare_rebase(real_rebase=must_rebase, force=options.force)
# pull the remote changes
- print 'Pulling from "%s"...' % repository
- git.fetch(repository)
- if must_rebase:
+ if policy == 'pull':
+ print 'Pulling from "%s"...' % repository
+ git.pull(repository)
+ elif policy == 'fetch-rebase':
+ print 'Fetching from "%s"...' % repository
+ git.fetch(repository)
rebase(git.fetch_head())
+ elif policy == 'rebase':
+ rebase(crt_series.get_parent_branch())
post_rebase(applied, options.nopush, options.merged)
'stgit.autoresolved': 'no',
'stgit.smtpserver': 'localhost:25',
'stgit.smtpdelay': '5',
- 'stgit.pullcmd': 'git-fetch',
- 'stgit.pull-does-rebase': 'yes',
+ 'stgit.pullcmd': 'git-pull',
+ 'stgit.fetchcmd': 'git-fetch',
+ 'stgit.pull-policy': 'pull',
'stgit.merger': 'diff3 -L current -L ancestor -L patched -m -E ' \
'"%(branch1)s" "%(ancestor)s" "%(branch2)s" > "%(output)s"',
'stgit.autoimerge': 'no',
if refspec:
args.append(refspec)
- command = config.get('stgit.pullcmd')
+ command = config.get('branch.%s.stgit.fetchcmd' % get_head_file()) or \
+ config.get('stgit.fetchcmd')
+ if __run(command, args) != 0:
+ raise GitException, 'Failed "%s %s"' % (command, repository)
+
+def pull(repository = 'origin', refspec = None):
+ """Fetches changes from the remote repository, using 'git-pull'
+ by default.
+ """
+ # we update the HEAD
+ __clear_head_cache()
+
+ args = [repository]
+ if refspec:
+ args.append(refspec)
+
+ command = config.get('branch.%s.stgit.pullcmd' % get_head_file()) or \
+ config.get('stgit.pullcmd')
if __run(command, args) != 0:
raise GitException, 'Failed "%s %s"' % (command, repository)
--- /dev/null
+#!/bin/sh
+#
+# Copyright (c) 2007 Yann Dirson
+#
+
+test_description='Excercise pull-policy "fetch-rebase".'
+
+. ./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 upstream
+
+test_expect_success \
+ 'Setup upstream repo, clone it, and add patches to the clone' \
+ '
+ (cd upstream && stg init) &&
+ stg clone upstream clone &&
+ (cd clone &&
+ git repo-config branch.master.stgit.pull-policy fetch-rebase &&
+ git repo-config --list &&
+ stg new c1 -m c1 &&
+ echo a > file && stg add file && stg refresh
+ )
+ '
+
+test_expect_success \
+ 'Add non-rewinding commit upstream and pull it from clone' \
+ '
+ (cd upstream && stg new u1 -m u1 &&
+ echo a > file2 && stg add file2 && stg refresh) &&
+ (cd clone && stg pull) &&
+ test -e clone/file2
+ '
+
+# note: with pre-1.5 Git the clone is not automatically recorded
+# as rewinding, and thus heads/origin is not moved, but the stack
+# is still correctly rebased
+test_expect_success \
+ 'Rewind/rewrite upstream commit and pull it from clone' \
+ '
+ (cd upstream && echo b >> file2 && stg refresh) &&
+ (cd clone && stg pull) &&
+ test `wc -l <clone/file2` = 2
+ '
+
+# this one ensures the guard against commits does not unduly trigger
+test_expect_success \
+ 'Rewind/rewrite upstream commit and fetch it from clone before pulling' \
+ '
+ (cd upstream && echo c >> file2 && stg refresh) &&
+ (cd clone && git fetch && stg pull) &&
+ test `wc -l <clone/file2` = 3
+ '
+
+# this one exercises the guard against commits
+# (use a new file to avoid mistaking a conflict for a success)
+test_expect_success \
+ 'New upstream commit and commit a patch in clone' \
+ '
+ (cd upstream && stg new u2 -m u2 &&
+ echo a > file3 && stg add file3 && stg refresh) &&
+ (cd clone && stg commit && stg new c2 -m c2 &&
+ echo a >> file && stg refresh)
+ '
+test_expect_failure \
+ 'Try to and commit a patch in clone' \
+ '(cd clone && stg pull)'
+
+test_done