Skip to content

Prepare for v2.20.0-rc0 #1932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 182 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
a46fab4
Merge branch 'require-windows-vista-or-later'
dscho Oct 11, 2018
aaaa1c1
mingw: fix getcwd when the parent directory cannot be queried
skvoboo Jan 15, 2016
0552f2b
mingw: factor out code to set stat() data
dscho Oct 19, 2018
8e80e95
mingw: replace MSVCRT's fstat() with a Win32-based implementation
kblees Sep 25, 2015
a379b71
mingw: implement nanosecond-precision file times
kblees Sep 26, 2015
c25c014
t7800: fix quoting
dscho Oct 23, 2016
2734865
mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8)
dscho Mar 13, 2018
31757e0
Merge branch 'dscho/mingw-utf-8-env'
dscho Oct 28, 2018
ec43f03
Merge branch 'mingw-isatty-and-dup2'
dscho Oct 12, 2018
43bcef1
Merge branch 'dscho/mingw-utf-8-env'
dscho Oct 28, 2018
706b555
Merge branch 'mingw-getcwd'
dscho Oct 19, 2018
6e35431
Merge pull request #443 from kblees/kb/nanosecond-file-times-v2.5.3
dscho Jun 8, 2018
10b344e
Merge branch 'mingw-getcwd'
dscho Oct 30, 2018
bc2cc6e
Allow for platform-specific core.* config settings
dscho Nov 17, 2016
fb0a8fb
Move Windows-specific config settings into compat/mingw.c
dscho Nov 17, 2016
a8e7ad6
mingw: unset PERL5LIB by default
dscho Nov 17, 2016
922e2a8
Merge branch 'perl5lib'
dscho Oct 11, 2018
4f781a9
Merge pull request #443 from kblees/kb/nanosecond-file-times-v2.5.3
dscho Jun 8, 2018
cf0d426
Merge branch 'perl5lib'
dscho Oct 11, 2018
c4a4fde
mingw (t5580): document bug when cloning from backslashed UNC paths
dscho Jun 19, 2017
e1558b6
mingw: special-case arguments to `sh`
dscho Jun 19, 2017
096c2f5
Mark .bat files as requiring CR/LF endings
dscho Nov 28, 2017
b6bd8b7
t0001 (mingw): do not expect specific order of stdout/stderr
dscho Oct 25, 2018
954e70d
cache-tree.c: avoid reusing the DEBUG constant
jeffhostetler Jun 3, 2016
9deb2e4
obstack: fix compiler warning
dscho Oct 27, 2016
a0be2c0
mingw: replace mingw_startup() hack
dscho Oct 30, 2018
e952c86
msvc: fix dependencies of compat/msvc.c
dscho Oct 20, 2016
4b94d4c
msvc: include sigset_t definition
Apr 21, 2016
db5aa8b
msvc: define O_ACCMODE
Apr 21, 2016
e5ebc9a
msvc: mark a variable as non-const
jeffhostetler Jun 3, 2016
e1c3d6e
msvc: do not re-declare the timespec struct
jeffhostetler Jun 3, 2016
9fee354
msvc: define ftello()
jeffhostetler Jun 3, 2016
ec55677
msvc: fix detect_msys_tty()
jeffhostetler Jan 10, 2017
813abad
msvc: add pragmas for common warnings
May 4, 2016
b2d6eb9
msvc: do not pretend to support all signals
jeffhostetler Jun 3, 2016
5d3ca0a
msvc: support building Git using MS Visual C++
jeffhostetler Jun 3, 2016
f8b3c1e
Vcproj.pm: auto-generate GUIDs
dscho Feb 16, 2018
9fce715
Vcproj.pm: list git.exe first to be startup project
Jul 19, 2015
ea88620
Vcproj.pm: do not configure VCWebServiceProxyGeneratorTool
dscho Oct 25, 2016
7aba9f8
Vcproj.pm: urlencode '<' and '>' when generating VC projects
dscho Oct 25, 2016
a7b5734
msvc: avoid debug assertion windows in Debug Mode
dscho Nov 30, 2016
931aec1
contrib/buildsystems: ignore invalidcontinue.obj
Jul 20, 2015
d38254a
msvc: ignore .dll and incremental compile output
dscho Nov 8, 2016
481b2bf
contrib/buildsystems: ignore irrelevant files in Generators/
dscho Oct 26, 2016
a5a5ec2
contrib/buildsystems: fix misleading error message
Jul 19, 2015
5d6bf02
contrib/buildsystems: handle quoted spaces in filenames
Jul 19, 2015
9a73519
contrib/buildsystems: ignore gettext stuff
Feb 9, 2015
e54d197
contrib/buildsystems: redirect errors of the dry run into a log file
Jul 19, 2015
b836446
contrib/buildsystems: optionally capture the dry-run in a file
Jul 16, 2015
9b8f810
contrib/buildsystems: handle the curl library option
May 4, 2016
7d1f883
contrib/buildsystems: handle libiconv, too
dscho Oct 27, 2016
b982a9c
contrib/buildsystems: handle options starting with a slash
dscho Oct 27, 2016
b62de3e
contrib/buildsystems: error out on unknown option
dscho Dec 4, 2017
bffa7c2
contrib/buildsystems: add a backend for modern Visual Studio versions
dscho Oct 26, 2016
f81e6b9
msvc: add a Makefile target to pre-generate the VS solution
dscho Nov 28, 2016
eb1be42
vcxproj: also link-or-copy builtins
dscho Dec 19, 2017
4881919
.gitignore: touch up the entries regarding Visual Studio
Jul 19, 2015
36afc29
WIP .gitignore: ignore library directories created by MSVC VS2008 bui…
Feb 23, 2015
302b956
.gitignore: ignore Visual Studio's temporary/generated files
dscho Oct 25, 2016
ff19271
bin-wrappers: append `.exe` to target paths if necessary
dscho Nov 25, 2016
2b81e2c
t5505,t5516: create .git/branches/ when needed
dscho Nov 30, 2016
2ca5c4e
git: avoid calling aliased builtins via their dashed form
dscho Nov 28, 2016
4bd3c49
Merge branch 'msvc'
jeffhostetler Oct 23, 2018
8eee421
Merge branch 'visual-studio'
jeffhostetler Oct 23, 2018
a7a948c
Win32: make FILETIME conversion functions public
dscho Oct 19, 2018
85e5470
Win32: dirent.c: Move opendir down
kblees Sep 8, 2013
7cc868e
Win32: Make the dirent implementation pluggable
kblees Sep 8, 2013
54f947e
rebase -r: demonstrate bug with conflicting merges
dscho Nov 12, 2018
769f8a8
rebase -r: do not write MERGE_HEAD unless needed
dscho Nov 12, 2018
94e041a
rebase -i: include MERGE_HEAD into files to clean up
dscho Nov 12, 2018
eff1e59
built-in rebase --skip/--abort: clean up stale .git/<name> files
dscho Nov 12, 2018
07a0e6f
status: rebase and merge can be in progress at the same time
dscho Nov 12, 2018
facdaff
mingw: replace an obsolete link with the superseding one
dscho Nov 15, 2018
d92ec3b
Merge branch 'rebase-r-and-merge-head-v1'
dscho Nov 15, 2018
020e7c4
Merge branch 'mingw-update-msdn-link-v1'
dscho Nov 15, 2018
ab992eb
sha1-name.c: add `get_oidf()` which acts like `get_oid()`
ungps May 5, 2018
59db786
strbuf.c: add `strbuf_join_argv()`
ungps Sep 6, 2018
7fb0dbe
fixup! strbuf.c: add `strbuf_join_argv()`
ungps Nov 13, 2018
4fefec0
stash: improve option parsing test coverage
klusark Apr 5, 2018
57b7e4e
t3903: modernize style
dscho Nov 15, 2018
27c57f2
stash: rename test cases to be more descriptive
ungps May 21, 2018
c0a8fe8
stash: add tests for `git stash show` config
ungps Aug 26, 2018
7b16ac0
stash: mention options in `show` synopsis
ungps Oct 7, 2018
42ee88b
fixup! Merge 'ps/stash-in-c'
dscho Nov 15, 2018
2379b6d
stash: convert apply to builtin
klusark Apr 5, 2018
75ad6d7
stash: convert drop and clear to builtin
klusark Apr 5, 2018
684ee99
stash: convert branch to builtin
klusark Apr 5, 2018
9c52972
stash: convert pop to builtin
klusark Apr 5, 2018
6a7758b
stash: convert list to builtin
ungps May 19, 2018
4a36231
stash: convert show to builtin
ungps May 19, 2018
a2fdd34
stash: convert store to builtin
ungps May 20, 2018
f466436
stash: convert create to builtin
ungps Jun 27, 2018
6ce68ab
stash: convert push to builtin
ungps Jul 26, 2018
350bfb7
stash: make push -q quiet
ungps Jul 26, 2018
87ca7a9
stash: convert save to builtin
ungps Jul 30, 2018
4ad0e88
stash: convert `stash--helper.c` into `stash.c`
ungps Jul 31, 2018
43a4888
stash: optimize `get_untracked_files()` and `check_changes()`
ungps Aug 1, 2018
6fd9d0f
stash: replace all `write-tree` child processes with API calls
ungps Aug 2, 2018
94e9043
Add back the original, scripted `git stash`
dscho Aug 24, 2018
b1a3aaf
stash: optionally use the scripted version again
dscho Aug 24, 2018
133f91c
Merge branch 'ps/stash-in-c-v10-pre1'
dscho Nov 15, 2018
4e49779
rebase (autostash): avoid duplicate call to state_dir_path()
dscho Oct 22, 2018
6d7b674
rebase (autostash): store the full OID in <state-dir>/autostash
dscho Oct 22, 2018
9001cce
rebase (autostash): use an explicit OID to apply the stash
dscho Oct 22, 2018
f4edc8c
rebase: fix typoes in error messages
gitster Sep 28, 2018
5a4dc1e
rebase --autostash: demonstrate a problem with dirty submodules
dscho Oct 23, 2018
d63232a
built-in rebase: demonstrate regression with --autostash
dscho Nov 7, 2018
b1811ac
rebase --autostash: fix issue with dirty submodules
dscho Oct 23, 2018
cc0dbd5
built-in rebase --autostash: leave the current branch alone if possible
dscho Nov 7, 2018
7d0ec44
rebase: consolidate clean-up code before leaving reset_head()
dscho Nov 12, 2018
f48aa67
rebase: prepare reset_head() for more flags
dscho Nov 12, 2018
8cfc373
built-in rebase: reinstate `checkout -q` behavior where appropriate
dscho Nov 12, 2018
3c9193e
Merge branch 'jc/rebase-in-c-5-test-typofix'
dscho Nov 15, 2018
3c2bac9
Merge branch 'js/rebase-autostash-fix'
dscho Nov 15, 2018
b468fec
Merge branch 'js/rebase-autostash-detach-fix'
dscho Nov 15, 2018
3a47dac
Merge branch 'js/builtin-rebase-perf-fix'
dscho Nov 15, 2018
bcebe56
fixup! builtin rebase: call `git am` directly
dscho Nov 15, 2018
f9a3ac1
Win32: make the lstat implementation pluggable
kblees Sep 8, 2013
fff578e
add infrastructure for read-only file system level caches
kblees Sep 8, 2013
a48d0a3
Win32: add a cache below mingw's lstat and dirent implementations
kblees Oct 1, 2013
e6eb0f7
fscache: load directories only once
kblees Jun 24, 2014
70f331e
Merge branch 'mingw-CreateHardLink'
dscho Oct 11, 2018
0acc6a1
Merge branch 'drive-prefix'
dscho Jun 8, 2018
66b5c61
Add a test demonstrating a problem with long submodule paths
vangdfang Jan 9, 2014
8004a40
Win32: support long paths
dscho Jul 28, 2015
0634106
Win32: support long paths
kblees Aug 30, 2015
de6c51e
Win32: fix 'lstat("dir/")' with long paths
kblees Jul 4, 2014
9647bab
Makefile: Set htmldir to match the default HTML docs location under MSYS
sschuberth Sep 4, 2013
36fbfaf
Merge branch 'unc-path-w-backslashes'
dscho Oct 30, 2018
2d33635
Help debugging with MSys2 by optionally executing bash with strace
dscho Feb 20, 2015
73e4dab
Build Python stuff with MSys2
dscho Feb 16, 2015
fae3397
mingw: Embed a manifest to trick UAC into Doing The Right Thing
cesarb Mar 9, 2015
e37820a
mingw: enable stack smashing protector
dscho Nov 2, 2015
6c94d94
Avoid illegal filenames when building Documentation on NTFS
dscho Apr 6, 2015
437feb0
gettext: always use UTF-8 on native Windows
kblees Apr 9, 2015
a63ead9
mingw: initialize HOME on startup
kblees Apr 6, 2015
b91c2a1
mingw: explicitly `fflush` stdout
Apr 16, 2015
ec9dafc
mingw: Support `git_terminal_prompt` with more terminals
kblees Mar 19, 2015
3220001
compat/terminal.c: only use the Windows console if bash 'read -r' fails
kblees May 9, 2015
719b23d
winansi: simplify loading the GetCurrentConsoleFontEx() function
dscho Jan 10, 2017
13b2272
MinGW: Use MakeMaker to build the Perl libraries
sschuberth Aug 29, 2013
1531451
Unbreak interactive GPG prompt upon signing
dscho Sep 6, 2016
ca1a830
Tests: optionally skip redirecting stdin/stdout/stderr
dscho Feb 20, 2015
4803a6a
mingw: ensure valid CTYPE
dscho Feb 21, 2017
ca0d0b4
Skip t9020 with MSys2
dscho Feb 23, 2015
56f8c22
mingw: make is_hidden tests in t0001/t5611 more robust
dscho Feb 21, 2017
6962a73
t9116: work around hard-to-debug hangs
dscho Jan 11, 2017
c204f2e
diff: munmap() file contents before running external diff
dscho Oct 5, 2017
740b127
strbuf_readlink: don't call readlink twice if hint is the exact link …
kblees May 11, 2015
37dbe34
strbuf_readlink: support link targets that exceed PATH_MAX
kblees May 11, 2015
8152a32
lockfile.c: use is_dir_sep() instead of hardcoded '/' checks
kblees May 11, 2015
145167a
t9001: work around hard-to-debug hangs
dscho Jan 11, 2017
0e4aced
Win32: don't call GetFileAttributes twice in mingw_lstat()
kblees May 12, 2015
e035159
Merge branch 'maybe-drop'
dscho Oct 12, 2018
7ec90aa
Win32: implement stat() with symlink support
kblees May 15, 2015
fd37175
Win32: remove separate do_lstat() function
kblees May 11, 2015
89302a1
Win32: let mingw_lstat() error early upon problems with reparse points
kblees May 23, 2015
b6b8e71
Win32: teach fscache and dirent about symlinks
kblees Jan 10, 2017
9b17d64
Win32: lstat(): return adequate stat.st_size for symlinks
kblees May 15, 2015
9ab0f68
Win32: factor out retry logic
kblees May 19, 2015
e2e52f1
Win32: change default of 'core.symlinks' to false
kblees May 23, 2015
87d95ad
Win32: add symlink-specific error codes
kblees May 15, 2015
d2a5387
Win32: mingw_unlink: support symlinks to directories
kblees May 23, 2015
4dcfe13
Win32: mingw_rename: support renaming symlinks
kblees May 19, 2015
cd69bab
Win32: mingw_chdir: change to symlink-resolved directory
kblees May 23, 2015
d810715
Win32: implement readlink()
kblees May 23, 2015
3f2d07a
Win32: implement basic symlink() functionality (file symlinks only)
kblees May 23, 2015
ffd1516
Win32: symlink: add support for symlinks to directories
dscho Oct 19, 2018
a180859
mingw: try to create symlinks without elevated permissions
dscho May 30, 2017
bd656cc
Merge branch 'msvc'
jeffhostetler Oct 23, 2018
8cf7cc7
Merge branch 'visual-studio'
jeffhostetler Oct 23, 2018
cb1b350
Merge branch 'fscache'
dscho Nov 15, 2018
586446c
Merge branch 'long-paths'
dscho Nov 15, 2018
ec9dfab
Merge branch 'msys2'
dscho Nov 15, 2018
98970ee
Merge branch 'kblees/kb/symlinks'
dscho Nov 15, 2018
598c370
Merge branch 'vcxproj' into prepare-for-2.20.0-rc0
dscho Nov 15, 2018
a2b43c9
fixup! stash/rebase: default to the non-builtin versions
dscho Nov 16, 2018
1cdbf4d
tests: add t/helper/ to the PATH with --with-dashes
dscho Jul 21, 2017
d482f01
squash! tests: explicitly use `git.exe` on Windows
dscho Oct 18, 2018
49d2a03
t0061: fix with --with-dashes and RUNTIME_PREFIX
dscho Oct 18, 2018
d2884a8
tests: optionally skip bin-wrappers/
dscho Oct 24, 2018
6a07e39
fixup! Add a build definition for Azure DevOps
dscho Nov 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ phases:
displayName: Windows
condition: succeeded()
queue:
name: Hosted VS2017
name: Hosted
timeoutInMinutes: 240
steps:
- powershell: |
Expand Down Expand Up @@ -215,7 +215,7 @@ phases:
. ci/lib.sh

make -j10 DEVELOPER=1 NO_PERL=1 || exit 1
NO_PERL=1 NO_SVN_TESTS=1 GIT_TEST_OPTS=\"--quiet --write-junit-xml\" time make -j15 -k DEVELOPER=1 test || {
NO_PERL=1 NO_SVN_TESTS=1 GIT_TEST_OPTS=\"--no-chain-lint --no-bin-wrappers --quiet --write-junit-xml\" time make -j15 -k DEVELOPER=1 test || {
NO_PERL=1 NO_SVN_TESTS=1 GIT_TEST_OPTS=\"-i -v -x\" make -k -C t failed; exit 1
}

Expand Down
256 changes: 136 additions & 120 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "wt-status.h"
#include "revision.h"
#include "rerere.h"
#include "branch.h"

static char const * const builtin_rebase_usage[] = {
N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
Expand Down Expand Up @@ -54,7 +55,7 @@ static int use_builtin_rebase(void)
cp.git_cmd = 1;
if (capture_command(&cp, &out, 6)) {
strbuf_release(&out);
return 0;
return 1;
}

strbuf_trim(&out);
Expand Down Expand Up @@ -281,8 +282,10 @@ static int apply_autostash(struct rebase_options *opts)
if (!file_exists(path))
return 0;

if (read_one(state_dir_path("autostash", opts), &autostash))
if (read_one(path, &autostash))
return error(_("Could not read '%s'"), path);
/* Ensure that the hash is not mistaken for a number */
strbuf_addstr(&autostash, "^0");
argv_array_pushl(&stash_apply.args,
"stash", "apply", autostash.buf, NULL);
stash_apply.git_cmd = 1;
Expand Down Expand Up @@ -364,9 +367,124 @@ N_("Resolve all conflicts manually, mark them as resolved with\n"
"To abort and get back to the state before \"git rebase\", run "
"\"git rebase --abort\".");

#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"

#define RESET_HEAD_DETACH (1<<0)
#define RESET_HEAD_HARD (1<<1)

static int reset_head(struct object_id *oid, const char *action,
const char *switch_to_branch, int detach_head,
const char *reflog_orig_head, const char *reflog_head);
const char *switch_to_branch, unsigned flags,
const char *reflog_orig_head, const char *reflog_head)
{
unsigned detach_head = flags & RESET_HEAD_DETACH;
unsigned reset_hard = flags & RESET_HEAD_HARD;
struct object_id head_oid;
struct tree_desc desc[2] = { { NULL }, { NULL } };
struct lock_file lock = LOCK_INIT;
struct unpack_trees_options unpack_tree_opts;
struct tree *tree;
const char *reflog_action;
struct strbuf msg = STRBUF_INIT;
size_t prefix_len;
struct object_id *orig = NULL, oid_orig,
*old_orig = NULL, oid_old_orig;
int ret = 0, nr = 0;

if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
BUG("Not a fully qualified branch: '%s'", switch_to_branch);

if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
ret = -1;
goto leave_reset_head;
}

