Skip to content

Commit bf10200

Browse files
committed
Merge branch 'dl/merge-autostash'
"git merge" learns the "--autostash" option. * dl/merge-autostash: (22 commits) pull: pass --autostash to merge t5520: make test_pull_autostash() accept expect_parent_num merge: teach --autostash option sequencer: implement apply_autostash_oid() sequencer: implement save_autostash() sequencer: unlink autostash in apply_autostash() sequencer: extract perform_autostash() from rebase rebase: generify create_autostash() rebase: extract create_autostash() reset: extract reset_head() from rebase rebase: generify reset_head() rebase: use apply_autostash() from sequencer.c sequencer: rename stash_sha1 to stash_oid sequencer: make apply_autostash() accept a path rebase: use read_oneliner() sequencer: make read_oneliner() extern sequencer: configurably warn on non-existent files sequencer: make read_oneliner() accept flags sequencer: make file exists check more efficient sequencer: stop leaking buf ...
2 parents 86ab15c + d9f15d3 commit bf10200

20 files changed

+666
-391
lines changed

Documentation/config/merge.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ merge.stat::
7070
Whether to print the diffstat between ORIG_HEAD and the merge result
7171
at the end of the merge. True by default.
7272

73+
merge.autoStash::
74+
When set to true, automatically create a temporary stash entry
75+
before the operation begins, and apply it after the operation
76+
ends. This means that you can run merge on a dirty worktree.
77+
However, use with care: the final stash application after a
78+
successful merge might result in non-trivial conflicts.
79+
This option can be overridden by the `--no-autostash` and
80+
`--autostash` options of linkgit:git-merge[1].
81+
Defaults to false.
82+
7383
merge.tool::
7484
Controls which merge tool is used by linkgit:git-mergetool[1].
7585
The list below shows the valid built-in values.

Documentation/git-merge.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,24 @@ will be appended to the specified message.
9494

9595
--abort::
9696
Abort the current conflict resolution process, and
97-
try to reconstruct the pre-merge state.
97+
try to reconstruct the pre-merge state. If an autostash entry is
98+
present, apply it to the worktree.
9899
+
99100
If there were uncommitted worktree changes present when the merge
100101
started, 'git merge --abort' will in some cases be unable to
101102
reconstruct these changes. It is therefore recommended to always
102103
commit or stash your changes before running 'git merge'.
103104
+
104105
'git merge --abort' is equivalent to 'git reset --merge' when
105-
`MERGE_HEAD` is present.
106+
`MERGE_HEAD` is present unless `MERGE_AUTOSTASH` is also present in
107+
which case 'git merge --abort' applies the stash entry to the worktree
108+
whereas 'git reset --merge' will save the stashed changes in the stash
109+
reflog.
106110

107111
--quit::
108112
Forget about the current merge in progress. Leave the index
109-
and the working tree as-is.
113+
and the working tree as-is. If `MERGE_AUTOSTASH` is present, the
114+
stash entry will be saved to the stash reflog.
110115

111116
--continue::
112117
After a 'git merge' stops due to conflicts you can conclude the

Documentation/git-pull.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ unless you have read linkgit:git-rebase[1] carefully.
134134
--no-rebase::
135135
Override earlier --rebase.
136136

137-
--autostash::
138-
--no-autostash::
139-
Before starting rebase, stash local modifications away (see
140-
linkgit:git-stash[1]) if needed, and apply the stash entry when
141-
done. `--no-autostash` is useful to override the `rebase.autoStash`
142-
configuration variable (see linkgit:git-config[1]).
143-
+
144-
This option is only valid when "--rebase" is used.
145-
146137
Options related to fetching
147138
~~~~~~~~~~~~~~~~~~~~~~~~~~~
148139

Documentation/merge-options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ ifndef::git-pull[]
160160

161161
endif::git-pull[]
162162

163+
--autostash::
164+
--no-autostash::
165+
Automatically create a temporary stash entry before the operation
166+
begins, and apply it after the operation ends. This means
167+
that you can run the operation on a dirty worktree. However, use
168+
with care: the final stash application after a successful
169+
merge might result in non-trivial conflicts.
170+
163171
--allow-unrelated-histories::
164172
By default, `git merge` command refuses to merge histories
165173
that do not share a common ancestor. This option can be

