summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/git-fast-import.txt21
-rw-r--r--fast-import.c10
-rwxr-xr-xt/t9300-fast-import.sh60
3 files changed, 77 insertions, 14 deletions
diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt
index 939ec4652b..445f6b8544 100644
--- a/Documentation/git-fast-import.txt
+++ b/Documentation/git-fast-import.txt
@@ -349,17 +349,16 @@ their syntax.
`from`
^^^^^^
-Only valid for the first commit made on this branch by this
-fast-import process. The `from` command is used to specify the commit
-to initialize this branch from. This revision will be the first
-ancestor of the new commit.
-
-Omitting the `from` command in the first commit of a new branch will
-cause fast-import to create that commit with no ancestor. This tends to be
-desired only for the initial commit of a project. Omitting the
-`from` command on existing branches is required, as the current
-commit on that branch is automatically assumed to be the first
-ancestor of the new commit.
+The `from` command is used to specify the commit to initialize
+this branch from. This revision will be the first ancestor of the
+new commit.
+
+Omitting the `from` command in the first commit of a new branch
+will cause fast-import to create that commit with no ancestor. This
+tends to be desired only for the initial commit of a project.
+Omitting the `from` command on existing branches is usually desired,
+as the current commit on that branch is automatically assumed to
+be the first ancestor of the new commit.
As `LF` is not valid in a Git refname or SHA-1 expression, no
quoting or escaping syntax is supported within `<committish>`.
diff --git a/fast-import.c b/fast-import.c
index f9cfc72637..fd3b117574 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1667,8 +1667,10 @@ static void cmd_from(struct branch *b)
if (strncmp("from ", command_buf.buf, 5))
return;
- if (b->last_commit)
- die("Can't reinitailize branch %s", b->name);
+ if (b->branch_tree.tree) {
+ release_tree_content_recursive(b->branch_tree.tree);
+ b->branch_tree.tree = NULL;
+ }
from = strchr(command_buf.buf, ' ') + 1;
s = lookup_branch(from);
@@ -1936,7 +1938,9 @@ static void cmd_reset_branch(void)
sp = strchr(command_buf.buf, ' ') + 1;
b = lookup_branch(sp);
if (b) {
- b->last_commit = 0;
+ hashclr(b->sha1);
+ hashclr(b->branch_tree.versions[0].sha1);
+ hashclr(b->branch_tree.versions[1].sha1);
if (b->branch_tree.tree) {
release_tree_content_recursive(b->branch_tree.tree);
b->branch_tree.tree = NULL;
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 8d28211294..970d683650 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -433,4 +433,64 @@ test_expect_success \
'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
diff -u expect actual'
+###
+### series J
+###
+
+cat >input <<INPUT_END
+commit refs/heads/J
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+create J
+COMMIT
+
+from refs/heads/branch
+
+reset refs/heads/J
+
+commit refs/heads/J
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+initialize J
+COMMIT
+
+INPUT_END
+test_expect_success \
+ 'J: reset existing branch creates empty commit' \
+ 'git-fast-import <input'
+test_expect_success \
+ 'J: branch has 1 commit, empty tree' \
+ 'test 1 = `git-rev-list J | wc -l` &&
+ test 0 = `git ls-tree J | wc -l`'
+
+###
+### series K
+###
+
+cat >input <<INPUT_END
+commit refs/heads/K
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+create K
+COMMIT
+
+from refs/heads/branch
+
+commit refs/heads/K
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+redo K
+COMMIT
+
+from refs/heads/branch^1
+
+INPUT_END
+test_expect_success \
+ 'K: reinit branch with from' \
+ 'git-fast-import <input'
+test_expect_success \
+ 'K: verify K^1 = branch^1' \
+ 'test `git-rev-parse --verify branch^1` \
+ = `git-rev-parse --verify K^1`'
+
test_done