if ((!oid || !reset_hard) && get_oid("HEAD", &head_oid)) {
ret = error(_("could not determine HEAD revision"));
goto leave_reset_head;
}

if (!oid)
oid = &head_oid;

memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
unpack_tree_opts.head_idx = 1;
unpack_tree_opts.src_index = the_repository->index;
unpack_tree_opts.dst_index = the_repository->index;
unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge;
unpack_tree_opts.update = 1;
unpack_tree_opts.merge = 1;
if (!detach_head)
unpack_tree_opts.reset = 1;

if (read_index_unmerged(the_repository->index) < 0) {
ret = error(_("could not read index"));
goto leave_reset_head;
}

if (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {
ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
goto leave_reset_head;
}

if (!fill_tree_descriptor(&desc[nr++], oid)) {
ret = error(_("failed to find tree of %s"), oid_to_hex(oid));
goto leave_reset_head;
}

if (unpack_trees(nr, desc, &unpack_tree_opts)) {
ret = -1;
goto leave_reset_head;
}

tree = parse_tree_indirect(oid);
prime_cache_tree(the_repository->index, tree);

if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0) {
ret = error(_("could not write index"));
goto leave_reset_head;
}

reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
prefix_len = msg.len;

if (!get_oid("ORIG_HEAD", &oid_old_orig))
old_orig = &oid_old_orig;
if (!get_oid("HEAD", &oid_orig)) {
orig = &oid_orig;
if (!reflog_orig_head) {
strbuf_addstr(&msg, "updating ORIG_HEAD");
reflog_orig_head = msg.buf;
}
update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
UPDATE_REFS_MSG_ON_ERR);
} else if (old_orig)

