Skip to content
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

Linked worktrees do not show changes #1052

Closed
1 task done
charpun opened this issue Feb 20, 2025 · 7 comments · Fixed by #1054
Closed
1 task done

Linked worktrees do not show changes #1052

charpun opened this issue Feb 20, 2025 · 7 comments · Fixed by #1054
Assignees
Labels
bug Something isn't working

Comments

@charpun
Copy link

charpun commented Feb 20, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

When running git cliff from a linked worktree, instead of outputting changes I instead get:

INFO  git_cliff > Including changes from the current directory: "../../../../<linked worktree directory>"

I suspect the changes in git-cliff/src/lib.rs lines 216–229 are the culprit.

Steps To Reproduce

Create a linked worktree and run git cliff or git-cliff

cd path/to/repo
git worktree add -b <your new branch> ../linked-worktree

cd ../linked-worktree

# Commit a bunch of changes

git cliff

Expected behavior

Should output a list of changes against the main branch.

Screenshots / Logs

No response

Software information

  • Operating system: macOS 15.3
  • Rust version: 1.83.0
  • Project version: 2.8.0

Additional context

No response

@charpun charpun added the bug Something isn't working label Feb 20, 2025
Copy link

welcome bot commented Feb 20, 2025

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

@orhun
Copy link
Owner

orhun commented Feb 20, 2025

Hello 👋🏼 Thanks for reporting.

When running git cliff from a linked worktree,

Interesting use case! I think I have never run into this before.

For convenience we added a directory detection mechanism for monorepos in #969 - I guess that's not compatible when you use worktrees.

One question though, does git-cliff work as expected when you don't switch directories and run it from the root? (i.e. without cd ../linked-worktree)

I guess the possible solution would be to check worktrees via calling worktrees and disable this detection.

@charpun
Copy link
Author

charpun commented Feb 20, 2025

@orhun, it does work when running from the main worktree.

/app
   /main ← main worktree
   /feature ← linked worktree
   /other-feature ← linked worktree

👆🏻 Running inside of any of these linked worktrees does not work, running inside of the main does.

The .git file in the linked worktree directories references the main worktree's .git directory, specifically .git/worktrees/<worktree>.

So I'm thinking something here (and I'll state for posterity that I am not a Rust guy):

pub fn path(&self) -> PathBuf {
	let mut path = self.inner.path().to_path_buf();
	if path.ends_with(".git") {
		path.pop();
	}
	path
}

And here:

// Include only the current directory if not running from the root repository
let mut include_path = args.include_path.clone();
if let Some(mut path_diff) =
	pathdiff::diff_paths(env::current_dir()?, repository.path())
{
	if include_path.is_none() && path_diff != Path::new("") {
		info!(
			"Including changes from the current directory: {:?}",
			path_diff.display()
		);
		path_diff.extend(["**", "*"]);
		include_path =
			Some(vec![Pattern::new(path_diff.to_string_lossy().as_ref())?]);
	}
}

Is treating the worktree like a subdirectory of the main directory and it ends up looking for ../../../../<linked worktree> instead of treating the root directory of the linked worktree as the root directory for git.

@charpun
Copy link
Author

charpun commented Feb 20, 2025

To be clear, this works as expected in v2.7.0

@orhun
Copy link
Owner

orhun commented Feb 21, 2025

Thanks for the info, I took a stab at fixing this in #1054 - it seemed to work fine to me locally. Could you also build from source and test it out if you have the chance?

@charpun
Copy link
Author

charpun commented Feb 21, 2025

Yup, everything appears to be working.

@orhun
Copy link
Owner

orhun commented Feb 21, 2025

Awesome, thanks for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants