make_option('--update',
help = 'only update the current patch files',
action = 'store_true'),
+ make_option('--index',
+ help = 'use the current contents of the index instead of looking at the working directory',
+ action = 'store_true'),
make_option('--undo',
help = 'revert the commit generated by the last refresh',
action = 'store_true'),
if not patch:
raise CmdException, 'No patches applied'
+ if options.index:
+ if args or options.update:
+ raise CmdException, \
+ 'Only full refresh is available with the --index option'
+ if options.patch:
+ raise CmdException, \
+ '--patch is not compatible with the --index option'
+
if not options.force:
check_head_top_equal(crt_series)
out.done()
return
- files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]
+ if not options.index:
+ files = [path for (stat, path) in git.tree_status(files = args, verbose = True)]
- if files or not crt_series.head_top_equal():
+ if options.index or files or not crt_series.head_top_equal():
if options.patch:
applied = crt_series.get_applied()
between = applied[:applied.index(patch):-1]
if autoresolved == 'yes':
resolved_all()
- crt_series.refresh_patch(files = files,
- backup = True, notes = options.annotate)
+
+ if options.index:
+ crt_series.refresh_patch(cache_update = False,
+ backup = True, notes = options.annotate)
+ else:
+ crt_series.refresh_patch(files = files,
+ backup = True, notes = options.annotate)
if crt_series.empty_patch(patch):
out.done('empty patch')
test_expect_success 'Initialize StGit stack' '
stg init &&
- echo expected.txt >> .git/info/exclude &&
+ echo expected*.txt >> .git/info/exclude &&
echo patches.txt >> .git/info/exclude &&
+ echo show.txt >> .git/info/exclude &&
+ echo diff.txt >> .git/info/exclude &&
stg new p0 -m "base" &&
for i in 1 2 3; do
echo base >> foo$i.txt &&
diff -u expected.txt patches.txt
'
+cat > expected.txt <<EOF
+p0
+p1
+p4
+EOF
+cat > expected2.txt <<EOF
+diff --git a/foo1.txt b/foo1.txt
+index 728535d..6f34984 100644
+--- a/foo1.txt
++++ b/foo1.txt
+@@ -1,3 +1,4 @@
+ base
+ foo 1
+ bar 1
++baz 1
+EOF
+cat > expected3.txt <<EOF
+diff --git a/foo1.txt b/foo1.txt
+index 6f34984..a80eb63 100644
+--- a/foo1.txt
++++ b/foo1.txt
+@@ -2,3 +2,4 @@ base
+ foo 1
+ bar 1
+ baz 1
++blah 1
+diff --git a/foo2.txt b/foo2.txt
+index 415c9f5..43168f2 100644
+--- a/foo2.txt
++++ b/foo2.txt
+@@ -1,3 +1,4 @@
+ base
+ foo 2
+ bar 2
++baz 2
+EOF
+test_expect_success 'Refresh --index' '
+ stg status &&
+ stg new p4 -m "refresh_index" &&
+ echo baz 1 >> foo1.txt &&
+ git add foo1.txt &&
+ echo blah 1 >> foo1.txt &&
+ echo baz 2 >> foo2.txt &&
+ stg refresh --index &&
+ stg patches foo1.txt > patches.txt &&
+ git diff HEAD^..HEAD > show.txt &&
+ stg diff > diff.txt &&
+ diff -u expected.txt patches.txt &&
+ diff -u expected2.txt show.txt &&
+ diff -u expected3.txt diff.txt &&
+ stg new p5 -m "cleanup again" &&
+ stg refresh
+'
test_done