This comment was marked as off-topic.

This comment was marked as off-topic.

delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
if (!reflog_head) {
strbuf_setlen(&msg, prefix_len);
strbuf_addstr(&msg, "updating HEAD");
reflog_head = msg.buf;
}
if (!switch_to_branch)
ret = update_ref(reflog_head, "HEAD", oid, orig,
detach_head ? REF_NO_DEREF : 0,
UPDATE_REFS_MSG_ON_ERR);
else {
ret = create_symref("HEAD", switch_to_branch, msg.buf);
if (!ret)
ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
UPDATE_REFS_MSG_ON_ERR);
}

leave_reset_head:
strbuf_release(&msg);
rollback_lock_file(&lock);
while (nr)
free((void *)desc[--nr].buffer);
return ret;
}


static int move_to_original_branch(struct rebase_options *opts)
{
Expand Down Expand Up @@ -697,112 +815,6 @@ static int run_specific_rebase(struct rebase_options *opts)
return status ? -1 : 0;
}

#define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"

static int reset_head(struct object_id *oid, const char *action,
const char *switch_to_branch, int detach_head,
const char *reflog_orig_head, const char *reflog_head)
{
struct object_id head_oid;
struct tree_desc desc;
struct lock_file lock = LOCK_INIT;
struct unpack_trees_options unpack_tree_opts;
struct tree *tree;
const char *reflog_action;
struct strbuf msg = STRBUF_INIT;
size_t prefix_len;
struct object_id *orig = NULL, oid_orig,
*old_orig = NULL, oid_old_orig;
int ret = 0;

if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
BUG("Not a fully qualified branch: '%s'", switch_to_branch);

if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)
return -1;

