File: Git_checkout_fails_using_--recurse-submodules.mdwn

package info (click to toggle)
git-annex 10.20250416-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 73,572 kB
  • sloc: haskell: 90,656; javascript: 9,103; sh: 1,469; makefile: 211; perl: 137; ansic: 44
file content (83 lines) | stat: -rw-r--r-- 2,858 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
### Please describe the problem.

Consider a parent repository with a single submodule and two branches in the parent repository. When checking out a branch in the parent using --recurse-submodules, git returns the error:

```
fatal: could not open 'sub/.git' for writing: Is a directory
```

This issue was originally mentioned in [this post](https://git-annex.branchable.com/submodules/) where there is a statement that "The conversion of .git file to .git symlink mostly won't bother git." It is precisely this change that git has a problem with when changing to a new branch. The original poster said there was a solution to use "git checkout mybranch && git submodule update", but this does not work with git version 2.40.0 and git-annex version 10.20230407. In this case, rather than giving a fatal error, git is unable to remove the submodule directory and leaves it untouched. However, this then leaves the new branch in a dirty state (because the submodule is an untracked or modified file). 

The end goal for using `--recurse-submodules` is so that either
  1) a submodule will exist only in a single branch and/or
  2) different branches in the parent will automatically point to different branches in the submodule

### What steps will reproduce the problem?
Here is a sequence of steps to reproduce the issue.

```bash
# create git repo to use as a submodule
SUB_DIR=/tmp/submodule-source
if [ -d $SUB_DIR ]; then
    sudo rm -rf $SUB_DIR
fi
mkdir -p $SUB_DIR
cd $SUB_DIR
git init
git annex init
# add file to main
touch sub_file1.txt
git annex add .
git commit -m "Add sub_file1.txt"

# setup parent dataset
PRNT_DIR=/tmp/submodule-annex
if [ -d $PRNT_DIR ]; then
    sudo rm -rf $PRNT_DIR
fi
mkdir -p $PRNT_DIR
cd $PRNT_DIR
git init
git annex init
# add file to main
touch file1.txt
git annex add .
git commit -m "Create file1.txt"

# Add branch 1 to parent dataset
cd $PRNT_DIR
git checkout -b branch_1 main
# add submodule 1 to branch 1 of parent dataset
git -c protocol.file.allow=always submodule add $SUB_DIR/.git sub
git commit -m "Add submodule 1"

# add new file to submodule annex
cd sub
touch sub_file2.txt
git annex add .
git commit -m "Create sub_file2.txt"

# register changes in the parent
cd ..
git add .
git commit -m "Register sub changes"

# return to main branch, this fails
git checkout main --recurse-submodules
# return to main branch, this fails
# git checkout main && git submodule update
```

### What version of git-annex are you using? On what operating system?

git version 2.40.0

git-annex version: 10.20230407

operating system: darwin aarch64



### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
Yes! Been familiarizing myself with it on and off over the last year and am very excited about it's possibilities.