Makefile

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ SCRIPT_SH += git-web--browse.sh
610610
SCRIPT_LIB += git-mergetool--lib
611611
SCRIPT_LIB += git-parse-remote
612612
SCRIPT_LIB += git-rebase--preserve-merges
613-
SCRIPT_LIB += git-sh-setup
614613
SCRIPT_LIB += git-sh-i18n
614+
SCRIPT_LIB += git-sh-setup
615615

616616
SCRIPT_PERL += git-add--interactive.perl
617617
SCRIPT_PERL += git-archimport.perl
@@ -679,9 +679,9 @@ PROGRAM_OBJS += daemon.o
679679
PROGRAM_OBJS += fast-import.o
680680
PROGRAM_OBJS += http-backend.o
681681
PROGRAM_OBJS += imap-send.o
682+
PROGRAM_OBJS += remote-testsvn.o
682683
PROGRAM_OBJS += sh-i18n--envsubst.o
683684
PROGRAM_OBJS += shell.o
684-
PROGRAM_OBJS += remote-testsvn.o
685685

686686
# Binary suffix, set to .exe for Windows builds
687687
X =
@@ -703,15 +703,16 @@ TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
703703
TEST_BUILTINS_OBJS += test-example-decorate.o
704704
TEST_BUILTINS_OBJS += test-genrandom.o
705705
TEST_BUILTINS_OBJS += test-genzeros.o
706+
TEST_BUILTINS_OBJS += test-hash-speed.o
706707
TEST_BUILTINS_OBJS += test-hash.o
707708
TEST_BUILTINS_OBJS += test-hashmap.o
708-
TEST_BUILTINS_OBJS += test-hash-speed.o
709709
TEST_BUILTINS_OBJS += test-index-version.o
710710
TEST_BUILTINS_OBJS += test-json-writer.o
711711
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
712712
TEST_BUILTINS_OBJS += test-match-trees.o
713713
TEST_BUILTINS_OBJS += test-mergesort.o
714714
TEST_BUILTINS_OBJS += test-mktemp.o
715+
TEST_BUILTINS_OBJS += test-oid-array.o
715716
TEST_BUILTINS_OBJS += test-oidmap.o
716717
TEST_BUILTINS_OBJS += test-online-cpus.o
717718
TEST_BUILTINS_OBJS += test-parse-options.o
@@ -732,7 +733,6 @@ TEST_BUILTINS_OBJS += test-run-command.o
732733
TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
733734
TEST_BUILTINS_OBJS += test-serve-v2.o
734735
TEST_BUILTINS_OBJS += test-sha1.o
735-
TEST_BUILTINS_OBJS += test-oid-array.o
736736
TEST_BUILTINS_OBJS += test-sha256.o
737737
TEST_BUILTINS_OBJS += test-sigchain.o
738738
TEST_BUILTINS_OBJS += test-strcmp-offset.o
@@ -742,10 +742,10 @@ TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
742742
TEST_BUILTINS_OBJS += test-subprocess.o
743743
TEST_BUILTINS_OBJS += test-trace2.o
744744
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
745-
TEST_BUILTINS_OBJS += test-xml-encode.o
746745
TEST_BUILTINS_OBJS += test-wildmatch.o
747746
TEST_BUILTINS_OBJS += test-windows-named-pipe.o
748747
TEST_BUILTINS_OBJS += test-write-cache.o
748+
TEST_BUILTINS_OBJS += test-xml-encode.o
749749

750750
# Do not add more tests here unless they have extra dependencies. Add
751751
# them in TEST_BUILTINS_OBJS above.
@@ -782,10 +782,10 @@ OTHER_PROGRAMS = git$X
782782

783783
# what test wrappers are needed and 'install' will install, in bindir
784784
BINDIR_PROGRAMS_NEED_X += git
785-
BINDIR_PROGRAMS_NEED_X += git-upload-pack
786785
BINDIR_PROGRAMS_NEED_X += git-receive-pack
787-
BINDIR_PROGRAMS_NEED_X += git-upload-archive
788786
BINDIR_PROGRAMS_NEED_X += git-shell
787+
BINDIR_PROGRAMS_NEED_X += git-upload-archive
788+
BINDIR_PROGRAMS_NEED_X += git-upload-pack
789789

790790
BINDIR_PROGRAMS_NO_X += git-cvsserver
791791