if (!oid) {
if (get_oid("HEAD", &head_oid)) {
rollback_lock_file(&lock);
return error(_("could not determine HEAD revision"));
}
oid = &head_oid;
}

memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
unpack_tree_opts.head_idx = 1;
unpack_tree_opts.src_index = the_repository->index;
unpack_tree_opts.dst_index = the_repository->index;
unpack_tree_opts.fn = oneway_merge;
unpack_tree_opts.update = 1;
unpack_tree_opts.merge = 1;
if (!detach_head)
unpack_tree_opts.reset = 1;

if (read_index_unmerged(the_repository->index) < 0) {
rollback_lock_file(&lock);
return error(_("could not read index"));
}

if (!fill_tree_descriptor(&desc, oid)) {
error(_("failed to find tree of %s"), oid_to_hex(oid));
rollback_lock_file(&lock);
free((void *)desc.buffer);
return -1;
}

if (unpack_trees(1, &desc, &unpack_tree_opts)) {
rollback_lock_file(&lock);
free((void *)desc.buffer);
return -1;
}

tree = parse_tree_indirect(oid);
prime_cache_tree(the_repository->index, tree);

if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK) < 0)
ret = error(_("could not write index"));
free((void *)desc.buffer);

if (ret)
return ret;

reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
prefix_len = msg.len;

