From: Peter Oberndorfer Date: Tue, 8 Jan 2008 16:42:46 +0000 (+0100) Subject: Add an --index option to "stg refresh" X-Git-Tag: v0.15-rc1~283 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/c3a72ae18c57389495e88a3a97217c3138694232 Add an --index option to "stg refresh" Add an --index option to "stg refresh" which takes the contents of the index as the new commit. This allows to stage only certain changes to a file by only adding the desired parts to the index with git-gui, ugit, git add -i or another tool that manipulates the index and then run stg refresh --index it. Also allows removing a file from a patch by running git reset HEAD^ -- file_to_remove followed by a stg refresh --index. Signed-off-by: Peter Oberndorfer Signed-off-by: Karl Hasselström --- diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py index 6288acc..4695c62 100644 --- a/stgit/commands/refresh.py +++ b/stgit/commands/refresh.py @@ -43,6 +43,9 @@ options = [make_option('-f', '--force', 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'), @@ -74,6 +77,14 @@ def func(parser, options, args): 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) @@ -83,9 +94,10 @@ def func(parser, options, args): 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] @@ -103,8 +115,13 @@ def func(parser, options, args): 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') diff --git a/t/t2700-refresh.sh b/t/t2700-refresh.sh index 2e7901c..9eae85d 100755 --- a/t/t2700-refresh.sh +++ b/t/t2700-refresh.sh @@ -6,8 +6,10 @@ test_description='Run "stg refresh"' 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 && @@ -62,4 +64,57 @@ test_expect_success 'Refresh bottom patch' ' diff -u expected.txt patches.txt ' +cat > expected.txt < expected2.txt < expected3.txt <> 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