@@ -825,9 +825,9 @@ LIB_OBJS += advice.o
825825
LIB_OBJS += alias.o
826826
LIB_OBJS += alloc.o
827827
LIB_OBJS += apply.o
828-
LIB_OBJS += archive.o
829828
LIB_OBJS += archive-tar.o
830829
LIB_OBJS += archive-zip.o
830+
LIB_OBJS += archive.o
831831
LIB_OBJS += argv-array.o
832832
LIB_OBJS += attr.o
833833
LIB_OBJS += base85.o
@@ -843,9 +843,9 @@ LIB_OBJS += checkout.o
843843
LIB_OBJS += color.o
844844
LIB_OBJS += column.o
845845
LIB_OBJS += combine-diff.o
846-
LIB_OBJS += commit.o
847846
LIB_OBJS += commit-graph.o
848847
LIB_OBJS += commit-reach.o
848+
LIB_OBJS += commit.o
849849
LIB_OBJS += compat/obstack.o
850850
LIB_OBJS += compat/terminal.o
851851
LIB_OBJS += config.o
@@ -859,17 +859,17 @@ LIB_OBJS += ctype.o
859859
LIB_OBJS += date.o
860860
LIB_OBJS += decorate.o
861861
LIB_OBJS += delta-islands.o
862+
LIB_OBJS += diff-delta.o
863+
LIB_OBJS += diff-lib.o
864+
LIB_OBJS += diff-no-index.o
865+
LIB_OBJS += diff.o
862866
LIB_OBJS += diffcore-break.o
863867
LIB_OBJS += diffcore-delta.o
864868
LIB_OBJS += diffcore-order.o
865869
LIB_OBJS += diffcore-pickaxe.o
866870
LIB_OBJS += diffcore-rename.o
867-
LIB_OBJS += diff-delta.o
868-
LIB_OBJS += diff-lib.o
869-
LIB_OBJS += diff-no-index.o
870-
LIB_OBJS += diff.o
871-
LIB_OBJS += dir.o
872871
LIB_OBJS += dir-iterator.o
872+
LIB_OBJS += dir.o
873873
LIB_OBJS += editor.o
874874
LIB_OBJS += entry.o
875875
LIB_OBJS += environment.o
@@ -888,7 +888,6 @@ LIB_OBJS += gpg-interface.o
888888
LIB_OBJS += graph.o
889889
LIB_OBJS += grep.o
890890
LIB_OBJS += hashmap.o
891-
LIB_OBJS += linear-assignment.o
892891
LIB_OBJS += help.o
893892
LIB_OBJS += hex.o
894893
LIB_OBJS += ident.o
@@ -898,9 +897,10 @@ LIB_OBJS += kwset.o
898897
LIB_OBJS += levenshtein.o
899898
LIB_OBJS += line-log.o
900899
LIB_OBJS += line-range.o
901-
LIB_OBJS += list-objects.o
902-
LIB_OBJS += list-objects-filter.o
900+
LIB_OBJS += linear-assignment.o
903901
LIB_OBJS += list-objects-filter-options.o
902+
LIB_OBJS += list-objects-filter.o
903+
LIB_OBJS += list-objects.o
904904
LIB_OBJS += ll-merge.o
905905
LIB_OBJS += lockfile.o
906906
LIB_OBJS += log-tree.o
@@ -909,32 +909,32 @@ LIB_OBJS += mailinfo.o
909909
LIB_OBJS += mailmap.o
910910
LIB_OBJS += match-trees.o
911911
LIB_OBJS += mem-pool.o
912-
LIB_OBJS += merge.o
913912
LIB_OBJS += merge-blobs.o
914913
LIB_OBJS += merge-recursive.o
914+
LIB_OBJS += merge.o
915915
LIB_OBJS += mergesort.o
916916
LIB_OBJS += midx.o
917917
LIB_OBJS += name-hash.o
918918
LIB_OBJS += negotiator/default.o
919919
LIB_OBJS += negotiator/skipping.o
920-
LIB_OBJS += notes.o
921920
LIB_OBJS += notes-cache.o
922921
LIB_OBJS += notes-merge.o
923922
LIB_OBJS += notes-utils.o
923+
LIB_OBJS += notes.o
924924
LIB_OBJS += object.o
925+
LIB_OBJS += oid-array.o
925926
LIB_OBJS += oidmap.o
926927
LIB_OBJS += oidset.o
927-
LIB_OBJS += oid-array.o
928-
LIB_OBJS += packfile.o
929-
LIB_OBJS += pack-bitmap.o
930928
LIB_OBJS += pack-bitmap-write.o
929+
LIB_OBJS += pack-bitmap.o
931930
LIB_OBJS += pack-check.o
932931
LIB_OBJS += pack-objects.o
933932
LIB_OBJS += pack-revindex.o
934933
LIB_OBJS += pack-write.o
934+
LIB_OBJS += packfile.o
935935
LIB_OBJS += pager.o
936-
LIB_OBJS += parse-options.o
937936
LIB_OBJS += parse-options-cb.o
937+
LIB_OBJS += parse-options.o
938938
LIB_OBJS += patch-delta.o
939939
LIB_OBJS += patch-ids.o
940940
LIB_OBJS += path.o
@@ -952,21 +952,22 @@ LIB_OBJS += quote.o
952952
LIB_OBJS += range-diff.o
953953
LIB_OBJS += reachable.o
954954
LIB_OBJS += read-cache.o
955-
LIB_OBJS += rebase.o
956955
LIB_OBJS += rebase-interactive.o
956+
LIB_OBJS += rebase.o
957+
LIB_OBJS += ref-filter.o
957958
LIB_OBJS += reflog-walk.o
958959
LIB_OBJS += refs.o
959960
LIB_OBJS += refs/files-backend.o
960961
LIB_OBJS += refs/iterator.o
961962
LIB_OBJS += refs/packed-backend.o
962963
LIB_OBJS += refs/ref-cache.o
963964
LIB_OBJS += refspec.o
964-
LIB_OBJS += ref-filter.o
965965
LIB_OBJS += remote.o
966966
LIB_OBJS += replace-object.o
967967
LIB_OBJS += repo-settings.o
968968
LIB_OBJS += repository.o
969969
LIB_OBJS += rerere.o
970+
LIB_OBJS += reset.o
970971
LIB_OBJS += resolve-undo.o
971972
LIB_OBJS += revision.o
972973
LIB_OBJS += run-command.o
@@ -975,8 +976,8 @@ LIB_OBJS += sequencer.o
975976
LIB_OBJS += serve.o
976977
LIB_OBJS += server-info.o
977978
LIB_OBJS += setup.o
978-
LIB_OBJS += sha1-lookup.o
979979
LIB_OBJS += sha1-file.o
980+
LIB_OBJS += sha1-lookup.o
980981
LIB_OBJS += sha1-name.o
981982
LIB_OBJS += shallow.o
982983
LIB_OBJS += sideband.o
@@ -986,9 +987,9 @@ LIB_OBJS += stable-qsort.o
986987
LIB_OBJS += strbuf.o
987988
LIB_OBJS += streaming.o
988989
LIB_OBJS += string-list.o
989-
LIB_OBJS += submodule.o
990-
LIB_OBJS += submodule-config.o
991990
LIB_OBJS += sub-process.o
991+
LIB_OBJS += submodule-config.o
992+
LIB_OBJS += submodule.o
992993
LIB_OBJS += symlinks.o
993994
LIB_OBJS += tag.o
994995
LIB_OBJS += tempfile.o
@@ -1007,11 +1008,11 @@ LIB_OBJS += trace2/tr2_tgt_normal.o
10071008
LIB_OBJS += trace2/tr2_tgt_perf.o
10081009
LIB_OBJS += trace2/tr2_tls.o
10091010
LIB_OBJS += trailer.o
1010-
LIB_OBJS += transport.o
10111011
LIB_OBJS += transport-helper.o
1012+
LIB_OBJS += transport.o
10121013
LIB_OBJS += tree-diff.o
1013-
LIB_OBJS += tree.o
10141014
LIB_OBJS += tree-walk.o
1015+
LIB_OBJS += tree.o
10151016
LIB_OBJS += unpack-trees.o
10161017
LIB_OBJS += upload-pack.o
10171018
LIB_OBJS += url.o
@@ -1051,9 +1052,9 @@ BUILTIN_OBJS += builtin/checkout.o
10511052
BUILTIN_OBJS += builtin/clean.o
10521053
BUILTIN_OBJS += builtin/clone.o
10531054
BUILTIN_OBJS += builtin/column.o
1055+
BUILTIN_OBJS += builtin/commit-graph.o
10541056
BUILTIN_OBJS += builtin/commit-tree.o
10551057
BUILTIN_OBJS += builtin/commit.o
1056-
BUILTIN_OBJS += builtin/commit-graph.o
10571058
BUILTIN_OBJS += builtin/config.o
10581059
BUILTIN_OBJS += builtin/count-objects.o
10591060
BUILTIN_OBJS += builtin/credential.o
@@ -1084,13 +1085,13 @@ BUILTIN_OBJS += builtin/ls-remote.o
10841085
BUILTIN_OBJS += builtin/ls-tree.o
10851086
BUILTIN_OBJS += builtin/mailinfo.o
10861087
BUILTIN_OBJS += builtin/mailsplit.o
1087-
BUILTIN_OBJS += builtin/merge.o
10881088
BUILTIN_OBJS += builtin/merge-base.o
10891089
BUILTIN_OBJS += builtin/merge-file.o
10901090
BUILTIN_OBJS += builtin/merge-index.o
10911091
BUILTIN_OBJS += builtin/merge-ours.o
10921092
BUILTIN_OBJS += builtin/merge-recursive.o
10931093
BUILTIN_OBJS += builtin/merge-tree.o
1094+
BUILTIN_OBJS += builtin/merge.o
10941095
BUILTIN_OBJS += builtin/mktag.o
10951096
BUILTIN_OBJS += builtin/mktree.o
10961097
BUILTIN_OBJS += builtin/multi-pack-index.o
@@ -1110,9 +1111,9 @@ BUILTIN_OBJS += builtin/read-tree.o
11101111
BUILTIN_OBJS += builtin/rebase.o
11111112
BUILTIN_OBJS += builtin/receive-pack.o
11121113
BUILTIN_OBJS += builtin/reflog.o
1113-
BUILTIN_OBJS += builtin/remote.o
11141114
BUILTIN_OBJS += builtin/remote-ext.o
11151115
BUILTIN_OBJS += builtin/remote-fd.o
1116+
BUILTIN_OBJS += builtin/remote.o
11161117
BUILTIN_OBJS += builtin/repack.o
11171118
BUILTIN_OBJS += builtin/replace.o
11181119
BUILTIN_OBJS += builtin/rerere.o
@@ -2331,16 +2332,16 @@ reconfigure config.mak.autogen: config.status
23312332
endif
23322333