if (!get_oid("ORIG_HEAD", &oid_old_orig))
old_orig = &oid_old_orig;
if (!get_oid("HEAD", &oid_orig)) {
orig = &oid_orig;
if (!reflog_orig_head) {
strbuf_addstr(&msg, "updating ORIG_HEAD");
reflog_orig_head = msg.buf;
}
update_ref(reflog_orig_head, "ORIG_HEAD", orig, old_orig, 0,
UPDATE_REFS_MSG_ON_ERR);
} else if (old_orig)
delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
if (!reflog_head) {
strbuf_setlen(&msg, prefix_len);
strbuf_addstr(&msg, "updating HEAD");
reflog_head = msg.buf;
}
if (!switch_to_branch)
ret = update_ref(reflog_head, "HEAD", oid, orig, REF_NO_DEREF,
UPDATE_REFS_MSG_ON_ERR);
else {
ret = create_symref("HEAD", switch_to_branch, msg.buf);
if (!ret)
ret = update_ref(reflog_head, "HEAD", oid, NULL, 0,
UPDATE_REFS_MSG_ON_ERR);
}

strbuf_release(&msg);
return ret;
}

static int rebase_config(const char *var, const char *value, void *data)
{
struct rebase_options *opts = data;
Expand Down Expand Up @@ -1177,8 +1189,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
rerere_clear(&merge_rr);
string_list_clear(&merge_rr, 1);

if (reset_head(NULL, "reset", NULL, 0, NULL, NULL) < 0)
if (reset_head(NULL, "reset", NULL, RESET_HEAD_HARD,
NULL, NULL) < 0)
die(_("could not discard worktree changes"));
remove_branch_state();
if (read_basic_state(&options))
exit(1);
goto run_rebase;
Expand All @@ -1193,9 +1207,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (read_basic_state(&options))
exit(1);
if (reset_head(&options.orig_head, "reset",
options.head_name, 0, NULL, NULL) < 0)
options.head_name, RESET_HEAD_HARD,
NULL, NULL) < 0)
die(_("could not move back to %s"),
oid_to_hex(&options.orig_head));
remove_branch_state();
ret = finish_rebase(&options);
goto cleanup;
}
Expand Down Expand Up @@ -1395,15 +1411,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
* git-rebase.txt caveats with "unless you know what you are doing"
*/
if (options.rebase_merges)
die(_("error: cannot combine '--preserve_merges' with "
die(_("error: cannot combine '--preserve-merges' with "
"'--rebase-merges'"));

if (options.rebase_merges) {
if (strategy_options.nr)
die(_("error: cannot combine '--rebase_merges' with "
die(_("error: cannot combine '--rebase-merges' with "
"'--strategy-option'"));
if (options.strategy)
die(_("error: cannot combine '--rebase_merges' with "
die(_("error: cannot combine '--rebase-merges' with "
"'--strategy'"));
}

Expand Down Expand Up @@ -1528,7 +1544,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
update_index_if_able(&the_index, &lock_file);
rollback_lock_file(&lock_file);

if (has_unstaged_changes(0) || has_uncommitted_changes(0)) {
if (has_unstaged_changes(1) || has_uncommitted_changes(1)) {
const char *autostash =
state_dir_path("autostash", &options);
struct child_process stash = CHILD_PROCESS_INIT;
Expand All @@ -1554,10 +1570,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
if (safe_create_leading_directories_const(autostash))
die(_("Could not create directory for '%s'"),
options.state_dir);
write_file(autostash, "%s", buf.buf);
write_file(autostash, "%s", oid_to_hex(&oid));
printf(_("Created autostash: %s\n"), buf.buf);
if (reset_head(&head->object.oid, "reset --hard",
NULL, 0, NULL, NULL) < 0)
NULL, RESET_HEAD_HARD, NULL, NULL) < 0)
die(_("could not reset --hard"));
printf(_("HEAD is now at %s"),
find_unique_abbrev(&head->object.oid,
Expand Down Expand Up @@ -1677,8 +1693,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
"it...\n"));

strbuf_addf(&msg, "rebase: checkout %s", options.onto_name);
if (reset_head(&options.onto->object.oid, "checkout", NULL, 1,
NULL, msg.buf))
if (reset_head(&options.onto->object.oid, "checkout", NULL,
RESET_HEAD_DETACH, NULL, msg.buf))
die(_("Could not detach HEAD"));
strbuf_release(&msg);

Expand Down
Loading