23332334
XDIFF_OBJS += xdiff/xdiffi.o
2334-
XDIFF_OBJS += xdiff/xprepare.o
2335-
XDIFF_OBJS += xdiff/xutils.o
23362335
XDIFF_OBJS += xdiff/xemit.o
2336+
XDIFF_OBJS += xdiff/xhistogram.o
23372337
XDIFF_OBJS += xdiff/xmerge.o
23382338
XDIFF_OBJS += xdiff/xpatience.o
2339-
XDIFF_OBJS += xdiff/xhistogram.o
2339+
XDIFF_OBJS += xdiff/xprepare.o
2340+
XDIFF_OBJS += xdiff/xutils.o
23402341

2342+
VCSSVN_OBJS += vcs-svn/fast_export.o
23412343
VCSSVN_OBJS += vcs-svn/line_buffer.o
23422344
VCSSVN_OBJS += vcs-svn/sliding_window.o
2343-
VCSSVN_OBJS += vcs-svn/fast_export.o
23442345
VCSSVN_OBJS += vcs-svn/svndiff.o
23452346
VCSSVN_OBJS += vcs-svn/svndump.o
23462347

@@ -3148,9 +3149,10 @@ endif
31483149
#
31493150
ALL_COMMANDS = $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS)
31503151
ALL_COMMANDS += git
3152+
ALL_COMMANDS += git-citool
3153+
ALL_COMMANDS += git-gui
31513154
ALL_COMMANDS += gitk
31523155
ALL_COMMANDS += gitweb
3153-
ALL_COMMANDS += git-gui git-citool
31543156

31553157
.PHONY: check-docs
31563158
check-docs::

branch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ void remove_merge_branch_state(struct repository *r)
344344
unlink(git_path_merge_rr(r));
345345
unlink(git_path_merge_msg(r));
346346
unlink(git_path_merge_mode(r));
347+
save_autostash(git_path_merge_autostash(r));
347348
}
348349

349350
void remove_branch_state(struct repository *r, int verbose)

0 commit comments

Comments
 (0)